Skip to content

Commit 317392f

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #885 from magento-east/MAGETWO-65207
East Bugfixes
2 parents cc9a6ce + 758adf4 commit 317392f

File tree

18 files changed

+537
-66
lines changed

18 files changed

+537
-66
lines changed

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\CatalogInventory\Api\StockRegistryInterface;
1111
use Magento\CatalogInventory\Api\StockStateInterface;
12+
use Magento\CatalogInventory\Model\Stock;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1415
use Magento\CatalogInventory\Helper\Data;
@@ -99,41 +100,43 @@ public function validate(Observer $observer)
99100
{
100101
/* @var $quoteItem \Magento\Quote\Model\Quote\Item */
101102
$quoteItem = $observer->getEvent()->getItem();
102-
103103
if (!$quoteItem ||
104104
!$quoteItem->getProductId() ||
105105
!$quoteItem->getQuote() ||
106106
$quoteItem->getQuote()->getIsSuperMode()
107107
) {
108108
return;
109109
}
110-
110+
$product = $quoteItem->getProduct();
111111
$qty = $quoteItem->getQty();
112112

113-
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
114-
$stockItem = $this->stockRegistry->getStockItem(
115-
$quoteItem->getProduct()->getId(),
116-
$quoteItem->getProduct()->getStore()->getWebsiteId()
117-
);
113+
/* @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
114+
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
118115
if (!$stockItem instanceof StockItemInterface) {
119116
throw new LocalizedException(__('The stock item for Product is not valid.'));
120117
}
121118

122-
$parentStockItem = false;
119+
/* @var \Magento\CatalogInventory\Api\Data\StockStatusInterface $stockStatus */
120+
$stockStatus = $this->stockRegistry->getStockStatus($product->getId(), $product->getStore()->getWebsiteId());
121+
122+
/* @var \Magento\CatalogInventory\Api\Data\StockStatusInterface $parentStockStatus */
123+
$parentStockStatus = false;
123124

124125
/**
125126
* Check if product in stock. For composite products check base (parent) item stock status
126127
*/
127128
if ($quoteItem->getParentItem()) {
128129
$product = $quoteItem->getParentItem()->getProduct();
129-
$parentStockItem = $this->stockRegistry->getStockItem(
130+
$parentStockStatus = $this->stockRegistry->getStockStatus(
130131
$product->getId(),
131132
$product->getStore()->getWebsiteId()
132133
);
133134
}
134135

135-
if ($stockItem) {
136-
if (!$stockItem->getIsInStock() || $parentStockItem && !$parentStockItem->getIsInStock()) {
136+
if ($stockStatus) {
137+
if ($stockStatus->getStockStatus() == Stock::STOCK_OUT_OF_STOCK
138+
|| $parentStockStatus && $parentStockStatus->getStockStatus() == Stock::STOCK_OUT_OF_STOCK
139+
) {
137140
$quoteItem->addErrorInfo(
138141
'cataloginventory',
139142
Data::ERROR_QTY,
@@ -156,13 +159,13 @@ public function validate(Observer $observer)
156159
* Check item for options
157160
*/
158161
if (($options = $quoteItem->getQtyOptions()) && $qty > 0) {
159-
$qty = $quoteItem->getProduct()->getTypeInstance()->prepareQuoteItemQty($qty, $quoteItem->getProduct());
162+
$qty = $product->getTypeInstance()->prepareQuoteItemQty($qty, $product);
160163
$quoteItem->setData('qty', $qty);
161-
if ($stockItem) {
164+
if ($stockStatus) {
162165
$result = $this->stockState->checkQtyIncrements(
163-
$quoteItem->getProduct()->getId(),
166+
$product->getId(),
164167
$qty,
165-
$quoteItem->getProduct()->getStore()->getWebsiteId()
168+
$product->getStore()->getWebsiteId()
166169
);
167170
if ($result->getHasError()) {
168171
$quoteItem->addErrorInfo(

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

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\CatalogInventory\Test\Unit\Model\Quote\Item\QuantityValidator\Initializer;
88

9+
use Magento\CatalogInventory\Api\Data\StockStatusInterface;
10+
use Magento\CatalogInventory\Model\Stock\Status;
911
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1012
use Magento\CatalogInventory\Model\StockRegistry;
1113
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\Initializer\Option;
@@ -112,10 +114,25 @@ class QuantityValidatorTest extends \PHPUnit_Framework_TestCase
112114
*/
113115
private $stockItemInitializer;
114116

117+
/**
118+
* @var \PHPUnit_Framework_MockObject_MockObject|StockStatusInterface
119+
*/
120+
private $stockStatusMock;
121+
115122
protected function setUp()
116123
{
117124
$objectManagerHelper = new ObjectManager($this);
118-
$this->stockRegistryMock = $this->getMock(StockRegistry::class, ['getStockItem'], [], '', false);
125+
126+
$this->stockRegistryMock = $this->getMock(
127+
StockRegistry::class,
128+
[],
129+
[],
130+
'',
131+
false
132+
);
133+
134+
$this->stockStatusMock = $this->getMock(Status::class, [], [], '', false);
135+
119136
$this->optionInitializer = $this->getMock(Option::class, [], [], '', false);
120137
$this->stockItemInitializer = $this->getMock(StockItem::class, [], [], '', false);
121138
$this->stockState = $this->getMock(StockState::class, [], [], '', false);
@@ -149,8 +166,10 @@ protected function setUp()
149166
);
150167
$this->productMock = $this->getMock(Product::class, [], [], '', false);
151168
$this->stockItemMock = $this->getMock(StockMock::class, [], [], '', false);
152-
$this->parentStockItemMock = $this->getMock(StockMock::class, [], [], '', false);
169+
$this->parentStockItemMock = $this->getMock(StockMock::class, ['getStockStatus'], [], '', false);
170+
153171
$this->typeInstanceMock = $this->getMock(Type::class, [], [], '', false);
172+
154173
$this->resultMock = $this->getMock(
155174
DataObject::class,
156175
['checkQtyIncrements', 'getMessage', 'getQuoteMessage', 'getHasError'],
@@ -171,9 +190,11 @@ public function testValidateOutOfStock()
171190
$this->stockRegistryMock->expects($this->at(0))
172191
->method('getStockItem')
173192
->willReturn($this->stockItemMock);
174-
$this->stockItemMock->expects($this->once())
175-
->method('getIsInStock')
176-
->willReturn(false);
193+
194+
$this->stockRegistryMock->expects($this->atLeastOnce())
195+
->method('getStockStatus')
196+
->willReturn($this->stockStatusMock);
197+
177198
$this->quoteItemMock->expects($this->once())
178199
->method('addErrorInfo')
179200
->with(
@@ -203,21 +224,27 @@ public function testValidateInStock()
203224
$this->stockRegistryMock->expects($this->at(0))
204225
->method('getStockItem')
205226
->willReturn($this->stockItemMock);
227+
206228
$this->stockRegistryMock->expects($this->at(1))
207-
->method('getStockItem')
208-
->willReturn($this->parentStockItemMock);
209-
$this->parentStockItemMock->expects($this->once())
210-
->method('getIsInStock')
211-
->willReturn(false);
229+
->method('getStockStatus')
230+
->willReturn($this->stockStatusMock);
231+
212232
$this->quoteItemMock->expects($this->any())
213233
->method('getParentItem')
214234
->willReturn($this->parentItemMock);
215-
$this->stockItemMock->expects($this->once())
216-
->method('getIsInStock')
235+
236+
$this->stockRegistryMock->expects($this->at(2))
237+
->method('getStockStatus')
238+
->willReturn($this->parentStockItemMock);
239+
240+
$this->parentStockItemMock->expects($this->once())
241+
->method('getStockStatus')
242+
->willReturn(false);
243+
244+
$this->stockStatusMock->expects($this->atLeastOnce())
245+
->method('getStockStatus')
217246
->willReturn(true);
218-
$this->stockRegistryMock->expects($this->at(0))
219-
->method('getStockItem')
220-
->willReturn($this->stockItemMock);
247+
221248
$this->quoteItemMock->expects($this->once())
222249
->method('addErrorInfo')
223250
->with(
@@ -250,15 +277,18 @@ public function testValidateWithOptions()
250277
$this->stockRegistryMock->expects($this->at(0))
251278
->method('getStockItem')
252279
->willReturn($this->stockItemMock);
280+
$this->stockRegistryMock->expects($this->at(1))
281+
->method('getStockStatus')
282+
->willReturn($this->stockStatusMock);
253283
$options = [$optionMock];
254284
$this->createInitialStub(1);
255285
$this->setUpStubForQuantity(1, true);
256286
$this->setUpStubForRemoveError();
257287
$this->parentStockItemMock->expects($this->any())
258-
->method('getIsInStock')
288+
->method('getStockStatus')
259289
->willReturn(true);
260-
$this->stockItemMock->expects($this->once())
261-
->method('getIsInStock')
290+
$this->stockStatusMock->expects($this->once())
291+
->method('getStockStatus')
262292
->willReturn(true);
263293
$this->quoteItemMock->expects($this->any())
264294
->method('getQtyOptions')
@@ -285,15 +315,18 @@ public function testValidateWithOptionsAndError()
285315
$this->stockRegistryMock->expects($this->at(0))
286316
->method('getStockItem')
287317
->willReturn($this->stockItemMock);
318+
$this->stockRegistryMock->expects($this->at(1))
319+
->method('getStockStatus')
320+
->willReturn($this->stockStatusMock);
288321
$options = [$optionMock];
289322
$this->createInitialStub(1);
290323
$this->setUpStubForQuantity(1, true);
291324
$this->setUpStubForRemoveError();
292325
$this->parentStockItemMock->expects($this->any())
293-
->method('getIsInStock')
326+
->method('getStockStatus')
294327
->willReturn(true);
295-
$this->stockItemMock->expects($this->once())
296-
->method('getIsInStock')
328+
$this->stockStatusMock->expects($this->once())
329+
->method('getStockStatus')
297330
->willReturn(true);
298331
$this->quoteItemMock->expects($this->any())
299332
->method('getQtyOptions')
@@ -321,11 +354,14 @@ public function testRemoveError()
321354
$this->stockRegistryMock->expects($this->at(0))
322355
->method('getStockItem')
323356
->willReturn($this->stockItemMock);
357+
$this->stockRegistryMock->expects($this->at(1))
358+
->method('getStockStatus')
359+
->willReturn($this->stockStatusMock);
324360
$this->quoteItemMock->expects($this->any())
325361
->method('getParentItem')
326362
->willReturn($this->parentItemMock);
327-
$this->stockItemMock->expects($this->once())
328-
->method('getIsInStock')
363+
$this->stockStatusMock->expects($this->once())
364+
->method('getStockStatus')
329365
->willReturn(true);
330366
$this->quoteItemMock->expects($this->never())
331367
->method('addErrorInfo');

app/code/Magento/GoogleAnalytics/Block/Ga.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ public function getOrdersTrackingCode()
112112
$result[] = "ga('require', 'ec', 'ec.js');";
113113

114114
foreach ($collection as $order) {
115-
if ($order->getIsVirtual()) {
116-
$address = $order->getBillingAddress();
117-
} else {
118-
$address = $order->getShippingAddress();
119-
}
120-
121115
foreach ($order->getAllVisibleItems() as $item) {
122116
$result[] = sprintf(
123117
"ga('ec:addProduct', {

0 commit comments

Comments
 (0)