PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/module-quote/Model/Quote/Address/Item.php

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