Skip to content

Commit 226733c

Browse files
committed
Merge branch 'MAGETWO-61151' into 2.0-develop-pr4
2 parents 2079bb4 + a76b13d commit 226733c

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,6 @@ protected function _getProductRequest($requestInfo)
335335
);
336336
}
337337

338-
if (!$request->hasQty()) {
339-
$request->setQty(1);
340-
}
341-
342338
$this->getRequestInfoFilter()->filter($request);
343339
return $request;
344340
}
@@ -364,7 +360,7 @@ public function addProduct($productInfo, $requestInfo = null)
364360
//If product was not found in cart and there is set minimal qty for it
365361
if ($minimumQty
366362
&& $minimumQty > 0
367-
&& $request->getQty() < $minimumQty
363+
&& !$request->getQty()
368364
&& !$this->getQuote()->hasProductId($productId)
369365
) {
370366
$request->setQty($minimumQty);
@@ -704,7 +700,7 @@ public function updateItem($itemId, $requestInfo = null, $updatingParams = null)
704700
// If product was not found in cart and there is set minimal qty for it
705701
if ($minimumQty
706702
&& $minimumQty > 0
707-
&& $request->getQty() < $minimumQty
703+
&& !$request->getQty()
708704
&& !$this->getQuote()->hasProductId($productId)
709705
) {
710706
$request->setQty($minimumQty);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\Model;
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
class CartTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var Cart
15+
*/
16+
private $cart;
17+
18+
/**
19+
* @var ProductRepositoryInterface
20+
*/
21+
private $productRepository;
22+
23+
protected function setUp()
24+
{
25+
$this->cart = Bootstrap::getObjectManager()->create(Cart::class);
26+
$this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
27+
}
28+
29+
/**
30+
* @magentoDataFixture Magento/Checkout/_files/set_product_min_in_cart.php
31+
* @magentoDbIsolation enabled
32+
* @magentoAppIsolation enabled
33+
*/
34+
public function testAddProductWithLowerQty()
35+
{
36+
$this->setExpectedException(
37+
\Magento\Framework\Exception\LocalizedException::class,
38+
'The fewest you may purchase is 3'
39+
);
40+
$product = $this->productRepository->get('simple');
41+
$this->cart->addProduct($product->getId(), ['qty' => 1]);
42+
}
43+
44+
/**
45+
* @magentoDataFixture Magento/Checkout/_files/set_product_min_in_cart.php
46+
* @magentoDbIsolation enabled
47+
*/
48+
public function testAddProductWithNoQty()
49+
{
50+
$product = $this->productRepository->get('simple');
51+
$this->cart->addProduct($product->getId(), []);
52+
}
53+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
include 'simple_product.php';
8+
9+
/** @var $product \Magento\Catalog\Model\Product */
10+
$product->setStockData(['use_config_manage_stock' => 0, 'min_sale_qty' => 3]);
11+
$product->save();

0 commit comments

Comments
 (0)