Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Option.php
Go to the documentation of this file.
1 <?php
7 
11 
20  \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface
21 {
25  protected $_item;
26 
30  protected $_product;
31 
35  protected $productRepository;
36 
45  public function __construct(
46  \Magento\Framework\Model\Context $context,
47  \Magento\Framework\Registry $registry,
49  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
50  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
51  array $data = []
52  ) {
53  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
54  $this->productRepository = $productRepository;
55  }
56 
62  protected function _construct()
63  {
64  $this->_init(\Magento\Wishlist\Model\ResourceModel\Item\Option::class);
65  }
66 
72  protected function _hasModelChanged()
73  {
74  if (!$this->hasDataChanges()) {
75  return false;
76  }
77 
78  return $this->_getResource()->hasDataChanged($this);
79  }
80 
87  public function setItem($item)
88  {
89  $this->setWishlistItemId($item->getId());
90  $this->_item = $item;
91  return $this;
92  }
93 
99  public function getItem()
100  {
101  return $this->_item;
102  }
103 
110  public function setProduct($product)
111  {
112  $this->setProductId($product->getId());
113  $this->_product = $product;
114  return $this;
115  }
116 
122  public function getProduct()
123  {
124  //In some cases product_id is present instead product instance
125  if (null === $this->_product && $this->getProductId()) {
126  $this->_product = $this->productRepository->getById($this->getProductId());
127  }
128  return $this->_product;
129  }
130 
136  public function getValue()
137  {
138  return $this->_getData('value');
139  }
140 
146  public function beforeSave()
147  {
148  if ($this->getItem()) {
149  $this->setWishlistItemId($this->getItem()->getId());
150  }
151  return parent::beforeSave();
152  }
153 
159  public function __clone()
160  {
161  $this->setId(null);
162  $this->_item = null;
163  return $this;
164  }
165 }
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ProductRepositoryInterface $productRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Option.php:45