5
5
*/
6
6
namespace Magento \Wishlist \Model \Item ;
7
7
8
- /**
9
- * Item option model
10
- */
11
8
use Magento \Catalog \Model \Product ;
12
9
use Magento \Wishlist \Model \Item ;
10
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
13
11
12
+ /**
13
+ * Item option model
14
+ * @method int getProductId()
15
+ */
14
16
class Option extends \Magento \Framework \Model \AbstractModel implements
15
17
\Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface
16
18
{
@@ -20,10 +22,35 @@ class Option extends \Magento\Framework\Model\AbstractModel implements
20
22
protected $ _item ;
21
23
22
24
/**
23
- * @var Product
25
+ * @var Product|null
24
26
*/
25
27
protected $ _product ;
26
28
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
+
27
54
/**
28
55
* Initialize resource model
29
56
*
@@ -91,6 +118,10 @@ public function setProduct($product)
91
118
*/
92
119
public function getProduct ()
93
120
{
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
+ }
94
125
return $ this ->_product ;
95
126
}
96
127
0 commit comments