Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: Displaying in stock options on product listing  (Read 4887 times)

Offline otterslide

  • Newbie
  • *
  • Posts: 17
  • Karma: +3/-0
    • View Profile
Displaying in stock options on product listing
« on: October 20, 2014, 01:13:31 PM »
Hello,

I have some items that have multiple sizes and I need to display the sizes on the main product listing before people click the listing.
I managed to display options out of the $Product object and looping them, however it is getting even the options which have 0 quantity left in stock.
Does anyone know how to check if an Option is in stock for a particular product?.. or how to get the list of in-stock options in a better way?..

Or even what code I can take a look at that is doing this already.. it must be doing it on the product listing page somehow to get the dropdown list.

this is what I came up with:

/template/pages/product/product_listing.tpl

      $options = $product['options'];
      if($options != null) {
         foreach ($options as $option) {
            if($option['option_value'] != null) {
            
               foreach ($option['option_value'] as $option_value) {
               $option_text .=  $option_value['name'];
               $option_text .= "<br/>";
               }
            }
         }
      }

Thanks!

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4359
  • Karma: +298/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: Displaying in stock options on product listing
« Reply #1 on: October 20, 2014, 01:27:36 PM »
Check the model for product
https://github.com/abantecart/abantecart-src/blob/master/public_html/storefront/model/catalog/product.php

getProductOptions method will give you all details for options including the stock.

Look at 'quantity' for each option.
Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

Offline otterslide

  • Newbie
  • *
  • Posts: 17
  • Karma: +3/-0
    • View Profile
Re: Displaying in stock options on product listing
« Reply #2 on: October 20, 2014, 01:36:32 PM »
Thanks, That seems to work, and already filters out 0 quantity,

$this->model_catalog_product->getProductOptions($product['product_id']);

Would be nice if this was cached in the product, I think this will query for each product, correct?


Check the model for product


getProductOptions method will give you all details for options including the stock.

Look at 'quantity' for each option.

Offline otterslide

  • Newbie
  • *
  • Posts: 17
  • Karma: +3/-0
    • View Profile
Re: Displaying in stock options on product listing
« Reply #3 on: October 20, 2014, 01:40:13 PM »
Never mind, It looks like it does cache,

$this->cache->set( 'product.options.'.$product_id, $product_option_data, $language_id );

thanks again.

Offline theriot3

  • Newbie
  • *
  • Posts: 24
  • Karma: +2/-0
    • View Profile
Re: Displaying in stock options on product listing
« Reply #4 on: January 11, 2015, 01:44:35 PM »
My site has somehow lost its handshake with product_list.tpl entirely—can't get to any of my products!

Completely blown.

Any Ideas?

Marc

 

Database Error

Please try again. If you come back to this error screen, report the error to an administrator.