12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Quote\Model\Quote;
- use Magento\Customer\Api\AddressMetadataInterface;
- use Magento\Customer\Api\Data\AddressInterfaceFactory;
- use Magento\Customer\Api\Data\RegionInterfaceFactory;
- use Magento\Framework\App\ObjectManager;
- use Magento\Framework\Serialize\Serializer\Json;
- use Magento\Store\Model\StoreManagerInterface;
- /**
- * Sales Quote address model
- *
- * @api
- * @method int getQuoteId()
- * @method Address setQuoteId(int $value)
- * @method string getCreatedAt()
- * @method Address setCreatedAt(string $value)
- * @method string getUpdatedAt()
- * @method Address setUpdatedAt(string $value)
- * @method \Magento\Customer\Api\Data\AddressInterface getCustomerAddress()
- * @method Address setCustomerAddressData(\Magento\Customer\Api\Data\AddressInterface $value)
- * @method string getAddressType()
- * @method Address setAddressType(string $value)
- * @method int getFreeShipping()
- * @method Address setFreeShipping(int $value)
- * @method bool getCollectShippingRates()
- * @method Address setCollectShippingRates(bool $value)
- * @method Address setShippingMethod(string $value)
- * @method string getShippingDescription()
- * @method Address setShippingDescription(string $value)
- * @method float getWeight()
- * @method Address setWeight(float $value)
- * @method float getSubtotal()
- * @method Address setSubtotal(float $value)
- * @method float getBaseSubtotal()
- * @method Address setBaseSubtotal(float $value)
- * @method Address setSubtotalWithDiscount(float $value)
- * @method Address setBaseSubtotalWithDiscount(float $value)
- * @method float getTaxAmount()
- * @method Address setTaxAmount(float $value)
- * @method float getBaseTaxAmount()
- * @method Address setBaseTaxAmount(float $value)
- * @method float getShippingAmount()
- * @method float getBaseShippingAmount()
- * @method float getShippingTaxAmount()
- * @method Address setShippingTaxAmount(float $value)
- * @method float getBaseShippingTaxAmount()
- * @method Address setBaseShippingTaxAmount(float $value)
- * @method float getDiscountAmount()
- * @method Address setDiscountAmount(float $value)
- * @method float getBaseDiscountAmount()
- * @method Address setBaseDiscountAmount(float $value)
- * @method float getGrandTotal()
- * @method Address setGrandTotal(float $value)
- * @method float getBaseGrandTotal()
- * @method Address setBaseGrandTotal(float $value)
- * @method string getCustomerNotes()
- * @method Address setCustomerNotes(string $value)
- * @method string getDiscountDescription()
- * @method Address setDiscountDescription(string $value)
- * @method null|array getDiscountDescriptionArray()
- * @method Address setDiscountDescriptionArray(array $value)
- * @method float getShippingDiscountAmount()
- * @method Address setShippingDiscountAmount(float $value)
- * @method float getBaseShippingDiscountAmount()
- * @method Address setBaseShippingDiscountAmount(float $value)
- * @method float getSubtotalInclTax()
- * @method Address setSubtotalInclTax(float $value)
- * @method float getBaseSubtotalTotalInclTax()
- * @method Address setBaseSubtotalTotalInclTax(float $value)
- * @method int getGiftMessageId()
- * @method Address setGiftMessageId(int $value)
- * @method float getDiscountTaxCompensationAmount()
- * @method Address setDiscountTaxCompensationAmount(float $value)
- * @method float getBaseDiscountTaxCompensationAmount()
- * @method Address setBaseDiscountTaxCompensationAmount(float $value)
- * @method float getShippingDiscountTaxCompensationAmount()
- * @method Address setShippingDiscountTaxCompensationAmount(float $value)
- * @method float getBaseShippingDiscountTaxCompensationAmnt()
- * @method Address setBaseShippingDiscountTaxCompensationAmnt(float $value)
- * @method float getShippingInclTax()
- * @method Address setShippingInclTax(float $value)
- * @method float getBaseShippingInclTax()
- * @method \Magento\SalesRule\Model\Rule[] getCartFixedRules()
- * @method int[] getAppliedRuleIds()
- * @method Address setBaseShippingInclTax(float $value)
- *
- * @property $_objectCopyService \Magento\Framework\DataObject\Copy
- * @SuppressWarnings(PHPMD.ExcessivePublicCount)
- * @SuppressWarnings(PHPMD.TooManyFields)
- * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @since 100.0.2
- */
- class Address extends \Magento\Customer\Model\Address\AbstractAddress implements
- \Magento\Quote\Api\Data\AddressInterface
- {
- const RATES_FETCH = 1;
- const RATES_RECALCULATE = 2;
- const ADDRESS_TYPE_BILLING = 'billing';
- const ADDRESS_TYPE_SHIPPING = 'shipping';
- /**
- * Prefix of model events
- *
- * @var string
- */
- protected $_eventPrefix = 'sales_quote_address';
- /**
- * Name of event object
- *
- * @var string
- */
- protected $_eventObject = 'quote_address';
- /**
- * Quote object
- *
- * @var \Magento\Quote\Model\Quote
- */
- protected $_items;
- /**
- * Quote object
- *
- * @var \Magento\Quote\Model\Quote
- */
- protected $_quote;
- /**
- * Sales Quote address rates
- *
- * @var \Magento\Quote\Model\Quote\Address\Rate
- */
- protected $_rates;
- /**
- * Total models collector
- *
- * @var \Magento\Quote\Model\Quote\Address\Total\Collector
- */
- protected $_totalCollector;
- /**
- * Total data as array
- *
- * @var array
- */
- protected $_totals = [];
- /**
- * @var array
- */
- protected $_totalAmounts = [];
- /**
- * @var array
- */
- protected $_baseTotalAmounts = [];
- /**
- * Core store config
- *
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- protected $_scopeConfig;
- /**
- * @var \Magento\Quote\Model\Quote\Address\ItemFactory
- */
- protected $_addressItemFactory;
- /**
- * @var \Magento\Quote\Model\ResourceModel\Quote\Address\Item\CollectionFactory
- */
- protected $_itemCollectionFactory;
- /**
- * @var \Magento\Quote\Model\Quote\Address\RateCollectorInterfaceFactory
- */
- protected $_rateCollector;
- /**
- * @var \Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory
- */
- protected $_rateCollectionFactory;
- /**
- * @var \Magento\Quote\Model\Quote\Address\Total\CollectorFactory
- */
- protected $_totalCollectorFactory;
- /**
- * @var \Magento\Quote\Model\Quote\Address\TotalFactory
- */
- protected $_addressTotalFactory;
- /**
- * @var \Magento\Quote\Model\Quote\Address\RateFactory
- * @since 101.0.0
- */
- protected $_addressRateFactory;
- /**
- * @var \Magento\Customer\Api\Data\AddressInterfaceFactory
- */
- protected $addressDataFactory;
- /**
- * @var Address\Validator
- */
- protected $validator;
- /**
- * @var \Magento\Customer\Model\Address\Mapper
- */
- protected $addressMapper;
- /**
- * @var Address\RateRequestFactory
- */
- protected $_rateRequestFactory;
- /**
- * @var Address\CustomAttributeListInterface
- */
- protected $attributeList;
- /**
- * @var TotalsCollector
- */
- protected $totalsCollector;
- /**
- * @var \Magento\Quote\Model\Quote\TotalsReader
- */
- protected $totalsReader;
- /**
- * @var Json
- */
- private $serializer;
- /**
- * @var StoreManagerInterface
- */
- private $storeManager;
- /**
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
- * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
- * @param \Magento\Directory\Helper\Data $directoryData
- * @param \Magento\Eav\Model\Config $eavConfig
- * @param \Magento\Customer\Model\Address\Config $addressConfig
- * @param \Magento\Directory\Model\RegionFactory $regionFactory
- * @param \Magento\Directory\Model\CountryFactory $countryFactory
- * @param AddressMetadataInterface $metadataService
- * @param AddressInterfaceFactory $addressDataFactory
- * @param RegionInterfaceFactory $regionDataFactory
- * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
- * @param Address\ItemFactory $addressItemFactory
- * @param \Magento\Quote\Model\ResourceModel\Quote\Address\Item\CollectionFactory $itemCollectionFactory
- * @param \Magento\Quote\Model\Quote\Address\RateFactory $addressRateFactory
- * @param Address\RateCollectorInterfaceFactory $rateCollector
- * @param \Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory $rateCollectionFactory
- * @param Address\RateRequestFactory $rateRequestFactory
- * @param Address\Total\CollectorFactory $totalCollectorFactory
- * @param Address\TotalFactory $addressTotalFactory
- * @param \Magento\Framework\DataObject\Copy $objectCopyService
- * @param \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory
- * @param Address\Validator $validator
- * @param \Magento\Customer\Model\Address\Mapper $addressMapper
- * @param Address\CustomAttributeListInterface $attributeList
- * @param TotalsCollector $totalsCollector
- * @param \Magento\Quote\Model\Quote\TotalsReader $totalsReader
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
- * @param array $data
- * @param Json $serializer
- * @param StoreManagerInterface $storeManager
- *
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __construct(
- \Magento\Framework\Model\Context $context,
- \Magento\Framework\Registry $registry,
- \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
- \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
- \Magento\Directory\Helper\Data $directoryData,
- \Magento\Eav\Model\Config $eavConfig,
- \Magento\Customer\Model\Address\Config $addressConfig,
- \Magento\Directory\Model\RegionFactory $regionFactory,
- \Magento\Directory\Model\CountryFactory $countryFactory,
- AddressMetadataInterface $metadataService,
- AddressInterfaceFactory $addressDataFactory,
- RegionInterfaceFactory $regionDataFactory,
- \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
- \Magento\Quote\Model\Quote\Address\ItemFactory $addressItemFactory,
- \Magento\Quote\Model\ResourceModel\Quote\Address\Item\CollectionFactory $itemCollectionFactory,
- \Magento\Quote\Model\Quote\Address\RateFactory $addressRateFactory,
- \Magento\Quote\Model\Quote\Address\RateCollectorInterfaceFactory $rateCollector,
- \Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory $rateCollectionFactory,
- \Magento\Quote\Model\Quote\Address\RateRequestFactory $rateRequestFactory,
- \Magento\Quote\Model\Quote\Address\Total\CollectorFactory $totalCollectorFactory,
- \Magento\Quote\Model\Quote\Address\TotalFactory $addressTotalFactory,
- \Magento\Framework\DataObject\Copy $objectCopyService,
- \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory,
- Address\Validator $validator,
- \Magento\Customer\Model\Address\Mapper $addressMapper,
- Address\CustomAttributeListInterface $attributeList,
- \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector,
- \Magento\Quote\Model\Quote\TotalsReader $totalsReader,
- \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
- \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
- array $data = [],
- Json $serializer = null,
- StoreManagerInterface $storeManager = null
- ) {
- $this->_scopeConfig = $scopeConfig;
- $this->_addressItemFactory = $addressItemFactory;
- $this->_itemCollectionFactory = $itemCollectionFactory;
- $this->_addressRateFactory = $addressRateFactory;
- $this->_rateCollector = $rateCollector;
- $this->_rateCollectionFactory = $rateCollectionFactory;
- $this->_rateRequestFactory = $rateRequestFactory;
- $this->_totalCollectorFactory = $totalCollectorFactory;
- $this->_addressTotalFactory = $addressTotalFactory;
- $this->_objectCopyService = $objectCopyService;
- $this->_carrierFactory = $carrierFactory;
- $this->addressDataFactory = $addressDataFactory;
- $this->validator = $validator;
- $this->addressMapper = $addressMapper;
- $this->attributeList = $attributeList;
- $this->totalsCollector = $totalsCollector;
- $this->totalsReader = $totalsReader;
- $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
- $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
- parent::__construct(
- $context,
- $registry,
- $extensionFactory,
- $customAttributeFactory,
- $directoryData,
- $eavConfig,
- $addressConfig,
- $regionFactory,
- $countryFactory,
- $metadataService,
- $addressDataFactory,
- $regionDataFactory,
- $dataObjectHelper,
- $resource,
- $resourceCollection,
- $data
- );
- }
- /**
- * Initialize resource
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_init(\Magento\Quote\Model\ResourceModel\Quote\Address::class);
- }
- /**
- * Initialize quote identifier before save
- *
- * @return $this
- */
- public function beforeSave()
- {
- parent::beforeSave();
- $this->_populateBeforeSaveData();
- return $this;
- }
- /**
- * Set the required fields
- *
- * @return void
- */
- protected function _populateBeforeSaveData()
- {
- if ($this->getQuote()) {
- $this->_dataSaveAllowed = (bool)$this->getQuote()->getId();
- if ($this->getQuote()->getId()) {
- $this->setQuoteId($this->getQuote()->getId());
- }
- $this->setCustomerId($this->getQuote()->getCustomerId());
- /**
- * Init customer address id if customer address is assigned
- */
- if ($this->getCustomerAddressData()) {
- $this->setCustomerAddressId($this->getCustomerAddressData()->getId());
- }
- if (!$this->getId()) {
- $this->setSameAsBilling((int)$this->_isSameAsBilling());
- }
- }
- }
- /**
- * Returns true if shipping address is same as billing
- *
- * @return bool
- */
- protected function _isSameAsBilling()
- {
- return $this->getAddressType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING &&
- ($this->_isNotRegisteredCustomer() ||
- $this->_isDefaultShippingNullOrSameAsBillingAddress());
- }
- /**
- * Checks if the user is a registered customer
- *
- * @return bool
- */
- protected function _isNotRegisteredCustomer()
- {
- return !$this->getQuote()->getCustomerId() || $this->getCustomerAddressId() === null;
- }
- /**
- * Returns true if shipping address is same as billing or it is undefined
- *
- * @return bool
- */
- protected function _isDefaultShippingNullOrSameAsBillingAddress()
- {
- $customer = $this->getQuote()->getCustomer();
- $customerId = $customer->getId();
- $defaultBillingAddress = null;
- $defaultShippingAddress = null;
- if ($customerId) {
- /* we should load data from the service once customer is saved */
- $defaultBillingAddress = $customer->getDefaultBilling();
- $defaultShippingAddress = $customer->getDefaultShipping();
- } else {
- /* we should load data from the quote if customer is not saved yet */
- $defaultBillingAddress = $customer->getDefaultBilling();
- $defaultShippingAddress = $customer->getDefaultShipping();
- }
- return !$defaultShippingAddress
- || $defaultBillingAddress
- && $defaultShippingAddress
- && $defaultBillingAddress == $defaultShippingAddress;
- }
- /**
- * Declare address quote model object
- *
- * @param \Magento\Quote\Model\Quote $quote
- * @return $this
- */
- public function setQuote(\Magento\Quote\Model\Quote $quote)
- {
- $this->_quote = $quote;
- $this->setQuoteId($quote->getId());
- return $this;
- }
- /**
- * Retrieve quote object
- *
- * @return \Magento\Quote\Model\Quote
- */
- public function getQuote()
- {
- return $this->_quote;
- }
- /**
- * Import quote address data from customer address Data Object.
- *
- * @param \Magento\Customer\Api\Data\AddressInterface $address
- * @return $this
- */
- public function importCustomerAddressData(\Magento\Customer\Api\Data\AddressInterface $address)
- {
- $this->_objectCopyService->copyFieldsetToTarget(
- 'customer_address',
- 'to_quote_address',
- $this->addressMapper->toFlatArray($address),
- $this
- );
- $quote = $this->getQuote();
- if ($address->getCustomerId() && (!empty($quote) && $address->getCustomerId() == $quote->getCustomerId())) {
- $customer = $quote->getCustomer();
- $this->setEmail($customer->getEmail());
- }
- return $this;
- }
- /**
- * Export data to customer address Data Object.
- *
- * @return \Magento\Customer\Api\Data\AddressInterface
- */
- public function exportCustomerAddress()
- {
- $customerAddressData = $this->_objectCopyService->getDataFromFieldset(
- 'sales_convert_quote_address',
- 'to_customer_address',
- $this
- );
- $customerAddressDataWithRegion = [];
- $customerAddressDataWithRegion['region']['region'] = $customerAddressData['region'];
- if (isset($customerAddressData['region_code'])) {
- $customerAddressDataWithRegion['region']['region_code'] = $customerAddressData['region_code'];
- }
- if ($customerAddressData['region_id']) {
- $customerAddressDataWithRegion['region']['region_id'] = $customerAddressData['region_id'];
- }
- $customerAddressData = array_merge($customerAddressData, $customerAddressDataWithRegion);
- $addressDataObject = $this->addressDataFactory->create();
- $this->dataObjectHelper->populateWithArray(
- $addressDataObject,
- $customerAddressData,
- \Magento\Customer\Api\Data\AddressInterface::class
- );
- return $addressDataObject;
- }
- /**
- * Convert object to array
- *
- * @param array $arrAttributes
- * @return array
- */
- public function toArray(array $arrAttributes = [])
- {
- $arr = parent::toArray($arrAttributes);
- $arr['rates'] = $this->getShippingRatesCollection()->toArray($arrAttributes);
- $arr['items'] = $this->getItemsCollection()->toArray($arrAttributes);
- foreach ($this->getTotals() as $k => $total) {
- $arr['totals'][$k] = $total->toArray();
- }
- return $arr;
- }
- /**
- * Retrieve address items collection
- *
- * @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
- */
- public function getItemsCollection()
- {
- if (null === $this->_items) {
- $this->_items = $this->_itemCollectionFactory->create()->setAddressFilter($this->getId());
- if ($this->getId()) {
- foreach ($this->_items as $item) {
- $item->setAddress($this);
- }
- }
- }
- return $this->_items;
- }
- /**
- * Get all available address items
- *
- * @return \Magento\Quote\Model\Quote\Address\Item[]
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- public function getAllItems()
- {
- // We calculate item list once and cache it in three arrays - all items
- $key = 'cached_items_all';
- if (!$this->hasData($key)) {
- $quoteItems = $this->getQuote()->getItemsCollection();
- $addressItems = $this->getItemsCollection();
- $items = [];
- if ($this->getQuote()->getIsMultiShipping() && $addressItems->count() > 0) {
- foreach ($addressItems as $aItem) {
- if ($aItem->isDeleted()) {
- continue;
- }
- if (!$aItem->getQuoteItemImported()) {
- $qItem = $this->getQuote()->getItemById($aItem->getQuoteItemId());
- if ($qItem) {
- $aItem->importQuoteItem($qItem);
- }
- }
- $items[] = $aItem;
- }
- } else {
- /*
- * For virtual quote we assign items only to billing address, otherwise - only to shipping address
- */
- $addressType = $this->getAddressType();
- $canAddItems = $this->getQuote()->isVirtual()
- ? $addressType == self::TYPE_BILLING
- : $addressType == self::TYPE_SHIPPING;
- if ($canAddItems) {
- foreach ($quoteItems as $qItem) {
- if ($qItem->isDeleted()) {
- continue;
- }
- $items[] = $qItem;
- }
- }
- }
- // Cache calculated lists
- $this->setData('cached_items_all', $items);
- }
- $items = $this->getData($key);
- return $items;
- }
- /**
- * Retrieve all visible items
- *
- * @return array
- */
- public function getAllVisibleItems()
- {
- $items = [];
- foreach ($this->getAllItems() as $item) {
- if (!$item->getParentItemId()) {
- $items[] = $item;
- }
- }
- return $items;
- }
- /**
- * Retrieve item quantity by id
- *
- * @param int $itemId
- * @return float|int
- */
- public function getItemQty($itemId = 0)
- {
- if ($this->hasData('item_qty')) {
- return $this->getData('item_qty');
- }
- $qty = 0;
- if ($itemId == 0) {
- foreach ($this->getAllItems() as $item) {
- $qty += $item->getQty();
- }
- } else {
- $item = $this->getItemById($itemId);
- if ($item) {
- $qty = $item->getQty();
- }
- }
- return $qty;
- }
- /**
- * Check Quote address has Items
- *
- * @return bool
- */
- public function hasItems()
- {
- return sizeof($this->getAllItems()) > 0;
- }
- /**
- * Get address item object by id without
- *
- * @param int $itemId
- * @return \Magento\Quote\Model\Quote\Address\Item|false
- */
- public function getItemById($itemId)
- {
- foreach ($this->getItemsCollection() as $item) {
- if ($item->getId() == $itemId) {
- return $item;
- }
- }
- return false;
- }
- /**
- * Get prepared not deleted item
- *
- * @param int $itemId
- * @return \Magento\Quote\Model\Quote\Address\Item|false
- */
- public function getValidItemById($itemId)
- {
- foreach ($this->getAllItems() as $item) {
- if ($item->getId() == $itemId) {
- return $item;
- }
- }
- return false;
- }
- /**
- * Retrieve item object by quote item Id
- *
- * @param int $itemId
- * @return \Magento\Quote\Model\Quote\Address\Item|false
- */
- public function getItemByQuoteItemId($itemId)
- {
- foreach ($this->getItemsCollection() as $item) {
- if ($item->getQuoteItemId() == $itemId) {
- return $item;
- }
- }
- return false;
- }
- /**
- * Remove item from collection
- *
- * @param int $itemId
- * @return $this
- */
- public function removeItem($itemId)
- {
- $item = $this->getItemById($itemId);
- if ($item) {
- $item->isDeleted(true);
- }
- return $this;
- }
- /**
- * Add item to address
- *
- * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
- * @param int $qty
- * @return $this
- */
- public function addItem(\Magento\Quote\Model\Quote\Item\AbstractItem $item, $qty = null)
- {
- if ($item instanceof \Magento\Quote\Model\Quote\Item) {
- if ($item->getParentItemId()) {
- return $this;
- }
- $addressItem = $this->_addressItemFactory->create()->setAddress($this)->importQuoteItem($item);
- $this->getItemsCollection()->addItem($addressItem);
- if ($item->getHasChildren()) {
- foreach ($item->getChildren() as $child) {
- $addressChildItem = $this->_addressItemFactory->create()->setAddress(
- $this
- )->importQuoteItem(
- $child
- )->setParentItem(
- $addressItem
- );
- $this->getItemsCollection()->addItem($addressChildItem);
- }
- }
- } else {
- $addressItem = $item;
- $addressItem->setAddress($this);
- if (!$addressItem->getId()) {
- $this->getItemsCollection()->addItem($addressItem);
- }
- }
- if ($qty) {
- $addressItem->setQty($qty);
- }
- return $this;
- }
- /**
- * Retrieve collection of quote shipping rates
- *
- * @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
- */
- public function getShippingRatesCollection()
- {
- if (null === $this->_rates) {
- $this->_rates = $this->_rateCollectionFactory->create()->setAddressFilter($this->getId());
- if ($this->getId()) {
- foreach ($this->_rates as $rate) {
- $rate->setAddress($this);
- }
- }
- }
- return $this->_rates;
- }
- /**
- * Retrieve all address shipping rates
- *
- * @return array
- */
- public function getAllShippingRates()
- {
- $rates = [];
- foreach ($this->getShippingRatesCollection() as $rate) {
- if (!$rate->isDeleted()) {
- $rates[] = $rate;
- }
- }
- return $rates;
- }
- /**
- * Retrieve all grouped shipping rates
- *
- * @return array
- */
- public function getGroupedAllShippingRates()
- {
- $rates = [];
- foreach ($this->getShippingRatesCollection() as $rate) {
- if (!$rate->isDeleted() && $this->_carrierFactory->get($rate->getCarrier())) {
- if (!isset($rates[$rate->getCarrier()])) {
- $rates[$rate->getCarrier()] = [];
- }
- $rates[$rate->getCarrier()][] = $rate;
- $rates[$rate->getCarrier()][0]->carrier_sort_order = $this->_carrierFactory->get(
- $rate->getCarrier()
- )->getSortOrder();
- }
- }
- uasort($rates, [$this, '_sortRates']);
- return $rates;
- }
- /**
- * Sort rates recursive callback
- *
- * @param array $firstItem
- * @param array $secondItem
- * @return int
- */
- protected function _sortRates($firstItem, $secondItem)
- {
- return (int) $firstItem[0]->carrier_sort_order <=> (int) $secondItem[0]->carrier_sort_order;
- }
- /**
- * Retrieve shipping rate by identifier
- *
- * @param int $rateId
- * @return \Magento\Quote\Model\Quote\Address\Rate|false
- */
- public function getShippingRateById($rateId)
- {
- foreach ($this->getShippingRatesCollection() as $rate) {
- if ($rate->getId() == $rateId) {
- return $rate;
- }
- }
- return false;
- }
- /**
- * Retrieve shipping rate by code
- *
- * @param string $code
- * @return \Magento\Quote\Model\Quote\Address\Rate|false
- */
- public function getShippingRateByCode($code)
- {
- foreach ($this->getShippingRatesCollection() as $rate) {
- if ($rate->getCode() == $code) {
- return $rate;
- }
- }
- return false;
- }
- /**
- * Mark all shipping rates as deleted
- *
- * @return $this
- */
- public function removeAllShippingRates()
- {
- foreach ($this->getShippingRatesCollection() as $rate) {
- $rate->isDeleted(true);
- }
- return $this;
- }
- /**
- * Add shipping rate
- *
- * @param \Magento\Quote\Model\Quote\Address\Rate $rate
- * @return $this
- */
- public function addShippingRate(\Magento\Quote\Model\Quote\Address\Rate $rate)
- {
- $rate->setAddress($this);
- $this->getShippingRatesCollection()->addItem($rate);
- return $this;
- }
- /**
- * Collecting shipping rates by address
- *
- * @return $this
- */
- public function collectShippingRates()
- {
- if (!$this->getCollectShippingRates()) {
- return $this;
- }
- $this->setCollectShippingRates(false);
- $this->removeAllShippingRates();
- if (!$this->getCountryId()) {
- return $this;
- }
- $found = $this->requestShippingRates();
- if (!$found) {
- $this->setShippingAmount(0)->setBaseShippingAmount(0)->setShippingMethod('')->setShippingDescription('');
- }
- return $this;
- }
- /**
- * Request shipping rates for entire address or specified address item
- *
- * Returns true if current selected shipping method code corresponds to one of the found rates
- *
- * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
- * @return bool
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- public function requestShippingRates(\Magento\Quote\Model\Quote\Item\AbstractItem $item = null)
- {
- /** @var $request \Magento\Quote\Model\Quote\Address\RateRequest */
- $request = $this->_rateRequestFactory->create();
- $request->setAllItems($item ? [$item] : $this->getAllItems());
- $request->setDestCountryId($this->getCountryId());
- $request->setDestRegionId($this->getRegionId());
- $request->setDestRegionCode($this->getRegionCode());
- $request->setDestStreet($this->getStreetFull());
- $request->setDestCity($this->getCity());
- $request->setDestPostcode($this->getPostcode());
- $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal());
- $packageWithDiscount = $item ? $item->getBaseRowTotal() -
- $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount();
- $request->setPackageValueWithDiscount($packageWithDiscount);
- $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight());
- $request->setPackageQty($item ? $item->getQty() : $this->getItemQty());
- /**
- * Need for shipping methods that use insurance based on price of physical products
- */
- $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() -
- $this->getBaseVirtualAmount();
- $request->setPackagePhysicalValue($packagePhysicalValue);
- $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight());
- /**
- * Store and website identifiers specified from StoreManager
- */
- if ($this->getQuote()->getStoreId()) {
- $storeId = $this->getQuote()->getStoreId();
- $request->setStoreId($storeId);
- $request->setWebsiteId($this->storeManager->getStore($storeId)->getWebsiteId());
- } else {
- $request->setStoreId($this->storeManager->getStore()->getId());
- $request->setWebsiteId($this->storeManager->getWebsite()->getId());
- }
- $request->setFreeShipping($this->getFreeShipping());
- /**
- * Currencies need to convert in free shipping
- */
- $request->setBaseCurrency($this->storeManager->getStore()->getBaseCurrency());
- $request->setPackageCurrency($this->storeManager->getStore()->getCurrentCurrency());
- $request->setLimitCarrier($this->getLimitCarrier());
- $baseSubtotalInclTax = $this->getBaseSubtotalTotalInclTax();
- $request->setBaseSubtotalInclTax($baseSubtotalInclTax);
- $result = $this->_rateCollector->create()->collectRates($request)->getResult();
- $found = false;
- if ($result) {
- $shippingRates = $result->getAllRates();
- foreach ($shippingRates as $shippingRate) {
- $rate = $this->_addressRateFactory->create()->importShippingRate($shippingRate);
- if (!$item) {
- $this->addShippingRate($rate);
- }
- if ($this->getShippingMethod() == $rate->getCode()) {
- if ($item) {
- $item->setBaseShippingAmount($rate->getPrice());
- } else {
- /** @var \Magento\Store\Api\Data\StoreInterface */
- $store = $this->storeManager->getStore();
- $amountPrice = $store->getBaseCurrency()
- ->convert($rate->getPrice(), $store->getCurrentCurrencyCode());
- $this->setBaseShippingAmount($rate->getPrice());
- $this->setShippingAmount($amountPrice);
- }
- $found = true;
- }
- }
- }
- return $found;
- }
- /******************************* Total Collector Interface *******************************************/
- /**
- * Get address totals as array
- *
- * @return array
- */
- public function getTotals()
- {
- $totalsData = array_merge($this->getData(), ['address_quote_items' => $this->getAllItems()]);
- $totals = $this->totalsReader->fetch($this->getQuote(), $totalsData);
- foreach ($totals as $total) {
- $this->addTotal($total);
- }
- return $this->_totals;
- }
- /**
- * Add total data or model
- *
- * @param \Magento\Quote\Model\Quote\Address\Total|array $total
- * @return $this
- */
- public function addTotal($total)
- {
- $addressTotal = null;
- if (is_array($total)) {
- /** @var \Magento\Quote\Model\Quote\Address\Total $addressTotal */
- $addressTotal = $this->_addressTotalFactory->create(\Magento\Quote\Model\Quote\Address\Total::class);
- $addressTotal->setData($total);
- } elseif ($total instanceof \Magento\Quote\Model\Quote\Address\Total) {
- $addressTotal = $total;
- }
- if ($addressTotal !== null) {
- $addressTotal->setAddress($this);
- $this->_totals[$addressTotal->getCode()] = $addressTotal;
- }
- return $this;
- }
- /******************************* End Total Collector Interface *******************************************/
- /**
- * Rewrite clone method
- *
- * @return \Magento\Quote\Model\Quote\Address
- */
- public function __clone()
- {
- $this->setId(null);
- }
- /**
- * Checks if it was set
- *
- * @return bool
- */
- public function itemsCollectionWasSet()
- {
- return null !== $this->_items;
- }
- /**
- * Checks if it was set
- *
- * @return bool
- */
- public function shippingRatesCollectionWasSet()
- {
- return null !== $this->_rates;
- }
- /**
- * Validate minimum amount
- *
- * @return bool
- */
- public function validateMinimumAmount()
- {
- $storeId = $this->getQuote()->getStoreId();
- $validateEnabled = $this->_scopeConfig->isSetFlag(
- 'sales/minimum_order/active',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- $storeId
- );
- if (!$validateEnabled) {
- return true;
- }
- if (!$this->getQuote()->getIsVirtual() xor $this->getAddressType() == self::TYPE_SHIPPING) {
- return true;
- }
- $includeDiscount = $this->_scopeConfig->getValue(
- 'sales/minimum_order/include_discount_amount',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- $storeId
- );
- $amount = $this->_scopeConfig->getValue(
- 'sales/minimum_order/amount',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- $storeId
- );
- $taxInclude = $this->_scopeConfig->getValue(
- 'sales/minimum_order/tax_including',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- $storeId
- );
- $taxes = $taxInclude ? $this->getBaseTaxAmount() : 0;
- return $includeDiscount ?
- ($this->getBaseSubtotalWithDiscount() + $taxes >= $amount) :
- ($this->getBaseSubtotal() + $taxes >= $amount);
- }
- /**
- * Retrieve applied taxes
- *
- * @return array
- */
- public function getAppliedTaxes()
- {
- $taxes = $this->getData('applied_taxes');
- return $taxes ? $this->serializer->unserialize($taxes) : [];
- }
- /**
- * Set applied taxes
- *
- * @param array $data
- * @return $this
- */
- public function setAppliedTaxes($data)
- {
- return $this->setData('applied_taxes', $this->serializer->serialize($data));
- }
- /******************************* Start Total Collector Interface *******************************************/
- /**
- * Set shipping amount
- *
- * @param float $value
- * @param bool $alreadyExclTax
- * @return $this
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function setShippingAmount($value, $alreadyExclTax = false)
- {
- return $this->setData('shipping_amount', $value);
- }
- /**
- * Set base shipping amount
- *
- * @param float $value
- * @param bool $alreadyExclTax
- * @return $this
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function setBaseShippingAmount($value, $alreadyExclTax = false)
- {
- return $this->setData('base_shipping_amount', $value);
- }
- /**
- * Set total amount value
- *
- * @param string $code
- * @param float $amount
- * @return $this
- */
- public function setTotalAmount($code, $amount)
- {
- $this->_totalAmounts[$code] = $amount;
- if ($code != 'subtotal') {
- $code = $code . '_amount';
- }
- $this->setData($code, $amount);
- return $this;
- }
- /**
- * Set total amount value in base store currency
- *
- * @param string $code
- * @param float $amount
- * @return $this
- */
- public function setBaseTotalAmount($code, $amount)
- {
- $this->_baseTotalAmounts[$code] = $amount;
- if ($code != 'subtotal') {
- $code = $code . '_amount';
- }
- $this->setData('base_' . $code, $amount);
- return $this;
- }
- /**
- * Add amount total amount value
- *
- * @param string $code
- * @param float $amount
- * @return $this
- */
- public function addTotalAmount($code, $amount)
- {
- $amount = $this->getTotalAmount($code) + $amount;
- $this->setTotalAmount($code, $amount);
- return $this;
- }
- /**
- * Add amount total amount value in base store currency
- *
- * @param string $code
- * @param float $amount
- * @return $this
- */
- public function addBaseTotalAmount($code, $amount)
- {
- $amount = $this->getBaseTotalAmount($code) + $amount;
- $this->setBaseTotalAmount($code, $amount);
- return $this;
- }
- /**
- * Get total amount value by code
- *
- * @param string $code
- * @return float|int
- */
- public function getTotalAmount($code)
- {
- if (isset($this->_totalAmounts[$code])) {
- return $this->_totalAmounts[$code];
- }
- return 0;
- }
- /**
- * Get total amount value by code in base store currency
- *
- * @param string $code
- * @return float|int
- */
- public function getBaseTotalAmount($code)
- {
- if (isset($this->_baseTotalAmounts[$code])) {
- return $this->_baseTotalAmounts[$code];
- }
- return 0;
- }
- /**
- * Get subtotal amount with applied discount in base currency
- *
- * @return float
- */
- public function getBaseSubtotalWithDiscount()
- {
- return $this->getBaseSubtotal() + $this->getBaseDiscountAmount();
- }
- /**
- * Get subtotal amount with applied discount
- *
- * @return float
- */
- public function getSubtotalWithDiscount()
- {
- return $this->getSubtotal() + $this->getDiscountAmount();
- }
- //@codeCoverageIgnoreStart
- /**
- * Get all total amount values
- *
- * @return array
- */
- public function getAllTotalAmounts()
- {
- return $this->_totalAmounts;
- }
- /**
- * Get all total amount values in base currency
- *
- * @return array
- */
- public function getAllBaseTotalAmounts()
- {
- return $this->_baseTotalAmounts;
- }
- /******************************* End Total Collector Interface *******************************************/
- /**
- * @inheritdoc
- */
- protected function _getValidationRulesBeforeSave()
- {
- return $this->validator;
- }
- /**
- * @inheritdoc
- */
- public function getCountryId()
- {
- return $this->getData(self::KEY_COUNTRY_ID);
- }
- /**
- * @inheritdoc
- */
- public function setCountryId($countryId)
- {
- return $this->setData(self::KEY_COUNTRY_ID, $countryId);
- }
- /**
- * @inheritdoc
- */
- public function getStreet()
- {
- $street = $this->getData(self::KEY_STREET);
- return is_array($street) ? $street : explode("\n", $street);
- }
- /**
- * @inheritdoc
- */
- public function setStreet($street)
- {
- return $this->setData(self::KEY_STREET, $street);
- }
- /**
- * @inheritdoc
- */
- public function getCompany()
- {
- return $this->getData(self::KEY_COMPANY);
- }
- /**
- * @inheritdoc
- */
- public function setCompany($company)
- {
- return $this->setData(self::KEY_COMPANY, $company);
- }
- /**
- * @inheritdoc
- */
- public function getTelephone()
- {
- return $this->getData(self::KEY_TELEPHONE);
- }
- /**
- * @inheritdoc
- */
- public function setTelephone($telephone)
- {
- return $this->setData(self::KEY_TELEPHONE, $telephone);
- }
- /**
- * @inheritdoc
- */
- public function getFax()
- {
- return $this->getData(self::KEY_FAX);
- }
- /**
- * @inheritdoc
- */
- public function setFax($fax)
- {
- return $this->setData(self::KEY_FAX, $fax);
- }
- /**
- * @inheritdoc
- */
- public function getPostcode()
- {
- return $this->getData(self::KEY_POSTCODE);
- }
- /**
- * @inheritdoc
- */
- public function setPostcode($postcode)
- {
- return $this->setData(self::KEY_POSTCODE, $postcode);
- }
- /**
- * @inheritdoc
- */
- public function getCity()
- {
- return $this->getData(self::KEY_CITY);
- }
- /**
- * @inheritdoc
- */
- public function setCity($city)
- {
- return $this->setData(self::KEY_CITY, $city);
- }
- /**
- * @inheritdoc
- */
- public function getFirstname()
- {
- return $this->getData(self::KEY_FIRSTNAME);
- }
- /**
- * @inheritdoc
- */
- public function setFirstname($firstname)
- {
- return $this->setData(self::KEY_FIRSTNAME, $firstname);
- }
- /**
- * @inheritdoc
- */
- public function getLastname()
- {
- return $this->getData(self::KEY_LASTNAME);
- }
- /**
- * @inheritdoc
- */
- public function setLastname($lastname)
- {
- return $this->setData(self::KEY_LASTNAME, $lastname);
- }
- /**
- * @inheritdoc
- */
- public function getMiddlename()
- {
- return $this->getData(self::KEY_MIDDLENAME);
- }
- /**
- * @inheritdoc
- */
- public function setMiddlename($middlename)
- {
- return $this->setData(self::KEY_MIDDLENAME, $middlename);
- }
- /**
- * @inheritdoc
- */
- public function getPrefix()
- {
- return $this->getData(self::KEY_PREFIX);
- }
- /**
- * @inheritdoc
- */
- public function setPrefix($prefix)
- {
- return $this->setData(self::KEY_PREFIX, $prefix);
- }
- /**
- * @inheritdoc
- */
- public function getSuffix()
- {
- return $this->getData(self::KEY_SUFFIX);
- }
- /**
- * @inheritdoc
- */
- public function setSuffix($suffix)
- {
- return $this->setData(self::KEY_SUFFIX, $suffix);
- }
- /**
- * @inheritdoc
- */
- public function getVatId()
- {
- return $this->getData(self::KEY_VAT_ID);
- }
- /**
- * @inheritdoc
- */
- public function setVatId($vatId)
- {
- return $this->setData(self::KEY_VAT_ID, $vatId);
- }
- /**
- * @inheritdoc
- */
- public function getCustomerId()
- {
- return $this->getData(self::KEY_CUSTOMER_ID);
- }
- /**
- * @inheritdoc
- */
- public function setCustomerId($customerId)
- {
- return $this->setData(self::KEY_CUSTOMER_ID, $customerId);
- }
- /**
- * @inheritdoc
- */
- public function getEmail()
- {
- $email = $this->getData(self::KEY_EMAIL);
- if (!$email && $this->getQuote()) {
- $email = $this->getQuote()->getCustomerEmail();
- $this->setEmail($email);
- }
- return $email;
- }
- /**
- * @inheritdoc
- */
- public function setEmail($email)
- {
- return $this->setData(self::KEY_EMAIL, $email);
- }
- /**
- * @inheritdoc
- */
- public function setRegion($region)
- {
- return $this->setData(self::KEY_REGION, $region);
- }
- /**
- * @inheritdoc
- */
- public function setRegionId($regionId)
- {
- return $this->setData(self::KEY_REGION_ID, $regionId);
- }
- /**
- * @inheritdoc
- */
- public function setRegionCode($regionCode)
- {
- return $this->setData(self::KEY_REGION_CODE, $regionCode);
- }
- /**
- * @inheritdoc
- */
- public function getSameAsBilling()
- {
- return $this->getData(self::SAME_AS_BILLING);
- }
- /**
- * @inheritdoc
- */
- public function setSameAsBilling($sameAsBilling)
- {
- return $this->setData(self::SAME_AS_BILLING, $sameAsBilling);
- }
- /**
- * @inheritdoc
- */
- public function getCustomerAddressId()
- {
- return $this->getData(self::CUSTOMER_ADDRESS_ID);
- }
- /**
- * @inheritdoc
- */
- public function setCustomerAddressId($customerAddressId)
- {
- return $this->setData(self::CUSTOMER_ADDRESS_ID, $customerAddressId);
- }
- /**
- * Get save in address book flag
- *
- * @return int|null
- */
- public function getSaveInAddressBook()
- {
- return $this->getData(self::SAVE_IN_ADDRESS_BOOK);
- }
- /**
- * Set save in address book flag
- *
- * @param int|null $saveInAddressBook
- * @return $this
- */
- public function setSaveInAddressBook($saveInAddressBook)
- {
- return $this->setData(self::SAVE_IN_ADDRESS_BOOK, $saveInAddressBook);
- }
- //@codeCoverageIgnoreEnd
- /**
- * @inheritdoc
- *
- * @return \Magento\Quote\Api\Data\AddressExtensionInterface|null
- */
- public function getExtensionAttributes()
- {
- return $this->_getExtensionAttributes();
- }
- /**
- * @inheritdoc
- *
- * @param \Magento\Quote\Api\Data\AddressExtensionInterface $extensionAttributes
- * @return $this
- */
- public function setExtensionAttributes(\Magento\Quote\Api\Data\AddressExtensionInterface $extensionAttributes)
- {
- return $this->_setExtensionAttributes($extensionAttributes);
- }
- /**
- * Shipping method
- *
- * @return string
- */
- public function getShippingMethod()
- {
- return $this->getData('shipping_method');
- }
- /**
- * @inheritdoc
- */
- protected function getCustomAttributesCodes()
- {
- return array_keys($this->attributeList->getAttributes());
- }
- }
|