Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Documentation/guides.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
interlink-shortcode="extcode/cart_products"
/>
<project title="Cart Products"
release="7.0.1"
release="7.0.2"
version="7.0"
copyright="2018 - 2025"
/>
Expand Down
124 changes: 124 additions & 0 deletions Tests/Acceptance/AddConfigurableProductWithStockHandlingToCartCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

declare(strict_types=1);

namespace Extcode\CartProducts\Tests\Acceptance;

/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\CartProducts\Tests\Acceptance\Support\Tester;

class AddConfigurableProductWithStockHandlingToCartCest
{
public function testAddDifferentItemsWithinAvailableAmountToCart(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]', 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');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Extcode\CartProducts\Tests\Acceptance;

/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\CartProducts\Tests\Acceptance\Support\Tester;

class AddConfigurableProductWithoutStockHandlingToCartCest
{
public function testAddDifferentItemsToCart(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=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');
}
}
102 changes: 102 additions & 0 deletions Tests/Acceptance/AddSimpleProductWithStockHandlingToCartCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);

namespace Extcode\CartProducts\Tests\Acceptance;

/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\CartProducts\Tests\Acceptance\Support\Tester;

class AddSimpleProductWithStockHandlingToCartCest
{
public function testAddDifferentItemsWithinAvailableAmountToCart(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]', 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');
}
}
Loading