【问题标题】:Magento product attribute not showing in checkout, shows in cartMagento 产品属性未显示在结帐中,显示在购物车中
【发布时间】:2016-02-29 20:21:41
【问题描述】:

这里有几个线程解释了如何在购物车或结帐中获取产品属性。但是,我就是无法让它工作。

购物车中我可以看到产品属性,但在结帐中看不到。

根据我的阅读,结帐不知道该产品,所以我需要加载它。这可以解释为什么我没有看到它。

我尝试了很多东西,但我要么没有让我的送货步骤加载到购物车中,要么就是不显示。

任何帮助都会很棒!这是我在自定义运输模块中的代码。

$cart = Mage::getSingleton('checkout/session');

//Order value by category
$gold = 0;

foreach ($cart->getQuote()->getAllItems() as $item) {

    $itemPrice = $item->getPrice();
    $qty = $item->getQty();
    $metalType = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getAttributeText('metal');

    if ($metalType == "Gold") {
        //Apply some business logic
        $gold = $itemPrice * $qty;
    }
}

Magento get cart single item price incl. tax

Magento Product Attribute Get Value

【问题讨论】:

  • 你试过->getMetal()吗?
  • ->getMetal() 破坏了网站。

标签: php magento magento-1.9


【解决方案1】:

Mage_Sales_Model_Resource_Quote_Item_Collection对象的afterLoad中,对每个引用项调用_assignProducts的方法。此方法使用以下代码加载产品集合:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->setStoreId($this->getStoreId())
    ->addIdFilter($this->_productIds)
    ->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes())
    ->addOptionsToResult()
    ->addStoreFilter()
    ->addUrlRewrite()
    ->addTierPriceData();

如果您通过以下方式将产品属性添加到新模块的 config.xml 中,则应将其添加为要在产品集合中选择的属性。

<sales>
    <quote>
        <item>
            <product_attributes>
                  <metal/>
            </product_attributes>
        </item>
    </quote>
</sales>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 2012-09-27
    • 1970-01-01
    相关资源
    最近更新 更多