Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Option Class Reference
Inheritance diagram for Option:
AbstractExtensibleModel OptionInterface AbstractModel CustomAttributesDataInterface ExtensibleDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 addSelection (\Magento\Catalog\Model\Product $selection)
 
 isSaleable ()
 
 getDefaultSelection ()
 
 isMultiSelection ()
 
 getSearchableData ($productId, $storeId)
 
 getSelectionById ($selectionId)
 
 getOptionId ()
 
 getTitle ()
 
 getRequired ()
 
 getType ()
 
 getPosition ()
 
 getSku ()
 
 getProductLinks ()
 
 setOptionId ($optionId)
 
 setTitle ($title)
 
 setRequired ($required)
 
 setType ($type)
 
 setPosition ($position)
 
 setSku ($sku)
 
 setProductLinks (array $productLinks=null)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Bundle\Api\Data\OptionExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const KEY_OPTION_ID = 'option_id'
 
const KEY_TITLE = 'title'
 
const KEY_REQUIRED = 'required'
 
const KEY_TYPE = 'type'
 
const KEY_POSITION = 'position'
 
const KEY_SKU = 'sku'
 
const KEY_PRODUCT_LINKS = 'product_links'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $defaultSelection = null
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Bundle Option Model

@api @method int getParentId() @method null|\Magento\Catalog\Model\Product[] getSelections() @method Option setParentId(int $value)

Since
100.0.2

Definition at line 17 of file Option.php.

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize resource model

Returns
void

Definition at line 40 of file Option.php.

41  {
42  $this->_init(\Magento\Bundle\Model\ResourceModel\Option::class);
43  parent::_construct();
44  }

◆ addSelection()

addSelection ( \Magento\Catalog\Model\Product  $selection)

Add selection to option

Parameters
\Magento\Catalog\Model\Product$selection
Returns
void

Definition at line 52 of file Option.php.

53  {
54  if (!$this->hasData('selections')) {
55  $this->setData('selections', []);
56  }
57  $selections = $this->getData('selections');
58  $selections[] = $selection;
59  $this->setSelections($selections);
60  }

◆ getDefaultSelection()

getDefaultSelection ( )

Retrieve default Selection object

Returns
\Magento\Catalog\Model\Product|null

Definition at line 87 of file Option.php.

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  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

{Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Bundle\Api\Data\OptionExtensionInterface|null
}

Returns
\Magento\Bundle\Api\Data\OptionExtensionInterface|null

Implements OptionInterface.

Definition at line 280 of file Option.php.

◆ getOptionId()

getOptionId ( )

{Get option id

Returns
int|null
}

Implements OptionInterface.

Definition at line 145 of file Option.php.

146  {
147  return $this->getData(self::KEY_OPTION_ID);
148  }

◆ getPosition()

getPosition ( )

{Get option position

Returns
int|null
}

Implements OptionInterface.

Definition at line 177 of file Option.php.

178  {
179  return $this->getData(self::KEY_POSITION);
180  }

◆ getProductLinks()

getProductLinks ( )

{Get product links

Returns
\Magento\Bundle\Api\Data\LinkInterface[]|null
}

Implements OptionInterface.

Definition at line 193 of file Option.php.

194  {
195  return $this->getData(self::KEY_PRODUCT_LINKS);
196  }

◆ getRequired()

getRequired ( )

{Get is required option

Returns
bool|null
}

Implements OptionInterface.

Definition at line 161 of file Option.php.

162  {
163  return $this->getData(self::KEY_REQUIRED);
164  }

◆ getSearchableData()

getSearchableData (   $productId,
  $storeId 
)

Retrieve options searchable data

Parameters
int$productId
int$storeId
Returns
array

Definition at line 117 of file Option.php.

118  {
119  return $this->_getResource()->getSearchableData($productId, $storeId);
120  }

◆ getSelectionById()

getSelectionById (   $selectionId)

Return selection by it's id

Parameters
int$selectionId
Returns
\Magento\Catalog\Model\Product|null

Definition at line 128 of file Option.php.

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  }

◆ getSku()

getSku ( )

{Get product sku

Returns
string|null
}

Implements OptionInterface.

Definition at line 185 of file Option.php.

186  {
187  return $this->getData(self::KEY_SKU);
188  }

◆ getTitle()

getTitle ( )

{Get option title

Returns
string|null
}

Implements OptionInterface.

Definition at line 153 of file Option.php.

154  {
155  return $this->getData(self::KEY_TITLE);
156  }

◆ getType()

getType ( )

{Get input type

Returns
string|null
}

Implements OptionInterface.

Definition at line 169 of file Option.php.

170  {
171  return $this->getData(self::KEY_TYPE);
172  }

◆ isMultiSelection()

isMultiSelection ( )

Check is multi Option selection

Returns
bool

Definition at line 105 of file Option.php.

106  {
107  return $this->getType() == 'checkbox' || $this->getType() == 'multi';
108  }

◆ isSaleable()

isSaleable ( )

Check Is Saleable Option

Returns
bool

Definition at line 67 of file Option.php.

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  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Bundle\Api\Data\OptionExtensionInterface  $extensionAttributes)

{Set an extension attributes object.

Parameters
\Magento\Bundle\Api\Data\OptionExtensionInterface$extensionAttributes
Returns
$this
}

Parameters
\Magento\Bundle\Api\Data\OptionExtensionInterface$extensionAttributes
Returns
$this

Implements OptionInterface.

Definition at line 291 of file Option.php.

292  {
294  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setOptionId()

setOptionId (   $optionId)

Set option id

Parameters
int$optionId
Returns
$this

Implements OptionInterface.

Definition at line 204 of file Option.php.

205  {
206  return $this->setData(self::KEY_OPTION_ID, $optionId);
207  }

◆ setPosition()

setPosition (   $position)

Set option position

Parameters
int$position
Returns
$this

Implements OptionInterface.

Definition at line 248 of file Option.php.

249  {
250  return $this->setData(self::KEY_POSITION, $position);
251  }

◆ setProductLinks()

setProductLinks ( array  $productLinks = null)

Set product links

Parameters

Implements OptionInterface.

Definition at line 270 of file Option.php.

271  {
272  return $this->setData(self::KEY_PRODUCT_LINKS, $productLinks);
273  }

◆ setRequired()

setRequired (   $required)

Set whether option is required

Parameters
bool$required
Returns
$this

Implements OptionInterface.

Definition at line 226 of file Option.php.

227  {
228  return $this->setData(self::KEY_REQUIRED, $required);
229  }
$required
Definition: wrapper.phtml:8

◆ setSku()

setSku (   $sku)

Set product sku

Parameters
string$sku
Returns
$this

Implements OptionInterface.

Definition at line 259 of file Option.php.

260  {
261  return $this->setData(self::KEY_SKU, $sku);
262  }

◆ setTitle()

setTitle (   $title)

Set option title

Parameters
string$title
Returns
$this

Implements OptionInterface.

Definition at line 215 of file Option.php.

216  {
217  return $this->setData(self::KEY_TITLE, $title);
218  }
$title
Definition: default.phtml:14

◆ setType()

setType (   $type)

Set input type

Parameters
string$type
Returns
$this

Implements OptionInterface.

Definition at line 237 of file Option.php.

238  {
239  return $this->setData(self::KEY_TYPE, $type);
240  }
$type
Definition: item.phtml:13

Field Documentation

◆ $defaultSelection

$defaultSelection = null
protected

#- #-

Definition at line 33 of file Option.php.

◆ KEY_OPTION_ID

const KEY_OPTION_ID = 'option_id'

#+ Constants

Definition at line 23 of file Option.php.

◆ KEY_POSITION

const KEY_POSITION = 'position'

Definition at line 27 of file Option.php.

◆ KEY_PRODUCT_LINKS

const KEY_PRODUCT_LINKS = 'product_links'

Definition at line 29 of file Option.php.

◆ KEY_REQUIRED

const KEY_REQUIRED = 'required'

Definition at line 25 of file Option.php.

◆ KEY_SKU

const KEY_SKU = 'sku'

Definition at line 28 of file Option.php.

◆ KEY_TITLE

const KEY_TITLE = 'title'

Definition at line 24 of file Option.php.

◆ KEY_TYPE

const KEY_TYPE = 'type'

Definition at line 26 of file Option.php.


The documentation for this class was generated from the following file: