为所有简单产品启用了地图的组产品应用地图

时间:2013-02-27 22:31:28

标签: magento

我们遇到Magento的问题,其中一个组产品(搜索,目录等)显示它的价格为“起始于:$ XX.XX”当所有的简单产品都启用了MAP。

我们希望价格显示“添加到购物车以查看价格”

我已将其跟踪到代码中的两个可能位置。

首先在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语句,或者只是在我返回之前将$ temp_id设置为msrp,那么它将起作用(但适用于所有产品)

所以我需要在上面的函数中添加一些代码来检查所有相关产品是否启用了MAP,或者更改函数canApplyMsrp来检查它。

应用程序/代码/核心/法师/目录/助手/ 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;
}

任何帮助都将不胜感激。

感谢。

1 个答案:

答案 0 :(得分:0)

将函数getPriceHTML更改为:

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();
}
似乎已经完成了这个伎俩。任何人都可以看到这种技术有任何问题吗?

相关问题