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?​

1 Answer 1


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).

  • 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
    Feb 15, 2017 at 13:30
  • 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. Feb 15, 2017 at 21:28
  • 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
    Feb 15, 2017 at 23:02
  • Actually, this changed along the way with a new event being offered - it's probably best to use craftcommerce.com/docs/… ...there is an example there to show you how to do it. I'll update my answer. Feb 15, 2017 at 23:07
  • Cool - thanks for all the input - much appreciated. Signing off for the night here but will try tomorrow.
    – Mike
    Feb 15, 2017 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.