Skip to content

Commit 3ef85b8

Browse files
author
Vladyslav Shcherbyna
committed
MAGETWO-32107: Stabilization and pull request
1 parent d495995 commit 3ef85b8

File tree

5 files changed

+47
-61
lines changed

5 files changed

+47
-61
lines changed

app/code/Magento/Quote/Helper/Data.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/code/Magento/Quote/Model/Quote.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ class Quote extends \Magento\Framework\Model\AbstractModel
191191
protected $_catalogProduct;
192192

193193
/**
194-
* Sales data
194+
* Quote validator
195195
*
196-
* @var \Magento\Quote\Helper\Data
196+
* @var \Magento\Quote\Model\QuoteValidator
197197
*/
198-
protected $quoteDataHelper;
198+
protected $quoteValidator;
199199

200200
/**
201201
* Core store config
@@ -330,7 +330,7 @@ class Quote extends \Magento\Framework\Model\AbstractModel
330330
/**
331331
* @param \Magento\Framework\Model\Context $context
332332
* @param \Magento\Framework\Registry $registry
333-
* @param \Magento\Quote\Helper\Data $quoteDataHelper
333+
* @param \Magento\Quote\Model\QuoteValidator $quoteValidator
334334
* @param \Magento\Catalog\Helper\Product $catalogProduct
335335
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
336336
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -363,7 +363,7 @@ class Quote extends \Magento\Framework\Model\AbstractModel
363363
public function __construct(
364364
\Magento\Framework\Model\Context $context,
365365
\Magento\Framework\Registry $registry,
366-
\Magento\Quote\Helper\Data $quoteDataHelper,
366+
\Magento\Quote\Model\QuoteValidator $quoteValidator,
367367
\Magento\Catalog\Helper\Product $catalogProduct,
368368
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
369369
\Magento\Store\Model\StoreManagerInterface $storeManager,
@@ -393,7 +393,7 @@ public function __construct(
393393
\Magento\Framework\Data\Collection\Db $resourceCollection = null,
394394
array $data = []
395395
) {
396-
$this->quoteDataHelper = $quoteDataHelper;
396+
$this->quoteValidator = $quoteValidator;
397397
$this->_catalogProduct = $catalogProduct;
398398
$this->_scopeConfig = $scopeConfig;
399399
$this->_storeManager = $storeManager;
@@ -1698,8 +1698,8 @@ public function collectTotals()
16981698
$this->setBaseGrandTotal((float)$this->getBaseGrandTotal() + $address->getBaseGrandTotal());
16991699
}
17001700

1701-
$this->quoteDataHelper->checkQuoteAmount($this, $this->getGrandTotal());
1702-
$this->quoteDataHelper->checkQuoteAmount($this, $this->getBaseGrandTotal());
1701+
$this->quoteValidator->validateQuoteAmount($this, $this->getGrandTotal());
1702+
$this->quoteValidator->validateQuoteAmount($this, $this->getBaseGrandTotal());
17031703

17041704
$this->setData('trigger_recollect', 0);
17051705
$this->_validateCouponCode();

app/code/Magento/Quote/Model/Quote/Address/Total/Subtotal.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ class Subtotal extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
1313
/**
1414
* Sales data
1515
*
16-
* @var \Magento\Quote\Helper\Data
16+
* @var \Magento\Quote\Model\QuoteValidator
1717
*/
18-
protected $quoteDataHelper = null;
18+
protected $quoteValidator = null;
1919

2020
/**
21-
* @param \Magento\Quote\Helper\Data $quoteDataHelper
21+
* @param \Magento\Quote\Model\QuoteValidator $quoteValidator
2222
*/
23-
public function __construct(\Magento\Quote\Helper\Data $quoteDataHelper)
23+
public function __construct(\Magento\Quote\Model\QuoteValidator $quoteValidator)
2424
{
25-
$this->quoteDataHelper = $quoteDataHelper;
25+
$this->quoteValidator = $quoteValidator;
2626
}
2727

2828
/**
@@ -62,8 +62,8 @@ public function collect(Address $address)
6262
/**
6363
* Initialize grand totals
6464
*/
65-
$this->quoteDataHelper->checkQuoteAmount($address->getQuote(), $address->getSubtotal());
66-
$this->quoteDataHelper->checkQuoteAmount($address->getQuote(), $address->getBaseSubtotal());
65+
$this->quoteValidator->validateQuoteAmount($address->getQuote(), $address->getSubtotal());
66+
$this->quoteValidator->validateQuoteAmount($address->getQuote(), $address->getBaseSubtotal());
6767
return $this;
6868
}
6969

app/code/Magento/Quote/Model/QuoteValidator.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@
99

1010
class QuoteValidator
1111
{
12+
/**
13+
* Maximum available number
14+
*/
15+
const MAXIMUM_AVAILABLE_NUMBER = 99999999;
16+
17+
/**
18+
* Validate quote amount
19+
*
20+
* @param QuoteEntity $quote
21+
* @param float $amount
22+
* @return $this
23+
*/
24+
public function validateQuoteAmount(QuoteEntity $quote, $amount)
25+
{
26+
if (!$quote->getHasError() && $amount >= self::MAXIMUM_AVAILABLE_NUMBER) {
27+
$quote->setHasError(true);
28+
$quote->addMessage(__('This item price or quantity is not valid for checkout.'));
29+
}
30+
return $this;
31+
}
32+
1233
/**
1334
* Validate quote before submit
1435
*

dev/tests/unit/testsuite/Magento/Quote/Helper/DataTest.php renamed to dev/tests/unit/testsuite/Magento/Quote/Model/QuoteValidatorTest.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
/**
33
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
44
*/
5-
namespace Magento\Quote\Helper;
5+
namespace Magento\Quote\Model;
66

7-
/**
8-
* Tests For Quote Data checker
9-
*/
10-
class DataTest extends \PHPUnit_Framework_TestCase
7+
class QuoteValidatorTest extends \PHPUnit_Framework_TestCase
118
{
129
/**
13-
* @var \Magento\Quote\Helper\Data
10+
* @var \Magento\Quote\Model\QuoteValidator
1411
*/
15-
protected $helper;
12+
protected $quoteValidator;
1613

1714
/**
1815
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Quote\Model\Quote
@@ -24,7 +21,7 @@ class DataTest extends \PHPUnit_Framework_TestCase
2421
*/
2522
protected function setUp()
2623
{
27-
$this->helper = new \Magento\Quote\Helper\Data();
24+
$this->quoteValidator = new \Magento\Quote\Model\QuoteValidator();
2825

2926
$this->quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote')
3027
->setMethods(['getHasError', 'setHasError', 'addMessage', '__wakeup'])
@@ -45,8 +42,8 @@ public function testCheckQuoteAmountExistingError()
4542
->method('addMessage');
4643

4744
$this->assertSame(
48-
$this->helper,
49-
$this->helper->checkQuoteAmount($this->quoteMock, Data::MAXIMUM_AVAILABLE_NUMBER + 1)
45+
$this->quoteValidator,
46+
$this->quoteValidator->validateQuoteAmount($this->quoteMock, QuoteValidator::MAXIMUM_AVAILABLE_NUMBER + 1)
5047
);
5148
}
5249

@@ -63,8 +60,8 @@ public function testCheckQuoteAmountAmountLessThanAvailable()
6360
->method('addMessage');
6461

6562
$this->assertSame(
66-
$this->helper,
67-
$this->helper->checkQuoteAmount($this->quoteMock, Data::MAXIMUM_AVAILABLE_NUMBER - 1)
63+
$this->quoteValidator,
64+
$this->quoteValidator->validateQuoteAmount($this->quoteMock, QuoteValidator::MAXIMUM_AVAILABLE_NUMBER - 1)
6865
);
6966
}
7067

@@ -83,8 +80,8 @@ public function testCheckQuoteAmountAmountGreaterThanAvailable()
8380
->with(__('This item price or quantity is not valid for checkout.'));
8481

8582
$this->assertSame(
86-
$this->helper,
87-
$this->helper->checkQuoteAmount($this->quoteMock, Data::MAXIMUM_AVAILABLE_NUMBER + 1)
83+
$this->quoteValidator,
84+
$this->quoteValidator->validateQuoteAmount($this->quoteMock, QuoteValidator::MAXIMUM_AVAILABLE_NUMBER + 1)
8885
);
8986
}
9087
}

0 commit comments

Comments
 (0)