【问题标题】:Apply map for a group product where all simple products have map enabled为所有简单产品都启用了地图的组产品应用地图
【发布时间】:2013-02-27 22:31:28
【问题描述】:

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

我们希望价格显示类似“添加到购物车以查看价格”之类的内容

我在代码中找到了两个可能的地方。

首先在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 来检查。

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;
}

任何帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: magento


    【解决方案1】:

    将函数 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();
    }
    

    似乎成功了。任何人都可以看到这种技术的任何问题吗?

    【讨论】:

    • 我的解决方案似乎不适用于相关产品中的网格或查看购物车时“您可能还需要”
    猜你喜欢
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多