Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/magento/magento2ce into …
Browse files Browse the repository at this point in the history
…MAGETWO-69556
  • Loading branch information
shiftedreality committed Jun 9, 2017
2 parents 46ae379 + 70c8c2e commit 9a8adb9
Show file tree
Hide file tree
Showing 82 changed files with 3,033 additions and 1,601 deletions.
72 changes: 69 additions & 3 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2509,13 +2509,15 @@ public function setTypeId($typeId)
/**
* {@inheritdoc}
*
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface|null
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface
*/
public function getExtensionAttributes()
{
$extensionAttributes = $this->_getExtensionAttributes();
if (!$extensionAttributes) {
return $this->extensionAttributesFactory->create(\Magento\Catalog\Api\Data\ProductInterface::class);
if (null === $extensionAttributes) {
/** @var \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes */
$extensionAttributes = $this->extensionAttributesFactory->create(ProductInterface::class);
$this->setExtensionAttributes($extensionAttributes);
}
return $extensionAttributes;
}
Expand Down Expand Up @@ -2639,4 +2641,68 @@ public function setAssociatedProductIds(array $productIds)
$this->getExtensionAttributes()->setConfigurableProductLinks($productIds);
return $this;
}

/**
* Get quantity and stock status data
*
* @return array|null
*
* @deprecated as Product model shouldn't be responsible for stock status
* @see StockItemInterface when you want to change the stock data
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
*/
public function getQuantityAndStockStatus()
{
return $this->getData('quantity_and_stock_status');
}

/**
* Set quantity and stock status data
*
* @param array $quantityAndStockStatusData
* @return $this
*
* @deprecated as Product model shouldn't be responsible for stock status
* @see StockItemInterface when you want to change the stock data
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
*/
public function setQuantityAndStockStatus($quantityAndStockStatusData)
{
$this->setData('quantity_and_stock_status', $quantityAndStockStatusData);
return $this;
}

/**
* Get stock data
*
* @return array|null
*
* @deprecated as Product model shouldn't be responsible for stock status
* @see StockItemInterface when you want to change the stock data
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
*/
public function getStockData()
{
return $this->getData('stock_data');
}

/**
* Set stock data
*
* @param array $stockData
* @return $this
*
* @deprecated as Product model shouldn't be responsible for stock status
* @see StockItemInterface when you want to change the stock data
* @see StockStatusInterface when you want to read the stock data for representation layer (storefront)
* @see StockItemRepositoryInterface::save as extension point for customization of saving process
*/
public function setStockData($stockData)
{
$this->setData('stock_data', $stockData);
return $this;
}
}
25 changes: 5 additions & 20 deletions app/code/Magento/Catalog/Model/Product/Attribute/Backend/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Model\Product\Attribute\Backend;

use Magento\Catalog\Model\Product;

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

/**
* Prepare inventory data from custom attribute
*
* @param Product $object
* @return void
*/
public function beforeSave($object)
{
$stockData = $object->getData($this->getAttribute()->getAttributeCode());
if (isset($stockData['qty']) && $stockData['qty'] === '') {
$stockData['qty'] = null;
}
if ($object->getStockData() !== null && $stockData !== null) {
$object->setStockData(array_replace((array)$object->getStockData(), (array)$stockData));
}
$object->unsetData($this->getAttribute()->getAttributeCode());
parent::beforeSave($object);
}

/**
* Validate
*
Expand Down
21 changes: 20 additions & 1 deletion app/code/Magento/Catalog/Model/Product/Copier.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function copy(\Magento\Catalog\Model\Product $product)

/** @var \Magento\Catalog\Model\Product $duplicate */
$duplicate = $this->productFactory->create();
$duplicate->setData($product->getData());
$productData = $product->getData();
$productData = $this->removeStockItem($productData);
$duplicate->setData($productData);
$duplicate->setOptions([]);
$duplicate->setIsDuplicate(true);
$duplicate->setOriginalLinkId($product->getData($metadata->getLinkField()));
Expand Down Expand Up @@ -116,4 +118,21 @@ private function getMetadataPool()
}
return $this->metadataPool;
}

/**
* Remove stock item
*
* @param array $productData
* @return array
*/
private function removeStockItem(array $productData)
{
if (isset($productData[ProductInterface::EXTENSION_ATTRIBUTES_KEY])) {
$extensionAttributes = $productData[ProductInterface::EXTENSION_ATTRIBUTES_KEY];
if (null !== $extensionAttributes->getStockItem()) {
$extensionAttributes->setData('stock_item', null);
}
}
return $productData;
}
}
Loading

0 comments on commit 9a8adb9

Please sign in to comment.