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
6 namespace Magento\Bundle\Model;
7 
19 {
23  const KEY_OPTION_ID = 'option_id';
24  const KEY_TITLE = 'title';
25  const KEY_REQUIRED = 'required';
26  const KEY_TYPE = 'type';
27  const KEY_POSITION = 'position';
28  const KEY_SKU = 'sku';
29  const KEY_PRODUCT_LINKS = 'product_links';
33  protected $defaultSelection = null;
34 
40  protected function _construct()
41  {
42  $this->_init(\Magento\Bundle\Model\ResourceModel\Option::class);
43  parent::_construct();
44  }
45 
52  public function addSelection(\Magento\Catalog\Model\Product $selection)
53  {
54  if (!$this->hasData('selections')) {
55  $this->setData('selections', []);
56  }
57  $selections = $this->getData('selections');
58  $selections[] = $selection;
59  $this->setSelections($selections);
60  }
61 
67  public function isSaleable()
68  {
69  $saleable = false;
70  $selections = $this->getSelections();
71  if ($selections) {
72  foreach ($selections as $selection) {
73  if ($selection->isSaleable()) {
74  $saleable = true;
75  break;
76  }
77  }
78  }
79  return $saleable;
80  }
81 
87  public function getDefaultSelection()
88  {
89  if (!$this->defaultSelection && $this->getSelections()) {
90  foreach ($this->getSelections() as $selection) {
91  if ($selection->getIsDefault()) {
92  $this->defaultSelection = $selection;
93  break;
94  }
95  }
96  }
98  }
99 
105  public function isMultiSelection()
106  {
107  return $this->getType() == 'checkbox' || $this->getType() == 'multi';
108  }
109 
118  {
119  return $this->_getResource()->getSearchableData($productId, $storeId);
120  }
121 
128  public function getSelectionById($selectionId)
129  {
130  $foundSelection = null;
131  foreach ($this->getSelections() as $selection) {
132  if ($selection->getSelectionId() == $selectionId) {
133  $foundSelection = $selection;
134  break;
135  }
136  }
137  return $foundSelection;
138  }
139 
140  //@codeCoverageIgnoreStart
141 
145  public function getOptionId()
146  {
147  return $this->getData(self::KEY_OPTION_ID);
148  }
149 
153  public function getTitle()
154  {
155  return $this->getData(self::KEY_TITLE);
156  }
157 
161  public function getRequired()
162  {
163  return $this->getData(self::KEY_REQUIRED);
164  }
165 
169  public function getType()
170  {
171  return $this->getData(self::KEY_TYPE);
172  }
173 
177  public function getPosition()
178  {
179  return $this->getData(self::KEY_POSITION);
180  }
181 
185  public function getSku()
186  {
187  return $this->getData(self::KEY_SKU);
188  }
189 
193  public function getProductLinks()
194  {
195  return $this->getData(self::KEY_PRODUCT_LINKS);
196  }
197 
204  public function setOptionId($optionId)
205  {
206  return $this->setData(self::KEY_OPTION_ID, $optionId);
207  }
208 
215  public function setTitle($title)
216  {
217  return $this->setData(self::KEY_TITLE, $title);
218  }
219 
226  public function setRequired($required)
227  {
228  return $this->setData(self::KEY_REQUIRED, $required);
229  }
230 
237  public function setType($type)
238  {
239  return $this->setData(self::KEY_TYPE, $type);
240  }
241 
248  public function setPosition($position)
249  {
250  return $this->setData(self::KEY_POSITION, $position);
251  }
252 
259  public function setSku($sku)
260  {
261  return $this->setData(self::KEY_SKU, $sku);
262  }
263 
270  public function setProductLinks(array $productLinks = null)
271  {
272  return $this->setData(self::KEY_PRODUCT_LINKS, $productLinks);
273  }
274 
280  public function getExtensionAttributes()
281  {
282  return $this->_getExtensionAttributes();
283  }
284 
291  public function setExtensionAttributes(\Magento\Bundle\Api\Data\OptionExtensionInterface $extensionAttributes)
292  {
293  return $this->_setExtensionAttributes($extensionAttributes);
294  }
295 
296  //@codeCoverageIgnoreEnd
297 }
$title
Definition: default.phtml:14
getSearchableData($productId, $storeId)
Definition: Option.php:117
setProductLinks(array $productLinks=null)
Definition: Option.php:270
addSelection(\Magento\Catalog\Model\Product $selection)
Definition: Option.php:52
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
getSelectionById($selectionId)
Definition: Option.php:128
$type
Definition: item.phtml:13
setExtensionAttributes(\Magento\Bundle\Api\Data\OptionExtensionInterface $extensionAttributes)
Definition: Option.php:291
$required
Definition: wrapper.phtml:8