3

I have create promotion products in my cart page which display product image, names and price however when i add a configuable product in to the list the price is showing £0.00. This is the code i am using to show the price.

<?php 
$specialPrice = Mage::helper('core')->formatPrice($_product->getFinalPrice());
$normalPrice = Mage::helper('core')->formatPrice($_product->getPrice());
        if ($normalPrice != $specialPrice){?>
    <div class="sale-price">
        <?php echo  'Now';
        echo  $specialPrice;?></div>
        <?php }else{?>
    <div class="norm-price"><br>
        <?php echo $normalPrice;}?</div>

I assume it is showing £0.00 as it is looking for the products price and as it is a grouped product the product itself does not have an actual price as the prices come from the products in the grouped products.

So my question is how can i check if a product is a grouped product and if it is then i need to check for the lowest price and then display that price?

I found some code which checks if a product is a grouped product and if so it grabs in the Associated products so now all i need to do is create a check which checks for the lowest price in the associated products

    <?php if($_product->getTypeId() == "grouped"): 
        $associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);

     endif; ?>

If you need more information or i haven't been clear please just let me know.

Thank you in advance

3
  • What do you get when you use something like var_dump($_product) or mage::log($_product) on these group products, are there prices anywhere? Regardless, you'll find the grouped product information within the product itself if it's configured correctly, just grab it from there. Nov 21, 2014 at 19:14
  • When i var dump on that product it doesnt have a "price" like the other product do all it has which relates to price is ["aw_cp_disable_price"]=> NULL and ["_calculatePrice":protected]=> bool(true) Because the product that is actually being loaded doesnt have a price its the product that are associated with this product that have the prices.
    – Adam Allen
    Nov 24, 2014 at 9:16
  • @hownowbrowncow, I have added new code to the question which i found that loads in the associated products now i just need to load all the prices and display the lowest. But i dont know how to do that?
    – Adam Allen
    Nov 24, 2014 at 9:38

1 Answer 1

2

Assuming your above code is correct in how one gets the sales price from a product this code below will get the associated products, iterate over their sale prices and normal prices and return the lowest value.

function getLowest($product){
$associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
$lowPrice=inf;
foreach($associatedProducts as $associatedProduct){
    $specialPrice = $associatedProduct->getFinalPrice();
    $associatedPrice = $associatedProduct->getPrice();
    if($lowPrice>$associatedPrice){
        $lowPrice=$associatedPrice;
    }
    if($lowPrice>$specialPrice && ($specialPrice!=null||$specialPrice!=0)){
        $lowPrice=$specialPrice;
    }
}
return Mage::helper('core')->formatPrice($lowPrice);
}

Then just use the low price as you would use the price you currently have :)

Hope that helps!

6
  • Thank you for all you help, do you know how i could take all the prices store in $lowprice and check which is the lowest? As at the moment i am displaying only the first products price which sometimes isnt the lowest
    – Adam Allen
    Nov 25, 2014 at 9:26
  • The code above does check which is the lowest. There should only be one value in $lowprice. The above gets all the associated products, iterates through them, and checks to see if it's lowere than $lowprice and, if it is, sets $lowprice to this products price (which would mean it is the new low). Nov 25, 2014 at 13:16
  • I think i know what my problem was, does it check if the product has a special price (on sale)?
    – Adam Allen
    Dec 3, 2014 at 15:35
  • I'm slightly confused as to why you want the special pricing, do you want it to override the lowest price? Do you want to display that as well? Does each associated product have a different sales price, and you want to display all the possible sales prices? Dec 3, 2014 at 16:42
  • Just the lowest price so weather it is a sale price or a normal price. and no most product have the same price but some do not for example we have small, medium and large hats, The Medium and large are on sale but the small costs us more to buy in so they are at the standard price. For this example i would want to show the customer the lwoest possible price they can buy the product for (the sale price)
    – Adam Allen
    Dec 3, 2014 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.