【发布时间】: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