【问题标题】:Magento get product collection via custom observerMagento 通过自定义观察者获取产品集合
【发布时间】:2023-03-31 12:24:01
【问题描述】:

我在 Magento 1.8.1.0 中有一个自定义观察者,当当前产品有任何追加销售产品时,它会在产品视图页面上调用。我已经验证(使用 Mage::log())观察者正在工作,但是当我尝试以下操作时:

public function updateUpsells(Varien_Event_Observer $oObserver)
{
    $iCurrentCategory = Mage::registry('current_category')->getId();
    $oUpsellCollection = $oObserver->getCollection();
    foreach ($oUpsellCollection->getItems() as $key => $oUpsellProduct) {
        $aCategoriesIds = $oUpsellProduct->getCategoryIds();
        if (!in_array($iCurrentCategory, $aCategoriesIds)) {
            $oUpsellCollection->removeItemByKey($key);
        }
    }
}

echo $oUpsellCollection; 上我没有任何回报?

有人知道如何获得追加销售产品系列吗?这是一个正确的方法吗?

【问题讨论】:

    标签: magento product observers


    【解决方案1】:
    $upsellCollection = $_product->getUpSellProductCollection();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 2014-07-15
      • 2016-05-05
      相关资源
      最近更新 更多