Commit f2bf2869 authored by Matt Glaman's avatar Matt Glaman Committed by Bojan Živanović
Browse files

Issue #2803257 by mglaman: OrderRefresh must not touch already completed orders

parent a8f82f64
Loading
Loading
Loading
Loading
+5 −1
Changes for modules/order/src/OrderRefresh.php: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -71,9 +71,13 @@ class OrderRefresh implements OrderRefreshInterface {
   * {@inheritdoc}
   */
  public function needsRefresh(OrderInterface $order) {
    // Refresh should only run on draft orders.
    if ($order->getState()->value != 'draft') {
      return FALSE;
    }

    /** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
    $order_type = $this->orderTypeStorage->load($order->bundle());

    // Check the order's changed time against the refresh frequency.
    // We use time() since the REQUEST_TIME constant can become stale. This is
    // especially true during CLI operations.
+9 −1
Changes for modules/order/tests/src/Kernel/OrderRefreshTest.php: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ use Drupal\profile\Entity\Profile;
class OrderRefreshTest extends EntityKernelTestBase {

  /**
   * The order refresh service.
   * The order refresh.
   *
   * @var \Drupal\commerce_order\OrderRefreshInterface
   */
@@ -63,6 +63,8 @@ class OrderRefreshTest extends EntityKernelTestBase {
  protected $variation2;

  /**
   * The order item storage.
   *
   * @var \Drupal\commerce_order\OrderItemStorageInterface
   */
  protected $orderItemStorage;
@@ -193,6 +195,12 @@ class OrderRefreshTest extends EntityKernelTestBase {
    $this->assertFalse($this->orderRefresh->needsRefresh($this->order));
    $this->order->setOwner($this->user);
    $this->assertTrue($this->orderRefresh->needsRefresh($this->order));

    sleep(1);
    $workflow = $this->order->getState()->getWorkflow();
    $this->order->getState()->applyTransition($workflow->getTransition('place'));
    $this->order->save();
    $this->assertFalse($this->orderRefresh->needsRefresh($this->order));
  }

  /**