From b974fe13032291accdb8eca4818f0f85fdde1973 Mon Sep 17 00:00:00 2001 From: Rafal Malenta Date: Mon, 6 Mar 2023 14:10:17 +0100 Subject: [PATCH] Added validation and behat --- features/adding_wishlist_product_to_cart.feature | 14 ++++++++++++++ src/Form/Type/AddProductsToCartType.php | 2 ++ 2 files changed, 16 insertions(+) diff --git a/features/adding_wishlist_product_to_cart.feature b/features/adding_wishlist_product_to_cart.feature index c37b809c..600b23ba 100644 --- a/features/adding_wishlist_product_to_cart.feature +++ b/features/adding_wishlist_product_to_cart.feature @@ -54,3 +54,17 @@ Feature: Adding wishlist product to cart And I check "Bushmills Black Bush Whiskey" And I add selected products to cart Then I should be notified that I should add more products + + @ui + Scenario: Adding more than available in stock wishlist products to cart + Given the store has a product "Jack Daniels Gentleman" priced at "$10.00" + And all store products appear under a main taxonomy + And the store has a product "Bushmills Black Bush Whiskey" priced at "$230.00" + And there is 1 units of product "Bushmills Black Bush Whiskey" available in the inventory + And the "Bushmills Black Bush Whiskey" product is tracked by the inventory + And I have these products in my wishlist + When I go to the wishlist page + And I select 6 quantity of "Bushmills Black Bush Whiskey" product + And I check "Bushmills Black Bush Whiskey" + And I add selected products to cart + Then I should be notified that "Bushmills Black Bush Whiskey" does not have sufficient stock diff --git a/src/Form/Type/AddProductsToCartType.php b/src/Form/Type/AddProductsToCartType.php index ceababe0..cd9ee48a 100644 --- a/src/Form/Type/AddProductsToCartType.php +++ b/src/Form/Type/AddProductsToCartType.php @@ -23,6 +23,7 @@ use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints\Valid; final class AddProductsToCartType extends AbstractType { @@ -56,6 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $form ->add('cartItem', AddToCartType::class, [ + 'constraints'=> new Valid(), 'label' => false, 'required' => false, 'product' => $wishlistProduct->getProduct(),