- 🇮🇱Israel jsacksick
This is probably outdated, if the order is locked it shouldn't be refreshed and therefore the price shouldn't be refreshed.
Since this is from 2019 I'm going to close this and mark it as outdated.
Every time an order is saved recalculateTotalPrice() is called. At first glance it makes sense to do this, but we run into problems with this when we implement a custom "Early bird" price resolver. Let me explain.
We allow the user to set an "Early bird" date on the product. Until this time a customer gets a discount. This is achieved through a price resolver and works just fine.
Let's take following example into consideration:
We have currently tackled this issue by implementing:
/**
* Implements hook_entity_type_alter().
*/
function my_module_entity_type_alter(array &$entity_types) {
// We have to override the commerce order class, to manipulate the recalculate function.
$entity_types['commerce_order']->setClass('Drupal\my_module\Entity\Order');
}
And then override the recalculateTotalPrice() method like so:
/**
* {@inheritdoc}
*/
public function recalculateTotalPrice() {
if (($state = $this->getState()) && $state->getId() == 'completed') {
// Never recalculate prices when order is completed.
return $this;
}
if ($this->isLocked()) {
// Do not recalculate prices when order is locked (when user is redirected to payment provider).
return $this;
}
return parent::recalculateTotalPrice();
}
Is there any mechanism we could add so custom module developers can add functionality which let's the order entity know "Hey, please in this case, do not recalculate the price of the order". Maybe through an event subscriber?
Or am I missing something completely and is this already possible?
Closed: outdated
2.0
Order
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
This is probably outdated, if the order is locked it shouldn't be refreshed and therefore the price shouldn't be refreshed.
Since this is from 2019 I'm going to close this and mark it as outdated.