Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Display Available Configurable Product Options on Product Listing page in Magento


Using my this post you can add Product Configurable option which are in stock like size, color etc. on your Product listing page.

You can add some simple code to our website, that will show which options are available, so when your customer is looking at your list pages, where you have multiple products being shown, you can clearly show them which sizes or colors are still in stock.

Configurable Product Options

As you can see in the image above, the available shoe sizes are being shown on each product. So your customer can easily find out the product for what they are looking.

To do this, use following code in  app/design/frontend/default/my-theme/template/catalog/product/
<?php
$sizes = array();
if($_product->isConfigurable()){
    $allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
    foreach ($allProducts as $subproduct) {
        if ($subproduct->isSaleable() && floor($subproduct->getStockItem()->getQty()) > 0 ) {
            $sizes[] = $subproduct->getAttributeText('config_sizes');
        }
    }
    if(count($sizes)>0) {
        sort($sizes);
        ?>
        <div>
        Sizes: <? echo implode(", ", $sizes); ?>
        </div>
        <?
    }
}
?>

Replace 'config_sizes' with your attribute code.

Please support us, Like us on Facebook.

0 comments:

Post a Comment

 

Copyright @ 2017 HKBlog.