我试图在Magento 1.7.0.2的产品视图页面上显示分组产品的价格,就像它显示在类别产品列表中一样("起始于:xx.xx").我以为我可以用
$this->getPriceHtml($_product, true);
Run Code Online (Sandbox Code Playgroud)
这样做是因为它在类别产品列表中的工作方式相同,但是作为我在Magento中尝试做的所有事情,它并不那么容易,因为该方法不会在产品视图页面上返回任何内容.
我更深入地了解了Magento的代码,并发现问题的原因是产品视图页面上没有设置产品的最低价格数据($ _product-> getMinimalPrice()返回null).
因此,我做了一些关于如何加载产品最低价格的研究,这提出了类似的想法
$_product->getPriceModel()->getMinimalPrice($_product);
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为显然该方法已被弃用并在最后一次更新中被删除或
$priceModel = Mage::getResourceModel('catalogindex/price');
$priceModel->setStoreId(Mage::app()->getStore()->getId());
$priceModel->setCustomerGroupId(Mage::getSingleton('customer/session')->getCustomerGroupId());
$minimalPrices = $priceModel->getMinimalPrices(array($_product->getId()));
$minimalPrice = $minimalPrices[0];
$_product->setData('minimal_price', $minimalPrice['value']);
$_product->setData('minimal_tax_class_id', $minimalPrice['tax_class_id']);
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为表'catalogindex_minimal_price'为空.
所以我的问题是,Magento如何在产品列表中加载最低价格?
magento ×1