Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Address.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Customer\Api\Data\AddressInterfaceFactory;
10 use Magento\Customer\Api\Data\RegionInterfaceFactory;
14 
100 class Address extends \Magento\Customer\Model\Address\AbstractAddress implements
102 {
103  const RATES_FETCH = 1;
104 
105  const RATES_RECALCULATE = 2;
106 
107  const ADDRESS_TYPE_BILLING = 'billing';
108 
109  const ADDRESS_TYPE_SHIPPING = 'shipping';
110 
116  protected $_eventPrefix = 'sales_quote_address';
117 
123  protected $_eventObject = 'quote_address';
124 
130  protected $_items;
131 
137  protected $_quote;
138 
144  protected $_rates;
145 
151  protected $_totalCollector;
152 
158  protected $_totals = [];
159 
163  protected $_totalAmounts = [];
164 
168  protected $_baseTotalAmounts = [];
169 
175  protected $_scopeConfig;
176 
181 
186 
190  protected $_rateCollector;
191 
196 
201 
206 
212 
217 
221  protected $validator;
222 
226  protected $addressMapper;
227 
232 
236  protected $attributeList;
237 
241  protected $totalsCollector;
242 
246  protected $totalsReader;
247 
251  private $serializer;
252 
256  private $storeManager;
257 
296  public function __construct(
297  \Magento\Framework\Model\Context $context,
298  \Magento\Framework\Registry $registry,
299  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
301  \Magento\Directory\Helper\Data $directoryData,
302  \Magento\Eav\Model\Config $eavConfig,
303  \Magento\Customer\Model\Address\Config $addressConfig,
304  \Magento\Directory\Model\RegionFactory $regionFactory,
305  \Magento\Directory\Model\CountryFactory $countryFactory,
307  AddressInterfaceFactory $addressDataFactory,
308  RegionInterfaceFactory $regionDataFactory,
309  \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
310  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
311  \Magento\Quote\Model\Quote\Address\ItemFactory $addressItemFactory,
312  \Magento\Quote\Model\ResourceModel\Quote\Address\Item\CollectionFactory $itemCollectionFactory,
313  \Magento\Quote\Model\Quote\Address\RateFactory $addressRateFactory,
315  \Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory $rateCollectionFactory,
316  \Magento\Quote\Model\Quote\Address\RateRequestFactory $rateRequestFactory,
317  \Magento\Quote\Model\Quote\Address\Total\CollectorFactory $totalCollectorFactory,
318  \Magento\Quote\Model\Quote\Address\TotalFactory $addressTotalFactory,
319  \Magento\Framework\DataObject\Copy $objectCopyService,
320  \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory,
326  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
327  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
328  array $data = [],
329  Json $serializer = null,
330  StoreManagerInterface $storeManager = null
331  ) {
332  $this->_scopeConfig = $scopeConfig;
333  $this->_addressItemFactory = $addressItemFactory;
334  $this->_itemCollectionFactory = $itemCollectionFactory;
335  $this->_addressRateFactory = $addressRateFactory;
336  $this->_rateCollector = $rateCollector;
337  $this->_rateCollectionFactory = $rateCollectionFactory;
338  $this->_rateRequestFactory = $rateRequestFactory;
339  $this->_totalCollectorFactory = $totalCollectorFactory;
340  $this->_addressTotalFactory = $addressTotalFactory;
341  $this->_objectCopyService = $objectCopyService;
342  $this->_carrierFactory = $carrierFactory;
343  $this->addressDataFactory = $addressDataFactory;
344  $this->validator = $validator;
345  $this->addressMapper = $addressMapper;
346  $this->attributeList = $attributeList;
347  $this->totalsCollector = $totalsCollector;
348  $this->totalsReader = $totalsReader;
349  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
350  $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
351  parent::__construct(
352  $context,
353  $registry,
354  $extensionFactory,
356  $directoryData,
357  $eavConfig,
358  $addressConfig,
359  $regionFactory,
360  $countryFactory,
365  $resource,
366  $resourceCollection,
367  $data
368  );
369  }
370 
376  protected function _construct()
377  {
378  $this->_init(\Magento\Quote\Model\ResourceModel\Quote\Address::class);
379  }
380 
386  public function beforeSave()
387  {
388  parent::beforeSave();
389  $this->_populateBeforeSaveData();
390  return $this;
391  }
392 
398  protected function _populateBeforeSaveData()
399  {
400  if ($this->getQuote()) {
401  $this->_dataSaveAllowed = (bool)$this->getQuote()->getId();
402 
403  if ($this->getQuote()->getId()) {
404  $this->setQuoteId($this->getQuote()->getId());
405  }
406  $this->setCustomerId($this->getQuote()->getCustomerId());
407 
411  if ($this->getCustomerAddressData()) {
412  $this->setCustomerAddressId($this->getCustomerAddressData()->getId());
413  }
414 
415  if (!$this->getId()) {
416  $this->setSameAsBilling((int)$this->_isSameAsBilling());
417  }
418  }
419  }
420 
426  protected function _isSameAsBilling()
427  {
428  return $this->getAddressType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING &&
429  ($this->_isNotRegisteredCustomer() ||
431  }
432 
438  protected function _isNotRegisteredCustomer()
439  {
440  return !$this->getQuote()->getCustomerId() || $this->getCustomerAddressId() === null;
441  }
442 
449  {
450  $customer = $this->getQuote()->getCustomer();
451  $customerId = $customer->getId();
452  $defaultBillingAddress = null;
453  $defaultShippingAddress = null;
454 
455  if ($customerId) {
456  /* we should load data from the service once customer is saved */
457  $defaultBillingAddress = $customer->getDefaultBilling();
458  $defaultShippingAddress = $customer->getDefaultShipping();
459  } else {
460  /* we should load data from the quote if customer is not saved yet */
461  $defaultBillingAddress = $customer->getDefaultBilling();
462  $defaultShippingAddress = $customer->getDefaultShipping();
463  }
464 
465  return !$defaultShippingAddress
466  || $defaultBillingAddress
467  && $defaultShippingAddress
468  && $defaultBillingAddress == $defaultShippingAddress;
469  }
470 
477  public function setQuote(\Magento\Quote\Model\Quote $quote)
478  {
479  $this->_quote = $quote;
480  $this->setQuoteId($quote->getId());
481  return $this;
482  }
483 
489  public function getQuote()
490  {
491  return $this->_quote;
492  }
493 
501  {
502  $this->_objectCopyService->copyFieldsetToTarget(
503  'customer_address',
504  'to_quote_address',
505  $this->addressMapper->toFlatArray($address),
506  $this
507  );
508 
509  $quote = $this->getQuote();
510  if ($address->getCustomerId() && (!empty($quote) && $address->getCustomerId() == $quote->getCustomerId())) {
511  $customer = $quote->getCustomer();
512  $this->setEmail($customer->getEmail());
513  }
514  return $this;
515  }
516 
522  public function exportCustomerAddress()
523  {
524  $customerAddressData = $this->_objectCopyService->getDataFromFieldset(
525  'sales_convert_quote_address',
526  'to_customer_address',
527  $this
528  );
529  $customerAddressDataWithRegion = [];
530  $customerAddressDataWithRegion['region']['region'] = $customerAddressData['region'];
531  if (isset($customerAddressData['region_code'])) {
532  $customerAddressDataWithRegion['region']['region_code'] = $customerAddressData['region_code'];
533  }
534  if ($customerAddressData['region_id']) {
535  $customerAddressDataWithRegion['region']['region_id'] = $customerAddressData['region_id'];
536  }
537  $customerAddressData = array_merge($customerAddressData, $customerAddressDataWithRegion);
538 
539  $addressDataObject = $this->addressDataFactory->create();
540  $this->dataObjectHelper->populateWithArray(
541  $addressDataObject,
542  $customerAddressData,
543  \Magento\Customer\Api\Data\AddressInterface::class
544  );
545  return $addressDataObject;
546  }
547 
554  public function toArray(array $arrAttributes = [])
555  {
556  $arr = parent::toArray($arrAttributes);
557  $arr['rates'] = $this->getShippingRatesCollection()->toArray($arrAttributes);
558  $arr['items'] = $this->getItemsCollection()->toArray($arrAttributes);
559  foreach ($this->getTotals() as $k => $total) {
560  $arr['totals'][$k] = $total->toArray();
561  }
562 
563  return $arr;
564  }
565 
571  public function getItemsCollection()
572  {
573  if (null === $this->_items) {
574  $this->_items = $this->_itemCollectionFactory->create()->setAddressFilter($this->getId());
575  if ($this->getId()) {
576  foreach ($this->_items as $item) {
577  $item->setAddress($this);
578  }
579  }
580  }
581 
582  return $this->_items;
583  }
584 
592  public function getAllItems()
593  {
594  // We calculate item list once and cache it in three arrays - all items
595  $key = 'cached_items_all';
596  if (!$this->hasData($key)) {
597  $quoteItems = $this->getQuote()->getItemsCollection();
598  $addressItems = $this->getItemsCollection();
599 
600  $items = [];
601  if ($this->getQuote()->getIsMultiShipping() && $addressItems->count() > 0) {
602  foreach ($addressItems as $aItem) {
603  if ($aItem->isDeleted()) {
604  continue;
605  }
606 
607  if (!$aItem->getQuoteItemImported()) {
608  $qItem = $this->getQuote()->getItemById($aItem->getQuoteItemId());
609  if ($qItem) {
610  $aItem->importQuoteItem($qItem);
611  }
612  }
613  $items[] = $aItem;
614  }
615  } else {
616  /*
617  * For virtual quote we assign items only to billing address, otherwise - only to shipping address
618  */
619  $addressType = $this->getAddressType();
620  $canAddItems = $this->getQuote()->isVirtual()
621  ? $addressType == self::TYPE_BILLING
622  : $addressType == self::TYPE_SHIPPING;
623 
624  if ($canAddItems) {
625  foreach ($quoteItems as $qItem) {
626  if ($qItem->isDeleted()) {
627  continue;
628  }
629  $items[] = $qItem;
630  }
631  }
632  }
633 
634  // Cache calculated lists
635  $this->setData('cached_items_all', $items);
636  }
637 
638  $items = $this->getData($key);
639 
640  return $items;
641  }
642 
648  public function getAllVisibleItems()
649  {
650  $items = [];
651  foreach ($this->getAllItems() as $item) {
652  if (!$item->getParentItemId()) {
653  $items[] = $item;
654  }
655  }
656 
657  return $items;
658  }
659 
666  public function getItemQty($itemId = 0)
667  {
668  if ($this->hasData('item_qty')) {
669  return $this->getData('item_qty');
670  }
671 
672  $qty = 0;
673  if ($itemId == 0) {
674  foreach ($this->getAllItems() as $item) {
675  $qty += $item->getQty();
676  }
677  } else {
678  $item = $this->getItemById($itemId);
679  if ($item) {
680  $qty = $item->getQty();
681  }
682  }
683 
684  return $qty;
685  }
686 
692  public function hasItems()
693  {
694  return sizeof($this->getAllItems()) > 0;
695  }
696 
703  public function getItemById($itemId)
704  {
705  foreach ($this->getItemsCollection() as $item) {
706  if ($item->getId() == $itemId) {
707  return $item;
708  }
709  }
710 
711  return false;
712  }
713 
720  public function getValidItemById($itemId)
721  {
722  foreach ($this->getAllItems() as $item) {
723  if ($item->getId() == $itemId) {
724  return $item;
725  }
726  }
727 
728  return false;
729  }
730 
737  public function getItemByQuoteItemId($itemId)
738  {
739  foreach ($this->getItemsCollection() as $item) {
740  if ($item->getQuoteItemId() == $itemId) {
741  return $item;
742  }
743  }
744  return false;
745  }
746 
753  public function removeItem($itemId)
754  {
755  $item = $this->getItemById($itemId);
756  if ($item) {
757  $item->isDeleted(true);
758  }
759 
760  return $this;
761  }
762 
770  public function addItem(\Magento\Quote\Model\Quote\Item\AbstractItem $item, $qty = null)
771  {
772  if ($item instanceof \Magento\Quote\Model\Quote\Item) {
773  if ($item->getParentItemId()) {
774  return $this;
775  }
776  $addressItem = $this->_addressItemFactory->create()->setAddress($this)->importQuoteItem($item);
777  $this->getItemsCollection()->addItem($addressItem);
778 
779  if ($item->getHasChildren()) {
780  foreach ($item->getChildren() as $child) {
781  $addressChildItem = $this->_addressItemFactory->create()->setAddress(
782  $this
783  )->importQuoteItem(
784  $child
785  )->setParentItem(
786  $addressItem
787  );
788  $this->getItemsCollection()->addItem($addressChildItem);
789  }
790  }
791  } else {
792  $addressItem = $item;
793  $addressItem->setAddress($this);
794  if (!$addressItem->getId()) {
795  $this->getItemsCollection()->addItem($addressItem);
796  }
797  }
798 
799  if ($qty) {
800  $addressItem->setQty($qty);
801  }
802 
803  return $this;
804  }
805 
811  public function getShippingRatesCollection()
812  {
813  if (null === $this->_rates) {
814  $this->_rates = $this->_rateCollectionFactory->create()->setAddressFilter($this->getId());
815  if ($this->getId()) {
816  foreach ($this->_rates as $rate) {
817  $rate->setAddress($this);
818  }
819  }
820  }
821  return $this->_rates;
822  }
823 
829  public function getAllShippingRates()
830  {
831  $rates = [];
832  foreach ($this->getShippingRatesCollection() as $rate) {
833  if (!$rate->isDeleted()) {
834  $rates[] = $rate;
835  }
836  }
837 
838  return $rates;
839  }
840 
846  public function getGroupedAllShippingRates()
847  {
848  $rates = [];
849  foreach ($this->getShippingRatesCollection() as $rate) {
850  if (!$rate->isDeleted() && $this->_carrierFactory->get($rate->getCarrier())) {
851  if (!isset($rates[$rate->getCarrier()])) {
852  $rates[$rate->getCarrier()] = [];
853  }
854 
855  $rates[$rate->getCarrier()][] = $rate;
856  $rates[$rate->getCarrier()][0]->carrier_sort_order = $this->_carrierFactory->get(
857  $rate->getCarrier()
858  )->getSortOrder();
859  }
860  }
861  uasort($rates, [$this, '_sortRates']);
862 
863  return $rates;
864  }
865 
873  protected function _sortRates($firstItem, $secondItem)
874  {
875  return (int) $firstItem[0]->carrier_sort_order <=> (int) $secondItem[0]->carrier_sort_order;
876  }
877 
884  public function getShippingRateById($rateId)
885  {
886  foreach ($this->getShippingRatesCollection() as $rate) {
887  if ($rate->getId() == $rateId) {
888  return $rate;
889  }
890  }
891 
892  return false;
893  }
894 
901  public function getShippingRateByCode($code)
902  {
903  foreach ($this->getShippingRatesCollection() as $rate) {
904  if ($rate->getCode() == $code) {
905  return $rate;
906  }
907  }
908 
909  return false;
910  }
911 
917  public function removeAllShippingRates()
918  {
919  foreach ($this->getShippingRatesCollection() as $rate) {
920  $rate->isDeleted(true);
921  }
922  return $this;
923  }
924 
932  {
933  $rate->setAddress($this);
934  $this->getShippingRatesCollection()->addItem($rate);
935 
936  return $this;
937  }
938 
944  public function collectShippingRates()
945  {
946  if (!$this->getCollectShippingRates()) {
947  return $this;
948  }
949 
950  $this->setCollectShippingRates(false);
951 
952  $this->removeAllShippingRates();
953 
954  if (!$this->getCountryId()) {
955  return $this;
956  }
957 
958  $found = $this->requestShippingRates();
959  if (!$found) {
960  $this->setShippingAmount(0)->setBaseShippingAmount(0)->setShippingMethod('')->setShippingDescription('');
961  }
962 
963  return $this;
964  }
965 
975  public function requestShippingRates(\Magento\Quote\Model\Quote\Item\AbstractItem $item = null)
976  {
978  $request = $this->_rateRequestFactory->create();
979  $request->setAllItems($item ? [$item] : $this->getAllItems());
980  $request->setDestCountryId($this->getCountryId());
981  $request->setDestRegionId($this->getRegionId());
982  $request->setDestRegionCode($this->getRegionCode());
983  $request->setDestStreet($this->getStreetFull());
984  $request->setDestCity($this->getCity());
985  $request->setDestPostcode($this->getPostcode());
986  $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal());
987  $packageWithDiscount = $item ? $item->getBaseRowTotal() -
988  $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount();
989  $request->setPackageValueWithDiscount($packageWithDiscount);
990  $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight());
991  $request->setPackageQty($item ? $item->getQty() : $this->getItemQty());
992 
996  $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() -
997  $this->getBaseVirtualAmount();
998  $request->setPackagePhysicalValue($packagePhysicalValue);
999 
1000  $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight());
1001 
1005  $request->setStoreId($this->storeManager->getStore()->getId());
1006  $request->setWebsiteId($this->storeManager->getWebsite()->getId());
1007  $request->setFreeShipping($this->getFreeShipping());
1011  $request->setBaseCurrency($this->storeManager->getStore()->getBaseCurrency());
1012  $request->setPackageCurrency($this->storeManager->getStore()->getCurrentCurrency());
1013  $request->setLimitCarrier($this->getLimitCarrier());
1014  $baseSubtotalInclTax = $this->getBaseSubtotalTotalInclTax();
1015  $request->setBaseSubtotalInclTax($baseSubtotalInclTax);
1016 
1017  $result = $this->_rateCollector->create()->collectRates($request)->getResult();
1018 
1019  $found = false;
1020  if ($result) {
1021  $shippingRates = $result->getAllRates();
1022 
1023  foreach ($shippingRates as $shippingRate) {
1024  $rate = $this->_addressRateFactory->create()->importShippingRate($shippingRate);
1025  if (!$item) {
1026  $this->addShippingRate($rate);
1027  }
1028 
1029  if ($this->getShippingMethod() == $rate->getCode()) {
1030  if ($item) {
1031  $item->setBaseShippingAmount($rate->getPrice());
1032  } else {
1033 
1035  $store = $this->storeManager->getStore();
1036  $amountPrice = $store->getBaseCurrency()
1037  ->convert($rate->getPrice(), $store->getCurrentCurrencyCode());
1038  $this->setBaseShippingAmount($rate->getPrice());
1039  $this->setShippingAmount($amountPrice);
1040  }
1041 
1042  $found = true;
1043  }
1044  }
1045  }
1046 
1047  return $found;
1048  }
1049 
1050  /******************************* Total Collector Interface *******************************************/
1051 
1057  public function getTotals()
1058  {
1059  $totalsData = array_merge($this->getData(), ['address_quote_items' => $this->getAllItems()]);
1060  $totals = $this->totalsReader->fetch($this->getQuote(), $totalsData);
1061  foreach ($totals as $total) {
1062  $this->addTotal($total);
1063  }
1064 
1065  return $this->_totals;
1066  }
1067 
1074  public function addTotal($total)
1075  {
1076  $addressTotal = null;
1077  if (is_array($total)) {
1079  $addressTotal = $this->_addressTotalFactory->create(\Magento\Quote\Model\Quote\Address\Total::class);
1080  $addressTotal->setData($total);
1081  } elseif ($total instanceof \Magento\Quote\Model\Quote\Address\Total) {
1082  $addressTotal = $total;
1083  }
1084 
1085  if ($addressTotal !== null) {
1086  $addressTotal->setAddress($this);
1087  $this->_totals[$addressTotal->getCode()] = $addressTotal;
1088  }
1089  return $this;
1090  }
1091 
1092  /******************************* End Total Collector Interface *******************************************/
1093 
1099  public function __clone()
1100  {
1101  $this->setId(null);
1102  }
1103 
1109  public function itemsCollectionWasSet()
1110  {
1111  return null !== $this->_items;
1112  }
1113 
1120  {
1121  return null !== $this->_rates;
1122  }
1123 
1129  public function validateMinimumAmount()
1130  {
1131  $storeId = $this->getQuote()->getStoreId();
1132  $validateEnabled = $this->_scopeConfig->isSetFlag(
1133  'sales/minimum_order/active',
1135  $storeId
1136  );
1137  if (!$validateEnabled) {
1138  return true;
1139  }
1140 
1141  if (!$this->getQuote()->getIsVirtual() xor $this->getAddressType() == self::TYPE_SHIPPING) {
1142  return true;
1143  }
1144 
1145  $amount = $this->_scopeConfig->getValue(
1146  'sales/minimum_order/amount',
1148  $storeId
1149  );
1150  $taxInclude = $this->_scopeConfig->getValue(
1151  'sales/minimum_order/tax_including',
1153  $storeId
1154  );
1155  $taxes = $taxInclude ? $this->getBaseTaxAmount() : 0;
1156 
1157  return ($this->getBaseSubtotalWithDiscount() + $taxes >= $amount);
1158  }
1159 
1165  public function getAppliedTaxes()
1166  {
1167  $taxes = $this->getData('applied_taxes');
1168  return $taxes ? $this->serializer->unserialize($taxes) : [];
1169  }
1170 
1177  public function setAppliedTaxes($data)
1178  {
1179  return $this->setData('applied_taxes', $this->serializer->serialize($data));
1180  }
1181 
1182  /******************************* Start Total Collector Interface *******************************************/
1183 
1192  public function setShippingAmount($value, $alreadyExclTax = false)
1193  {
1194  return $this->setData('shipping_amount', $value);
1195  }
1196 
1205  public function setBaseShippingAmount($value, $alreadyExclTax = false)
1206  {
1207  return $this->setData('base_shipping_amount', $value);
1208  }
1209 
1217  public function setTotalAmount($code, $amount)
1218  {
1219  $this->_totalAmounts[$code] = $amount;
1220  if ($code != 'subtotal') {
1221  $code = $code . '_amount';
1222  }
1223  $this->setData($code, $amount);
1224 
1225  return $this;
1226  }
1227 
1236  {
1237  $this->_baseTotalAmounts[$code] = $amount;
1238  if ($code != 'subtotal') {
1239  $code = $code . '_amount';
1240  }
1241  $this->setData('base_' . $code, $amount);
1242 
1243  return $this;
1244  }
1245 
1253  public function addTotalAmount($code, $amount)
1254  {
1255  $amount = $this->getTotalAmount($code) + $amount;
1256  $this->setTotalAmount($code, $amount);
1257 
1258  return $this;
1259  }
1260 
1269  {
1271  $this->setBaseTotalAmount($code, $amount);
1272 
1273  return $this;
1274  }
1275 
1282  public function getTotalAmount($code)
1283  {
1284  if (isset($this->_totalAmounts[$code])) {
1285  return $this->_totalAmounts[$code];
1286  }
1287 
1288  return 0;
1289  }
1290 
1297  public function getBaseTotalAmount($code)
1298  {
1299  if (isset($this->_baseTotalAmounts[$code])) {
1300  return $this->_baseTotalAmounts[$code];
1301  }
1302 
1303  return 0;
1304  }
1305 
1312  {
1313  return $this->getBaseSubtotal() + $this->getBaseDiscountAmount();
1314  }
1315 
1321  public function getSubtotalWithDiscount()
1322  {
1323  return $this->getSubtotal() + $this->getDiscountAmount();
1324  }
1325 
1326  //@codeCoverageIgnoreStart
1327 
1333  public function getAllTotalAmounts()
1334  {
1335  return $this->_totalAmounts;
1336  }
1337 
1343  public function getAllBaseTotalAmounts()
1344  {
1345  return $this->_baseTotalAmounts;
1346  }
1347 
1348  /******************************* End Total Collector Interface *******************************************/
1349 
1353  protected function _getValidationRulesBeforeSave()
1354  {
1355  return $this->validator;
1356  }
1357 
1361  public function getCountryId()
1362  {
1363  return $this->getData(self::KEY_COUNTRY_ID);
1364  }
1365 
1369  public function setCountryId($countryId)
1370  {
1371  return $this->setData(self::KEY_COUNTRY_ID, $countryId);
1372  }
1373 
1377  public function getStreet()
1378  {
1379  $street = $this->getData(self::KEY_STREET);
1380  return is_array($street) ? $street : explode("\n", $street);
1381  }
1382 
1386  public function setStreet($street)
1387  {
1388  return $this->setData(self::KEY_STREET, $street);
1389  }
1390 
1394  public function getCompany()
1395  {
1396  return $this->getData(self::KEY_COMPANY);
1397  }
1398 
1402  public function setCompany($company)
1403  {
1404  return $this->setData(self::KEY_COMPANY, $company);
1405  }
1406 
1410  public function getTelephone()
1411  {
1412  return $this->getData(self::KEY_TELEPHONE);
1413  }
1414 
1418  public function setTelephone($telephone)
1419  {
1420  return $this->setData(self::KEY_TELEPHONE, $telephone);
1421  }
1422 
1426  public function getFax()
1427  {
1428  return $this->getData(self::KEY_FAX);
1429  }
1430 
1434  public function setFax($fax)
1435  {
1436  return $this->setData(self::KEY_FAX, $fax);
1437  }
1438 
1442  public function getPostcode()
1443  {
1444  return $this->getData(self::KEY_POSTCODE);
1445  }
1446 
1450  public function setPostcode($postcode)
1451  {
1452  return $this->setData(self::KEY_POSTCODE, $postcode);
1453  }
1454 
1458  public function getCity()
1459  {
1460  return $this->getData(self::KEY_CITY);
1461  }
1462 
1466  public function setCity($city)
1467  {
1468  return $this->setData(self::KEY_CITY, $city);
1469  }
1470 
1474  public function getFirstname()
1475  {
1476  return $this->getData(self::KEY_FIRSTNAME);
1477  }
1478 
1482  public function setFirstname($firstname)
1483  {
1484  return $this->setData(self::KEY_FIRSTNAME, $firstname);
1485  }
1486 
1490  public function getLastname()
1491  {
1492  return $this->getData(self::KEY_LASTNAME);
1493  }
1494 
1498  public function setLastname($lastname)
1499  {
1500  return $this->setData(self::KEY_LASTNAME, $lastname);
1501  }
1502 
1506  public function getMiddlename()
1507  {
1508  return $this->getData(self::KEY_MIDDLENAME);
1509  }
1510 
1514  public function setMiddlename($middlename)
1515  {
1516  return $this->setData(self::KEY_MIDDLENAME, $middlename);
1517  }
1518 
1522  public function getPrefix()
1523  {
1524  return $this->getData(self::KEY_PREFIX);
1525  }
1526 
1530  public function setPrefix($prefix)
1531  {
1532  return $this->setData(self::KEY_PREFIX, $prefix);
1533  }
1534 
1538  public function getSuffix()
1539  {
1540  return $this->getData(self::KEY_SUFFIX);
1541  }
1542 
1546  public function setSuffix($suffix)
1547  {
1548  return $this->setData(self::KEY_SUFFIX, $suffix);
1549  }
1550 
1554  public function getVatId()
1555  {
1556  return $this->getData(self::KEY_VAT_ID);
1557  }
1558 
1562  public function setVatId($vatId)
1563  {
1564  return $this->setData(self::KEY_VAT_ID, $vatId);
1565  }
1566 
1570  public function getCustomerId()
1571  {
1572  return $this->getData(self::KEY_CUSTOMER_ID);
1573  }
1574 
1578  public function setCustomerId($customerId)
1579  {
1580  return $this->setData(self::KEY_CUSTOMER_ID, $customerId);
1581  }
1582 
1586  public function getEmail()
1587  {
1588  $email = $this->getData(self::KEY_EMAIL);
1589  if (!$email && $this->getQuote()) {
1590  $email = $this->getQuote()->getCustomerEmail();
1591  $this->setEmail($email);
1592  }
1593  return $email;
1594  }
1595 
1599  public function setEmail($email)
1600  {
1601  return $this->setData(self::KEY_EMAIL, $email);
1602  }
1603 
1607  public function setRegion($region)
1608  {
1609  return $this->setData(self::KEY_REGION, $region);
1610  }
1611 
1615  public function setRegionId($regionId)
1616  {
1617  return $this->setData(self::KEY_REGION_ID, $regionId);
1618  }
1619 
1623  public function setRegionCode($regionCode)
1624  {
1625  return $this->setData(self::KEY_REGION_CODE, $regionCode);
1626  }
1627 
1631  public function getSameAsBilling()
1632  {
1633  return $this->getData(self::SAME_AS_BILLING);
1634  }
1635 
1639  public function setSameAsBilling($sameAsBilling)
1640  {
1641  return $this->setData(self::SAME_AS_BILLING, $sameAsBilling);
1642  }
1643 
1647  public function getCustomerAddressId()
1648  {
1649  return $this->getData(self::CUSTOMER_ADDRESS_ID);
1650  }
1651 
1655  public function setCustomerAddressId($customerAddressId)
1656  {
1657  return $this->setData(self::CUSTOMER_ADDRESS_ID, $customerAddressId);
1658  }
1659 
1665  public function getSaveInAddressBook()
1666  {
1667  return $this->getData(self::SAVE_IN_ADDRESS_BOOK);
1668  }
1669 
1676  public function setSaveInAddressBook($saveInAddressBook)
1677  {
1678  return $this->setData(self::SAVE_IN_ADDRESS_BOOK, $saveInAddressBook);
1679  }
1680 
1681  //@codeCoverageIgnoreEnd
1682 
1688  public function getExtensionAttributes()
1689  {
1690  return $this->_getExtensionAttributes();
1691  }
1692 
1699  public function setExtensionAttributes(\Magento\Quote\Api\Data\AddressExtensionInterface $extensionAttributes)
1700  {
1701  return $this->_setExtensionAttributes($extensionAttributes);
1702  }
1703 
1709  public function getShippingMethod()
1710  {
1711  return $this->getData('shipping_method');
1712  }
1713 
1717  protected function getCustomAttributesCodes()
1718  {
1719  return array_keys($this->attributeList->getAttributes());
1720  }
1721 }
$suffix
Definition: name.phtml:27
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$customer
Definition: customers.php:11
$email
Definition: details.phtml:13
__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)
Definition: Address.php:296
setBaseTotalAmount($code, $amount)
Definition: Address.php:1235
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
$quote
importCustomerAddressData(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Address.php:500
_sortRates($firstItem, $secondItem)
Definition: Address.php:873
$resource
Definition: bulk.php:12
$rates
Definition: tax.phtml:35
setSameAsBilling($sameAsBilling)
Definition: Address.php:1639
$address
Definition: customer.php:38
$amount
Definition: order.php:14
setBaseShippingAmount($value, $alreadyExclTax=false)
Definition: Address.php:1205
$prefix
Definition: name.phtml:25
$value
Definition: gender.phtml:16
$totals
Definition: totalbar.phtml:10
addItem(\Magento\Quote\Model\Quote\Item\AbstractItem $item, $qty=null)
Definition: Address.php:770
setCustomerAddressId($customerAddressId)
Definition: Address.php:1655
setExtensionAttributes(\Magento\Quote\Api\Data\AddressExtensionInterface $extensionAttributes)
Definition: Address.php:1699
addBaseTotalAmount($code, $amount)
Definition: Address.php:1268
toArray(array $arrAttributes=[])
Definition: Address.php:554
setSaveInAddressBook($saveInAddressBook)
Definition: Address.php:1676
addShippingRate(\Magento\Quote\Model\Quote\Address\Rate $rate)
Definition: Address.php:931
setShippingAmount($value, $alreadyExclTax=false)
Definition: Address.php:1192
$code
Definition: info.phtml:12
setQuote(\Magento\Quote\Model\Quote $quote)
Definition: Address.php:477
$items