【问题标题】:Magento 1.9 - How to get final product price on add to cart?Magento 1.9 - 如何在添加到购物车时获得最终产品价格?
【发布时间】:2020-10-18 00:06:08
【问题描述】:

最终更新

显然,我只是需要在此处发布问题的压力。如果其他人遇到同样的问题,这似乎可行,并且涵盖了正在使用的目录价格规则的情况。特别是对于 Magento 1.9 的官方 Facebook Ads Magento 插件,您必须将此代码添加到 app/code/community/Facebook/AdsExtension/Block/AddToCart.php 文件

public function getValue() {
    $latestItem = Mage::getSingleton('checkout/session')
   ->getQuote()
   ->getItemsCollection()
   ->getLastItem()
   ->getProduct();
    return $latestItem->getFinalPrice();
  }

原始问题

我知道它是 EOL,但我又坚持运行 Magento 1.9 几个月。我正在尝试修复 Facebook 的官方 Pixel 模块,因为它在添加到购物车事件中缺少产品价值。返回值的方法完全丢失。我正在努力弄清楚如何在将单个产品添加到购物车时获取其价格,因为它似乎在离开产品页面后触发。

public function getValue() {
    $collection = Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection();
    $collection->getSelect()->order('created_at DESC');
    $latestItem = $collection->getLastItem();
    $product = $latestItem->getProduct();
    return $product->getPrice();
  }

这就是我想出的。我正在拉出添加到购物车的最后一件商品并从中获取价格,但它会返回完整的产品价格,而忽略正在应用的任何目录价格规则。我也觉得我通过所有这些调用来获取价值的过程过于复杂,并提取了整套报价项目,然后对其进行排序并从中提取一个产品。

有人对获取刚刚添加到购物车的商品价格的最佳方法有什么建议吗?似乎有很多关于如何在添加到购物车过程中更新商品价格的问题,但我没有运气找到有人问同样的问题并给出了有效的答案。 TIA

更新:我发现了这个,这似乎是一种更清洁的退货方式,但价格仍然是全零售价,没有反映任何可能打折的目录价格规则。信用:Magento get last product added to cart

  public function getValue() {
    $latestItem = Mage::getSingleton('checkout/session')
   ->getQuote()
   ->getItemsCollection()
   ->getLastItem()
   ->getProduct();
    return $latestItem->getPrice();
  }

【问题讨论】:

    标签: php magento zend-framework magento-1.9


    【解决方案1】:

    已回答并将其添加到原始问题中,但这似乎有效

    public function getValue() {
        $latestItem = Mage::getSingleton('checkout/session')
       ->getQuote()
       ->getItemsCollection()
       ->getLastItem()
       ->getProduct();
        return $latestItem->getFinalPrice();
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-02
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多