Skip to content

Commit e63ca85

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-54680
2 parents a211ad8 + 8bf902a commit e63ca85

File tree

36 files changed

+1351
-244
lines changed

36 files changed

+1351
-244
lines changed

app/code/Magento/Backend/view/adminhtml/templates/system/shipping/applicable_country.phtml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ CountryModel.prototype = {
6161
if (applyCountryElement && applyCountryElement.id) {
6262
var specifCountryElement = $(applyCountryElement.id.replace(/sallowspecific/, 'specificcountry'));
6363
var showMethodElement = $(applyCountryElement.id.replace(/sallowspecific/, 'showmethod'));
64+
// 'Use Default' checkbox of the related county list UI element
65+
var useDefaultElement = document.getElementById(specifCountryElement.id + '_inherit');
66+
6467
//var specifErrMsgElement = $(applyCountryElement.id.replace(/sallowspecific/, 'specificerrmsg'));
6568
if (specifCountryElement) {
6669
if (applyCountryElement.value == 1) {
67-
//if specific country element selected
68-
specifCountryElement.enable();
70+
// enable related country select only if its 'Use Default' checkbox is absent or is unchecked
71+
specifCountryElement.disabled = useDefaultElement ? useDefaultElement.checked : false;
6972
if (showMethodElement) {
7073
this.showElement(showMethodElement.up(1));
7174
}

app/code/Magento/Catalog/Console/Command/ImagesResizeCommand.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,15 @@
55
*/
66
namespace Magento\Catalog\Console\Command;
77

8-
use Magento\Catalog\Model\Product;
9-
use Magento\Catalog\Model\Product\Image\Cache as ImageCache;
10-
use Magento\Catalog\Model\Product\Image\CacheFactory as ImageCacheFactory;
11-
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
12-
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
13-
use Magento\Framework\App\State as AppState;
14-
use Magento\Framework\Exception\NoSuchEntityException;
15-
use Symfony\Component\Console\Command\Command;
16-
use Symfony\Component\Console\Input\InputInterface;
17-
use Symfony\Component\Console\Output\OutputInterface;
18-
19-
class ImagesResizeCommand extends Command
8+
class ImagesResizeCommand extends \Symfony\Component\Console\Command\Command
209
{
2110
/**
22-
* @var AppState
11+
* @var \Magento\Framework\App\State
2312
*/
2413
protected $appState;
2514

2615
/**
27-
* @var ProductCollectionFactory
16+
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
2817
*/
2918
protected $productCollectionFactory;
3019

@@ -34,21 +23,21 @@ class ImagesResizeCommand extends Command
3423
protected $productRepository;
3524

3625
/**
37-
* @var ImageCacheFactory
26+
* @var \Magento\Catalog\Model\Product\Image\CacheFactory
3827
*/
3928
protected $imageCacheFactory;
4029

4130
/**
42-
* @param AppState $appState
43-
* @param ProductCollectionFactory $productCollectionFactory
31+
* @param \Magento\Framework\App\State $appState
32+
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
4433
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
45-
* @param ImageCacheFactory $imageCacheFactory
34+
* @param \Magento\Catalog\Model\Product\Image\CacheFactory $imageCacheFactory
4635
*/
4736
public function __construct(
48-
AppState $appState,
49-
ProductCollectionFactory $productCollectionFactory,
37+
\Magento\Framework\App\State $appState,
38+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
5039
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
51-
ImageCacheFactory $imageCacheFactory
40+
\Magento\Catalog\Model\Product\Image\CacheFactory $imageCacheFactory
5241
) {
5342
$this->appState = $appState;
5443
$this->productCollectionFactory = $productCollectionFactory;
@@ -69,11 +58,13 @@ protected function configure()
6958
/**
7059
* {@inheritdoc}
7160
*/
72-
protected function execute(InputInterface $input, OutputInterface $output)
73-
{
74-
$this->appState->setAreaCode('catalog');
61+
protected function execute(
62+
\Symfony\Component\Console\Input\InputInterface $input,
63+
\Symfony\Component\Console\Output\OutputInterface $output
64+
) {
65+
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
7566

76-
/** @var ProductCollection $productCollection */
67+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
7768
$productCollection = $this->productCollectionFactory->create();
7869
$productIds = $productCollection->getAllIds();
7970
if (!count($productIds)) {
@@ -85,13 +76,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
8576
try {
8677
foreach ($productIds as $productId) {
8778
try {
88-
/** @var Product $product */
79+
/** @var \Magento\Catalog\Model\Product $product */
8980
$product = $this->productRepository->getById($productId);
90-
} catch (NoSuchEntityException $e) {
81+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
9182
continue;
9283
}
9384

94-
/** @var ImageCache $imageCache */
85+
/** @var \Magento\Catalog\Model\Product\Image\Cache $imageCache */
9586
$imageCache = $this->imageCacheFactory->create();
9687
$imageCache->generate($product);
9788

app/code/Magento/Catalog/Console/Command/ProductAttributesCleanUp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function configure()
7878
protected function execute(InputInterface $input, OutputInterface $output)
7979
{
8080
$output->setDecorated(true);
81-
$this->appState->setAreaCode('catalog');
81+
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
8282
$connection = $this->attributeResource->getConnection();
8383
$attributeTables = $this->getAttributeTables();
8484

app/code/Magento/Catalog/Test/Unit/Console/Command/ImagesResizeCommandTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\App\State as AppState;
1515
use Magento\Framework\Exception\NoSuchEntityException;
1616
use Symfony\Component\Console\Tester\CommandTester;
17+
use \Magento\Framework\App\Area;
1718

1819
/**
1920
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -79,7 +80,7 @@ public function testExecuteNoProducts()
7980
{
8081
$this->appState->expects($this->once())
8182
->method('setAreaCode')
82-
->with('catalog')
83+
->with(Area::AREA_GLOBAL)
8384
->willReturnSelf();
8485

8586
$this->productCollection->expects($this->once())
@@ -101,7 +102,7 @@ public function testExecute()
101102

102103
$this->appState->expects($this->once())
103104
->method('setAreaCode')
104-
->with('catalog')
105+
->with(Area::AREA_GLOBAL)
105106
->willReturnSelf();
106107

107108
$this->productCollection->expects($this->once())
@@ -142,7 +143,7 @@ public function testExecuteWithException()
142143

143144
$this->appState->expects($this->once())
144145
->method('setAreaCode')
145-
->with('catalog')
146+
->with(Area::AREA_GLOBAL)
146147
->willReturnSelf();
147148

148149
$this->productCollection->expects($this->once())

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator.php

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99

1010
use Magento\CatalogInventory\Api\StockRegistryInterface;
1111
use Magento\CatalogInventory\Api\StockStateInterface;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
14+
use Magento\CatalogInventory\Helper\Data;
15+
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\Initializer\Option;
16+
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\Initializer\StockItem;
17+
use Magento\Framework\Event\Observer;
1218

19+
/**
20+
* Class QuantityValidator
21+
*/
1322
class QuantityValidator
1423
{
1524
/**
@@ -23,24 +32,25 @@ class QuantityValidator
2332
protected $stockItemInitializer;
2433

2534
/**
26-
* @var StockRegistryInterface
35+
* @var \Magento\CatalogInventory\Api\StockRegistryInterface
2736
*/
2837
protected $stockRegistry;
2938

3039
/**
31-
* @var StockStateInterface
40+
* @var \Magento\CatalogInventory\Api\StockStateInterface
3241
*/
3342
protected $stockState;
3443

3544
/**
36-
* @param QuantityValidator\Initializer\Option $optionInitializer
37-
* @param QuantityValidator\Initializer\StockItem $stockItemInitializer
45+
* @param Option $optionInitializer
46+
* @param StockItem $stockItemInitializer
3847
* @param StockRegistryInterface $stockRegistry
3948
* @param StockStateInterface $stockState
49+
* @return void
4050
*/
4151
public function __construct(
42-
QuantityValidator\Initializer\Option $optionInitializer,
43-
QuantityValidator\Initializer\StockItem $stockItemInitializer,
52+
Option $optionInitializer,
53+
StockItem $stockItemInitializer,
4454
StockRegistryInterface $stockRegistry,
4555
StockStateInterface $stockState
4656
) {
@@ -50,6 +60,30 @@ public function __construct(
5060
$this->stockState = $stockState;
5161
}
5262

63+
/**
64+
* Add error information to Quote Item
65+
*
66+
* @param \Magento\Framework\DataObject $result
67+
* @param \Magento\Quote\Model\Quote\Item $quoteItem
68+
* @param bool $removeError
69+
* @return void
70+
*/
71+
private function addErrorInfoToQuote($result, $quoteItem)
72+
{
73+
$quoteItem->addErrorInfo(
74+
'cataloginventory',
75+
Data::ERROR_QTY,
76+
$result->getMessage()
77+
);
78+
79+
$quoteItem->getQuote()->addErrorInfo(
80+
$result->getQuoteMessageIndex(),
81+
'cataloginventory',
82+
Data::ERROR_QTY,
83+
$result->getQuoteMessage()
84+
);
85+
}
86+
5387
/**
5488
* Check product inventory data when quote item quantity declaring
5589
*
@@ -61,7 +95,7 @@ public function __construct(
6195
* @SuppressWarnings(PHPMD.NPathComplexity)
6296
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
6397
*/
64-
public function validate(\Magento\Framework\Event\Observer $observer)
98+
public function validate(Observer $observer)
6599
{
66100
/* @var $quoteItem \Magento\Quote\Model\Quote\Item */
67101
$quoteItem = $observer->getEvent()->getItem();
@@ -81,9 +115,8 @@ public function validate(\Magento\Framework\Event\Observer $observer)
81115
$quoteItem->getProduct()->getId(),
82116
$quoteItem->getProduct()->getStore()->getWebsiteId()
83117
);
84-
/* @var $stockItem \Magento\CatalogInventory\Api\Data\StockItemInterface */
85-
if (!$stockItem instanceof \Magento\CatalogInventory\Api\Data\StockItemInterface) {
86-
throw new \Magento\Framework\Exception\LocalizedException(__('The stock item for Product is not valid.'));
118+
if (!$stockItem instanceof StockItemInterface) {
119+
throw new LocalizedException(__('The stock item for Product is not valid.'));
87120
}
88121

89122
$parentStockItem = false;
@@ -103,19 +136,19 @@ public function validate(\Magento\Framework\Event\Observer $observer)
103136
if (!$stockItem->getIsInStock() || $parentStockItem && !$parentStockItem->getIsInStock()) {
104137
$quoteItem->addErrorInfo(
105138
'cataloginventory',
106-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY,
139+
Data::ERROR_QTY,
107140
__('This product is out of stock.')
108141
);
109142
$quoteItem->getQuote()->addErrorInfo(
110143
'stock',
111144
'cataloginventory',
112-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY,
145+
Data::ERROR_QTY,
113146
__('Some of the products are out of stock.')
114147
);
115148
return;
116149
} else {
117150
// Delete error from item and its quote, if it was set due to item out of stock
118-
$this->_removeErrorsFromQuoteAndItem($quoteItem, \Magento\CatalogInventory\Helper\Data::ERROR_QTY);
151+
$this->_removeErrorsFromQuoteAndItem($quoteItem, Data::ERROR_QTY);
119152
}
120153
}
121154

@@ -134,65 +167,47 @@ public function validate(\Magento\Framework\Event\Observer $observer)
134167
if ($result->getHasError()) {
135168
$quoteItem->addErrorInfo(
136169
'cataloginventory',
137-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY_INCREMENTS,
170+
Data::ERROR_QTY_INCREMENTS,
138171
$result->getMessage()
139172
);
140173

141174
$quoteItem->getQuote()->addErrorInfo(
142175
$result->getQuoteMessageIndex(),
143176
'cataloginventory',
144-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY_INCREMENTS,
177+
Data::ERROR_QTY_INCREMENTS,
145178
$result->getQuoteMessage()
146179
);
147180
} else {
148181
// Delete error from item and its quote, if it was set due to qty problems
149182
$this->_removeErrorsFromQuoteAndItem(
150183
$quoteItem,
151-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY_INCREMENTS
184+
Data::ERROR_QTY_INCREMENTS
152185
);
153186
}
154187
}
188+
// variable to keep track if we have previously encountered an error in one of the options
189+
$removeError = true;
155190

156191
foreach ($options as $option) {
157192
$result = $this->optionInitializer->initialize($option, $quoteItem, $qty);
158193
if ($result->getHasError()) {
159194
$option->setHasError(true);
160-
161-
$quoteItem->addErrorInfo(
162-
'cataloginventory',
163-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY,
164-
$result->getMessage()
165-
);
166-
167-
$quoteItem->getQuote()->addErrorInfo(
168-
$result->getQuoteMessageIndex(),
169-
'cataloginventory',
170-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY,
171-
$result->getQuoteMessage()
172-
);
173-
} else {
174-
// Delete error from item and its quote, if it was set due to qty lack
175-
$this->_removeErrorsFromQuoteAndItem($quoteItem, \Magento\CatalogInventory\Helper\Data::ERROR_QTY);
195+
//Setting this to false, so no error statuses are cleared
196+
$removeError = false;
197+
$this->addErrorInfoToQuote($result, $quoteItem, $removeError);
176198
}
177199
}
200+
if ($removeError) {
201+
$this->_removeErrorsFromQuoteAndItem($quoteItem, Data::ERROR_QTY);
202+
}
178203
} else {
179-
$result = $this->stockItemInitializer->initialize($stockItem, $quoteItem, $qty);
180-
if ($result->getHasError()) {
181-
$quoteItem->addErrorInfo(
182-
'cataloginventory',
183-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY,
184-
$result->getMessage()
185-
);
186-
187-
$quoteItem->getQuote()->addErrorInfo(
188-
$result->getQuoteMessageIndex(),
189-
'cataloginventory',
190-
\Magento\CatalogInventory\Helper\Data::ERROR_QTY,
191-
$result->getQuoteMessage()
192-
);
193-
} else {
194-
// Delete error from item and its quote, if it was set due to qty lack
195-
$this->_removeErrorsFromQuoteAndItem($quoteItem, \Magento\CatalogInventory\Helper\Data::ERROR_QTY);
204+
if ($quoteItem->getParentItem() === null) {
205+
$result = $this->stockItemInitializer->initialize($stockItem, $quoteItem, $qty);
206+
if ($result->getHasError()) {
207+
$this->addErrorInfoToQuote($result, $quoteItem);
208+
} else {
209+
$this->_removeErrorsFromQuoteAndItem($quoteItem, Data::ERROR_QTY);
210+
}
196211
}
197212
}
198213
}

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/Option.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function initialize(
101101
);
102102

103103
$stockItem = $this->getStockItem($option, $quoteItem);
104+
$stockItem->setProductName($option->getProduct()->getName());
104105
$result = $this->stockState->checkQuoteItemQty(
105106
$option->getProduct()->getId(),
106107
$optionQty,

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/Initializer/OptionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ protected function setUp()
106106
'__wakeup',
107107
'unsIsChildItem',
108108
'getItemId',
109+
'setProductName'
109110
];
110111

111112
$this->stockItemMock = $this->getMock(

0 commit comments

Comments
 (0)