<p>You can add custom fields to store the 'other' price for your products (and/or variants), like, as you say, a matrix, or probably even a table would do.  The fields can then be edited by admins in the back end.</p>

<p>In your templates, you'd selectively display whichever price the particular market needs - this would just be basic template logic.</p>

<p>Then, you'll also need a simple custom plugin that listens to <code>onPopulateLineItem</code> and checks which market the customer is in, and modifies the lineItem price accordingly (by retrieving the correct price form the appropriate field).  Once the lineItem prices are modified as appropriate, they'll be used for the payments and stored with the order, factored into totals etc.</p>

<p>There is an example of modifying a lineItem in the docs here:
<a href="https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem" rel="nofollow noreferrer">https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem</a></p>

<p>Unless you have other requirements not mentioned, for someone with Commerce experience, that would be really be quite simple to implement.</p>

<p>(Based on ~ a years work with Commerce and related plugin writing).</p>

CC BY-SA 3.0
2017-08-25T09:28:49.453Z
I created a plugin for this exact same thing: https://github.com/cliveportman/priceswitcher
Clive Portman
CC BY-SA 3.0
2017-02-15T13:30:18.473Z
Thanks Jeremy. I'm guessing then that modifying the lineItem value will also preserve other Commerce logic around things like applying discounts, etc? And what about cart actions (changing quantity)... those will use the updated lineItem value also?
Mike
CC BY-SA 3.0
2017-02-15T21:28:26.430Z
Yes, the cart is made of of the `linteitem` data structures and all cart operations, calculations etc are done on those - they're entirely separate to the actual products (although there's reference back to the product of course, in case you need to get at fields etc.  When the order is finalised, snapshots of all the data at the time are taken as well.  So yes, barring any bugs, if you change the `lineitem` price all should work as you expect with the adjusted price.
Jeremy Daalder
CC BY-SA 3.0
2017-02-15T23:02:55.253Z
One last question Jeremy. See my update on the original post. I'm updating the lineItem value but when the Cart page loads is does not reflect that new price. Thoughts? ​Is there a lineItem or cart update method that needs to be called?​
Mike
CC BY-SA 3.0
2017-02-15T23:07:16.303Z
Actually, this changed along the way with a new event being offered - it's probably best to use https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem

...there is an example there to show you how to do it.  I'll update my answer.
Jeremy Daalder
CC BY-SA 3.0
2017-02-15T23:14:49.053Z
Cool - thanks for all the input - much appreciated. Signing off for the night here but will try tomorrow.
Mike
CC BY-SA 3.0
2017-02-15T23:18:19.890Z
Yep I just did a quick plugin here to check and it's working fine, with totals etc as they should be.  Good night!
Jeremy Daalder
CC BY-SA 3.0
2017-02-15T02:23:03.420Z
2017-02-15T23:08:52.817Z
2017-02-15T23:08:52.817Z
Jeremy Daalder
<p>We are considering using Commerce for a site where the company sets hard coded prices for the various regions and countries they sell in. I know Commerce has multi-currency support but pricing is in a primary currency and then you set conversion rates. However our client just sets prices - there's not a consistent conversion rate. So, for example, a US product would be $700, it would be $950 in Canada and 14000 pesos in Mexico.</p>

<p>Is there a way to achieve this with Commerce in a fashion where the client can update these prices in the admin? It's an important requirement for them and we're considering other platforms but thought someone might have some insight specific to Commerce because we do like Craft for other reasons. Thanks!</p>

<p>--- UPDATE ---</p>

<p>Trying this as per the accepted answer and the lineItem price on the Cart page doesn't seem to reflect what gets set in the plugin. My code...</p>

<pre><code>class NewPricingPlugin extends BasePlugin
{
    function init(){
        craft()-&gt;on('commerce_cart.onBeforeAddToCart', function($event){
​​           $line = $event-&gt;params['lineItem'];

​​ ​          ​NewPricingPlugin::log(​$line['price']​);​ # = $9.00
​
​           // this sets the lineitem price, but when the cart page
           // loads the price hasn't changed.
​           ​$line['price'] = 1000;

​ ​          ​NewPricingPlugin::log(​$line['price']​);​ # = $1000.00
​    ​    });
​    ​}

    // other plugin methods...
}
</code></pre>

<p>​Is there a lineItem or cart update method that needs to be called?​</p>

<plugin-craftcommerce><currency>
Craft Commerce: Hard code different product prices based on currency?
# Craft Commerce: Hard code different product prices based on currency?

(Asked by: username_0 on 2017-01-26)

We are considering using Commerce for a site where the company sets hard coded prices for the various regions and countries they sell in. I know Commerce has multi-currency support but pricing is in a primary currency and then you set conversion rates. However our client just sets prices - there's not a consistent conversion rate. So, for example, a US product would be $700, it would be $950 in Canada and 14000 pesos in Mexico.
Is there a way to achieve this with Commerce in a fashion where the client can update these prices in the admin? It's an important requirement for them and we're considering other platforms but thought someone might have some insight specific to Commerce because we do like Craft for other reasons. Thanks!
--- UPDATE ---
Trying this as per the accepted answer and the lineItem price on the Cart page doesn't seem to reflect what gets set in the plugin. My code...
class NewPricingPlugin extends BasePlugin
{
    function init(){
        craft()->on('commerce_cart.onBeforeAddToCart', function($event){
​​           $line = $event->params['lineItem'];

​​ ​          ​NewPricingPlugin::log(​$line['price']​);​ # = $9.00
​
​           // this sets the lineitem price, but when the cart page
           // loads the price hasn't changed.
​           ​$line['price'] = 1000;

​ ​          ​NewPricingPlugin::log(​$line['price']​);​ # = $1000.00
​    ​    });
​    ​}

    // other plugin methods...
}

​Is there a lineItem or cart update method that needs to be called?​

**Tags:** plugin-craftcommerce, currency


---

## 1 answers

### Answer by username_1 on 2017-02-15. Score: 5 | Accepted answer

You can add custom fields to store the 'other' price for your products (and/or variants), like, as you say, a matrix, or probably even a table would do. The fields can then be edited by admins in the back end.

In your templates, you'd selectively display whichever price the particular market needs - this would just be basic template logic.

Then, you'll also need a simple custom plugin that listens to `onPopulateLineItem` and checks which market the customer is in, and modifies the lineItem price accordingly (by retrieving the correct price form the appropriate field). Once the lineItem prices are modified as appropriate, they'll be used for the payments and stored with the order, factored into totals etc.

There is an example of modifying a lineItem in the docs here:
<https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem>

Unless you have other requirements not mentioned, for someone with Commerce experience, that would be really be quite simple to implement.

(Based on ~ a years work with Commerce and related plugin writing).

> **Comments:**
> **username_0**: Thanks Jeremy. I'm guessing then that modifying the lineItem value will also preserve other Commerce logic around things like applying discounts, etc? And what about cart actions (changing quantity)... those will use the updated lineItem value also?  
> **username_1**: Yes, the cart is made of of the `linteitem` data structures and all cart operations, calculations etc are done on those - they're entirely separate to the actual products (although there's reference back to the product of course, in case you need to get at fields etc.  When the order is finalised, snapshots of all the data at the time are taken as well.  So yes, barring any bugs, if you change the `lineitem` price all should work as you expect with the adjusted price.  
> **username_0**: One last question Jeremy. See my update on the original post. I'm updating the lineItem value but when the Cart page loads is does not reflect that new price. Thoughts? ​Is there a lineItem or cart update method that needs to be called?​  
> **username_1**: Actually, this changed along the way with a new event being offered - it's probably best to use https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem  ...there is an example there to show you how to do it.  I'll update my answer.  
> **username_0**: Cool - thanks for all the input - much appreciated. Signing off for the night here but will try tomorrow.  
> **username_1**: Yep I just did a quick plugin here to check and it's working fine, with totals etc as they should be.  Good night!  
> **username_2**: I created a plugin for this exact same thing: https://github.com/cliveportman/priceswitcher  

---

