4

我希望能够根据我使用此代码的几个教程将报价项目的价格更改为不同于产品的价格:

$quoteItem->setCustomPrice($price);
$quoteItem->setOriginalCustomPrice($price);
$quoteItem->getProduct()->setIsSuperMode(true);
$quote->save();

之后,当我到达购物车时,它显示的是正常价格,而不是自定义价格。我检查了购物车中的报价项目,它们有正确的 customPrice,但它似乎被忽略了。我是否必须激活其他东西才能使此自定义价格生效?

PS:

Magento v1.7

4

2 回答 2

9

好的,所以我发现了问题,不知何故它没有保存在我的脚本中。不知道为什么,但我已经将我的代码重写为 2 个函数,1 个用于添加产品,另一个用于更改价格。

所以这段代码就是必要的:

$quoteItem->setCustomPrice($price);
$quoteItem->setOriginalCustomPrice($price);
$quoteItem->getProduct()->setIsSuperMode(true);
$quoteItem->save();

无需保存报价,只需报价项目。

于 2013-10-31T12:14:19.230 回答
2

应该很容易解决:如果我没记错的话,您正在尝试保存报价项目的价格,但您却保存了报价。您还需要保存报价项目本身。

$quoteItem->setCustomPrice($price);
$quoteItem->setOriginalCustomPrice($price);
$quoteItem->getProduct()->setIsSuperMode(true);
$quoteItem->save();
$quote->save();
于 2013-10-22T10:00:18.867 回答