diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c8b6de..a58d513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# Version 17.0.6 + +## Bugfixes + +* none + +## Features + +* Add support for optional region address fields 'region_id' and 'region_code' + # Version 17.0.5 ## Bugfixes diff --git a/src/Observers/CustomerAddressExportObserver.php b/src/Observers/CustomerAddressExportObserver.php index 8b3cf74..781c94d 100644 --- a/src/Observers/CustomerAddressExportObserver.php +++ b/src/Observers/CustomerAddressExportObserver.php @@ -96,7 +96,7 @@ protected function process() } // initialize the array for the links $artefacts = array(); - + $artefacts[] = $this->newArtefact( array( ColumnKeys::ENTITY_ID => $this->getValue(ColumnKeys::ENTITY_ID), @@ -114,6 +114,8 @@ protected function process() ColumnKeys::POSTCODE => $this->getValue(ColumnKeys::ADDRESS_POSTCODE), ColumnKeys::PREFIX => $this->getValue(ColumnKeys::ADDRESS_PREFIX), ColumnKeys::REGION => $this->getValue(ColumnKeys::ADDRESS_REGION), + ColumnKeys::REGION_CODE => $this->getValue(ColumnKeys::ADDRESS_REGION_CODE), + ColumnKeys::REGION_ID => $this->getValue(ColumnKeys::ADDRESS_REGION_ID), ColumnKeys::STREET => $addressStreet, ColumnKeys::SUFFIX => $this->getValue(ColumnKeys::ADDRESS_SUFFIX), ColumnKeys::TELEPHONE => $this->getValue(ColumnKeys::ADDRESS_TELEPHONE), @@ -137,6 +139,8 @@ protected function process() ColumnKeys::POSTCODE => ColumnKeys::ADDRESS_POSTCODE, ColumnKeys::PREFIX => ColumnKeys::ADDRESS_PREFIX, ColumnKeys::REGION => ColumnKeys::ADDRESS_REGION, + ColumnKeys::REGION_CODE => ColumnKeys::ADDRESS_REGION_CODE, + ColumnKeys::REGION_ID => ColumnKeys::ADDRESS_REGION_ID, ColumnKeys::STREET => ColumnKeys::ADDRESS_STREET, ColumnKeys::SUFFIX => ColumnKeys::ADDRESS_SUFFIX, ColumnKeys::TELEPHONE => ColumnKeys::ADDRESS_TELEPHONE, diff --git a/src/Observers/CustomerAddressObserver.php b/src/Observers/CustomerAddressObserver.php index 38656b3..64b41f6 100644 --- a/src/Observers/CustomerAddressObserver.php +++ b/src/Observers/CustomerAddressObserver.php @@ -122,7 +122,7 @@ protected function prepareAttributes() ); return []; } - + // initialize the customer values $entityId = $this->getValue(ColumnKeys::ENTITY_ID); $city = $this->getValue(ColumnKeys::CITY, ''); @@ -135,7 +135,13 @@ protected function prepareAttributes() $postcode = $this->getValue(ColumnKeys::POSTCODE); $prefix = $this->getValue(ColumnKeys::PREFIX); $region = $this->getValue(ColumnKeys::REGION); + $regionCode = $this->getValue(ColumnKeys::REGION_CODE); $regionId = $this->getValue(ColumnKeys::REGION_ID); + + if (empty($regionId) && !empty($regionCode)) { + $regionId = $this->getCountryRegionIdByCode($regionCode); + } + $street = $this->getValue(ColumnKeys::STREET, ''); $suffix = $this->getValue(ColumnKeys::SUFFIX); $telephone = $this->checkCustomerPhoneConfig($this->getValue(ColumnKeys::TELEPHONE, '')); @@ -305,6 +311,18 @@ protected function getStoreWebsiteIdByCode($code) return $this->getSubject()->getStoreWebsiteIdByCode($code); } + /** + * Return's the region ID for the given code, if it exists. + * + * @param string|null $code The code of the requested customer group + * + * @return integer|null The region ID + */ + protected function getCountryRegionIdByCode($code) + { + return $this->getSubject()->getCountryRegionIdByCode($code); + } + /** * @param string $value value of customer column * diff --git a/src/Subjects/AbstractCustomerAddressSubject.php b/src/Subjects/AbstractCustomerAddressSubject.php index d2f1242..041aa18 100644 --- a/src/Subjects/AbstractCustomerAddressSubject.php +++ b/src/Subjects/AbstractCustomerAddressSubject.php @@ -33,6 +33,13 @@ abstract class AbstractCustomerAddressSubject extends AbstractEavSubject implements EntitySubjectInterface { + /** + * The available country regions. + * + * @var array + */ + protected $countryRegions = array(); + /** * The ID of the product that has been created recently. * @@ -95,8 +102,11 @@ public function setUp($serial) // load the status of the actual import $status = $this->getRegistryProcessor()->getAttribute(RegistryKeys::STATUS); - // load the global data we've prepared initially - $this->storeWebsites = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::STORE_WEBSITES]; + if (isset($status[RegistryKeys::GLOBAL_DATA])) { + // load the global data we've prepared initially + $this->storeWebsites = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::STORE_WEBSITES]; + $this->countryRegions = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::COUNTRY_REGIONS]; + } // invoke the parent method parent::setUp($serial); @@ -126,6 +136,18 @@ public function getStoreWebsiteIdByCode($code) ); } + /** + * @param string $code  The code of the region code to return the region ID for + * @return integer|null + */ + public function getCountryRegionIdByCode($code) + { + if (isset($this->countryRegions[$code])) { + return (integer)$this->countryRegions[$code][MemberNames::REGION_ID]; + } + return null; + } + /** * Merge the columns from the configuration with all image type columns to define which * columns should be cleaned-up. diff --git a/src/Utils/ColumnKeys.php b/src/Utils/ColumnKeys.php index 2a24c56..978283f 100644 --- a/src/Utils/ColumnKeys.php +++ b/src/Utils/ColumnKeys.php @@ -82,6 +82,13 @@ class ColumnKeys extends \TechDivision\Import\Customer\Utils\ColumnKeys */ const REGION = 'region'; + /** + * Name for the column 'region_code'. + * + * @var string + */ + const REGION_CODE = 'region_code'; + /** * Name for the column 'region_id'. * @@ -222,6 +229,20 @@ class ColumnKeys extends \TechDivision\Import\Customer\Utils\ColumnKeys */ const ADDRESS_REGION = '_address_region'; + /** + * Name for the column '_address_region_code'. + * + * @var string + */ + const ADDRESS_REGION_CODE = '_address_region_code'; + + /** + * Name for the column '_address_region_id'. + * + * @var string + */ + const ADDRESS_REGION_ID = '_address_region_id'; + /** * Name for the column '_address_street'. * diff --git a/src/Utils/MemberNames.php b/src/Utils/MemberNames.php index ebbab7f..b4d3a05 100644 --- a/src/Utils/MemberNames.php +++ b/src/Utils/MemberNames.php @@ -68,6 +68,13 @@ class MemberNames extends \TechDivision\Import\Customer\Utils\MemberNames */ const REGION = 'region'; + /** + * Name for the member 'region_code'. + * + * @var string + */ + const REGION_CODE = 'region_code'; + /** * Name for the member 'region_id'. * @@ -137,4 +144,11 @@ class MemberNames extends \TechDivision\Import\Customer\Utils\MemberNames * @var string */ const VAT_REQUEST_SUCCESS = 'vat_request_success'; + + /** + * Name for the column 'iso_code'. + * + * @var string + */ + const DIRECTORY_REGION_CODE = 'code'; } diff --git a/src/Utils/RegistryKeys.php b/src/Utils/RegistryKeys.php index ac1e7f4..1a88ac7 100644 --- a/src/Utils/RegistryKeys.php +++ b/src/Utils/RegistryKeys.php @@ -14,6 +14,8 @@ namespace TechDivision\Import\Customer\Address\Utils; +use TechDivision\Import\Customer\Utils\RegistryKeys as CustomerRegistryKeys; + /** * Utility class containing the unique registry keys. * @@ -23,9 +25,8 @@ * @link https://github.com/techdivision/import-customer-address * @link http://www.techdivision.com */ -class RegistryKeys extends \TechDivision\Import\Utils\RegistryKeys +class RegistryKeys extends CustomerRegistryKeys { - /** * Key for the registry entry containing the preloaded SKU => entity ID mapping. *