Merge branch '1.12' into 1.13

* 1.12:
  Prevent the cart recalculation when the form has errors
This commit is contained in:
Grzegorz Sadowski 2023-03-27 08:23:36 +02:00
commit 51512b9f2d
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
4 changed files with 29 additions and 2 deletions

View file

@ -9,13 +9,27 @@ Feature: Verifying inventory quantity on cart summary
And the store has a product "Iron Maiden T-Shirt" priced at "12.54"
And this product is tracked by the inventory
And there are 5 units of product "Iron Maiden T-Shirt" available in the inventory
And the store has a product "Black Dress" priced at "50.20"
And this product is tracked by the inventory
And there are 10 units of product "Black Dress" available in the inventory
@ui @api
Scenario: Being unable to save a cart with product that is out of stock
Given I have added 3 products "Iron Maiden T-Shirt" in the cart
When I change product "Iron Maiden T-Shirt" quantity to 6 in my cart
And I update my cart
Then I should be notified that this product cannot be updated
Then I should be notified that this product has insufficient stock
@ui @no-api
Scenario: Preventing the cart recalculation when the form has errors
Given I have added 3 products "Iron Maiden T-Shirt" in the cart
And I have added 1 products "Black Dress" in the cart
When I change product "Iron Maiden T-Shirt" quantity to 4 in my cart
And I change product "Black Dress" quantity to 11 in my cart
Then I should be notified that this product has insufficient stock
And I should see "Iron Maiden T-Shirt" with quantity 4 in my cart
And I should see "Black Dress" with quantity 11 in my cart
And my cart's total should be "$100.36"
@ui @api
Scenario: Placing an order with products that have sufficient quantity

View file

@ -250,6 +250,7 @@ final class CartContext implements Context
/**
* @Then /^I should be notified that (this product) does not have sufficient stock$/
* @Then /^I should be notified that (this product) has insufficient stock$/
* @Then /^I should be notified that (this product) cannot be updated$/
*/
public function iShouldBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product): void

View file

@ -532,7 +532,7 @@ final class CartContext implements Context
}
/**
* @Then /^I should be notified that (this product) cannot be updated$/
* @Then /^I should be notified that (this product) has insufficient stock$/
*/
public function iShouldBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product)
{

View file

@ -119,6 +119,10 @@ class OrderController extends ResourceController
return $this->redirectHandler->redirectToResource($configuration, $resource);
}
if ($form->isSubmitted() && !$form->isValid()) {
$this->resetChangesOnCart($resource);
}
if (!$configuration->isHtmlRequest()) {
return $this->viewHandler->handle($configuration, View::create($form, Response::HTTP_BAD_REQUEST));
}
@ -134,6 +138,14 @@ class OrderController extends ResourceController
);
}
private function resetChangesOnCart(OrderInterface $cart): void
{
$this->manager->refresh($cart);
foreach ($cart->getItems() as $item) {
$this->manager->refresh($item);
}
}
/**
* @psalm-suppress DeprecatedMethod
*/