0
votes

we have an issue with Magento where a group product (in search, catalog, etc) is showing it's price as "Starting at: $XX.XX" when all of it's simple products have MAP enabled.

We'd like the price to display something like "add to cart to view price"

I've track this down to two possible places in the code.

First in app/code/core/Mage/Catalog/Block/Product/Abstract.php

public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = '')
{
    $type_id = $product->getTypeId();
    if (Mage::helper('catalog')->canApplyMsrp($product)) {
        $realPriceHtml = $this->_preparePriceRenderer($type_id)
            ->setProduct($product)
            ->setDisplayMinimalPrice($displayMinimalPrice)
            ->setIdSuffix($idSuffix)
            ->toHtml();
        $product->setAddToCartUrl($this->getAddToCartUrl($product));
        $product->setRealPriceHtml($realPriceHtml);
        $type_id = $this->_mapRenderer;
    }

    return $this->_preparePriceRenderer($type_id)
        ->setProduct($product)
        ->setDisplayMinimalPrice($displayMinimalPrice)
        ->setIdSuffix($idSuffix)
        ->toHtml();
}

If I figured out if I comment out the if statement or just set $temp_id to msrp before I return, it will work (but for all products)

So I need to either add some code in the above function to check if all associated products have MAP enabled or change the function canApplyMsrp to check for that.

app/code/core/Mage/Catalog/Helper/Data.php

public function canApplyMsrp($product, $visibility = null, $checkAssociatedItems = true)
{
    if (!$this->isMsrpEnabled()) {
        return false;
    }

    if (is_numeric($product)) {
        $product = Mage::getModel('catalog/product')
            ->setStoreId(Mage::app()->getStore()->getId())
            ->load($product);
    }

    if (!$this->canApplyMsrpToProductType($product)) {
        return false;
    }

    $result = $product->getMsrpEnabled();
    if ($result == Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type_Enabled::MSRP_ENABLE_USE_CONFIG) {
        $result = $this->isMsrpApplyToAll();
    }

    if (!$product->hasMsrpEnabled() && $this->isMsrpApplyToAll()) {
        $result = true;
    }

    if ($result && $visibility !== null) {
        $productVisibility = $product->getMsrpDisplayActualPriceType();
        if ($productVisibility == Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type_Price::TYPE_USE_CONFIG) {
            $productVisibility = $this->getMsrpDisplayActualPriceType();
        }
        $result = ($productVisibility == $visibility);
    }

    if ($product->getTypeInstance(true)->isComposite($product)
        && $checkAssociatedItems
        && (!$result || $visibility !== null)
    ) {
        $resultInOptions = $product->getTypeInstance(true)->isMapEnabledInOptions($product, $visibility);
        if ($resultInOptions !== null) {
            $result = $resultInOptions;
        }
    }

    return $result;
}

Any help would be appreciated.

Thanks.

1

1 Answers

0
votes

Changing the function getPriceHTML to:

public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = '')
{
    $type_id = $product->getTypeId();
    if (Mage::helper('catalog')->canApplyMsrp($product)) {
        $realPriceHtml = $this->_preparePriceRenderer($type_id)
            ->setProduct($product)
            ->setDisplayMinimalPrice($displayMinimalPrice)
            ->setIdSuffix($idSuffix)
            ->toHtml();
        $product->setAddToCartUrl($this->getAddToCartUrl($product));
        $product->setRealPriceHtml($realPriceHtml);
        $type_id = $this->_mapRenderer;
    }
    else if ($type_id == 'grouped')
    {
        $all_map = true;
        $associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
        foreach ($associatedProducts as $simpleProduct)
        {
            if (!Mage::helper('catalog')->canApplyMsrp($simpleProduct)) {
                $all_map = false;
                break;
            }
        }
        if ($all_map)
        {
            $realPriceHtml = $this->_preparePriceRenderer($type_id)
                ->setProduct($product)
                ->setDisplayMinimalPrice($displayMinimalPrice)
                ->setIdSuffix($idSuffix)
                ->toHtml();
            $product->setAddToCartUrl($this->getAddToCartUrl($product));
            $product->setRealPriceHtml($realPriceHtml);
            $type_id = $this->_mapRenderer;
        }
    }

    return $this->_preparePriceRenderer($type_id)
        ->setProduct($product)
        ->setDisplayMinimalPrice($displayMinimalPrice)
        ->setIdSuffix($idSuffix)
        ->toHtml();
}

Seems to have done the trick. Can anyone see any issues with this technique?