2016-06-15 1 views
1

以下のコードは、単純な製品のカスタム価格を設定するために使用されています。必要に応じてカートにカスタム価格を設定しますが、通貨を切り替えると、カスタム価格の値は現在の通貨記号と同じままです。Magentoのカスタム価格の値が通貨の変更によって変換されない

$item->setCustomPrice($customPrice); 
      $item->setOriginalCustomPrice($customPrice); 
      $item->getProduct()->setIsSuperMode(true); 

通貨の切り替えで動作するカスタムの価格を設定する方法はあります。コードの下

答えて

1

が、私はこれを行うには解決策を見つけました。

ファーストステップ:

第2のステップは、ANを作成することです:

@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); 

第2工程を使用してカスタムの価格を引用する項目を追加します。モジュールの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; 
       } 
      } 
     } 

を次のコードを追加します。これが同じ問題を抱えている人に役立つことを願っています。 誰かがより良い解決策を持っている方が好きです。おかげさまで

0

使用は

//First you need to find base currency code and then find current currency code... 
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode(); 
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode(); 
$price = $customPrice; 


// and then convert price from base currency to current currency 
$customPrice = $Current_currency_price = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode); 

は、あなたがあなたのコードを使用することができます...それはあなたを助けることを願っています:

$item->setCustomPrice($customPrice); 
$item->setOriginalCustomPrice($customPrice); 
$item->getProduct()->setIsSuperMode(true); 
+0

返信ありがとうございます。しかし、私は現在の通貨で問題に直面していません。私はカスタム価格でカートに商品を追加しました。これは問題ありません。今すぐカートのページで通貨を切り替えると、その商品の価格の値は変更されません。 –

+0

こんにちは@ gulshan maurya、あなたは上記のタスクの解決策を見つけましたか?私にここで教えてください –

+0

私はまだ解決策を見つけられませんでしたが、関連するタスクは現在保留中です。もし私がより良い解決策を得るなら、私はここで更新します。 –

関連する問題