Item.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\Quote\Address;
  7. use Magento\Quote\Model\Quote;
  8. /**
  9. * Quote item model.
  10. *
  11. * @api
  12. * @method int getParentItemId()
  13. * @method \Magento\Quote\Model\Quote\Address\Item setParentItemId(int $value)
  14. * @method int getQuoteAddressId()
  15. * @method \Magento\Quote\Model\Quote\Address\Item setQuoteAddressId(int $value)
  16. * @method int getQuoteItemId()
  17. * @method \Magento\Quote\Model\Quote\Address\Item setQuoteItemId(int $value)
  18. * @method string getCreatedAt()
  19. * @method \Magento\Quote\Model\Quote\Address\Item setCreatedAt(string $value)
  20. * @method string getUpdatedAt()
  21. * @method \Magento\Quote\Model\Quote\Address\Item setUpdatedAt(string $value)
  22. * @method string getAppliedRuleIds()
  23. * @method \Magento\Quote\Model\Quote\Address\Item setAppliedRuleIds(string $value)
  24. * @method string getAdditionalData()
  25. * @method \Magento\Quote\Model\Quote\Address\Item setAdditionalData(string $value)
  26. * @method float getWeight()
  27. * @method \Magento\Quote\Model\Quote\Address\Item setWeight(float $value)
  28. * @method \Magento\Quote\Model\Quote\Address\Item setQty(float $value)
  29. * @method float getDiscountAmount()
  30. * @method \Magento\Quote\Model\Quote\Address\Item setDiscountAmount(float $value)
  31. * @method \Magento\Quote\Model\Quote\Address\Item setTaxAmount(float $value)
  32. * @method float getRowTotal()
  33. * @method \Magento\Quote\Model\Quote\Address\Item setRowTotal(float $value)
  34. * @method float getBaseRowTotal()
  35. * @method \Magento\Quote\Model\Quote\Address\Item setBaseRowTotal(float $value)
  36. * @method float getRowTotalWithDiscount()
  37. * @method \Magento\Quote\Model\Quote\Address\Item setRowTotalWithDiscount(float $value)
  38. * @method float getBaseDiscountAmount()
  39. * @method \Magento\Quote\Model\Quote\Address\Item setBaseDiscountAmount(float $value)
  40. * @method \Magento\Quote\Model\Quote\Address\Item setBaseTaxAmount(float $value)
  41. * @method float getRowWeight()
  42. * @method \Magento\Quote\Model\Quote\Address\Item setRowWeight(float $value)
  43. * @method int getProductId()
  44. * @method \Magento\Quote\Model\Quote\Address\Item setProductId(int $value)
  45. * @method int getSuperProductId()
  46. * @method \Magento\Quote\Model\Quote\Address\Item setSuperProductId(int $value)
  47. * @method int getParentProductId()
  48. * @method \Magento\Quote\Model\Quote\Address\Item setParentProductId(int $value)
  49. * @method int getStoreId()
  50. * @method \Magento\Quote\Model\Quote\Address\Item setStoreId(int $value)
  51. * @method string getSku()
  52. * @method \Magento\Quote\Model\Quote\Address\Item setSku(string $value)
  53. * @method string getImage()
  54. * @method \Magento\Quote\Model\Quote\Address\Item setImage(string $value)
  55. * @method string getName()
  56. * @method \Magento\Quote\Model\Quote\Address\Item setName(string $value)
  57. * @method string getDescription()
  58. * @method \Magento\Quote\Model\Quote\Address\Item setDescription(string $value)
  59. * @method int getFreeShipping()
  60. * @method \Magento\Quote\Model\Quote\Address\Item setFreeShipping(int $value)
  61. * @method int getIsQtyDecimal()
  62. * @method \Magento\Quote\Model\Quote\Address\Item setIsQtyDecimal(int $value)
  63. * @method float getDiscountPercent()
  64. * @method \Magento\Quote\Model\Quote\Address\Item setDiscountPercent(float $value)
  65. * @method int getNoDiscount()
  66. * @method \Magento\Quote\Model\Quote\Address\Item setNoDiscount(int $value)
  67. * @method float getTaxPercent()
  68. * @method \Magento\Quote\Model\Quote\Address\Item setTaxPercent(float $value)
  69. * @method float getBasePrice()
  70. * @method \Magento\Quote\Model\Quote\Address\Item setBasePrice(float $value)
  71. * @method float getBaseCost()
  72. * @method \Magento\Quote\Model\Quote\Address\Item setBaseCost(float $value)
  73. * @method float getPriceInclTax()
  74. * @method \Magento\Quote\Model\Quote\Address\Item setPriceInclTax(float $value)
  75. * @method float getBasePriceInclTax()
  76. * @method \Magento\Quote\Model\Quote\Address\Item setBasePriceInclTax(float $value)
  77. * @method float getRowTotalInclTax()
  78. * @method \Magento\Quote\Model\Quote\Address\Item setRowTotalInclTax(float $value)
  79. * @method float getBaseRowTotalInclTax()
  80. * @method \Magento\Quote\Model\Quote\Address\Item setBaseRowTotalInclTax(float $value)
  81. * @method int getGiftMessageId()
  82. * @method \Magento\Quote\Model\Quote\Address\Item setGiftMessageId(int $value)
  83. * @method float getDiscountTaxCompensationAmount()
  84. * @method \Magento\Quote\Model\Quote\Address\Item setDiscountTaxCompensationAmount(float $value)
  85. * @method float getBaseDiscountTaxCompensationAmount()
  86. * @method \Magento\Quote\Model\Quote\Address\Item setBaseDiscountTaxCompensationAmount(float $value)
  87. *
  88. * @author Magento Core Team <core@magentocommerce.com>
  89. * @since 100.0.2
  90. */
  91. class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem
  92. {
  93. /**
  94. * Quote address model object
  95. *
  96. * @var \Magento\Quote\Model\Quote\Address
  97. */
  98. protected $_address;
  99. /**
  100. * @var Quote
  101. */
  102. protected $_quote;
  103. /**
  104. * @inheritdoc
  105. */
  106. protected function _construct()
  107. {
  108. $this->_init(\Magento\Quote\Model\ResourceModel\Quote\Address\Item::class);
  109. }
  110. /**
  111. * @inheritdoc
  112. */
  113. public function beforeSave()
  114. {
  115. parent::beforeSave();
  116. if ($this->getAddress()) {
  117. $this->setQuoteAddressId($this->getAddress()->getId());
  118. }
  119. return $this;
  120. }
  121. /**
  122. * Declare address model
  123. *
  124. * @param \Magento\Quote\Model\Quote\Address $address
  125. * @return $this
  126. */
  127. public function setAddress(\Magento\Quote\Model\Quote\Address $address)
  128. {
  129. $this->_address = $address;
  130. $this->_quote = $address->getQuote();
  131. return $this;
  132. }
  133. /**
  134. * Retrieve address model
  135. *
  136. * @return \Magento\Quote\Model\Quote\Address
  137. */
  138. public function getAddress()
  139. {
  140. return $this->_address;
  141. }
  142. /**
  143. * Retrieve quote model instance
  144. *
  145. * @return Quote
  146. */
  147. public function getQuote()
  148. {
  149. return $this->_quote;
  150. }
  151. /**
  152. * Import quote item.
  153. *
  154. * @param \Magento\Quote\Model\Quote\Item $quoteItem
  155. * @return $this
  156. */
  157. public function importQuoteItem(\Magento\Quote\Model\Quote\Item $quoteItem)
  158. {
  159. $this->_quote = $quoteItem->getQuote();
  160. $this->setQuoteItem(
  161. $quoteItem
  162. )->setQuoteItemId(
  163. $quoteItem->getId()
  164. )->setProductId(
  165. $quoteItem->getProductId()
  166. )->setProduct(
  167. $quoteItem->getProduct()
  168. )->setStoreId(
  169. $quoteItem->getStoreId()
  170. )->setSku(
  171. $quoteItem->getSku()
  172. )->setName(
  173. $quoteItem->getName()
  174. )->setDescription(
  175. $quoteItem->getDescription()
  176. )->setWeight(
  177. $quoteItem->getWeight()
  178. )->setPrice(
  179. $quoteItem->getPrice()
  180. )->setCost(
  181. $quoteItem->getCost()
  182. );
  183. if (!$this->hasQty()) {
  184. $this->setQty($quoteItem->getQty());
  185. }
  186. $this->setQuoteItemImported(true);
  187. return $this;
  188. }
  189. /**
  190. * @inheritdoc
  191. * @since 101.1.1
  192. */
  193. public function getOptionByCode($code)
  194. {
  195. if ($this->getQuoteItem()) {
  196. return $this->getQuoteItem()->getOptionBycode($code);
  197. }
  198. return null;
  199. }
  200. }