Skip to content

Commit 59714b8

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into bugfix
2 parents a661aa2 + 3fbefa4 commit 59714b8

File tree

14 files changed

+183
-213
lines changed

14 files changed

+183
-213
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
170170
$product->lockAttribute('media');
171171
}
172172

173-
if ($this->storeManager->hasSingleStore() && empty($product->getWebsiteIds())) {
174-
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
175-
}
176-
177173
/**
178174
* Check "Use Default Value" checkboxes values
179175
*/

app/code/Magento/Catalog/Model/ResourceModel/Product.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ public function delete($object)
315315
*/
316316
protected function _saveWebsiteIds($product)
317317
{
318-
if (empty(array_diff($product->getWebsiteIds(), [0]))) {
319-
$product->setWebsiteIds([1]);
318+
if ($this->_storeManager->isSingleStoreMode()) {
319+
$id = $this->_storeManager->getDefaultStoreView()->getWebsiteId();
320+
$product->setWebsiteIds([$id]);
320321
}
321322
$websiteIds = $product->getWebsiteIds();
322323

app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
5656
/**
5757
* @var MetadataPool
5858
*/
59-
protected $metadataPool;
59+
private $metadataPool;
6060

6161
/**
6262
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
@@ -219,7 +219,8 @@ public function addProductFilter($products)
219219
if (!is_array($products)) {
220220
$products = [$products];
221221
}
222-
$this->getSelect()->where('links.product_id IN (?)', $products);
222+
$identifierField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getIdentifierField();
223+
$this->getSelect()->where("product_entity_table.$identifierField IN (?)", $products);
223224
$this->_hasLinkFilter = true;
224225
}
225226

@@ -258,6 +259,7 @@ protected function _beforeLoad()
258259
{
259260
if ($this->getLinkModel()) {
260261
$this->_joinLinks();
262+
$this->joinProductsToLinks();
261263
}
262264
return parent::_beforeLoad();
263265
}
@@ -423,12 +425,28 @@ public function addLinkAttributeToFilter($code, $condition)
423425
/**
424426
* Get MetadataPool instance
425427
* @return MetadataPool
428+
* @deprecated
426429
*/
427-
protected function getMetadataPool()
430+
private function getMetadataPool()
428431
{
429432
if (!$this->metadataPool) {
430433
$this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
431434
}
432435
return $this->metadataPool;
433436
}
437+
438+
/**
439+
* Join Product To Links
440+
* @return void
441+
*/
442+
private function joinProductsToLinks()
443+
{
444+
if ($this->_hasLinkFilter) {
445+
$metaDataPool = $this->getMetadataPool()->getMetadata(ProductInterface::class);
446+
$linkField = $metaDataPool->getLinkField();
447+
$entityTable = $metaDataPool->getEntityTable();
448+
$this->getSelect()
449+
->join(['product_entity_table' => $entityTable], "links.product_id = product_entity_table.$linkField", []);
450+
}
451+
}
434452
}

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,6 @@ protected function setUp()
196196
*/
197197
public function testInitialize()
198198
{
199-
$this->websiteMock->expects($this->once())
200-
->method('getId')
201-
->willReturn($this->websiteId);
202-
$this->storeMock->expects($this->once())
203-
->method('getWebsite')
204-
->willReturn($this->websiteMock);
205-
$this->storeManagerMock->expects($this->once())
206-
->method('getStore')
207-
->with(true)
208-
->willReturn($this->storeMock);
209199
$this->customOptionMock->expects($this->once())
210200
->method('setProductSku');
211201
$this->customOptionMock->expects($this->once())
@@ -270,9 +260,6 @@ public function testInitialize()
270260
->method('filter')
271261
->with(['stock_data'])
272262
->willReturn(['stock_data']);
273-
$this->storeManagerMock->expects($this->once())
274-
->method('hasSingleStore')
275-
->willReturn(true);
276263
$this->productMock->expects($this->once())
277264
->method('isLockedAttribute')
278265
->with('media')
@@ -300,9 +287,6 @@ public function testInitialize()
300287
$this->productMock->expects($this->once())
301288
->method('getSku')
302289
->willReturn('sku');
303-
$this->productMock->expects($this->once())
304-
->method('setWebsiteIds')
305-
->with([$this->websiteId]);
306290
$this->productMock->expects($this->any())
307291
->method('getOptionsReadOnly')
308292
->willReturn(false);

app/code/Magento/Downloadable/etc/di.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
<type name="Magento\Catalog\Model\Product\CartConfiguration">
1515
<plugin name="Downloadable" type="Magento\Downloadable\Model\Product\CartConfiguration\Plugin\Downloadable" />
1616
</type>
17+
<virtualType name="context_for_downloadable" type="Magento\Framework\View\Element\Template\Context">
18+
<arguments>
19+
<argument name="urlBuilder" xsi:type="object">Magento\Framework\Url</argument>
20+
</arguments>
21+
</virtualType>
22+
<type name="Magento\Downloadable\Block\Sales\Order\Email\Items\Order\Downloadable">
23+
<arguments>
24+
<argument name="context" xsi:type="object">context_for_downloadable</argument>
25+
</arguments>
26+
</type>
1727
<type name="Magento\Catalog\Model\Product\TypeTransitionManager">
1828
<plugin name="downloadable_product_transition" type="Magento\Downloadable\Model\Product\TypeTransitionManager\Plugin\Downloadable" />
1929
<arguments>

app/code/Magento/Sales/Model/Order/Creditmemo/Item.php

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,16 @@ public function setOrderItem(\Magento\Sales\Model\Order\Item $item)
127127
public function getOrderItem()
128128
{
129129
if ($this->_orderItem === null) {
130-
$this->_orderItem = $this->getOrderItemWithoutCaching();
130+
if ($this->getCreditmemo()) {
131+
$orderItem = $this->getCreditmemo()->getOrder()->getItemById($this->getOrderItemId());
132+
} else {
133+
$orderItem = $this->_orderItemFactory->create()->load($this->getOrderItemId());
134+
}
135+
$this->_orderItem = $orderItem;
131136
}
132137
return $this->_orderItem;
133138
}
134139

135-
/**
136-
* Retrieve order item instance without set it to property.
137-
* It is need for ability to process setQty on api when credit memo and order has not built yet.
138-
*
139-
* @return \Magento\Sales\Model\Order\Item
140-
*/
141-
private function getOrderItemWithoutCaching()
142-
{
143-
if ($this->getCreditmemo()) {
144-
$orderItem = $this->getCreditmemo()->getOrder()->getItemById($this->getOrderItemId());
145-
} else {
146-
$orderItem = $this->_orderItemFactory->create()->load($this->getOrderItemId());
147-
}
148-
149-
return $orderItem;
150-
}
151-
152140
/**
153141
* Checks if quantity available for refund
154142
*
@@ -164,26 +152,12 @@ private function isQtyAvailable($qty, \Magento\Sales\Model\Order\Item $orderItem
164152
/**
165153
* Declare qty
166154
*
167-
* @param float $qty
155+
* @param float $qty
168156
* @return $this
169-
* @throws \Magento\Framework\Exception\LocalizedException
170157
*/
171158
public function setQty($qty)
172159
{
173-
$orderItem = $this->getOrderItemWithoutCaching();
174-
if ($orderItem->getIsQtyDecimal()) {
175-
$qty = (double)$qty;
176-
} else {
177-
$qty = (int)$qty;
178-
}
179-
$qty = $qty > 0 ? $qty : 0;
180-
if ($this->isQtyAvailable($qty, $orderItem)) {
181-
$this->setData('qty', $qty);
182-
} else {
183-
throw new \Magento\Framework\Exception\LocalizedException(
184-
__('We found an invalid quantity to refund item "%1".', $this->getName())
185-
);
186-
}
160+
$this->setData(CreditmemoItemInterface::QTY, $qty);
187161
return $this;
188162
}
189163

@@ -196,7 +170,8 @@ public function register()
196170
{
197171
$orderItem = $this->getOrderItem();
198172

199-
$orderItem->setQtyRefunded($orderItem->getQtyRefunded() + $this->getQty());
173+
$qty = $this->processQty();
174+
$orderItem->setQtyRefunded($orderItem->getQtyRefunded() + $qty);
200175
$orderItem->setTaxRefunded($orderItem->getTaxRefunded() + $this->getTaxAmount());
201176
$orderItem->setBaseTaxRefunded($orderItem->getBaseTaxRefunded() + $this->getBaseTaxAmount());
202177
$orderItem->setDiscountTaxCompensationRefunded(
@@ -213,22 +188,46 @@ public function register()
213188
return $this;
214189
}
215190

191+
/**
192+
* @return int|float
193+
* @throws \Magento\Framework\Exception\LocalizedException
194+
*/
195+
private function processQty()
196+
{
197+
$orderItem = $this->getOrderItem();
198+
$qty = $this->getQty();
199+
if ($orderItem->getIsQtyDecimal()) {
200+
$qty = (double)$qty;
201+
} else {
202+
$qty = (int)$qty;
203+
}
204+
$qty = $qty > 0 ? $qty : 0;
205+
if ($this->isQtyAvailable($qty, $orderItem)) {
206+
return $qty;
207+
} else {
208+
throw new \Magento\Framework\Exception\LocalizedException(
209+
__('We found an invalid quantity to refund item "%1".', $this->getName())
210+
);
211+
}
212+
}
213+
216214
/**
217215
* @return $this
218216
*/
219217
public function cancel()
220218
{
221-
$this->getOrderItem()->setQtyRefunded($this->getOrderItem()->getQtyRefunded() - $this->getQty());
219+
$qty = $this->processQty();
220+
$this->getOrderItem()->setQtyRefunded($this->getOrderItem()->getQtyRefunded() - $qty);
222221
$this->getOrderItem()->setTaxRefunded(
223222
$this->getOrderItem()->getTaxRefunded() -
224223
$this->getOrderItem()->getBaseTaxAmount() *
225-
$this->getQty() /
224+
$qty /
226225
$this->getOrderItem()->getQtyOrdered()
227226
);
228227
$this->getOrderItem()->setDiscountTaxCompensationRefunded(
229228
$this->getOrderItem()->getDiscountTaxCompensationRefunded() -
230229
$this->getOrderItem()->getDiscountTaxCompensationAmount() *
231-
$this->getQty() /
230+
$qty /
232231
$this->getOrderItem()->getQtyOrdered()
233232
);
234233
return $this;
@@ -250,21 +249,22 @@ public function calcRowTotal()
250249
$rowTotalInclTax = $orderItem->getRowTotalInclTax();
251250
$baseRowTotalInclTax = $orderItem->getBaseRowTotalInclTax();
252251

253-
if (!$this->isLast() && $orderItemQtyInvoiced > 0 && $this->getQty() >= 0) {
252+
$qty = $this->processQty();
253+
if (!$this->isLast() && $orderItemQtyInvoiced > 0 && $qty >= 0) {
254254
$availableQty = $orderItemQtyInvoiced - $orderItem->getQtyRefunded();
255-
$rowTotal = $creditmemo->roundPrice($rowTotal / $availableQty * $this->getQty());
256-
$baseRowTotal = $creditmemo->roundPrice($baseRowTotal / $availableQty * $this->getQty(), 'base');
255+
$rowTotal = $creditmemo->roundPrice($rowTotal / $availableQty * $qty);
256+
$baseRowTotal = $creditmemo->roundPrice($baseRowTotal / $availableQty * $qty, 'base');
257257
}
258258
$this->setRowTotal($rowTotal);
259259
$this->setBaseRowTotal($baseRowTotal);
260260

261261
if ($rowTotalInclTax && $baseRowTotalInclTax) {
262262
$orderItemQty = $orderItem->getQtyOrdered();
263263
$this->setRowTotalInclTax(
264-
$creditmemo->roundPrice($rowTotalInclTax / $orderItemQty * $this->getQty(), 'including')
264+
$creditmemo->roundPrice($rowTotalInclTax / $orderItemQty * $qty, 'including')
265265
);
266266
$this->setBaseRowTotalInclTax(
267-
$creditmemo->roundPrice($baseRowTotalInclTax / $orderItemQty * $this->getQty(), 'including_base')
267+
$creditmemo->roundPrice($baseRowTotalInclTax / $orderItemQty * $qty, 'including_base')
268268
);
269269
}
270270
return $this;
@@ -278,7 +278,8 @@ public function calcRowTotal()
278278
public function isLast()
279279
{
280280
$orderItem = $this->getOrderItem();
281-
if ((string)(double)$this->getQty() == (string)(double)$orderItem->getQtyToRefund()) {
281+
$qty = $this->processQty();
282+
if ((string)(double)$qty == (string)(double)$orderItem->getQtyToRefund()) {
282283
return true;
283284
}
284285
return false;

0 commit comments

Comments
 (0)