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->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
Comment #2
valicInteresting case, will take a look at this
Comment #3
valicOk, 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
Comment #4
valicOk, 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
Comment #6
valicCommitted 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)