public function OrderRefresh::needsRefresh in Commerce Core 8.2
Checks whether the given order needs to be refreshed.
An order needs to be refreshed:
- If a refresh was explicitly requested via $order->setNeedsRefresh() due to the order being modified.
- If it was not refreshed today (date changes can affect tax rate amounts, promotion availability)
- If it was not refreshed for longer than the refresh frequency.
Parameters
\Drupal\commerce_order\Entity\OrderInterface $order: The order.
Return value
bool TRUE if the order needs to be refreshed, FALSE otherwise.
Overrides OrderRefreshInterface::needsRefresh
1 call to OrderRefresh::needsRefresh()
- OrderRefresh::shouldRefresh in modules/
order/ src/ OrderRefresh.php - Checks whether the order should be refreshed.
File
- modules/
order/ src/ OrderRefresh.php, line 116
Class
- OrderRefresh
- Default implementation for order refresh.
Namespace
Drupal\commerce_orderCode
public function needsRefresh(OrderInterface $order) {
// Only draft orders should be automatically refreshed.
if ($order
->getState()
->getId() != 'draft') {
return FALSE;
}
// Only unlocked orders should be automatically refreshed.
if ($order
->isLocked()) {
return FALSE;
}
// Accommodate long-running processes by always using the current time.
$current_time = $this->time
->getCurrentTime();
$order_time = $order
->getChangedTime();
if (date('Y-m-d', $current_time) != date('Y-m-d', $order_time)) {
// Refresh on a date change regardless of the refresh frequency.
// Date changes can impact tax rate amounts, availability of promotions.
return TRUE;
}
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = $this->orderTypeStorage
->load($order
->bundle());
$refreshed_ago = $current_time - $order_time;
if ($refreshed_ago >= $order_type
->getRefreshFrequency()) {
return TRUE;
}
return FALSE;
}