public function testGetEntityTypeId() { $mockEntityType = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Type')->disableOriginalConstructor()->getMock(); $mockEntityType->expects($this->any())->method('getId')->will($this->returnValue(self::ORIG_CUSTOMER_ID)); $this->resource->expects($this->any())->method('getEntityType')->will($this->returnValue($mockEntityType)); $this->assertEquals(self::ORIG_CUSTOMER_ID, $this->address->getEntityTypeId()); }
public function testUpdateDataOverrideExistingData() { /** @var \Magento\Customer\Model\Data\Address $addressData */ $addressData = $this->addressFactory->create()->setId(2)->setCity('CityY')->setCompany('CompanyY')->setPostcode('88888'); $this->addressModel->updateData($addressData); /** @var \Magento\Customer\Model\Data\Address $addressData */ $updatedAddressData = $this->addressFactory->create()->setId(3)->setCity('CityZ')->setCompany('CompanyZ')->setPostcode('99999'); $updatedAddressData = $this->addressModel->updateData($updatedAddressData)->getDataModel(); $this->assertEquals(3, $updatedAddressData->getId()); $this->assertEquals('CityZ', $updatedAddressData->getCity()); $this->assertEquals('CompanyZ', $updatedAddressData->getCompany()); $this->assertEquals('99999', $updatedAddressData->getPostcode()); }
public function testDeleteById() { $addressId = 12; $customerId = 43; $this->address->expects($this->once())->method('getCustomerId')->willReturn($customerId); $addressCollection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection', [], [], '', false); $this->addressRegistry->expects($this->once())->method('retrieve')->with($addressId)->willReturn($this->address); $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customer); $this->customer->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollection); $addressCollection->expects($this->once())->method('clear'); $this->addressResourceModel->expects($this->once())->method('delete')->with($this->address); $this->addressRegistry->expects($this->once())->method('remove')->with($addressId); $this->assertTrue($this->repository->deleteById($addressId)); }
/** * Add error message * * @param Address $customerAddress * @return $this */ protected function addErrorMessage($customerAddress) { $message = [(string) __('Your Tax ID cannot be validated.')]; $customer = $customerAddress->getCustomer(); if (!$this->scopeConfig->isSetFlag(HelperAddress::XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT) && !$customer->getDisableAutoGroupChange()) { $message[] = (string) __('You will be charged tax.'); } $email = $this->scopeConfig->getValue('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE); $message[] = (string) __('If you believe this is an error, please contact us at %1', $email); $this->messageManager->addError(implode(' ', $message)); return $this; }
/** * Get shipping price * * @param float $price * @param bool|null $includingTax * @param Address|null $shippingAddress * @param int|null $ctc * @param null|string|bool|int|Store $store * @return float */ public function getShippingPrice($price, $includingTax = null, $shippingAddress = null, $ctc = null, $store = null) { $pseudoProduct = new \Magento\Framework\Object(); $pseudoProduct->setTaxClassId($this->getShippingTaxClass($store)); $billingAddress = false; if ($shippingAddress && $shippingAddress->getQuote() && $shippingAddress->getQuote()->getBillingAddress()) { $billingAddress = $shippingAddress->getQuote()->getBillingAddress(); } $price = $this->catalogHelper->getTaxPrice($pseudoProduct, $price, $includingTax, $shippingAddress, $billingAddress, $ctc, $store, $this->shippingPriceIncludesTax($store)); return $price; }
/** * Check if address is primary * * @param Address $address * @return boolean */ public function isAddressPrimary(Address $address) { if (!$address->getId()) { return false; } return $address->getId() == $this->getDefaultBilling() || $address->getId() == $this->getDefaultShipping(); }
/** * Validate Customer Addresses attribute values. * * @param CustomerAddressModel $customerAddressModel the model to validate * @return InputException * * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ private function _validate(CustomerAddressModel $customerAddressModel) { $exception = new InputException(); if ($customerAddressModel->getShouldIgnoreValidation()) { return $exception; } if (!\Zend_Validate::is($customerAddressModel->getFirstname(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'firstname'])); } if (!\Zend_Validate::is($customerAddressModel->getLastname(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'lastname'])); } if (!\Zend_Validate::is($customerAddressModel->getStreetLine(1), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'street'])); } if (!\Zend_Validate::is($customerAddressModel->getCity(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'city'])); } if (!\Zend_Validate::is($customerAddressModel->getTelephone(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'telephone'])); } $havingOptionalZip = $this->directoryData->getCountriesWithOptionalZip(); if (!in_array($customerAddressModel->getCountryId(), $havingOptionalZip) && !\Zend_Validate::is($customerAddressModel->getPostcode(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'postcode'])); } if (!\Zend_Validate::is($customerAddressModel->getCountryId(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'countryId'])); } if ($customerAddressModel->getCountryModel()->getRegionCollection()->getSize() && !\Zend_Validate::is($customerAddressModel->getRegionId(), 'NotEmpty') && $this->directoryData->isRegionRequired($customerAddressModel->getCountryId())) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId'])); } return $exception; }
/** * Replace existing Address Model with a new one * * @param Address $address * @return $this */ public function push(Address $address) { $this->registry[$address->getId()] = $address; return $this; }
/** * Updates an Address Model based on information from an Address Data Object. * * @param AddressModel $addressModel * @param Address $address * @return void */ public function updateAddressModel(AddressModel $addressModel, Address $address) { // Set all attributes $attributes = AddressConverter::toFlatArray($address); foreach ($attributes as $attributeCode => $attributeData) { if (Address::KEY_REGION === $attributeCode && $address->getRegion() instanceof Region) { $addressModel->setDataUsingMethod(Region::KEY_REGION, $address->getRegion()->getRegion()); $addressModel->setDataUsingMethod(Region::KEY_REGION_CODE, $address->getRegion()->getRegionCode()); $addressModel->setDataUsingMethod(Region::KEY_REGION_ID, $address->getRegion()->getRegionId()); } else { $addressModel->setDataUsingMethod($attributeCode, $attributeData); } } // Set customer related data $isBilling = $address->isDefaultBilling(); $addressModel->setIsDefaultBilling($isBilling); $addressModel->setIsDefaultShipping($address->isDefaultShipping()); // Need to use attribute set or future updates can cause data loss if (!$addressModel->getAttributeSetId()) { $addressModel->setAttributeSetId(CustomerMetadataServiceInterface::ATTRIBUTE_SET_ID_ADDRESS); } }
/** * 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)); }
/** * Check whether specified shipping address is default for its customer * * @param Address $address * @return bool */ protected function isDefaultShipping($address) { return $address->getId() && $address->getId() == $address->getCustomer()->getDefaultShipping() || $address->getIsPrimaryShipping() || $address->getIsDefaultShipping(); }
public function testRegionId() { $this->address->setRegionId(1); $this->assertEquals(1, $this->address->getRegionId()); }