Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Service/Order/AddressData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Magmodules\Channable\Model\Config;
use Magento\Customer\Api\Data\AddressInterfaceFactory;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\Data\RegionInterfaceFactory;
use Magento\Customer\Api\Data\RegionInterface;
use Magento\Framework\App\ObjectManager;

class AddressData
{
Expand All @@ -28,6 +31,11 @@ class AddressData
*/
private $addressFactory;

/**
* @var RegionInterfaceFactory
*/
private $regionFactory;

/**
* AddressData constructor.
*
Expand All @@ -38,11 +46,13 @@ class AddressData
public function __construct(
AddressRepositoryInterface $addressRepository,
AddressInterfaceFactory $addressFactory,
Config $config
Config $config,
RegionInterfaceFactory $regionFactory = null
) {
$this->addressRepository = $addressRepository;
$this->addressFactory = $addressFactory;
$this->config = $config;
$this->regionFactory = $regionFactory ?: ObjectManager::getInstance()->get(RegionInterfaceFactory::class);
}

/**
Expand Down Expand Up @@ -84,7 +94,7 @@ public function execute($type, $order, $storeId, $customerId = null)
'street' => $this->getStreet($address, $storeId),
'city' => $address['city'],
'country_id' => $address['country_code'],
'region' => !empty($address['state_code']) ? $address['state_code'] : null,
'region' => $this->getRegion($address['state_code']),
'postcode' => $address['zip_code'],
'telephone' => $telephone,
'vat_id' => !empty($address['vat_id']) ? $address['vat_id'] : null,
Expand Down Expand Up @@ -172,4 +182,17 @@ private function cleanEmail($email)
{
return str_replace([':'], '', $email);
}

/**
* @param $stateCode
* @return mixed
*/
private function getRegion($stateCode)
{
if (!($stateCode instanceof RegionInterface)) {
$stateCode = $this->regionFactory->create()->setRegionCode($stateCode);
}

return $stateCode;
}
}