所以我现在正在处理\app\code\core\Mage\Checkout\Helper\Data.php。我正在尝试调用一个变量,但它似乎不起作用。
更新1 我已经能够通过这样的方法传递变量,但是我需要手动声明产品ID,有什么方法可以让该方法根据我添加到购物车的产品获取产品ID吗?
$_productId = Mage::registry('current_product')->getId();
在我的情况下不起作用。
我的测试如下:
public function formatPrice($price)
{
$_productId = 463089; // need to call the current product by the enter the ID manually
$_product = Mage::getModel('catalog/product')->load($_productId);
$oldPrice = $_product->getFinalPrice(); //should be the original product price
return $this->getQuote()->getStore()->formatPrice($oldPrice);
}
刷新页面后的结果:
一切都变成了 670
非常感谢
最佳答案
您正在“处理\app\code\core\Mage\Checkout\Helper\Data.php”,这是第一个问题。 切勿编辑 Magento 核心。
假设您将其移至您自己的事件观察器以修改数据,您将加载产品 ID,并将静态变量设置为 463089
,然后不执行任何操作来计算新价格,然后显示产品价格。
从您的代码来看,价格始终保持不变是完全合理的,因为您手动设置要从中提取价格的产品。
商品的数量没有改变价格可能有多种原因。它可能与您所做的其他核心编辑有关。
关于javascript - 如何将变量传递到 Magento 中的 Data.php 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29382036/