Skip to content

Commit

Permalink
mutations add<Product Type>ProductsToCart dosn't check if the cart is…
Browse files Browse the repository at this point in the history
… active
  • Loading branch information
XxXgeoXxX committed Mar 13, 2019
1 parent 2363896 commit 4d4a982
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
16 changes: 6 additions & 10 deletions app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public function execute(string $cartHash, ?int $customerId): Quote
);
}

if (!$cart->getIsActive()) {
throw new GraphQlNoSuchEntityException(
__('Current customer does not have an active cart.')
);
}

$cartCustomerId = (int)$cart->getCustomerId();

/* Guest cart, allow operations */
Expand All @@ -84,16 +90,6 @@ public function execute(string $cartHash, ?int $customerId): Quote
)
);
}

if ($customerId) {
try {
return $this->cartRepository->getActiveForCustomer($customerId);
} catch (\Exception $e) {
throw new GraphQlNoSuchEntityException(
__($e->getMessage())
);
}
}
return $cart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ public function testGetNonExistentCart()
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException \Exception
* @expectedExceptionMessage Current customer does not have an active cart.
*/
public function testGetInactiveCart()
{
$quote = $this->quoteFactory->create();
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
$quote->setCustomerId(1);
$quote->setIsActive(false);
$this->quoteResource->save($quote);
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());

$query = $this->getCartQuery($maskedQuoteId);

$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @param string $maskedQuoteId
* @return string
Expand Down

0 comments on commit 4d4a982

Please sign in to comment.