Magento Expert Forum - Improve your Magento experience

Results 1 to 5 of 5

How to display price range for configurable product in Magento 2.

  1. #1
    Junior Member emmanguyen's Avatar
    Join Date
    Nov 2016
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to display price range for configurable product in Magento 2.

    As you know, for the configurable product which have different child products’ price, the default Magento only displays the maximum price. Moreover, displaying configurable products in Magento 2 has other drawbacks which make the purchasing process more complicated. Checkout the blog below and you can find all the cons and the solutions for these:
    http://bsscommerce.com/blog/some-tho...-in-magento-2/

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Oct 2016
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    As you know, configurable products, which have a list of options for variable attributes, is a popular kind of product in Magento sites. Up to now, Magento supported store owners to create configurable products in Magento 2 with simpler steps compared to process in Magento 1. However, displaying configurable products in frontend of Magento site is not an easy-to- solve problem because of its complexity. Most of store owners have demand of showing their configurable product in the most eye-catching way so that customers can see through all of its attribute, make comparison and quickly make buying decision.

    Although Magento 2 has simpler setting up process for configurable product, when displaying in frontend, it still has disadvantages that prevent customers from purchasing quickly.

    Disadvantages of display configurable products in Magento 2
    As you can see, in frontend of default Magento 2, we only can see the entire configurable product with its attributes and options following. Customers only can see the product they want after selecting options and add to cart . It's hard for customers to have a overall review of all possible children products and make comparisons.

    configurable product default Magento 2

    Moreover, in default configurable product page, customers have to add children product to cart one by one rather than adding multiple products to cart in one time. For example, if a customer wants to buy 4 shirts with black color and size S, 10 shirts with gray color and size M, 15 shirts with blue color and size M, he has to add product to cart 3 times. It means how many times customers need to add to cart is equivalent to how many children products he wants to buy. Imagine that a product has 2 attributes with 20 children products and customers want to buy all of them, they must add to cart 20 times! It is such an inconvenience that may annoy customers, especially for wholesalers. If customers want to buy in bulk, they may not be patient enough to repeat add-to-cart action and then quit purchasing. So, you lose an potential customer!
    Optomize your OnPage and Get High Rank Google With - this toolkit - Serplify Pro Review

    Igloo Page Builder Create your Landing page and Sales Page for Page Builder - Buy it and Get Special Gift
    Feedback software for Small business- Convertifire Review - Bonus Free

  3. #3
    Junior Member
    Join Date
    Dec 2016
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here's a solution to this problem that takes into account the potential for configurable products having more than one price-changing attribute.
    It's written in the form of function that takes a configurable product id, and returns a string of min to max price.
    Code:
    function getPriceRange($productId) {
    
     $max = '';
     $min = '';
    
     $pricesByAttributeValues = array();
    
     $product = Mage::getModel('catalog/product')->load($productId); 
     $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
     $basePrice = $product->getFinalPrice();
    
     foreach ($attributes as $attribute){
        $prices = $attribute->getPrices();
        foreach ($prices as $price){
            if ($price['is_percent']){ //if the price is specified in percents
                $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
            }
            else { //if the price is absolute value
                $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
            }
        }
     }
    
    
     $simple = $product->getTypeInstance()->getUsedProducts();
    
     foreach ($simple as $sProduct){
        $totalPrice = $basePrice;
    
        foreach ($attributes as $attribute){
    
            $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
            if (isset($pricesByAttributeValues[$value])){
                $totalPrice += $pricesByAttributeValues[$value];
            }
        }
        if(!$max || $totalPrice > $max)
            $max = $totalPrice;
        if(!$min || $totalPrice < $min)
            $min = $totalPrice;
     }
    
     return "$min - $max";
    
    }

  4. #4
    Junior Member
    Join Date
    Dec 2016
    Posts
    78
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by Pallavi_G View Post
    Here's a solution to this problem that takes into account the potential for configurable products having more than one price-changing attribute.
    It's written in the form of function that takes a configurable product id, and returns a string of min to max price.
    Code:
    function getPriceRange($productId) {
    
     $max = '';
     $min = '';
    
     $pricesByAttributeValues = array();
    
     $product = Mage::getModel('catalog/product')->load($productId); 
     $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
     $basePrice = $product->getFinalPrice();
    
     foreach ($attributes as $attribute){
        $prices = $attribute->getPrices();
        foreach ($prices as $price){
            if ($price['is_percent']){ //if the price is specified in percents
                $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
            }
            else { //if the price is absolute value
                $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
            }
        }
     }
    
    
     $simple = $product->getTypeInstance()->getUsedProducts();
    
     foreach ($simple as $sProduct){
        $totalPrice = $basePrice;
    
        foreach ($attributes as $attribute){
    
            $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
            if (isset($pricesByAttributeValues[$value])){
                $totalPrice += $pricesByAttributeValues[$value];
            }
        }
        if(!$max || $totalPrice > $max)
            $max = $totalPrice;
        if(!$min || $totalPrice < $min)
            $min = $totalPrice;
     }
    
     return "$min - $max";
    
    }
    Thanks, man

  5. #5
    Junior Member marknguyen's Avatar
    Join Date
    Nov 2015
    Posts
    555
    Thanks
    6
    Thanked 27 Times in 27 Posts

    Default

    You can try this extension: Configurable Product Wholesale Display for Magento 2.
    The module supports showing price range of configurable products. Beside, it can show all associated products in a grid table view so that wholesale customers can order configurable products with larger number and add all chosen items to cart at ease.



    Hope it helps.
    Attached Images Attached Images  

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •