Describe your bug or feature request.
When running PriceCalculator::calculate() one may pass the list of order processors that will modify the price to for example get the price before and after the promotion. Order processor services, tagged with targeted adjustment types, will be triggered during price calculation but their order, defined in service definition yml, is not respected.
If a bug, provide steps to reproduce it from a clean install.
Prerequisities:
Installed Commerce Demo
Added new currency - NOK
Added new store with currency in NOK, Store is configured with tax not included in prices.
Added new tax type - Norwegian VAT
Added Simple product with price 100NOK
Added promotion 50 NOK off all products
This is drush output:
No adjustment types passed over to price calculator:
bash-4.4$ drush ev "var_dump(\Drupal::service('commerce_order.price_calculator')->calculate(\Drupal\commerce_product\Entity\ProductVariation::load(50), 1, new \Drupal\commerce\Context(\Drupal::currentUser(), \Drupal::service('commerce_store.current_store')->getStore()), [])->getCalculatedPrice());"
/var/www/html/vendor/drush/drush/src/Commands/core/PhpCommands.php(31) : eval()'d code:1:
class Drupal\commerce_price\Price#2339 (2) {
protected $number =>
string(10) "100.000000"
protected $currencyCode =>
string(3) "NOK"
}'tax' adjustment type passed over to price calculator (default VAT rate is 25%):
bash-4.4$ drush ev "var_dump(\Drupal::service('commerce_order.price_calculator')->calculate(\Drupal\commerce_product\Entity\ProductVariation::load(50), 1, new \Drupal\commerce\Context(\Drupal::currentUser(), \Drupal::service('commerce_store.current_store')->getStore()), ['tax'])->getCalculatedPrice());"
/var/www/html/vendor/drush/drush/src/Commands/core/PhpCommands.php(31) : eval()'d code:1:
class Drupal\commerce_price\Price#4102 (2) {
protected $number =>
string(6) "125.00"
protected $currencyCode =>
string(3) "NOK"
}'promotion' and 'tax' adjustment types passed over to price calculator in order they're normally prioritized:
bash-4.4$ drush ev "var_dump(\Drupal::service('commerce_order.price_calculator')->calculate(\Drupal\commerce_product\Entity\ProductVariation::load(50), 1, new \Drupal\commerce\Context(\Drupal::currentUser(), \Drupal::service('commerce_store.current_store')->getStore()), ['promotion','tax'])->getCalculatedPrice());"
/var/www/html/vendor/drush/drush/src/Commands/core/PhpCommands.php(31) : eval()'d code:1:
class Drupal\commerce_price\Price#4474 (2) {
protected $number =>
string(5) "62.50"
protected $currencyCode =>
string(3) "NOK"
}'promotion' and 'tax' adjustment types passed over to price calculator in reverse order:
bash-4.4$ drush ev "var_dump(\Drupal::service('commerce_order.price_calculator')->calculate(\Drupal\commerce_product\Entity\ProductVariation::load(50), 1, new \Drupal\commerce\Context(\Drupal::currentUser(), \Drupal::service('commerce_store.current_store')->getStore()), ['tax','promotion'])->getCalculatedPrice());"
/var/www/html/vendor/drush/drush/src/Commands/core/PhpCommands.php(31) : eval()'d code:1:
class Drupal\commerce_price\Price#4412 (2) {
protected $number =>
string(5) "75.00"
protected $currencyCode =>
string(3) "NOK"
}By comparing the last two outputs one can notice that order processors are not following service priority.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | commerce-price-calculator-processor-order-3202986-4.patch | 2.07 KB | chrisscrumping |
Issue fork commerce-3202986
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
zaporylieComment #3
zaporylieIMHO there are two issues here:
1. Processors are grouped by adjustment type, so the order is lost here. Ex. PaymentOrderProcessor and TaxOrderProcessor are both declared as 'tax' - the former with priority 400, the latter 50 (promotion processor is 100 so in between those two)
2. There are later merged in on adjustment type basis, type after type, based on the order of $adjustment_types passed to the PriceCalculator::calculate().
Comment #4
chrisscrumping commentedI came across this bug today due to #2982355: Incorrect percentage discounts when prices are entered with tax, but displayed without (or vice-versa). Created a quick patch to fix the processor order in PriceCalculator::calculate(): instead of grouping the selected processors by adjustment type, it now runs them in their global priority order (as PriceCalculatorPass already registers them, and as OrderRefresh runs them).
Comment #6
tbkot commentedComment #10
jsacksick commentedComment #12
anybodyThank you all! Please check #2982355: Incorrect percentage discounts when prices are entered with tax, but displayed without (or vice-versa) as potential follow-up (or duplicate).