3

编辑:基本上,我的问题是我需要在类别视图中获取可配置产品的 minimum_price 。以前,这通过使用

$_product = $this->getProduct();

$_product->getMinimalPrice();

但是,它不再起作用了。我注意到,当它仍然有效时,倾销$_product将包含“minimal_price”。现在,情况不再如此。有谁知道可能是什么原因?

OLD:我目前正在与一个非常奇怪的错误作斗争。我更新到 magento 1.9,但并非一切都按预期工作。类别页面变得非常缓慢。所以我再次降级到 1.8,它在我们的测试开发服务器上运行良好,但现在可配置产品的价格不会再显示在类别网站上。即使在干净的 magento 上安装 1.7(使用相同的数据库!)它也不起作用。

我发现,首先,在 Magento 1.9 中更改了 price.phtml 并添加了另外两个调用,这导致加载时间增加:

$_convertedFinalPrice = $_store->roundPrice($_store->convertPrice($_product->getFinalPrice()));
$_specialPriceStoreLabel = $this->getProductAttribute('special_price')->getStoreLabel();

对我来说主要问题是价格不再显示。我注意到以下内容:

当我转储$_product->debug();它不再包含 minimum_price 。getMinimalPrice()这很可能是不再工作的原因。

奇怪的是,就像我在另一个测试开发站点上所说的那样,它仍在工作并且$_product->debug();仍然包含 minimum_price。

有人解释为什么在一个页面上仍然包含 minimum_price,但在不同的站点上却没有?

谢谢

4

2 回答 2

0

我对 Magento 的代码进行了更深入的研究,并追踪了 Magento 是如何加载产品列表中的产品的。查看产品列表时,产品集合由模型 Mage_Catalog_Model_Layer 加载,该模型通过向集合的 SQL 添加连接来将最低价格和其他东西添加到集合中的产品中,但我尚未找到执行相同操作的模型单一产品而不是集合的东西。

Because I don’t want to use a direct SQL query, I checked out the CatalogIndex module, but that module seems not to be working at all because all its indexing tables are empty or even corrupted.

$data_grouped = Mage::getModel("catalogindex/data_grouped"); $minimal = $data_grouped->getMinimalPrice(array($_product->getId()), Mage::app()->getStore());

looked good at first but it gives me the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_product_index_price.value' in 'field list'

The CatalogIndex module is either deprecated or I’m just too stupid to enable it.

However, I have now created a workaround in my price.phtml template, which uses the same method to retrieve the minimal price and tax percents as the product list does: At the beginning of the template I added the following:

$this->setProduct(Mage::getModel("catalog/product")->getCollection() ->addAttributeToSelect(Mage::getSingleton("catalog/config")->getProductAttributes()) ->addAttributeToFilter("entity_id" , $this->getProduct()->getId()) ->setPage(1, 1) ->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() ->load() ->getFirstItem() );

which may not be the perfect solution, but it does the job and it does it a little cleaner than iterating over all child products and finding the minimal price that way.
于 2014-07-04T05:10:01.007 回答
0

记得启用平面目录和平面类别;)

于 2014-07-19T14:12:56.040 回答