Skip to content

Commit 9a8adb9

Browse files
Merge branch 'develop' of https://github.com/magento/magento2ce into MAGETWO-69556
2 parents 46ae379 + 70c8c2e commit 9a8adb9

File tree

82 files changed

+3033
-1601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3033
-1601
lines changed

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

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,13 +2509,15 @@ public function setTypeId($typeId)
25092509
/**
25102510
* {@inheritdoc}
25112511
*
2512-
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface|null
2512+
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface
25132513
*/
25142514
public function getExtensionAttributes()
25152515
{
25162516
$extensionAttributes = $this->_getExtensionAttributes();
2517-
if (!$extensionAttributes) {
2518-
return $this->extensionAttributesFactory->create(\Magento\Catalog\Api\Data\ProductInterface::class);
2517+
if (null === $extensionAttributes) {
2518+
/** @var \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes */
2519+
$extensionAttributes = $this->extensionAttributesFactory->create(ProductInterface::class);
2520+
$this->setExtensionAttributes($extensionAttributes);
25192521
}
25202522
return $extensionAttributes;
25212523
}
@@ -2639,4 +2641,68 @@ public function setAssociatedProductIds(array $productIds)
26392641
$this->getExtensionAttributes()->setConfigurableProductLinks($productIds);
26402642
return $this;
26412643
}
2644+
2645+
/**
2646+
* Get quantity and stock status data
2647+
*
2648+
* @return array|null
2649+
*
2650+
* @deprecated as Product model shouldn't be responsible for stock status
2651+
* @see StockItemInterface when you want to change the stock data
2652+
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
2653+
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
2654+
*/
2655+
public function getQuantityAndStockStatus()
2656+
{
2657+
return $this->getData('quantity_and_stock_status');
2658+
}
2659+
2660+
/**
2661+
* Set quantity and stock status data
2662+
*
2663+
* @param array $quantityAndStockStatusData
2664+
* @return $this
2665+
*
2666+
* @deprecated as Product model shouldn't be responsible for stock status
2667+
* @see StockItemInterface when you want to change the stock data
2668+
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
2669+
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
2670+
*/
2671+
public function setQuantityAndStockStatus($quantityAndStockStatusData)
2672+
{
2673+
$this->setData('quantity_and_stock_status', $quantityAndStockStatusData);
2674+
return $this;
2675+
}
2676+
2677+
/**
2678+
* Get stock data
2679+
*
2680+
* @return array|null
2681+
*
2682+
* @deprecated as Product model shouldn't be responsible for stock status
2683+
* @see StockItemInterface when you want to change the stock data
2684+
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
2685+
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
2686+
*/
2687+
public function getStockData()
2688+
{
2689+
return $this->getData('stock_data');
2690+
}
2691+
2692+
/**
2693+
* Set stock data
2694+
*
2695+
* @param array $stockData
2696+
* @return $this
2697+
*
2698+
* @deprecated as Product model shouldn't be responsible for stock status
2699+
* @see StockItemInterface when you want to change the stock data
2700+
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
2701+
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
2702+
*/
2703+
public function setStockData($stockData)
2704+
{
2705+
$this->setData('stock_data', $stockData);
2706+
return $this;
2707+
}
26422708
}

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Stock.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Catalog\Model\Product\Attribute\Backend;
87

98
use Magento\Catalog\Model\Product;
109

1110
/**
1211
* Quantity and Stock Status attribute processing
12+
*
13+
* @deprecated as this attribute should be removed
14+
* @see StockItemInterface when you want to change the stock data
15+
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
16+
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
1317
*/
1418
class Stock extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
1519
{
@@ -47,25 +51,6 @@ public function afterLoad($object)
4751
return parent::afterLoad($object);
4852
}
4953

50-
/**
51-
* Prepare inventory data from custom attribute
52-
*
53-
* @param Product $object
54-
* @return void
55-
*/
56-
public function beforeSave($object)
57-
{
58-
$stockData = $object->getData($this->getAttribute()->getAttributeCode());
59-
if (isset($stockData['qty']) && $stockData['qty'] === '') {
60-
$stockData['qty'] = null;
61-
}
62-
if ($object->getStockData() !== null && $stockData !== null) {
63-
$object->setStockData(array_replace((array)$object->getStockData(), (array)$stockData));
64-
}
65-
$object->unsetData($this->getAttribute()->getAttributeCode());
66-
parent::beforeSave($object);
67-
}
68-
6954
/**
7055
* Validate
7156
*

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public function copy(\Magento\Catalog\Model\Product $product)
5959

6060
/** @var \Magento\Catalog\Model\Product $duplicate */
6161
$duplicate = $this->productFactory->create();
62-
$duplicate->setData($product->getData());
62+
$productData = $product->getData();
63+
$productData = $this->removeStockItem($productData);
64+
$duplicate->setData($productData);
6365
$duplicate->setOptions([]);
6466
$duplicate->setIsDuplicate(true);
6567
$duplicate->setOriginalLinkId($product->getData($metadata->getLinkField()));
@@ -116,4 +118,21 @@ private function getMetadataPool()
116118
}
117119
return $this->metadataPool;
118120
}
121+
122+
/**
123+
* Remove stock item
124+
*
125+
* @param array $productData
126+
* @return array
127+
*/
128+
private function removeStockItem(array $productData)
129+
{
130+
if (isset($productData[ProductInterface::EXTENSION_ATTRIBUTES_KEY])) {
131+
$extensionAttributes = $productData[ProductInterface::EXTENSION_ATTRIBUTES_KEY];
132+
if (null !== $extensionAttributes->getStockItem()) {
133+
$extensionAttributes->setData('stock_item', null);
134+
}
135+
}
136+
return $productData;
137+
}
119138
}

0 commit comments

Comments
 (0)