Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add multiple items from product listing page


mugitty

Recommended Posts

Posted

I'm stumped and could use some direction...

 

I have been running an osc2.2 pre-MS1 store for some time now which shows multiple quantity boxes and a single "Add to cart" button on the product listing pages, so that several items can be added to a cart in multiple quantities with one click. It also has a feature that if certain conditions exist (such as attributes or special handling), there is an image presented instead of a quantity box for items with those features. This forces the customer to go to the item page if those conditions exist, so they can make their attribute selection or see what the details for special handling are.

 

see an example page HERE

 

The fundamental changes that were done to accomplish this were to add a new file "addtocart.php" in the catalog directory and then to make some changes to catalog/includes/modules/product_listing.php which included adding some form functions which reference the aforementioned file and changing the PRODUCT_LIST_BUY_NOW case like so:

                if (tep_get_products_stock($listing['products_id']) == 9) {
                   $lc_text = ' <b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image_button('button_special_handling.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a></b> ';
               } elseif (tep_get_products_stock($listing['products_id']) == 8) {
                   $lc_text = ' <b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image_button('button_special_handling.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a></b> ';
               } elseif (tep_get_products_stock($listing['products_id']) == 7) {
                   $lc_text = ' <b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image_button('button_special_handling.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a></b> ';
               } elseif (tep_get_products_stock($listing['products_id']) == 6) {
                   $lc_text = ' <b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image_button('button_special_handling.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a></b> ';
               } elseif (tep_has_product_attributes($listing['products_id'])) {
                   $lc_text = ' <b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a></b> ';
               } else {
                   $how_many_buy_now++;
                   //$lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';
                   $lc_text = '<input type="text" name="Qty_ProdId_' . $listing['products_id'] . '" value="0" maxlength="6" size="4">';

I am now trying to set up a store with an MS2 release and use this same feature for the product listing pages. As you can see in the PRODUCT_BUY_NOW segment posted above, I used the tep_get_products_stock function from catalog/includes/functions/general.php to determine whether I would show a select box or an attribute/special handling image, which works fine in both the older store and the new one (since I don't do anything with product quantities for tracking inventory).

 

For the new store though, since I have added an excellent contribution, Product Availability Options by Steve Kemp, which allows me to show specific availability per product, I thought it would make sense to use the products_availability_id field which is added to table PRODUCTS for the switch which determines whether to show a quantity box or an image, thus freeing up the products stock field, should I ever need to use it. I thought if I just copied the tep_get_products_stock function and gave it different names, that it would then call the new function (tep_get_prod_avail):

// Return a product's stock
// TABLES: products
 function tep_get_products_stock($products_id) {
   $products_id = tep_get_prid($products_id);
   $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
   $stock_values = tep_db_fetch_array($stock_query);

   return $stock_values['products_quantity'];
 }

// Return a product's availability ID
// TABLES: products
 function tep_get_prod_avail($products_id) {
   $products_id = tep_get_prid($products_id);
   $avail_query = tep_db_query("select products_availability_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
   $avail_values = tep_db_fetch_array($avail_query);

   return $avail_values['products_availabilty_id'];
 }

But, for some reason that I just can't see, if I try to use the new function

                if (tep_get_prod_avail($listing['products_id']) == 9) {
...etc

the pictures will not show up as they should (I just get all quantity boxes).

(could it have anything to do with which items/fields are tied to $listing? - I can't seem to find where these are defined)

 

Any ideas of what to look at would be much appreciated!

... if you want to REALLY see something that doesn't set up right out of the box without some tweaking,

try being a Foster Parent!

  • 4 weeks later...
Posted

FYI, it looks like the products_availability_id is misspelled at the end of the function, not sure if this is all that is needed, but definitely that one needed fixing.

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...