Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Item Class Reference
Inheritance diagram for Item:
AbstractModel ItemInterface DataObject

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime\DateTime $date, \Magento\Catalog\Model\ResourceModel\Url $catalogUrl, OptionFactory $wishlistOptFactory, CollectionFactory $wishlOptionCollectionFactory, \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig, ProductRepositoryInterface $productRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null)
 
 setQty ($qty)
 
 saveItemOptions ()
 
 setIsOptionsSaved ($flag)
 
 isOptionsSaved ()
 
 afterSave ()
 
 validate ()
 
 beforeSave ()
 
 loadByProductWishlist ($wishlistId, $productId, $sharedStores)
 
 getProduct ()
 
 addToCart (\Magento\Checkout\Model\Cart $cart, $delete=false)
 
 getProductUrl ()
 
 getBuyRequest ()
 
 mergeBuyRequest ($buyRequest)
 
 setBuyRequest ($buyRequest)
 
 isRepresent ($product, $buyRequest)
 
 representProduct ($product)
 
 compareOptions ($options1, $options2)
 
 setOptions ($options)
 
 getOptions ()
 
 getOptionsByCode ()
 
 addOption ($option)
 
 removeOption ($code)
 
 getOptionByCode ($code)
 
 canHaveQty ()
 
 getCustomDownloadUrl ()
 
 setCustomDownloadUrl ($url)
 
 getFileDownloadParams ()
 
 loadWithOptions ($id, $optionsFilter=null)
 
- 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)
 

Protected Member Functions

 _construct ()
 
 _compareOptions ($options1, $options2)
 
 _addOptionCode ($option)
 
 _hasModelChanged ()
 
- 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

 $_customOptionDownloadUrl = 'wishlist/index/downloadCustomOption'
 
 $_eventPrefix = 'wishlist_item'
 
 $_eventObject = 'item'
 
 $_options = []
 
 $_optionsByCode = []
 
 $_notRepresentOptions = ['info_buyRequest']
 
 $_flagOptionsSaved = null
 
 $_storeManager
 
 $_date
 
 $_catalogUrl
 
 $_wishlistOptFactory
 
 $_wishlOptionCollectionFactory
 
 $productTypeConfig
 
 $productRepository
 
- 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

Wishlist item model

@method int getWishlistId() @method \Magento\Wishlist\Model\Item setWishlistId(int $value) @method int getProductId() @method \Magento\Wishlist\Model\Item setProductId(int $value) @method int getStoreId() @method \Magento\Wishlist\Model\Item setStoreId(int $value) @method string getAddedAt() @method \Magento\Wishlist\Model\Item setAddedAt(string $value) @method string getDescription() @method \Magento\Wishlist\Model\Item setDescription(string $value) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

@api

Since
100.0.2

Definition at line 36 of file Item.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Stdlib\DateTime\DateTime  $date,
\Magento\Catalog\Model\ResourceModel\Url  $catalogUrl,
OptionFactory  $wishlistOptFactory,
CollectionFactory  $wishlOptionCollectionFactory,
\Magento\Catalog\Model\ProductTypes\ConfigInterface  $productTypeConfig,
ProductRepositoryInterface  $productRepository,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
\Magento\Framework\Serialize\Serializer\Json  $serializer = null 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Stdlib\DateTime\DateTime$date
\Magento\Catalog\Model\ResourceModel\Url$catalogUrl
OptionFactory$wishlistOptFactory
CollectionFactory$wishlOptionCollectionFactory
\Magento\Catalog\Model\ProductTypes\ConfigInterface$productTypeConfig
ProductRepositoryInterface$productRepository
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data
\Magento\Framework\Serialize\Serializer\Json | null$serializer@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 146 of file Item.php.

160  {
161  $this->productTypeConfig = $productTypeConfig;
162  $this->_storeManager = $storeManager;
163  $this->_date = $date;
164  $this->_catalogUrl = $catalogUrl;
165  $this->_wishlistOptFactory = $wishlistOptFactory;
166  $this->_wishlOptionCollectionFactory = $wishlOptionCollectionFactory;
168  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
169  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
170  $this->productRepository = $productRepository;
171  }
$storeManager
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _addOptionCode()

_addOptionCode (   $option)
protected

Register option code

Parameters
Option$option
Returns
$this
Exceptions

Definition at line 223 of file Item.php.

224  {
225  if (!isset($this->_optionsByCode[$option->getCode()])) {
226  $this->_optionsByCode[$option->getCode()] = $option;
227  } else {
228  throw new \Magento\Framework\Exception\LocalizedException(
229  __('An item option with code %1 already exists.', $option->getCode())
230  );
231  }
232  return $this;
233  }
__()
Definition: __.php:13

◆ _compareOptions()

_compareOptions (   $options1,
  $options2 
)
protected

Check if two options array are identical

Parameters
array$options1
array$options2
Returns
bool

Definition at line 202 of file Item.php.

203  {
204  $skipOptions = ['id', 'qty', 'return_url'];
205  foreach ($options1 as $code => $value) {
206  if (in_array($code, $skipOptions)) {
207  continue;
208  }
209  if (!isset($options2[$code]) || $options2[$code] != $value) {
210  return false;
211  }
212  }
213  return true;
214  }
$value
Definition: gender.phtml:16
$code
Definition: info.phtml:12

◆ _construct()

_construct ( )
protected

Initialize resource model

Returns
void

Definition at line 178 of file Item.php.

179  {
180  $this->_init(\Magento\Wishlist\Model\ResourceModel\Item::class);
181  }

◆ _hasModelChanged()

_hasModelChanged ( )
protected

Checks that item model has data changes. Call save item options if model isn't need to save in DB

Returns
boolean

Definition at line 241 of file Item.php.

242  {
243  if (!$this->hasDataChanges()) {
244  return false;
245  }
246 
247  return $this->_getResource()->hasDataChanged($this);
248  }

◆ addOption()

addOption (   $option)

Add option to item

Parameters
Option | \Magento\Framework\DataObject | array$option
Returns
$this
Exceptions

Definition at line 658 of file Item.php.

659  {
660  if (is_array($option)) {
661  $option = $this->_wishlistOptFactory->create()->setData($option)->setItem($this);
662  } elseif ($option instanceof Option) {
663  $option->setItem($this);
664  } elseif ($option instanceof \Magento\Framework\DataObject) {
665  $option = $this->_wishlistOptFactory->create()->setData($option->getData())
666  ->setProduct($option->getProduct())
667  ->setItem($this);
668  } else {
669  throw new \Magento\Framework\Exception\LocalizedException(__('Invalid item option format.'));
670  }
671 
672  $exOption = $this->getOptionByCode($option->getCode());
673  if ($exOption) {
674  $exOption->addData($option->getData());
675  } else {
676  $this->_addOptionCode($option);
677  $this->_options[] = $option;
678  }
679  return $this;
680  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ addToCart()

addToCart ( \Magento\Checkout\Model\Cart  $cart,
  $delete = false 
)

Add or Move item product to shopping cart

Return true if product was successful added or exception with code Return false for disabled or unvisible products

Parameters
\Magento\Checkout\Model\Cart$cart
bool$deletedelete the item after successful add to cart
Returns
bool
Exceptions

Definition at line 405 of file Item.php.

406  {
407  $product = $this->getProduct();
408 
409  $storeId = $this->getStoreId();
410 
411  if ($product->getStatus() != \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
412  return false;
413  }
414 
415  if (!$product->isVisibleInSiteVisibility()) {
416  if ($product->getStoreId() == $storeId) {
417  return false;
418  }
419  $urlData = $this->_catalogUrl->getRewriteByProductStore([$product->getId() => $storeId]);
420  if (!isset($urlData[$product->getId()])) {
421  return false;
422  }
423  $product->setUrlDataObject(new \Magento\Framework\DataObject($urlData));
424  $visibility = $product->getUrlDataObject()->getVisibility();
425  if (!in_array($visibility, $product->getVisibleInSiteVisibilities())) {
426  return false;
427  }
428  }
429 
430  if (!$product->isSalable()) {
431  throw new ProductException(__('Product is not salable.'));
432  }
433 
434  $buyRequest = $this->getBuyRequest();
435 
436  $cart->addProduct($product, $buyRequest);
437  if (!$product->isVisibleInSiteVisibility()) {
438  $cart->getQuote()->getItemByProduct($product)->setStoreId($storeId);
439  }
440 
441  if ($delete) {
442  $this->delete();
443  }
444 
445  return true;
446  }
__()
Definition: __.php:13
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ afterSave()

afterSave ( )

Save item options after item saved

Returns
$this

Definition at line 299 of file Item.php.

300  {
301  $this->saveItemOptions();
302  return parent::afterSave();
303  }

◆ beforeSave()

beforeSave ( )

Check required data

Returns
$this

Definition at line 328 of file Item.php.

329  {
330  parent::beforeSave();
331 
332  // validate required item data
333  $this->validate();
334 
335  // set current store id if it is not defined
336  if ($this->getStoreId() === null) {
337  $this->setStoreId($this->_storeManager->getStore()->getId());
338  }
339 
340  // set current date if added at data is not defined
341  if ($this->getAddedAt() === null) {
342  $this->setAddedAt($this->_date->gmtDate());
343  }
344 
345  return $this;
346  }

◆ canHaveQty()

canHaveQty ( )

Returns whether Qty field is valid for this item

Returns
bool

Definition at line 716 of file Item.php.

717  {
718  $product = $this->getProduct();
719  return !$this->productTypeConfig->isProductSet($product->getTypeId());
720  }

◆ compareOptions()

compareOptions (   $options1,
  $options2 
)

Check if two options array are identical First options array is prerogative Second options array checked against first one

Parameters
array$options1
array$options2
Returns
bool

Definition at line 603 of file Item.php.

604  {
605  foreach ($options1 as $option) {
606  $code = $option->getCode();
607  if (in_array($code, $this->_notRepresentOptions)) {
608  continue;
609  }
610  if (!isset($options2[$code]) || $options2[$code]->getValue() != $option->getValue()) {
611  return false;
612  }
613  }
614  return true;
615  }
$code
Definition: info.phtml:12

◆ getBuyRequest()

getBuyRequest ( )

Returns formatted buy request - object, holding request received from product view page with keys and options for configured product

Returns
\Magento\Framework\DataObject

Definition at line 473 of file Item.php.

474  {
475  $option = $this->getOptionByCode('info_buyRequest');
476  $initialData = $option ? $this->serializer->unserialize($option->getValue()) : [];
477 
478  if ($initialData instanceof \Magento\Framework\DataObject) {
479  $initialData = $initialData->getData();
480  }
481 
482  $buyRequest = new \Magento\Framework\DataObject($initialData);
483  $buyRequest->setOriginalQty($buyRequest->getQty())->setQty($this->getQty() * 1);
484  return $buyRequest;
485  }
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ getCustomDownloadUrl()

getCustomDownloadUrl ( )

Get current custom option download url

Returns
string

Definition at line 727 of file Item.php.

728  {
729  return $this->_customOptionDownloadUrl;
730  }

◆ getFileDownloadParams()

getFileDownloadParams ( )

Returns special download params (if needed) for custom option with type = 'file'. Needed to implement \Magento\Catalog\Model\Product\Configuration\Item\Interface.

We have to customize only controller url, so return it.

Returns
null|\Magento\Framework\DataObject

Implements ItemInterface.

Definition at line 751 of file Item.php.

752  {
753  $params = new \Magento\Framework\DataObject();
754  $params->setUrl($this->_customOptionDownloadUrl);
755  return $params;
756  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getOptionByCode()

getOptionByCode (   $code)

Get item option by code

Parameters
string$code
Returns
Option|null

Implements ItemInterface.

Definition at line 703 of file Item.php.

704  {
705  if (isset($this->_optionsByCode[$code]) && !$this->_optionsByCode[$code]->isDeleted()) {
706  return $this->_optionsByCode[$code];
707  }
708  return null;
709  }
$code
Definition: info.phtml:12

◆ getOptions()

getOptions ( )

Get all item options

Returns
Option[]

Definition at line 636 of file Item.php.

637  {
638  return $this->_options;
639  }

◆ getOptionsByCode()

getOptionsByCode ( )

Get all item options as array with codes in array key

Returns
array

Definition at line 646 of file Item.php.

647  {
648  return $this->_optionsByCode;
649  }

◆ getProduct()

getProduct ( )

Retrieve item product instance

Exceptions

Reset product final price because it related to custom options

Implements ItemInterface.

Definition at line 371 of file Item.php.

372  {
373  $product = $this->_getData('product');
374  if ($product === null) {
375  if (!$this->getProductId()) {
376  throw new \Magento\Framework\Exception\LocalizedException(__('Cannot specify product.'));
377  }
378  try {
379  $product = $this->productRepository->getById($this->getProductId(), false, $this->getStoreId(), true);
380  } catch (NoSuchEntityException $e) {
381  throw new \Magento\Framework\Exception\LocalizedException(__('Cannot specify product.'), $e);
382  }
383  $this->setData('product', $product);
384  }
385 
389  $product->setFinalPrice(null);
390  $product->setCustomOptions($this->_optionsByCode);
391  return $product;
392  }
__()
Definition: __.php:13

◆ getProductUrl()

getProductUrl ( )

Retrieve Product View Page URL

If product has required options add special key to URL

Returns
string

Definition at line 455 of file Item.php.

456  {
457  $product = $this->getProduct();
458  $query = [];
459 
460  if ($product->getTypeInstance()->hasRequiredOptions($product)) {
461  $query['options'] = 'cart';
462  }
463 
464  return $product->getUrlModel()->getUrl($product, ['_query' => $query]);
465  }

◆ isOptionsSaved()

isOptionsSaved ( )

Were options saved?

Returns
bool

Definition at line 289 of file Item.php.

290  {
292  }

◆ isRepresent()

isRepresent (   $product,
  $buyRequest 
)

Check product representation in item

Parameters
\Magento\Catalog\Model\Product$product
\Magento\Framework\DataObject$buyRequest
Returns
bool

Definition at line 539 of file Item.php.

540  {
541  if ($this->getProductId() != $product->getId()) {
542  return false;
543  }
544 
545  $selfOptions = $this->getBuyRequest()->getData();
546 
547  if (empty($buyRequest) && !empty($selfOptions)) {
548  return false;
549  }
550  if (empty($selfOptions) && !empty($buyRequest)) {
551  if (!$product->isComposite()) {
552  return true;
553  } else {
554  return false;
555  }
556  }
557 
558  $requestArray = $buyRequest->getData();
559 
560  if (!$this->_compareOptions($requestArray, $selfOptions)) {
561  return false;
562  }
563  if (!$this->_compareOptions($selfOptions, $requestArray)) {
564  return false;
565  }
566  return true;
567  }
_compareOptions($options1, $options2)
Definition: Item.php:202
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ loadByProductWishlist()

loadByProductWishlist (   $wishlistId,
  $productId,
  $sharedStores 
)

Load item by product, wishlist and shared stores

Parameters
int$wishlistId
int$productId
array$sharedStores
Returns
$this

Definition at line 356 of file Item.php.

357  {
358  $this->_getResource()->loadByProductWishlist($this, $wishlistId, $productId, $sharedStores);
359  $this->_afterLoad();
360  $this->setOrigData();
361 
362  return $this;
363  }

◆ loadWithOptions()

loadWithOptions (   $id,
  $optionsFilter = null 
)

Loads item together with its options (default load() method doesn't load options). If we need to load only some of options, then option code or array of option codes can be provided in $optionsFilter.

Parameters
int$id
null | string | array$optionsFilter
Returns
$this

Definition at line 768 of file Item.php.

769  {
770  $this->load($id);
771  if (!$this->getId()) {
772  return $this;
773  }
774 
775  $options = $this->_wishlOptionCollectionFactory->create()->addItemFilter($this);
776  if ($optionsFilter) {
777  $options->addFieldToFilter('code', $optionsFilter);
778  }
779 
780  $this->setOptions($options->getOptionsByItem($this));
781  return $this;
782  }
$id
Definition: fieldset.phtml:14

◆ mergeBuyRequest()

mergeBuyRequest (   $buyRequest)

Merge data to item info_buyRequest option

Parameters
array | \Magento\Framework\DataObject$buyRequest
Returns
$this

Definition at line 493 of file Item.php.

494  {
495  if ($buyRequest instanceof \Magento\Framework\DataObject) {
496  $buyRequest = $buyRequest->getData();
497  }
498 
499  if (empty($buyRequest) || !is_array($buyRequest)) {
500  return $this;
501  }
502 
503  $oldBuyRequest = $this->getBuyRequest()->getData();
504  $sBuyRequest = $this->serializer->serialize($buyRequest + $oldBuyRequest);
505 
506  $option = $this->getOptionByCode('info_buyRequest');
507  if ($option) {
508  $option->setValue($sBuyRequest);
509  } else {
510  $this->addOption(['code' => 'info_buyRequest', 'value' => $sBuyRequest]);
511  }
512 
513  return $this;
514  }
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ removeOption()

removeOption (   $code)

Remove option from item options

Parameters
string$code
Returns
$this

Definition at line 688 of file Item.php.

689  {
690  $option = $this->getOptionByCode($code);
691  if ($option) {
692  $option->isDeleted(true);
693  }
694  return $this;
695  }
$code
Definition: info.phtml:12

◆ representProduct()

representProduct (   $product)

Check product representation in item

Parameters
\Magento\Catalog\Model\Product$product
Returns
bool

Definition at line 575 of file Item.php.

576  {
577  $itemProduct = $this->getProduct();
578  if ($itemProduct->getId() != $product->getId()) {
579  return false;
580  }
581 
582  $itemOptions = $this->getOptionsByCode();
583  $productOptions = $product->getCustomOptions();
584 
585  if (!$this->compareOptions($itemOptions, $productOptions)) {
586  return false;
587  }
588  if (!$this->compareOptions($productOptions, $itemOptions)) {
589  return false;
590  }
591  return true;
592  }
compareOptions($options1, $options2)
Definition: Item.php:494

◆ saveItemOptions()

saveItemOptions ( )

Save item options

Returns
$this

Definition at line 255 of file Item.php.

256  {
257  foreach ($this->_options as $index => $option) {
258  if ($option->isDeleted()) {
259  $option->delete();
260  unset($this->_options[$index]);
261  unset($this->_optionsByCode[$option->getCode()]);
262  } else {
263  $option->save();
264  }
265  }
266 
267  $this->_flagOptionsSaved = true;
268  // Report to watchers that options were saved
269 
270  return $this;
271  }
$index
Definition: list.phtml:44

◆ setBuyRequest()

setBuyRequest (   $buyRequest)

Set buy request - object, holding request received from product view page with keys and options for configured product

Parameters
\Magento\Framework\DataObject$buyRequest
Returns
$this

Definition at line 523 of file Item.php.

524  {
525  $buyRequest->setId($this->getId());
526 
527  $_buyRequest = $this->serializer->serialize($buyRequest->getData());
528  $this->setData('buy_request', $_buyRequest);
529  return $this;
530  }
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ setCustomDownloadUrl()

setCustomDownloadUrl (   $url)

Sets custom option download url

Parameters
string$url
Returns
void

Definition at line 738 of file Item.php.

739  {
740  $this->_customOptionDownloadUrl = $url;
741  }

◆ setIsOptionsSaved()

setIsOptionsSaved (   $flag)

Mark option save requirement

Parameters
bool$flag
Returns
void

Definition at line 279 of file Item.php.

280  {
281  $this->_flagOptionsSaved = $flag;
282  }

◆ setOptions()

setOptions (   $options)

Initialize item options

Parameters
array$options
Returns
$this

Definition at line 623 of file Item.php.

624  {
625  foreach ($options as $option) {
626  $this->addOption($option);
627  }
628  return $this;
629  }

◆ setQty()

setQty (   $qty)

Set quantity. If quantity is less than 0 - set it to 1

Parameters
int$qty
Returns
$this

Definition at line 189 of file Item.php.

190  {
191  $this->setData('qty', $qty >= 0 ? $qty : 1);
192  return $this;
193  }

◆ validate()

validate ( )

Validate wish list item data

Returns
bool
Exceptions

Definition at line 311 of file Item.php.

312  {
313  if (!$this->getWishlistId()) {
314  throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t specify a wish list.'));
315  }
316  if (!$this->getProductId()) {
317  throw new \Magento\Framework\Exception\LocalizedException(__('Cannot specify product.'));
318  }
319 
320  return true;
321  }
__()
Definition: __.php:13

Field Documentation

◆ $_catalogUrl

$_catalogUrl
protected

Definition at line 101 of file Item.php.

◆ $_customOptionDownloadUrl

$_customOptionDownloadUrl = 'wishlist/index/downloadCustomOption'
protected

Definition at line 42 of file Item.php.

◆ $_date

$_date
protected

Definition at line 96 of file Item.php.

◆ $_eventObject

$_eventObject = 'item'
protected

Definition at line 58 of file Item.php.

◆ $_eventPrefix

$_eventPrefix = 'wishlist_item'
protected

Definition at line 49 of file Item.php.

◆ $_flagOptionsSaved

$_flagOptionsSaved = null
protected

Definition at line 86 of file Item.php.

◆ $_notRepresentOptions

$_notRepresentOptions = ['info_buyRequest']
protected

Definition at line 79 of file Item.php.

◆ $_options

$_options = []
protected

Definition at line 65 of file Item.php.

◆ $_optionsByCode

$_optionsByCode = []
protected

Definition at line 72 of file Item.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 91 of file Item.php.

◆ $_wishlistOptFactory

$_wishlistOptFactory
protected

Definition at line 106 of file Item.php.

◆ $_wishlOptionCollectionFactory

$_wishlOptionCollectionFactory
protected

Definition at line 111 of file Item.php.

◆ $productRepository

$productRepository
protected

Definition at line 121 of file Item.php.

◆ $productTypeConfig

$productTypeConfig
protected

Definition at line 116 of file Item.php.


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