mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
fix cart operator to sum up items that are equal.
This commit is contained in:
parent
5d898acc05
commit
b5222a514d
2 changed files with 16 additions and 1 deletions
|
|
@ -46,7 +46,7 @@ abstract class CartOperator implements CartOperatorInterface
|
|||
*/
|
||||
public function addItem(CartInterface $cart, ItemInterface $item)
|
||||
{
|
||||
if (0 > $cart->countItems()) {
|
||||
if (false === $cart->isEmpty()) {
|
||||
foreach ($cart->getItems() as $existingItem) {
|
||||
if ($existingItem->equals($item)) {
|
||||
$existingItem->setQuantity($existingItem->getQuantity() + $item->getQuantity());
|
||||
|
|
|
|||
|
|
@ -32,6 +32,21 @@ class CartOperatorTest extends \PHPUnit_Framework_TestCase
|
|||
$cartOperator->addItem($cart, $item);
|
||||
}
|
||||
|
||||
public function testAddItemIncreasesQuantityIfThereAreItemsThatAreEqual()
|
||||
{
|
||||
$item = $this->getItem();
|
||||
$item->setQuantity(3);
|
||||
|
||||
$cart = $this->getCart();
|
||||
|
||||
$cartOperator = $this->getCartOperator();
|
||||
$cartOperator->addItem($cart, $item);
|
||||
$cartOperator->addItem($cart, $item);
|
||||
|
||||
$this->assertEquals(1, $cart->countItems());
|
||||
$this->assertEquals(6, $item->getQuantity());
|
||||
}
|
||||
|
||||
public function testRefreshSetsTotalItems()
|
||||
{
|
||||
$cart = $this->getMockCart();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue