mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Merge branch '1.12' into 1.13
* 1.12: Prevent the cart recalculation when the form has errors
This commit is contained in:
commit
51512b9f2d
4 changed files with 29 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue