Skip to content

Commit

Permalink
Merge pull request #24 from techdivision/customer-address-region-fields
Browse files Browse the repository at this point in the history
Add support for optional region address fields 'region_id' and 'region_code'
  • Loading branch information
kenza-ya authored May 10, 2023
2 parents b0e702c + 841f988 commit cba2a7e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/Observers/CustomerAddressExportObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion src/Observers/CustomerAddressObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function prepareAttributes()
);
return [];
}

// initialize the customer values
$entityId = $this->getValue(ColumnKeys::ENTITY_ID);
$city = $this->getValue(ColumnKeys::CITY, '');
Expand All @@ -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, ''));
Expand Down Expand Up @@ -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
*
Expand Down
26 changes: 24 additions & 2 deletions src/Subjects/AbstractCustomerAddressSubject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions src/Utils/ColumnKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
*
Expand Down Expand Up @@ -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'.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Utils/MemberNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
*
Expand Down Expand Up @@ -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';
}
5 changes: 3 additions & 2 deletions src/Utils/RegistryKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down

0 comments on commit cba2a7e

Please sign in to comment.