我找到了一个解决方案,做到这一点。
第一步:
添加项目使用自定义的价格由@Ashish拉吉建议下面的代码来引用
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$price = $customPrice;
$customPrice = $Current_currency_price = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode);
$item->setCustomPrice($customPrice);
$item->setOriginalCustomPrice($customPrice);
$item->getProduct()->setIsSuperMode(true);
第二步:
第二步是建立一个通过在模块的config.xml文件中添加以下代码来控制员发布观察者
<events>
<controller_action_postdispatch>
<observers>
<frontend_currency_change>
<class>modulename/observer</class>
<method>hookToControllerActionPostDispatch</method>
</frontend_currency_change>
</observers>
</controller_action_postdispatch>
</events>
并添加以下代码,以观察者类
public function hookToControllerActionPostDispatch($observer) {
if ($observer->getEvent()->getControllerAction()->getFullActionName() == 'directory_currency_switch') {
$quote = Mage::getSingleton('checkout/session')->getQuote();
if ($quote && $quote->hasItems()) {
foreach ($quote->getAllVisibleItems() as $item):
//add condition for target item
$customPrice = 23;//use custom price logic
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$customPrice = Mage::helper('directory')->currencyConvert($customPrice, $baseCurrencyCode, $currentCurrencyCode);
$item->setCustomPrice($customPrice);
$item->setOriginalCustomPrice($customPrice);
$item->getProduct()->setIsSuperMode(true);
$quote->collectTotals()->save();
endforeach;
}
}
}
这是为我工作。希望这可以帮助有同样问题的人。 如果有人有更好的解决方案,我会更喜欢。 谢谢。
感谢您的回复。但我并不面临当前货币的问题。我已添加自定义价格的购物车中的项目是好的。现在,如果我在购物车页面上切换货币,那么价格价值保持不变,该项目。 –
嗨@gulshan maurya,你发现上述任务的决议?请让我知道 –
我还没有找到任何解决方案,相关任务暂时搁置。我会在这里更新,如果我会得到更好的解决方案。 –