Skip to content

Commit 16fea62

Browse files
author
Michail Slabko
committed
MAGETWO-44542: It is impossible to Reorder an Order created by Sample Data
1 parent dc3aee6 commit 16fea62

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

app/code/Magento/Wishlist/Model/Item/Option.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*/
66
namespace Magento\Wishlist\Model\Item;
77

8-
/**
9-
* Item option model
10-
*/
118
use Magento\Catalog\Model\Product;
129
use Magento\Wishlist\Model\Item;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
1311

12+
/**
13+
* Item option model
14+
* @method int getProductId()
15+
*/
1416
class Option extends \Magento\Framework\Model\AbstractModel implements
1517
\Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface
1618
{
@@ -20,10 +22,35 @@ class Option extends \Magento\Framework\Model\AbstractModel implements
2022
protected $_item;
2123

2224
/**
23-
* @var Product
25+
* @var Product|null
2426
*/
2527
protected $_product;
2628

29+
/**
30+
* @var ProductRepositoryInterface
31+
*/
32+
protected $productRepository;
33+
34+
/**
35+
* @param \Magento\Framework\Model\Context $context
36+
* @param \Magento\Framework\Registry $registry
37+
* @param ProductRepositoryInterface $productRepository
38+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
39+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
40+
* @param array $data
41+
*/
42+
public function __construct(
43+
\Magento\Framework\Model\Context $context,
44+
\Magento\Framework\Registry $registry,
45+
ProductRepositoryInterface $productRepository,
46+
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
47+
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
48+
array $data = []
49+
) {
50+
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
51+
$this->productRepository = $productRepository;
52+
}
53+
2754
/**
2855
* Initialize resource model
2956
*
@@ -91,6 +118,10 @@ public function setProduct($product)
91118
*/
92119
public function getProduct()
93120
{
121+
//In some cases product_id is present instead product instance
122+
if (null === $this->_product && $this->getProductId()) {
123+
$this->_product = $this->productRepository->getById($this->getProductId());
124+
}
94125
return $this->_product;
95126
}
96127

0 commit comments

Comments
 (0)