Jump to content

Recommended Posts

This addon adds a quantity box to the product page. It is only compatible with the latest Community Version that uses Action files for handling the buy now button.

Share this post


Link to post
Share on other sites

Dear Jack. Wonderful and really handy. I wondered if you can tell me how to place a text like "Quantity:" before the quantity box. I think it is a bit confusing without it. Would be very grateful. Regards, Martin

Share this post


Link to post
Share on other sites

In the includes/modules/content/product_info/templates/quantity.php file, find this line

echo  tep_draw_input_field('buyqty', '1', 'size="3" maxlength="3" style="width:60px;margin-right:10px;"')   ;

and add this above it

echo MODULE_CONTENT_PI_QUANTITY_BOX_TEXT;

And in the includes/languages/English/modules/content/product_info/cm_pi_quantity.php file, add this as the last line:

const MODULE_CONTENT_PI_QUANTITY_BOX_TEXT = 'Quantity';

 

Share this post


Link to post
Share on other sites

Hello Jack, this is working great on the website... on a PC. On my android, however neither the qty box nor the buy button work although they show correctly. If I take it off and just use the stock buy now button that works on android. I am on Frozen BS3, the website for testing is https://www.artful-webdesign.com/osc234/  

Thanks for your help

Share this post


Link to post
Share on other sites

It is most likely due to some other item on the page being overlaying the button(s). Please try this (not texted). At the top of the includes/modules/content/product_info/templates/quantity.php file, add the following:

<style>
div.cm-pi-quantity-box {z-index:100;}
</style>

 

Share this post


Link to post
Share on other sites

Perfect ! Thank you ever so much, Jack. Thought I was going crazy. Could this also be adapted to the product listing pages ?

Share this post


Link to post
Share on other sites

Glad it worked. Thanks for letting me know. I'll add it to the next version.

Yes, it can be added to the product listing page but that is only useful if the products don't have attributes or if only one item is being ordered. For example, if you have 10 products showing on the page and you set the quantity for each and then click add to cart, if one of the products has an attribute then the code redirects to that page and all of the selections are lost. It will work fine if attributes don't exist for any of them. Since, I think, most sites use attributes that code change wouldn't be very useful. But maybe adding it as an option in the settings to let the shop owner decide would be a good way to do it.

Share this post


Link to post
Share on other sites

Thanks Jack, was just thinking as many products do not have options. It could behave so that if there are options it goes to the product page where there would be a qty button and for those without options just directly add the qty on the product listing page (or all-products page) and add to cart. Just an idea...

Share this post


Link to post
Share on other sites

That would be the way one would want it to work. But when the add to cart on the product listing page is clicked. it handles all of the selected items as a whole, not one at a time. So if none of them have attributes, then the whole list is passed to the shopping cart. But if one has attributes, the list is dropped and the code redirects to that one product. This is how oscommerce has worked from the beginning.

Share this post


Link to post
Share on other sites

So artfulweb,, did you manage  to incorporate this into the product_listing page? I can't believe this isn't part of the stock shop already.


Ah, the world wide web. What a wonderful place.

Share this post


Link to post
Share on other sites

@freakystreakJust so you know,, if you want to address a specific person, you should include an @ before their user name. That will cause them to be notified of your post. The way you mentioned the user means the only way he will see it is if he happens to look into this thread.

Share this post


Link to post
Share on other sites

Sorry Jack. Can you help in how to achieve this? All i want is quantity box in product listing. Using 2.3.4.1.Edge CE latest edition.


Ah, the world wide web. What a wonderful place.

Share this post


Link to post
Share on other sites

No need to apologize. I was just letting you know in case you were not aware of it. :)

Did you see my previous post about the way this would work. If your products didn't have attributes, then your customers my find this a great feature. But if they do have attributes, it might make them angry, or at least give the impression of a broken site, since it would ignore some of their selections.

I think the correct way to do this would be to add a dropdown for each item that shows the attributes. But that is a big job and unlikely to be done without paying someone to do it.

Share this post


Link to post
Share on other sites

Cheers mate, I can have products without attributes. May I just explain the reason why I need to do this.  I've been tasked with the job of creating a trade or wholesale store. For this I know for a fact that the usually way to display the products is to have a table view of the products that the customer can just scroll down and add quantities and then select buy to add them all to the cart. I thought that by adding a quantity box, I have tried to adapt your code for the product_info quantity box but as yet haven't got it to work, to the product_listing page, I could achieve something similar. Now, I have managed to do this before with an older version of OSCommerce but since the application_top file has now been modulized, the code no longer is compatible. If you could give any advice as I know that you've been very helpful in the past with your addons etc. Many thanks


Ah, the world wide web. What a wonderful place.

Share this post


Link to post
Share on other sites

This addon wouldn't work for what you want to do, at least not without quite a bit of editing. You would be better off converting one of the existing addons to do it. I'm sorry but I don't have time to look at the code to see what changes are needed.

Share this post


Link to post
Share on other sites

No worries Jack. Appreciate you don't have a lot of time. Thanks.


Ah, the world wide web. What a wonderful place.

Share this post


Link to post
Share on other sites
On 7/27/2018 at 1:06 AM, Jack_mcs said:

In the includes/modules/content/product_info/templates/quantity.php file, find this line


echo  tep_draw_input_field('buyqty', '1', 'size="3" maxlength="3" style="width:60px;margin-right:10px;"')   ;

and add this above it


echo MODULE_CONTENT_PI_QUANTITY_BOX_TEXT;

And in the includes/languages/English/modules/content/product_info/cm_pi_quantity.php file, add this as the last line:


const MODULE_CONTENT_PI_QUANTITY_BOX_TEXT = 'Quantity';

 

Hello @Jack_mcs, this pointer of yours reminds of a website which offers a "tick" sign (or character) trailing the add-to-cart button whenever the product on the product info page has already been added in the shopping cart. This saves the customer the extra effort of clicking on the Add-to-Cart button again when returning to the same product info page. So, I tried to add an echo statement behind the button as shown below:

 

  if ($cart->in_cart($product_info['products_id'])) {
            echo MODULE_CONTENT_PI_QUANTITY_TEXT_ALREADY_IN_CART;
  }

 

The above codes do not seem to work. I am not a programmer and am not able to figure out why. Could you please help?

Thank you very much in advance.

 

Share this post


Link to post
Share on other sites

I don't know what "do not seem to work" means so I can only guess at the problem. You need to be sure you have added the definition you are using to the language file.  It will also make a difference where you added the code so maybe you have it in the wrong place.

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks. I  moved the codes to the file cm_pi_quantity.php and declare $cart as a global variable. It works now.

Quote

 

    function execute() {
      global $oscTemplate, $product_info, $languages_id, $cart;
      
      $products_attributes_query = tep_db_query("select count(*) as total from products_options popt, products_attributes patrib where patrib.products_id='" . (int)$_GET['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
      $products_attributes = tep_db_fetch_array($products_attributes_query);
      
      $content_width = (int)MODULE_CONTENT_PI_QUANTITY_CONTENT_WIDTH;

      if ($cart->in_cart($product_info['products_id'])) {
           $incart = "";
      }

      ob_start();
      include('includes/modules/content/' . $this->group . '/templates/quantity.php');
      $template = ob_get_clean();

      $oscTemplate->addContent($template, $this->group);
    }

 

In the template file quantity.php, I added this to the end of the button:

Quote

echo $incart;

 

Edited by kgtee

Share this post


Link to post
Share on other sites

Hello Jack,

Using php 7.2 with FROZEN I turned on error reporting to track down potential errors on the site for future ugrades and fell on this :

PHP Deprecated:  Non-static method osC_Actions_add_product_quantity::execute() should not be called statically in /xxx/xx/xxx/htdocs/includes/classes/actions.php on line 20

The \includes\actions\add_product_quantity.php file is this:

__________________________________________

    class osC_Actions_add_product_quantity {
        function execute() {
            global $PHP_SELF, $messageStack, $cart, $goto, $parameters;

      if (isset($_POST['products_id'])) {       
        $pid = (int)$_POST['products_id'];        
        $attributes = isset($_POST['id']) ? $_POST['id'] : '';
    
        $cart->add_cart($_POST['products_id'], $cart->get_quantity(tep_get_uprid($pid, $attributes)) + $_POST['buyqty'], $attributes);
    
        $messageStack->add_session('product_action', sprintf(PRODUCT_ADDED, tep_get_products_name((int)$_POST['products_id'])), 'success');
      }
      
      tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));      
        }
    }

_______________________________

Any ideas? Thank you in advance.

Barbie
 

Share this post


Link to post
Share on other sites
12 minutes ago, artfulweb said:

function execute() {

Change the above to

public static function execute() {

Please let me know if it still fails.

Share this post


Link to post
Share on other sites

Perfect Jack! No more error.

Thanks so much.

Barbie

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×