Hi there,
I'm porting https://www.drupal.org/project/commerce_donate to Drupal 8 using some sample code provided by Bojan
https://github.com/bojanz/donation_example

However, when switching currencies I get an error

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\commerce_price\Exception\CurrencyMismatchException</em>:  in <em class="placeholder">Drupal\commerce_price\Price-&gt;assertSameCurrency()</em> (line <em class="placeholder">296</em> of <em class="placeholder">modules/contrib/commerce/modules/price/src/Price.php</em>)

The Product doesn't have a Price field.

Any suggestions on how to overcome this issue?

Other products with 'Dynamic' pricing may have similar issues, but I can't find anything yet

Comments

alanburke created an issue. See original summary.

valic’s picture

Assigned: Unassigned » valic

Interesting case, will take a look at this

valic’s picture

Assigned: valic » Unassigned
StatusFileSize
new1.25 KB

Ok, price resolvers only resolve prices for PurchasableEntity, the donation does not have it.

The fix could be added to CurrencyOrderProcessor, to loop through all order items and search for ones without PurchasableEntity.
And then set a price with a new currency.

But that only solves unit price and seems more like hotfix. Definitely needed to be run before processor triggers recalculateTotalPrice for order.

Attaching patch for this, but doubt that this will be a final solution.

Proper solution needs :
- converting prices before we reach recalculateTotalPrice in CurrencyOrderProcessor
- to be outside of CurrencyOrderProcessor if possible

Question is do order items without PurchasableEntity could have fields per currency, etc. (in non-donation cases).
Probably we should make reusable new logic from price resolver (\Drupal\commerce_currency_resolver\Resolver\CommerceCurrencyResolver)
which support fields, instead of just automatically convert the price

UPDATE for last part
Oh my god, we don't have PurchasableEntity -> therefor not any fields to be attached anywhere

valic’s picture

Status: Active » Needs work

Ok, for now it should stay in OrderProcessor, due to this issue.

What needs to be additional checked it's probably custom adjustment on order item itself

  • valic committed ec8d305 on 8.x-1.x
    Issue #3015540 by valic, alanburke: Handling Products without a price...
valic’s picture

Status: Needs work » Fixed

Committed code from the patch. Order items without PurchasableEntity are now auto-calculated.

So the general case is solved.

Adjustment part is not. This should be up to end logic custom tracked, adding / removal of custom adjustments. (referring to non-donation potential examples)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.