/** * @param $data * @param $expected * * @dataProvider validateDataProvider */ public function testValidate($data, $expected) { $this->directoryDataMock->expects($this->once())->method('getCountriesWithOptionalZip')->will($this->returnValue([])); $this->directoryDataMock->expects($this->never())->method('isRegionRequired'); $this->model->setData($data); $this->assertEquals($expected, $this->model->validate()); }
/** * Before object save manipulations * * @return $this */ protected function _beforeSave() { parent::_beforeSave(); if (!$this->getParentId() && $this->getOrder()) { $this->setParentId($this->getOrder()->getId()); } // Init customer address id if customer address is assigned $customerData = $this->getCustomerAddressData(); if ($customerData) { $this->setCustomerAddressId($customerData->getId()); } return $this; }
/** * 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; }
/** * {@inheritdoc} */ public function getDataModel($defaultBillingAddressId = null, $defaultShippingAddressId = null) { if ($this->getCustomerId() || $this->getParentId()) { if ($this->getCustomer()->getDefaultBillingAddress()) { $defaultBillingAddressId = $this->getCustomer()->getDefaultBillingAddress()->getId(); } if ($this->getCustomer()->getDefaultShippingAddress()) { $defaultShippingAddressId = $this->getCustomer()->getDefaultShippingAddress()->getId(); } } return parent::getDataModel($defaultBillingAddressId, $defaultShippingAddressId); }
/** * Get product price with all tax settings processing * * @param \Magento\Catalog\Model\Product $product * @param float $price inputted product price * @param bool $includingTax return price include tax flag * @param null|\Magento\Customer\Model\Address\AbstractAddress $shippingAddress * @param null|\Magento\Customer\Model\Address\AbstractAddress $billingAddress * @param null|int $ctc customer tax class * @param null|string|bool|int|\Magento\Store\Model\Store $store * @param bool $priceIncludesTax flag what price parameter contain tax * @param bool $roundPrice * @return float * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getTaxPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true) { if (!$price) { return $price; } $store = $this->_storeManager->getStore($store); if ($this->_taxConfig->needPriceConversion($store)) { if ($priceIncludesTax === null) { $priceIncludesTax = $this->_taxConfig->priceIncludesTax($store); } $shippingAddressDataObject = null; if ($shippingAddress === null) { $shippingAddressDataObject = $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxShippingAddress()); } elseif ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) { $shippingAddressDataObject = $shippingAddress->getDataModel(); } $billingAddressDataObject = null; if ($billingAddress === null) { $billingAddressDataObject = $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxBillingAddress()); } elseif ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) { $billingAddressDataObject = $billingAddress->getDataModel(); } $taxClassKey = $this->_taxClassKeyFactory->create(); $taxClassKey->setType(TaxClassKeyInterface::TYPE_ID)->setValue($product->getTaxClassId()); if ($ctc === null && $this->_customerSession->getCustomerGroupId() != null) { $ctc = $this->customerGroupRepository->getById($this->_customerSession->getCustomerGroupId())->getTaxClassId(); } $customerTaxClassKey = $this->_taxClassKeyFactory->create(); $customerTaxClassKey->setType(TaxClassKeyInterface::TYPE_ID)->setValue($ctc); $item = $this->_quoteDetailsItemFactory->create(); $item->setQuantity(1)->setCode($product->getSku())->setShortDescription($product->getShortDescription())->setTaxClassKey($taxClassKey)->setIsTaxIncluded($priceIncludesTax)->setType('product')->setUnitPrice($price); $quoteDetails = $this->_quoteDetailsFactory->create(); $quoteDetails->setShippingAddress($shippingAddressDataObject)->setBillingAddress($billingAddressDataObject)->setCustomerTaxClassKey($customerTaxClassKey)->setItems([$item])->setCustomerId($this->_customerSession->getCustomerId()); $storeId = null; if ($store) { $storeId = $store->getId(); } $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetails, $storeId, $roundPrice); $items = $taxDetails->getItems(); $taxDetailsItem = array_shift($items); if ($includingTax !== null) { if ($includingTax) { $price = $taxDetailsItem->getPriceInclTax(); } else { $price = $taxDetailsItem->getPrice(); } } else { switch ($this->_taxConfig->getPriceDisplayType($store)) { case Config::DISPLAY_TYPE_EXCLUDING_TAX: case Config::DISPLAY_TYPE_BOTH: $price = $taxDetailsItem->getPrice(); break; case Config::DISPLAY_TYPE_INCLUDING_TAX: $price = $taxDetailsItem->getPriceInclTax(); break; default: break; } } } if ($roundPrice) { return $this->priceCurrency->round($price); } else { return $price; } }
/** * Delete customer address * * @return $this */ public function delete() { parent::delete(); $this->setData(array()); return $this; }
/** * Init indexing process after customer delete * * @return \Magento\Framework\Model\AbstractModel */ public function afterDeleteCommit() { $this->reindex(); return parent::afterDeleteCommit(); }
/** * Make address Data Object out of an address model * * @param AbstractAddress $addressModel * @param int $defaultBillingId * @param int $defaultShippingId * @return Address */ public function createAddressFromModel(AbstractAddress $addressModel, $defaultBillingId, $defaultShippingId) { $addressId = $addressModel->getId(); $attributes = $this->_metadataService->getAllAddressAttributeMetadata(); $addressData = array(); foreach ($attributes as $attribute) { $code = $attribute->getAttributeCode(); if (!is_null($addressModel->getData($code))) { $addressData[$code] = $addressModel->getData($code); } } $isDefaultBilling = $addressModel->getData('is_default_billing') === null && intval($addressId) ? $addressId === $defaultBillingId : $addressModel->getData('is_default_billing'); $isDefaultShipping = $addressModel->getData('is_default_shipping') === null && intval($addressId) ? $addressId === $defaultShippingId : $addressModel->getData('is_default_shipping'); $this->_addressBuilder->populateWithArray(array_merge($addressData, array(Address::KEY_STREET => $addressModel->getStreet(), Address::KEY_DEFAULT_BILLING => $isDefaultBilling, Address::KEY_DEFAULT_SHIPPING => $isDefaultShipping, Address::KEY_REGION => array(Region::KEY_REGION => $addressModel->getRegion(), Region::KEY_REGION_ID => $addressModel->getRegionId(), Region::KEY_REGION_CODE => $addressModel->getRegionCode())))); if ($addressId) { $this->_addressBuilder->setId($addressId); } if ($addressModel->getCustomerId() || $addressModel->getParentId()) { $customerId = $addressModel->getCustomerId() ?: $addressModel->getParentId(); $this->_addressBuilder->setCustomerId($customerId); } $addressDataObject = $this->_addressBuilder->create(); return $addressDataObject; }
/** * 2016-04-04 * @param AA|CA|QA|OA $a * @return Customer|Quote|Order|null */ function df_address_owner($a) { return $a instanceof CA ? $a->getCustomer() : ($a instanceof QA ? $a->getQuote() : ($a instanceof OA ? $a->getOrder() : null)); }
/** * Convert an AbstractAddress object to an address object compatible * with the address validation service. * * @param AbstractCustomerAddress * @return \EbayEnterprise\Address\Api\Data\AddressInterface */ public function convertAbstractAddressToDataAddress(AbstractCustomerAddress $address) { $data = ['street' => array_filter($address->getStreet(), [$this, 'filterEmptyStreets']), 'city' => $address->getCity(), 'region_code' => $address->getRegionCode(), 'region_id' => $address->getRegionId(), 'region_name' => $address->getRegion(), 'country_id' => $address->getCountryId(), 'postcode' => $address->getPostcode()]; return $this->addressFactory->create(['data' => $data]); }
/** * Returns street * * @return string[] */ public function getStreet() { return parent::getStreet(); }
/** * @param AbstractAddress|null $address * @return string * @deprecated All new code should use renderArray based on Metadata service */ public function getFormat(AbstractAddress $address = null) { $countryFormat = $address === null ? false : $address->getCountryModel()->getFormat($this->getType()->getCode()); $format = $countryFormat ? $countryFormat->getFormat() : $this->getType()->getDefaultFormat(); return $format; }