Skip to content

Commit

Permalink
Merge pull request #91 from magmodules/1.4.18
Browse files Browse the repository at this point in the history
1.4.18
  • Loading branch information
Marvin-Magmodules authored Apr 13, 2020
2 parents 4027685 + d58bc12 commit f6b1b0e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
38 changes: 30 additions & 8 deletions Service/Order/AddressData.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php
/**
* Copyright © 2019 Magmodules.eu. All rights reserved.
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magmodules\Channable\Service\Order;

use Magmodules\Channable\Model\Config;
use Magento\Customer\Api\Data\AddressInterfaceFactory;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Directory\Model\RegionFactory;

class AddressData
{
Expand All @@ -28,21 +30,28 @@ class AddressData
*/
private $addressFactory;

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

/**
* AddressData constructor.
*
* @param AddressRepositoryInterface $addressRepository
* @param AddressInterfaceFactory $addressFactory
* @param Config $config
* @param AddressInterfaceFactory $addressFactory
* @param Config $config
* @param RegionFactory $regionFactory
*/
public function __construct(
AddressRepositoryInterface $addressRepository,
AddressInterfaceFactory $addressFactory,
Config $config
Config $config,
RegionFactory $regionFactory
) {
$this->addressRepository = $addressRepository;
$this->addressFactory = $addressFactory;
$this->config = $config;
$this->regionFactory = $regionFactory;
}

/**
Expand Down Expand Up @@ -84,7 +93,9 @@ 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' => !empty($address['state_code'])
? $this->getRegionId($address['state_code'], $address['country_code'])
: null,
'postcode' => $address['zip_code'],
'telephone' => $telephone,
'vat_id' => !empty($address['vat_id']) ? $address['vat_id'] : null,
Expand Down Expand Up @@ -120,7 +131,7 @@ private function getStreet($address, $storeId)
}

if ($numberOfStreetLines == 1) {
$street = trim(implode(' ', $street));
$street = [trim(implode(' ', $street))];
}

if ($numberOfStreetLines == 2) {
Expand Down Expand Up @@ -149,7 +160,7 @@ private function saveAddress($addressData, $customerId, $type)
->setStreet($addressData['street'])
->setCity($addressData['city'])
->setCountryId($addressData['country_id'])
->setRegion($addressData['region'])
->setRegionId($addressData['region'])
->setPostcode($addressData['postcode'])
->setVatId($addressData['vat_id'])
->setTelephone($addressData['telephone']);
Expand All @@ -172,4 +183,15 @@ private function cleanEmail($email)
{
return str_replace([':'], '', $email);
}

/**
* @param string $code
* @param string $countryId
* @return mixed
*/
private function getRegionId(string $code, string $countryId)
{
$region = $this->regionFactory->create();
return $region->loadByCode($code, $countryId)->getId();
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento2-channable",
"description": "Channable integration for Magento 2",
"type": "magento2-module",
"version": "1.4.17",
"version": "1.4.18",
"license": "BSD-2-Clause",
"homepage": "https://github.com/magmodules/magento2-channable",
"require": {
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magmodules_Channable" setup_version="1.4.17"/>
<module name="Magmodules_Channable" setup_version="1.4.18"/>
</config>

0 comments on commit f6b1b0e

Please sign in to comment.