简体   繁体   English

如何在Magento上处理多种货币和自定义报价项目价格?

[英]How to handle multiple-currency and custom quote item price on Magento?

I have a magento store with two currency, and my items in cart have a dynamic price. 我有一个有两种货币的洋红色商店,我在购物车中的商品有动态价格。 I succesfully calculate my quote_item price, with an observer and setCustomPrice and setOriginalCustom price 我用观察者和setCustomPrice以及setOriginalCustom价格成功计算了我的quote_item价格

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

And my observer: 我的观察者:

<sales_quote_add_item>

But i have a problem, when i change the currency of my store, the subtotal is not update. 但我有一个问题,当我更改我的商店的货币时,小计不是更新。 How to handle multiple-currency and custom quote item price ? 如何处理多种货币和自定义报价项目的价格?

handle it through observer 通过观察者处理它

< sales_quote_item_set_product> <sales_quote_item_set_product>

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

I've had this very same issue over the last week. 我在上周遇到了同样的问题。 Using the ->setOriginalCustomPrice method is fine for a single currency site, but with currency switching, its rigidness means you need to update the cart items and list price everytime the currency is switched, which is very inefficient in my opinion. 使用 - > setOriginalCustomPrice方法适用于单一货币站点,但是通过货币切换,其刚性意味着您需要在每次切换货币时更新购物车项目和清单价格,这在我看来效率非常低。

I came up with a more elegant solution. 我想出了一个更优雅的解决方案。 Create a module and within the model section of your config add this; 创建一个模块,并在配置的模型部分添加此项;

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

Counter intuitively, the main ->getFinalPrice function is in the product model and not the price model. 直观地说,主要的 - > getFinalPrice函数在产品模型中,而不是价格模型。

Now create your new Product.php model in /app/code/local/Namespace/Module/Model/Product.php 现在在/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]; }

}

}

On the particular project I was working on, the client is using multiple price lists for customer specific pricing, the scope of which would make Magento horrendously slow to index pricing. 在我正在进行的特定项目中,客户使用多个价格表来进行客户特定定价,其范围将使Magento的指数定价变得非常缓慢。 So we've loaded all the data to a custom table and perform a lookup to return the customer's correct price or qty break. 因此,我们已将所有数据加载到自定义表格并执行查找以返回客户的正确价格或数量中断。

It's dead easy to hook your own logic in and return what ever price you wish. 将你自己的逻辑挂钩并返回你想要的价格是很容易的。 This fully supports currency conversion, so no need to fiddle around re-converting prices. 这完全支持货币转换,因此无需扭转重新转换价格。

Hope this helps someone out. 希望这有助于某人。 Enjoy :) 请享用 :)

你可能错过了一个电话:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM