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

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, Option\Value $productOptionValue, \Magento\Catalog\Model\Product\Option\Type\Factory $optionFactory, \Magento\Framework\Stdlib\StringUtils $string, Option\Validator\Pool $validatorPool, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory=null)
 
 addValue (Option\Value $value)
 
 getValueById ($valueId)
 
 hasValues ($type=null)
 
 getValues ()
 
 getValueInstance ()
 
 addOption ($option)
 
 getOptions ()
 
 setOptions ($options)
 
 unsetOptions ()
 
 getProduct ()
 
 setProduct (Product $product=null)
 
 getGroupByType ($type=null)
 
 groupFactory ($type)
 
 beforeSave ()
 
 afterSave ()
 
 getPrice ($flag=false)
 
 deletePrices ($optionId)
 
 deleteTitles ($optionId)
 
 getProductOptions (Product $product)
 
 getValuesCollection ()
 
 getOptionValuesByOptionId ($optionIds, $storeId)
 
 duplicate ($oldProductId, $newProductId)
 
 getSearchableData ($productId, $storeId)
 
 getProductSku ()
 
 getOptionId ()
 
 getTitle ()
 
 getType ()
 
 getSortOrder ()
 
 getIsRequire ()
 
 getPriceType ()
 
 getSku ()
 
 getFileExtension ()
 
 getMaxCharacters ()
 
 getImageSizeX ()
 
 getImageSizeY ()
 
 setProductSku ($productSku)
 
 setOptionId ($optionId)
 
 setTitle ($title)
 
 setType ($type)
 
 setSortOrder ($sortOrder)
 
 setIsRequire ($isRequired)
 
 setPrice ($price)
 
 setPriceType ($priceType)
 
 setSku ($sku)
 
 setFileExtension ($fileExtension)
 
 setMaxCharacters ($maxCharacters)
 
 setImageSizeX ($imageSizeX)
 
 setImageSizeY ($imageSizeY)
 
 setValues (array $values=null)
 
 getExtensionAttributes ()
 
 getRegularPrice ()
 
 getProductOptionCollection (Product $product)
 
 setExtensionAttributes (\Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface $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)
 
- Public Member Functions inherited from ProductCustomOptionInterface
 getPrice ()
 

Data Fields

const KEY_PRODUCT_SKU = 'product_sku'
 
const KEY_OPTION_ID = 'option_id'
 
const KEY_TITLE = 'title'
 
const KEY_TYPE = 'type'
 
const KEY_SORT_ORDER = 'sort_order'
 
const KEY_IS_REQUIRE = 'is_require'
 
const KEY_PRICE = 'price'
 
const KEY_PRICE_TYPE = 'price_type'
 
const KEY_SKU = 'sku'
 
const KEY_FILE_EXTENSION = 'file_extension'
 
const KEY_MAX_CHARACTERS = 'max_characters'
 
const KEY_IMAGE_SIZE_Y = 'image_size_y'
 
const KEY_IMAGE_SIZE_X = 'image_size_x'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from ProductCustomOptionInterface
const OPTION_GROUP_TEXT = 'text'
 
const OPTION_GROUP_FILE = 'file'
 
const OPTION_GROUP_SELECT = 'select'
 
const OPTION_GROUP_DATE = 'date'
 
const OPTION_TYPE_FIELD = 'field'
 
const OPTION_TYPE_AREA = 'area'
 
const OPTION_TYPE_FILE = 'file'
 
const OPTION_TYPE_DROP_DOWN = 'drop_down'
 
const OPTION_TYPE_RADIO = 'radio'
 
const OPTION_TYPE_CHECKBOX = 'checkbox'
 
const OPTION_TYPE_MULTIPLE = 'multiple'
 
const OPTION_TYPE_DATE = 'date'
 
const OPTION_TYPE_DATE_TIME = 'date_time'
 
const OPTION_TYPE_TIME = 'time'
 

Protected Member Functions

 _getResource ()
 
 _construct ()
 
 _clearData ()
 
 _clearReferences ()
 
 _getValidationRulesBeforeSave ()
 
- 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

 $optionRepository
 
 $product
 
 $options = []
 
 $values = null
 
 $productOptionValue
 
 $optionTypeFactory
 
 $string
 
 $validatorPool
 
- 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 = []
 

Static Protected Attributes

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

Detailed Description

Catalog product option model

@api @method int getProductId() @method \Magento\Catalog\Model\Product\Option setProductId(int $value)

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.ExcessivePublicCount)
Since
100.0.2

Definition at line 32 of file Option.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Api\ExtensionAttributesFactory  $extensionFactory,
\Magento\Framework\Api\AttributeValueFactory  $customAttributeFactory,
Option\Value  $productOptionValue,
\Magento\Catalog\Model\Product\Option\Type\Factory  $optionFactory,
\Magento\Framework\Stdlib\StringUtils  $string,
Option\Validator\Pool  $validatorPool,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
ProductCustomOptionValuesInterfaceFactory  $customOptionValuesFactory = null 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Api\ExtensionAttributesFactory$extensionFactory
\Magento\Framework\Api\AttributeValueFactory$customAttributeFactory
Option\Value$productOptionValue
Option\Type\Factory$optionFactory
\Magento\Framework\Stdlib\StringUtils$string
Option\Validator\Pool$validatorPool
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data
ProductCustomOptionValuesInterfaceFactory | null$customOptionValuesFactory@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 126 of file Option.php.

139  {
140  $this->productOptionValue = $productOptionValue;
141  $this->optionTypeFactory = $optionFactory;
142  $this->validatorPool = $validatorPool;
143  $this->string = $string;
144  $this->customOptionValuesFactory = $customOptionValuesFactory ?:
145  \Magento\Framework\App\ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
146 
147  parent::__construct(
148  $context,
149  $registry,
150  $extensionFactory,
152  $resource,
153  $resourceCollection,
154  $data
155  );
156  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _clearData()

_clearData ( )
protected

Clearing object's data

Returns
$this

Definition at line 535 of file Option.php.

536  {
537  $this->_data = [];
538  $this->values = null;
539  return $this;
540  }

◆ _clearReferences()

_clearReferences ( )
protected

Clearing cyclic references

Returns
$this

Definition at line 547 of file Option.php.

548  {
549  if (!empty($this->values)) {
550  foreach ($this->values as $value) {
551  $value->unsetOption();
552  }
553  }
554  return $this;
555  }
$value
Definition: gender.phtml:16

◆ _construct()

_construct ( )
protected
Returns
void

Definition at line 172 of file Option.php.

173  {
174  $this->_init(\Magento\Catalog\Model\ResourceModel\Product\Option::class);
175  parent::_construct();
176  }

◆ _getResource()

_getResource ( )
protected

Get resource instance

Returns
\Magento\Framework\Model\ResourceModel\Db\AbstractDb
Deprecated:
102.0.0 because resource models should be used directly

Definition at line 164 of file Option.php.

165  {
166  return $this->_resource ?: parent::_getResource();
167  }

◆ _getValidationRulesBeforeSave()

_getValidationRulesBeforeSave ( )
protected

{}

Definition at line 560 of file Option.php.

561  {
562  return $this->validatorPool->get($this->getType());
563  }

◆ addOption()

addOption (   $option)

Add option for save it

Parameters
array$option
Returns
$this

Definition at line 241 of file Option.php.

242  {
243  $this->options[] = $option;
244  return $this;
245  }

◆ addValue()

addValue ( Option\Value  $value)

Add value of option to values array

Parameters
Option\Value$value
Returns
$this

Definition at line 184 of file Option.php.

185  {
186  $this->values[$value->getId()] = $value;
187  return $this;
188  }
$value
Definition: gender.phtml:16

◆ afterSave()

afterSave ( )
Returns
\Magento\Framework\Model\AbstractModel
Exceptions

Definition at line 402 of file Option.php.

403  {
404  $values = $this->getValues() ?: $this->getData('values');
405  if (is_array($values)) {
406  foreach ($values as $value) {
407  if ($value instanceof ProductCustomOptionValuesInterface) {
408  $data = $value->getData();
409  } else {
410  $data = $value;
411  }
412 
413  $this->customOptionValuesFactory->create()
414  ->addValue($data)
415  ->setOption($this)
416  ->saveValues();
417  }
418  } elseif ($this->getGroupByType($this->getType()) === self::OPTION_GROUP_SELECT) {
419  throw new LocalizedException(__('Select type options required values rows.'));
420  }
421 
422  return parent::afterSave();
423  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$value
Definition: gender.phtml:16

◆ beforeSave()

beforeSave ( )

{} @SuppressWarnings(PHPMD.CyclomaticComplexity)

Since
101.0.0

if previous option has different group from one is came now need to remove all data of previous group

Definition at line 352 of file Option.php.

353  {
354  parent::beforeSave();
355  if ($this->getData('previous_type') != '') {
356  $previousType = $this->getData('previous_type');
357 
362  if ($this->getGroupByType($previousType) != $this->getGroupByType($this->getData('type'))) {
363  switch ($this->getGroupByType($previousType)) {
365  $this->unsetData('values');
366  if ($this->getId()) {
367  $this->getValueInstance()->deleteValue($this->getId());
368  }
369  break;
371  $this->setData('file_extension', '');
372  $this->setData('image_size_x', '0');
373  $this->setData('image_size_y', '0');
374  break;
376  $this->setData('max_characters', '0');
377  break;
379  break;
380  }
381  if ($this->getGroupByType($this->getData('type')) == self::OPTION_GROUP_SELECT) {
382  $this->setData('sku', '');
383  $this->unsetData('price');
384  $this->unsetData('price_type');
385  if ($this->getId()) {
386  $this->deletePrices($this->getId());
387  }
388  }
389  }
390  }
391  if ($this->getGroupByType($this->getData('type')) === self::OPTION_GROUP_FILE) {
392  $this->cleanFileExtensions();
393  }
394 
395  return $this;
396  }

◆ deletePrices()

deletePrices (   $optionId)

Delete prices of option

Parameters
int$optionId
Returns
$this

Definition at line 448 of file Option.php.

449  {
450  $this->getResource()->deletePrices($optionId);
451  return $this;
452  }

◆ deleteTitles()

deleteTitles (   $optionId)

Delete titles of option

Parameters
int$optionId
Returns
$this

Definition at line 460 of file Option.php.

461  {
462  $this->getResource()->deleteTitles($optionId);
463  return $this;
464  }

◆ duplicate()

duplicate (   $oldProductId,
  $newProductId 
)

Duplicate options for product

Parameters
int$oldProductId
int$newProductId
Returns
$this

Definition at line 511 of file Option.php.

512  {
513  $this->getResource()->duplicate($this, $oldProductId, $newProductId);
514 
515  return $this;
516  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

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

Returns
\Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface|null
}

Returns
\Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface|null

Implements ProductCustomOptionInterface.

Definition at line 833 of file Option.php.

◆ getFileExtension()

getFileExtension ( )
Returns
string|null

Implements ProductCustomOptionInterface.

Definition at line 654 of file Option.php.

655  {
656  return $this->getData(self::KEY_FILE_EXTENSION);
657  }

◆ getGroupByType()

getGroupByType (   $type = null)

Get group name of option by given option type

Parameters
string$type
Returns
string

Definition at line 308 of file Option.php.

309  {
310  if ($type === null) {
311  $type = $this->getType();
312  }
313  $optionGroupsToTypes = [
314  self::OPTION_TYPE_FIELD => self::OPTION_GROUP_TEXT,
315  self::OPTION_TYPE_AREA => self::OPTION_GROUP_TEXT,
316  self::OPTION_TYPE_FILE => self::OPTION_GROUP_FILE,
317  self::OPTION_TYPE_DROP_DOWN => self::OPTION_GROUP_SELECT,
318  self::OPTION_TYPE_RADIO => self::OPTION_GROUP_SELECT,
319  self::OPTION_TYPE_CHECKBOX => self::OPTION_GROUP_SELECT,
320  self::OPTION_TYPE_MULTIPLE => self::OPTION_GROUP_SELECT,
321  self::OPTION_TYPE_DATE => self::OPTION_GROUP_DATE,
322  self::OPTION_TYPE_DATE_TIME => self::OPTION_GROUP_DATE,
323  self::OPTION_TYPE_TIME => self::OPTION_GROUP_DATE,
324  ];
325 
326  return $optionGroupsToTypes[$type] ?? '';
327  }
$type
Definition: item.phtml:13

◆ getImageSizeX()

getImageSizeX ( )
Returns
int|null

Implements ProductCustomOptionInterface.

Definition at line 670 of file Option.php.

671  {
672  return $this->getData(self::KEY_IMAGE_SIZE_X);
673  }

◆ getImageSizeY()

getImageSizeY ( )
Returns
int|null

Implements ProductCustomOptionInterface.

Definition at line 678 of file Option.php.

679  {
680  return $this->getData(self::KEY_IMAGE_SIZE_Y);
681  }

◆ getIsRequire()

getIsRequire ( )

Get is require

Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Implements ProductCustomOptionInterface.

Definition at line 626 of file Option.php.

627  {
628  return $this->_getData(self::KEY_IS_REQUIRE);
629  }

◆ getMaxCharacters()

getMaxCharacters ( )
Returns
int|null

Implements ProductCustomOptionInterface.

Definition at line 662 of file Option.php.

663  {
664  return $this->getData(self::KEY_MAX_CHARACTERS);
665  }

◆ getOptionId()

getOptionId ( )

Get option id

Returns
int|null @codeCoverageIgnoreStart

Implements ProductCustomOptionInterface.

Definition at line 585 of file Option.php.

586  {
587  return $this->_getData(self::KEY_OPTION_ID);
588  }

◆ getOptions()

getOptions ( )

Get all options

Returns
array

Definition at line 252 of file Option.php.

253  {
254  return $this->options;
255  }

◆ getOptionValuesByOptionId()

getOptionValuesByOptionId (   $optionIds,
  $storeId 
)

Get collection of values by given option ids

Parameters
array$optionIds
int$storeId
Returns
Collection

Definition at line 497 of file Option.php.

498  {
499  $collection = $this->productOptionValue->getValuesByOption($optionIds, $this->getId(), $storeId);
500 
501  return $collection;
502  }

◆ getPrice()

getPrice (   $flag = false)

Return price. If $flag is true and price is percent return converted percent to price

Parameters
bool$flag
Returns
float

Definition at line 432 of file Option.php.

433  {
434  if ($flag && $this->getPriceType() == self::$typePercent) {
435  $basePrice = $this->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
436  $price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
437  return $price;
438  }
439  return $this->_getData(self::KEY_PRICE);
440  }
$price

◆ getPriceType()

getPriceType ( )

Get price type

Returns
string|null

Implements ProductCustomOptionInterface.

Definition at line 636 of file Option.php.

637  {
638  return $this->_getData(self::KEY_PRICE_TYPE);
639  }

◆ getProduct()

getProduct ( )

Retrieve product instance

Returns
Product

Definition at line 285 of file Option.php.

286  {
287  return $this->product;
288  }

◆ getProductOptionCollection()

getProductOptionCollection ( Product  $product)
Parameters
Product$product
Returns
\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

Definition at line 858 of file Option.php.

859  {
860  $collection = clone $this->getCollection();
861  $collection->addFieldToFilter(
862  'product_id',
863  $product->getData($this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField())
864  )->addTitleToResult(
865  $product->getStoreId()
866  )->addPriceToResult(
867  $product->getStoreId()
868  )->setOrder(
869  'sort_order',
870  'asc'
871  )->setOrder(
872  'title',
873  'asc'
874  );
875 
876  if ($this->getAddRequiredFilter()) {
877  $collection->addRequiredFilter($this->getAddRequiredFilterValue());
878  }
879 
880  $collection->addValuesToResult($product->getStoreId());
881  return $collection;
882  }

◆ getProductOptions()

getProductOptions ( Product  $product)

Get Product Option Collection

Parameters
Product$product
Returns
\Magento\Catalog\Model\ResourceModel\Product\Option\Collection
Since
101.0.0

Definition at line 473 of file Option.php.

474  {
475  return $this->getOptionRepository()->getProductOptions($product, $this->getAddRequiredFilter());
476  }

◆ getProductSku()

getProductSku ( )

Get product SKU

Returns
string

Implements ProductCustomOptionInterface.

Definition at line 570 of file Option.php.

571  {
572  $productSku = $this->_getData(self::KEY_PRODUCT_SKU);
573  if (!$productSku && $this->getProduct()) {
574  $productSku = $this->getProduct()->getSku();
575  }
576  return $productSku;
577  }

◆ getRegularPrice()

getRegularPrice ( )

Return regular price.

Returns
float|int
Since
101.0.0

Definition at line 844 of file Option.php.

845  {
846  if ($this->getPriceType() == self::$typePercent) {
847  $basePrice = $this->getProduct()->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
848  $price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
849  return $price;
850  }
851  return $this->_getData(self::KEY_PRICE);
852  }
$price

◆ getSearchableData()

getSearchableData (   $productId,
  $storeId 
)

Retrieve option searchable data

Parameters
int$productId
int$storeId
Returns
array

Definition at line 525 of file Option.php.

526  {
527  return $this->_getResource()->getSearchableData($productId, $storeId);
528  }

◆ getSku()

getSku ( )

Get Sku

Returns
string|null

Implements ProductCustomOptionInterface.

Definition at line 646 of file Option.php.

647  {
648  return $this->_getData(self::KEY_SKU);
649  }

◆ getSortOrder()

getSortOrder ( )

Get sort order

Returns
int

Implements ProductCustomOptionInterface.

Definition at line 615 of file Option.php.

616  {
617  return $this->_getData(self::KEY_SORT_ORDER);
618  }

◆ getTitle()

getTitle ( )

Get option title

Returns
string

Implements ProductCustomOptionInterface.

Definition at line 595 of file Option.php.

596  {
597  return $this->_getData(self::KEY_TITLE);
598  }

◆ getType()

getType ( )

Get option type

Returns
string

Implements ProductCustomOptionInterface.

Definition at line 605 of file Option.php.

606  {
607  return $this->_getData(self::KEY_TYPE);
608  }

◆ getValueById()

getValueById (   $valueId)

Get value by given id

Parameters
int$valueId
Returns
Option\Value|null

Definition at line 196 of file Option.php.

197  {
198  if (isset($this->values[$valueId])) {
199  return $this->values[$valueId];
200  }
201 
202  return null;
203  }

◆ getValueInstance()

getValueInstance ( )

Retrieve value instance

Returns
Option\Value

Definition at line 230 of file Option.php.

231  {
233  }

◆ getValues()

getValues ( )
Returns
ProductCustomOptionValuesInterface[]|null

Implements ProductCustomOptionInterface.

Definition at line 220 of file Option.php.

221  {
222  return $this->values;
223  }

◆ getValuesCollection()

getValuesCollection ( )

Get collection of values for current option

Returns
Collection

Definition at line 483 of file Option.php.

484  {
485  $collection = $this->getValueInstance()->getValuesCollection($this);
486 
487  return $collection;
488  }

◆ groupFactory()

groupFactory (   $type)

Group model factory

Parameters
string$typeOption type
Returns
\Magento\Catalog\Model\Product\Option\Type\DefaultType
Exceptions
LocalizedException

Definition at line 336 of file Option.php.

337  {
338  $group = $this->getGroupByType($type);
339  if (!empty($group)) {
340  return $this->optionTypeFactory->create(
341  'Magento\Catalog\Model\Product\Option\Type\\' . $this->string->upperCaseWords($group)
342  );
343  }
344  throw new LocalizedException(__('The option type to get group instance is incorrect.'));
345  }
$group
Definition: sections.phtml:16
__()
Definition: __.php:13
$type
Definition: item.phtml:13

◆ hasValues()

hasValues (   $type = null)

Whether or not the option type contains sub-values

Parameters
string$type
Returns
bool
Since
102.0.0

Definition at line 212 of file Option.php.

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface  $extensionAttributes)

{Set an extension attributes object.

Parameters
\Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface$extensionAttributes
Returns
$this
}

Parameters
\Magento\Catalog\Api\Data\ProductCustomOptionExtensionInterface$extensionAttributes
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 890 of file Option.php.

892  {
894  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setFileExtension()

setFileExtension (   $fileExtension)
Parameters
string$fileExtension
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 786 of file Option.php.

787  {
788  return $this->setData(self::KEY_FILE_EXTENSION, $fileExtension);
789  }

◆ setImageSizeX()

setImageSizeX (   $imageSizeX)
Parameters
int$imageSizeX
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 804 of file Option.php.

805  {
806  return $this->setData(self::KEY_IMAGE_SIZE_X, $imageSizeX);
807  }

◆ setImageSizeY()

setImageSizeY (   $imageSizeY)
Parameters
int$imageSizeY
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 813 of file Option.php.

814  {
815  return $this->setData(self::KEY_IMAGE_SIZE_Y, $imageSizeY);
816  }

◆ setIsRequire()

setIsRequire (   $isRequired)

Set is require

Parameters
bool$isRequired
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 744 of file Option.php.

745  {
746  return $this->setData(self::KEY_IS_REQUIRE, $isRequired);
747  }

◆ setMaxCharacters()

setMaxCharacters (   $maxCharacters)
Parameters
int$maxCharacters
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 795 of file Option.php.

796  {
797  return $this->setData(self::KEY_MAX_CHARACTERS, $maxCharacters);
798  }

◆ setOptionId()

setOptionId (   $optionId)

Set option id

Parameters
int$optionId
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 700 of file Option.php.

701  {
702  return $this->setData(self::KEY_OPTION_ID, $optionId);
703  }

◆ setOptions()

setOptions (   $options)

Set options for array

Parameters
array$options
Returns
$this

Definition at line 263 of file Option.php.

264  {
265  $this->options = $options;
266  return $this;
267  }

◆ setPrice()

setPrice (   $price)

Set price

Parameters
float$price
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 755 of file Option.php.

756  {
757  return $this->setData(self::KEY_PRICE, $price);
758  }
$price

◆ setPriceType()

setPriceType (   $priceType)

Set price type

Parameters
string$priceType
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 766 of file Option.php.

767  {
768  return $this->setData(self::KEY_PRICE_TYPE, $priceType);
769  }
$priceType
Definition: msrp.phtml:18

◆ setProduct()

setProduct ( Product  $product = null)

Set product instance

Parameters
Product$product
Returns
$this

Definition at line 296 of file Option.php.

297  {
298  $this->product = $product;
299  return $this;
300  }

◆ setProductSku()

setProductSku (   $productSku)

Set product SKU

Parameters
string$productSku
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 689 of file Option.php.

690  {
691  return $this->setData(self::KEY_PRODUCT_SKU, $productSku);
692  }

◆ setSku()

setSku (   $sku)

Set Sku

Parameters
string$sku
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 777 of file Option.php.

778  {
779  return $this->setData(self::KEY_SKU, $sku);
780  }

◆ setSortOrder()

setSortOrder (   $sortOrder)

Set sort order

Parameters
int$sortOrder
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 733 of file Option.php.

734  {
735  return $this->setData(self::KEY_SORT_ORDER, $sortOrder);
736  }

◆ setTitle()

setTitle (   $title)

Set option title

Parameters
string$title
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 711 of file Option.php.

712  {
713  return $this->setData(self::KEY_TITLE, $title);
714  }
$title
Definition: default.phtml:14

◆ setType()

setType (   $type)

Set option type

Parameters
string$type
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 722 of file Option.php.

723  {
724  return $this->setData(self::KEY_TYPE, $type);
725  }
$type
Definition: item.phtml:13

◆ setValues()

setValues ( array  $values = null)
Parameters
ProductCustomOptionValuesInterface[]$values
Returns
$this

Implements ProductCustomOptionInterface.

Definition at line 822 of file Option.php.

823  {
824  $this->values = $values;
825  return $this;
826  }

◆ unsetOptions()

unsetOptions ( )

Set options to empty array

Returns
$this

Definition at line 274 of file Option.php.

275  {
276  $this->options = [];
277  return $this;
278  }

Field Documentation

◆ $optionRepository

$optionRepository
protected

Definition at line 38 of file Option.php.

◆ $options

$options = []
protected

Definition at line 70 of file Option.php.

◆ $optionTypeFactory

$optionTypeFactory
protected

Definition at line 89 of file Option.php.

◆ $product

$product
protected

#- #-

Definition at line 65 of file Option.php.

◆ $productOptionValue

$productOptionValue
protected

Definition at line 82 of file Option.php.

◆ $string

$string
protected

Definition at line 94 of file Option.php.

◆ $typePercent

$typePercent = 'percent'
staticprotected

Option type percent

Since
101.0.0

Definition at line 44 of file Option.php.

◆ $validatorPool

$validatorPool
protected

Definition at line 99 of file Option.php.

◆ $values

$values = null
protected

Definition at line 75 of file Option.php.

◆ KEY_FILE_EXTENSION

const KEY_FILE_EXTENSION = 'file_extension'

Definition at line 58 of file Option.php.

◆ KEY_IMAGE_SIZE_X

const KEY_IMAGE_SIZE_X = 'image_size_x'

Definition at line 61 of file Option.php.

◆ KEY_IMAGE_SIZE_Y

const KEY_IMAGE_SIZE_Y = 'image_size_y'

Definition at line 60 of file Option.php.

◆ KEY_IS_REQUIRE

const KEY_IS_REQUIRE = 'is_require'

Definition at line 54 of file Option.php.

◆ KEY_MAX_CHARACTERS

const KEY_MAX_CHARACTERS = 'max_characters'

Definition at line 59 of file Option.php.

◆ KEY_OPTION_ID

const KEY_OPTION_ID = 'option_id'

Definition at line 50 of file Option.php.

◆ KEY_PRICE

const KEY_PRICE = 'price'

Definition at line 55 of file Option.php.

◆ KEY_PRICE_TYPE

const KEY_PRICE_TYPE = 'price_type'

Definition at line 56 of file Option.php.

◆ KEY_PRODUCT_SKU

const KEY_PRODUCT_SKU = 'product_sku'

#+ Constants

Definition at line 49 of file Option.php.

◆ KEY_SKU

const KEY_SKU = 'sku'

Definition at line 57 of file Option.php.

◆ KEY_SORT_ORDER

const KEY_SORT_ORDER = 'sort_order'

Definition at line 53 of file Option.php.

◆ KEY_TITLE

const KEY_TITLE = 'title'

Definition at line 51 of file Option.php.

◆ KEY_TYPE

const KEY_TYPE = 'type'

Definition at line 52 of file Option.php.


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