سؤال

I have a problem with my grouped products. When i make a grouped product which has a tiered price. The price shows perfectly. but if the products which are in the grouped product doesnt have a tier price it shows the highest price instead of the lowest. I have looked through the code and i dont really understand why this is happening.

this is the code in my price.phtml that shows the grouped product price

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

        <?php if ( $_product->getTierPrice()) ?>
        <?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;
                $product_price = array();
                foreach($product_tier_prices as $key=>$value){
                    $value = (object)$value;
                    $tierprices[] = $value->price;
                }
            }
        }  
    }
} ?>

<?php endif; ?>


<?php if(count($tierprices) > 0){ ?>
    <span class="price" id="product-minimal-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
        <span class="price-label"><?php echo $this->__('From: ') ?></span><?php echo $_coreHelper->currency(min($tierprices), true, false) ?>
    </span>
     <?php if ($_taxHelper->displayBothPrices()): ?>
                    <span class="price-excluding-tax">
                        <!--<span class="label"><?php echo $this->helper('tax')->__('Excl. VAT') ?></span>-->
                    </span>
                    <?php endif?>

<?php } else { ?>

    <?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 ($associatedProducts): ?>
        <div class="price-box">
            <p<?php if ($showMinPrice): ?> class="minimal-price"<?php endif ?>>
                <?php if ($showMinPrice): ?>
                    <span class="price-label"><?php echo $this->__('From: ') ?></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>

                <?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): */ ?>
هل كانت مفيدة؟

المحلول

I had a look through some old questions on stack overflow and foudn this solution which seems to work for me. just add this to the begging on the price .phtml

<?php $this->setProduct(
    Mage::getModel("catalog/product")->getCollection()
        ->addAttributeToSelect(Mage::getSingleton("catalog/config")->getProductAttributes())
        ->addAttributeToFilter("entity_id", $this->getProduct()->getId())
        ->setPage(1, 1)
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->load()
        ->getFirstItem()
);?>

And by th elooks of it everything it working fine now. any problems and i wil write it in a comment. for anyone else who is having this trouble

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top