Question

I have a problem i cant figure out (mainly because of my lack of experience) When i search for an product which is a grouped product it shows the lowest price which is what i need. However some of these product have tiered prices as well (buy 5 for £3) so i want the tiered price to be displayed on the search and product list pages. I have found the code which displays the lowest price, but i dont know how to check if the product has a tiered price and if so to diplay that price instead of the lowest. I assume you would need an IF statement to check where there is a tiered price on any of the products and if true then display it but i do not know how to code this.

This is the code which is being using to display the lowest price:

<?php else: /* if (!$_product->isGrouped()): */ ?>

    <?php
    $showMinPrice = $this->getDisplayMinimalPrice();
    if ($showMinPrice && $_minimalPriceValue) {
        $_exclTax = $_taxHelper->getPrice($_product, $_minimalPriceValue);
        $_inclTax = $_taxHelper->getPrice($_product, $_minimalPriceValue, true);
        $price = $showMinPrice ? $_minimalPriceValue : 0;
    } else {
        $price = $_convertedFinalPrice;
        $_exclTax = $_taxHelper->getPrice($_product, $price);
        $_inclTax = $_taxHelper->getPrice($_product, $price, true);
    }
    ?>
    <?php if ($price): ?>
        <div class="price-box">
            <p<?php if ($showMinPrice): ?> class="minimal-price"<?php endif ?>>
                <?php if ($showMinPrice): ?>
                    <span class="price-label"><?php echo $this->__('As low as') ?></span>
                <?php endif ?>
                <?php if ($_taxHelper->displayBothPrices()): ?>
                    <span class="price-excluding-tax">
                        <span class="label"><?php echo $this->helper('tax')->__('Excl. VAT') ?></span>
                        <span class="price"
                              id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                            <?php echo $_coreHelper->formatPrice($_exclTax, false) ?>
                        </span>
                    </span>
                 <!--   <span class="price-including-tax">
                        <span class="label"><?php// echo $this->helper('tax')->__('Incl. VAT') ?></span>
                        <span class="price"
                              id="price-including-tax-<?php //echo $_id ?><?php //echo $this->getIdSuffix() ?>">
                            <?php //echo $_coreHelper->formatPrice($_inclTax, false) ?>
                        </span>
                    </span>-->
                <?php else: ?>
                    <?php
                    $_showPrice = $_inclTax;
                    if (!$_taxHelper->displayPriceIncludingTax()) {
                        $_showPrice = $_exclTax;
                    }
                    ?>
                    <span class="price" id="product-minimal-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    <?php echo $_coreHelper->formatPrice($_showPrice, false) ?>
                </span>
                <?php endif; ?>
            </p>
        </div>
    <?php endif; /* if ($this->getDisplayMinimalPrice() && $_minimalPrice): */ ?>
<?php endif; /* if (!$_product->isGrouped()): */ ?>

I assume the If statement would off like this:

if ( $_product->getTierPrice()): ?>

<?php endif; ?>

My main issue is I am not sure what to put inside the statement or where to put it.

If anyone could help that would be great. Also if i have not been to clear or you need more information just let me know.

Thank you

Was it helpful?

Solution

To check the tier price of any product, you can use the following code in the conditions :

<?php
$tierprices = array();
if ($_product->getTypeId() == 'grouped'){
    $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
    foreach ($associatedProducts as $assoc_product) {
    //$assoc_product = Mage::getModel('catalog/product')->load($assoc_product->getId());// use this only if necessary
        if($assoc_product->getTierPrice()){
            $product_tier_prices = $this->getTierPrices($assoc_product);
            if(count($product_tier_prices) > 0){
                $product_tier_prices = (object)$product_tier_prices;
                foreach($product_tier_prices as $key=>$value){
                    $value = (object)$value;
                    $tierprices[] = $value->price;
                }
            }
        }  
    }
} ?>

In this way you will get tier prices of all the associated products of Group product. You need to use the following condition to display "minimum tier" or "as low as":

<?php if(count($tierprices) > 0){ ?>
    <span class="price" id="product-minimal-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
        <?php echo $_coreHelper->currency(min($tierprices), true, false) ?>
    </span>

<?php } else { ?>
all your rest of normal price will come here.
<?php } ?>

Note: The code was not tested.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top