Option.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\Quote\Item;
  7. /**
  8. * Item option model
  9. *
  10. * @method int getItemId()
  11. * @method \Magento\Quote\Model\Quote\Item\Option setItemId(int $value)
  12. * @method int getProductId()
  13. * @method \Magento\Quote\Model\Quote\Item\Option setProductId(int $value)
  14. * @method string getCode()
  15. * @method \Magento\Quote\Model\Quote\Item\Option setCode(string $value)
  16. * @method \Magento\Quote\Model\Quote\Item\Option setValue(string $value)
  17. */
  18. class Option extends \Magento\Framework\Model\AbstractModel implements
  19. \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface
  20. {
  21. /**
  22. * @var \Magento\Quote\Model\Quote\Item
  23. */
  24. protected $_item;
  25. /**
  26. * @var \Magento\Catalog\Model\Product
  27. */
  28. protected $_product;
  29. /**
  30. * Initialize resource model
  31. *
  32. * @return void
  33. */
  34. protected function _construct()
  35. {
  36. $this->_init(\Magento\Quote\Model\ResourceModel\Quote\Item\Option::class);
  37. }
  38. /**
  39. * Checks that item option model has data changes
  40. *
  41. * @return boolean
  42. */
  43. protected function _hasModelChanged()
  44. {
  45. if (!$this->hasDataChanges()) {
  46. return false;
  47. }
  48. return $this->_getResource()->hasDataChanged($this);
  49. }
  50. /**
  51. * Set quote item
  52. *
  53. * @param \Magento\Quote\Model\Quote\Item $item
  54. * @return $this
  55. */
  56. public function setItem($item)
  57. {
  58. $this->setItemId($item->getId());
  59. $this->_item = $item;
  60. return $this;
  61. }
  62. /**
  63. * Get option item
  64. *
  65. * @return \Magento\Quote\Model\Quote\Item
  66. */
  67. public function getItem()
  68. {
  69. return $this->_item;
  70. }
  71. /**
  72. * Set option product
  73. *
  74. * @param \Magento\Catalog\Model\Product $product
  75. * @return $this
  76. */
  77. public function setProduct($product)
  78. {
  79. $this->setProductId($product->getId());
  80. $this->_product = $product;
  81. return $this;
  82. }
  83. /**
  84. * Get option product
  85. *
  86. * @return \Magento\Catalog\Model\Product
  87. */
  88. public function getProduct()
  89. {
  90. return $this->_product;
  91. }
  92. /**
  93. * Get option value
  94. *
  95. * @return mixed
  96. */
  97. public function getValue()
  98. {
  99. return $this->_getData('value');
  100. }
  101. /**
  102. * Initialize item identifier before save data
  103. *
  104. * @return $this
  105. */
  106. public function beforeSave()
  107. {
  108. if ($this->getItem()) {
  109. $this->setItemId($this->getItem()->getId());
  110. }
  111. return parent::beforeSave();
  112. }
  113. /**
  114. * Clone option object
  115. *
  116. * @return $this
  117. */
  118. public function __clone()
  119. {
  120. $this->setId(null);
  121. $this->_item = null;
  122. return $this;
  123. }
  124. }