Skip to content

Commit

Permalink
ENGCOM-4494: mutations add<Product Type>ProductsToCart dosn't check i…
Browse files Browse the repository at this point in the history
…f the cart is active #455

 - Merge Pull Request magento/graphql-ce#455 from XxXgeoXxX/graphql-ce:2.3-develop#408
 - Merged commits:
   1. e431556
   2. 2363896
   3. 4d4a982
   4. a984663
   5. 1daadb8
  • Loading branch information
magento-engcom-team committed Mar 13, 2019
2 parents 6cc68c6 + 1daadb8 commit db2a76c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 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 (false === (bool)$cart->getIsActive()) {
throw new GraphQlNoSuchEntityException(
__('Current user does not have an active cart.')
);
}

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

/* Guest cart, allow operations */
Expand Down
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 user 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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ public function testGetNonExistentCart()
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @expectedException \Exception
* @expectedExceptionMessage Current user 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->setIsActive(false);
$this->quoteResource->save($quote);
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());

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

$this->graphQlQuery($query);
}

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

0 comments on commit db2a76c

Please sign in to comment.