如何将变量传递给 Magento 中的 Data.php?
How to pass variable into the Data.php in Magento?
所以我目前正在研究 \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
非常感谢
你是"working on \app\code\core\Mage\Checkout\Helper\Data.php",这是第一个问题。 永远不要编辑 Magento 核心。
假设您将此移动到您自己的事件观察器以修改数据,您正在加载产品 ID 并将静态变量设置为 463089
,然后不执行任何操作来计算新价格,然后显示产品价格。
从您的代码来看,价格始终保持不变是完全合理的,因为您是手动设置从哪个产品中提取价格。
商品的 数量 没有改变价格可能有多种原因。它可能与您可能进行的其他核心编辑有关。
所以我目前正在研究 \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
非常感谢
你是"working on \app\code\core\Mage\Checkout\Helper\Data.php",这是第一个问题。 永远不要编辑 Magento 核心。
假设您将此移动到您自己的事件观察器以修改数据,您正在加载产品 ID 并将静态变量设置为 463089
,然后不执行任何操作来计算新价格,然后显示产品价格。
从您的代码来看,价格始终保持不变是完全合理的,因为您是手动设置从哪个产品中提取价格。
商品的 数量 没有改变价格可能有多种原因。它可能与您可能进行的其他核心编辑有关。