diff --git a/Classes/Domain/DoctrineRepository/Product/BeVariantRepository.php b/Classes/Domain/DoctrineRepository/Product/BeVariantRepository.php index 5ccf9f8..8d554af 100644 --- a/Classes/Domain/DoctrineRepository/Product/BeVariantRepository.php +++ b/Classes/Domain/DoctrineRepository/Product/BeVariantRepository.php @@ -9,6 +9,7 @@ * LICENSE file that was distributed with this source code. */ +use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; @@ -26,10 +27,10 @@ public function getStock(int $uid): int ->select('stock') ->from('tx_cartproducts_domain_model_product_bevariant') ->where( - $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->orWhere( - $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->executeQuery() ->fetchOne(); @@ -44,10 +45,10 @@ public function addQuantityToStock(int $uid, int $quantity): void $queryBuilder ->update('tx_cartproducts_domain_model_product_bevariant') ->where( - $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->orWhere( - $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->set('stock', $currentStock - $quantity) ->executeStatement(); diff --git a/Classes/Domain/DoctrineRepository/Product/ProductRepository.php b/Classes/Domain/DoctrineRepository/Product/ProductRepository.php index 0150df0..dd84870 100644 --- a/Classes/Domain/DoctrineRepository/Product/ProductRepository.php +++ b/Classes/Domain/DoctrineRepository/Product/ProductRepository.php @@ -9,6 +9,7 @@ * LICENSE file that was distributed with this source code. */ +use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; @@ -26,10 +27,10 @@ public function getStock(int $uid): int ->select('stock') ->from('tx_cartproducts_domain_model_product_product') ->where( - $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->orWhere( - $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->executeQuery() ->fetchOne(); @@ -44,10 +45,10 @@ public function addQuantityToStock(int $uid, int $quantity): void $queryBuilder ->update('tx_cartproducts_domain_model_product_product') ->where( - $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->orWhere( - $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) ->set('stock', $currentStock + $quantity) ->executeStatement(); diff --git a/Documentation/guides.xml b/Documentation/guides.xml index 4b882fe..c470cb6 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -11,7 +11,7 @@ interlink-shortcode="extcode/cart_products" /> diff --git a/Tests/Acceptance/AddConfigurableProductWithStockHandlingToCartCest.php b/Tests/Acceptance/AddConfigurableProductWithStockHandlingToCartCest.php new file mode 100644 index 0000000..4e9cb1b --- /dev/null +++ b/Tests/Acceptance/AddConfigurableProductWithStockHandlingToCartCest.php @@ -0,0 +1,124 @@ +amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=6&cHash=93520e7d2c5c85e6563ce0e5b8eba102'); + + $I->see('Configurable Product 2', 'h1'); + $I->see(' ', '#product-price .in-stock'); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 1); + $I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red'); + $I->click('#product-6.add-to-cart-form input.btn[type="submit"]'); + $I->see('In stock (5 pieces)', '#product-price .in-stock'); + + $I->see('Item was added to cart.', '#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 2); + $I->selectOption('tx_cart_cart[beVariants][1]', 'M - green'); + $I->click('#product-6.add-to-cart-form input.btn[type="submit"]'); + $I->see('In stock (3 pieces)', '#product-price .in-stock'); + + $I->see('2 Items were added to cart.', '#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 4); + $I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red'); + $I->click('#product-6.add-to-cart-form input.btn[type="submit"]'); + $I->see('In stock (5 pieces)', '#product-price .in-stock'); + + $I->see('4 Items were added to cart.', '#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + } + + public function testAddMoreItemsThanInStockOfASimpleProductToCart(Tester $I): void + { + $I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=6&cHash=93520e7d2c5c85e6563ce0e5b8eba102'); + + $I->see('Configurable Product 2', 'h1'); + $I->see(' ', '#product-price .in-stock'); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 6); + $I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red'); + $I->click('#product-6.add-to-cart-form input.btn[type="submit"]'); + $I->see('In stock (5 pieces)', '#product-price .in-stock'); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->see('Desired number of this item not available.', '#product-6 .form-message .form-error'); + + $I->wait(3); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + } + + public function testAddOneAndThanMoreItemsThanInStockOfASimpleProductToCart(Tester $I): void + { + $I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=6&cHash=93520e7d2c5c85e6563ce0e5b8eba102'); + + $I->see('Configurable Product 2', 'h1'); + $I->see(' ', '#product-price .in-stock'); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 1); + $I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red'); + $I->click('#product-6.add-to-cart-form input.btn[type="submit"]'); + $I->see('In stock (5 pieces)', '#product-price .in-stock'); + + $I->see('Item was added to cart.', '#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 5); + $I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red'); + $I->click('#product-6.add-to-cart-form input.btn[type="submit"]'); + $I->see('In stock (5 pieces)', '#product-price .in-stock'); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->see('Desired number of this item not available.', '#product-6 .form-message .form-error'); + + $I->wait(3); + + $I->dontSeeElement('#product-6 .form-message .form-success'); + $I->dontSeeElement('#product-6 .form-message .form-error'); + } +} diff --git a/Tests/Acceptance/AddConfigurableProductWithoutStockHandlingToCartCest.php b/Tests/Acceptance/AddConfigurableProductWithoutStockHandlingToCartCest.php new file mode 100644 index 0000000..9312d95 --- /dev/null +++ b/Tests/Acceptance/AddConfigurableProductWithoutStockHandlingToCartCest.php @@ -0,0 +1,61 @@ +amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=5&cHash=4c2d7ef7c3ec394907ad93a1a0434fc8'); + + $I->see('Configurable Product 1', 'h1'); + $I->dontSeeElement('#product-price .in-stock'); + + $I->dontSeeElement('#product-5 .form-message .form-success'); + $I->dontSeeElement('#product-5 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 1); + $I->selectOption('tx_cart_cart[beVariants][1]', 'red'); + $I->click('#product-5.add-to-cart-form input.btn[type="submit"]'); + + $I->see('Item was added to cart.', '#product-5 .form-message .form-success'); + $I->dontSeeElement('#product-5 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-5 .form-message .form-success'); + $I->dontSeeElement('#product-5 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 2); + $I->selectOption('tx_cart_cart[beVariants][1]', 'green'); + $I->click('#product-5.add-to-cart-form input.btn[type="submit"]'); + + $I->see('2 Items were added to cart.', '#product-5 .form-message .form-success'); + $I->dontSeeElement('#product-5 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-5 .form-message .form-success'); + $I->dontSeeElement('#product-5 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 100); + $I->selectOption('tx_cart_cart[beVariants][1]', 'red'); + $I->click('#product-5.add-to-cart-form input.btn[type="submit"]'); + + $I->see('100 Items were added to cart.', '#product-5 .form-message .form-success'); + $I->dontSeeElement('#product-5 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-5 .form-message .form-success'); + $I->dontSeeElement('#product-5 .form-message .form-error'); + } +} diff --git a/Tests/Acceptance/AddSimpleProductWithStockHandlingToCartCest.php b/Tests/Acceptance/AddSimpleProductWithStockHandlingToCartCest.php new file mode 100644 index 0000000..d54be8c --- /dev/null +++ b/Tests/Acceptance/AddSimpleProductWithStockHandlingToCartCest.php @@ -0,0 +1,102 @@ +amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=1&cHash=275cce22d935c04473314c31f46f7ada'); + + $I->see('Simple Product 1', 'h1'); + $I->see('10', '#product-price .in-stock'); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 1); + $I->click('#product-1.add-to-cart-form input.btn[type="submit"]'); + + $I->see('Item was added to cart.', '#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 2); + $I->click('#product-1.add-to-cart-form input.btn[type="submit"]'); + + $I->see('2 Items were added to cart.', '#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + } + + public function testAddMoreItemsThanInStockOfASimpleProductToCart(Tester $I): void + { + $I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=1&cHash=275cce22d935c04473314c31f46f7ada'); + + $I->see('Simple Product 1', 'h1'); + $I->see('10', '#product-price .in-stock'); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 11); + $I->click('#product-1.add-to-cart-form input.btn[type="submit"]'); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->see('Desired number of this item not available.', '#product-1 .form-message .form-error'); + + $I->wait(3); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + } + + public function testAddOneAndThanMoreItemsThanInStockOfASimpleProductToCart(Tester $I): void + { + $I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=1&cHash=275cce22d935c04473314c31f46f7ada'); + + $I->see('Simple Product 1', 'h1'); + $I->see('10', '#product-price .in-stock'); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 1); + $I->click('#product-1.add-to-cart-form input.btn[type="submit"]'); + + $I->see('Item was added to cart.', '#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 10); + $I->click('#product-1.add-to-cart-form input.btn[type="submit"]'); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->see('Desired number of this item not available.', '#product-1 .form-message .form-error'); + + $I->wait(3); + + $I->dontSeeElement('#product-1 .form-message .form-success'); + $I->dontSeeElement('#product-1 .form-message .form-error'); + } +} diff --git a/Tests/Acceptance/AddSimpleProductWithoutStockHandlingToCartCest.php b/Tests/Acceptance/AddSimpleProductWithoutStockHandlingToCartCest.php new file mode 100644 index 0000000..8d4585c --- /dev/null +++ b/Tests/Acceptance/AddSimpleProductWithoutStockHandlingToCartCest.php @@ -0,0 +1,58 @@ +amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=2&cHash=36af38e6c5bbac81dcd80c3a3c53f4a1'); + + $I->see('Simple Product 2', 'h1'); + $I->dontSeeElement('#product-price .in-stock'); + + $I->dontSeeElement('#product-2 .form-message .form-success'); + $I->dontSeeElement('#product-2 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 1); + $I->click('#product-2.add-to-cart-form input.btn[type="submit"]'); + + $I->see('Item was added to cart.', '#product-2 .form-message .form-success'); + $I->dontSeeElement('#product-2 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-2 .form-message .form-success'); + $I->dontSeeElement('#product-2 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 2); + $I->click('#product-2.add-to-cart-form input.btn[type="submit"]'); + + $I->see('2 Items were added to cart.', '#product-2 .form-message .form-success'); + $I->dontSeeElement('#product-2 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-2 .form-message .form-success'); + $I->dontSeeElement('#product-2 .form-message .form-error'); + + $I->fillField('tx_cart_cart[quantity]', 100); + $I->click('#product-2.add-to-cart-form input.btn[type="submit"]'); + + $I->see('100 Items were added to cart.', '#product-2 .form-message .form-success'); + $I->dontSeeElement('#product-2 .form-message .form-error'); + $I->wait(3); + + $I->dontSeeElement('#product-2 .form-message .form-success'); + $I->dontSeeElement('#product-2 .form-message .form-error'); + } +} diff --git a/Tests/Fixtures/ProductsDatabase.php b/Tests/Fixtures/ProductsDatabase.php index 8779f58..6702c22 100644 --- a/Tests/Fixtures/ProductsDatabase.php +++ b/Tests/Fixtures/ProductsDatabase.php @@ -28,6 +28,8 @@ 'description' => '', 'path_segment' => 'simple-product-2', 'price' => 19.99, + 'handle_stock' => 0, + 'stock' => 10, 'related_products' => 1, ], 2 => [ diff --git a/ext_emconf.php b/ext_emconf.php index 31b5925..a75cb4b 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Cart - Products', 'description' => 'Shopping Cart(s) for TYPO3 - Products', 'category' => 'plugin', - 'version' => '7.0.1', + 'version' => '7.0.2', 'state' => 'stable', 'author' => 'Daniel Gohlke', 'author_email' => 'ext@extco.de',