【问题标题】:$_product doesn't contain all needed data (minmal_price)$_product 不包含所有需要的数据 (minmal_price)
【发布时间】:2014-07-03 16:13:35
【问题描述】:

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

$_product = $this->getProduct();

$_product->getMinimalPrice();

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

旧: 我目前正在努力解决一个非常奇怪的错误。我更新到 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,但在另一个网站上却没有?

谢谢

【问题讨论】:

    标签: php magento configurable-product


    【解决方案1】:

    我更深入地研究了 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"); $最小 = $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() ->加载() ->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.
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      猜你喜欢
      • 2011-09-26
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 2010-10-29
      • 2015-02-01
      • 1970-01-01
      相关资源
      最近更新 更多