/** * Convert a customer address object to an address object compatible * with the address validation service. * * @param CustomerAddressInterface * @return \EbayEnterprise\Address\Api\Data\AddressInterface */ public function convertCustomerAddressToDataAddress(CustomerAddressInterface $address) { // When the region object on the customer address already has a region // code, it isn't necessary to load the direction region model to get the code. $customerRegion = $address->getRegion(); $region = $this->regionHelper->loadRegion($customerRegion->getRegionId(), $customerRegion->getRegionCode(), $customerRegion->getRegion(), $address->getCountryId()); $data = ['street' => array_filter($address->getStreet(), [$this, 'filterEmptyStreets']), 'city' => $address->getCity(), 'region_code' => $region->getCode(), 'region_id' => $region->getId(), 'region_name' => $region->getName(), 'country_id' => $address->getCountryId(), 'postcode' => $address->getPostcode()]; return $this->addressFactory->create(['data' => $data]); }
/** * When a region model needs to be loaded and there is no region id or region * code, but there is a region name and a country code, a new region model * should be created and loaded using the regin name and country id. */ public function testLoadRegionByName() { $regionId = null; $regionCode = null; $regionName = 'New Jersey'; $countryId = 'US'; $this->directoryRegionFactory->expects($this->once())->method('create')->will($this->returnValue($this->directoryRegion)); $this->directoryRegion->expects($this->never())->method('load'); $this->directoryRegion->expects($this->never())->method('loadByCode'); $this->directoryRegion->expects($this->once())->method('loadByName')->with($this->identicalTo($regionName), $this->identicalTo($countryId))->will($this->returnSelf()); $this->assertSame($this->directoryRegion, $this->regionHelper->loadRegion($regionId, $regionCode, $regionName, $countryId)); }
/** * Transfer the SDK payload data to a Magento address object. * * @param IPhysicalAddress * @param AddressInterface * @return AddressInterface */ public function transferPhysicalAddressPayloadToAddress(IPhysicalAddress $addressPayload, AddressInterface $address) { $region = $this->regionHelper->loadRegion(null, $addressPayload->getMainDivision(), null, $addressPayload->getCountryCode()); return $address->setStreet(explode("\n", $addressPayload->getLines()))->setCity($addressPayload->getCity())->setCountryId($addressPayload->getCountryCode())->setRegionCode($region->getCode())->setRegionId($region->getId())->setRegionName($region->getName())->setPostcode($addressPayload->getPostalCode()); }