【问题标题】:How to handle multiple-currency and custom quote item price on Magento?如何在 Magento 上处理多币种和自定义报价项目价格?
【发布时间】:2013-04-01 18:24:11
【问题描述】:

我有一家使用两种货币的 magento 商店,我在购物车中的商品具有动态价格。 我成功计算了我的 quote_item 价格,使用观察者和 setCustomPrice 和 setOriginalCustom 价格

 $quote_item->setCustomPrice($price);
 $quote_item->setOriginalCustomPrice($price);

还有我的观察者:

<sales_quote_add_item>

但是我有一个问题,当我更改商店的货币时,小计没有更新。 如何处理多币种和自定义报价项目价格?

【问题讨论】:

  • 我这里也有同样的问题,你找到解决办法了吗?
  • 你好@Guillaume,我有同样的问题。您找到任何解决方案了吗?请在这里分享。

标签: php magento


【解决方案1】:

通过观察者处理

$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
if($currentCurrencyCode!=$baseCurrencyCode)
    $price= Mage::helper('directory')->currencyConvert($baseprice, $baseCurrencyCode, $currentCurrencyCode); 
else
    $price = $baseprice;

$item->setPrice($baseprice);
$item->setRowTotal($item->getQty() * $price);

【讨论】:

    【解决方案2】:

    上周我也遇到了同样的问题。使用 ->setOriginalCustomPrice 方法对于单币种站点来说很好,但是对于货币切换,它的刚性意味着您需要在每次切换货币时更新购物车项目和标价,在我看来这非常低效。

    我想出了一个更优雅的解决方案。创建一个模块并在配置的模型部分中添加它;

    <models>
            <catalog>
                <rewrite>
                    <product>PixieMedia_CustomPrice_Model_Product</product>
                </rewrite>
            </catalog>
    </models>
    

    直观地反击,主要的->getFinalPrice函数在产品模型中,而不是价格模型中。

    现在在 /app/code/local/Namespace/Module/Model/Product.php 中创建新的 Product.php 模型

    class PixieMedia_CustomPrice_Model_Product extends Mage_Catalog_Model_Product {
    
    public function getFinalPrice($qty=null)
    // REWRITTEN FUNCTION TO RETURN THE SPECIAL PRICE AND ENSURE CURRENCY CONVERSION
    {
        $qBreak = false;
        $customPrice = Mage::Helper('pixiemedia_customprice')->getCustomerPrice($this);
    
        if($qty) { 
            $qBreak = $this->getQtyBreakPrice($this->getSku(),$qty,$customPrice[0]); 
            }
    
        if($qBreak) { return $qBreak; } else { return $customPrice[0]; }
    
    }
    
    }
    

    在我从事的特定项目中,客户使用多个价目表进行客户特定定价,其范围会使 Magento 索引定价的速度非常缓慢。因此,我们已将所有数据加载到自定义表中并执行查找以返回客户的正确价格或数量中断。

    很容易将自己的逻辑挂钩并返回您想要的任何价格。这完全支持货币转换,因此无需折腾重新转换价格。

    希望这可以帮助某人。享受:)

    【讨论】:

      【解决方案3】:

      您可能错过了以下电话:

      $quote->collectTotals()->save();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-05-13
        • 2012-07-17
        • 1970-01-01
        • 2015-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多