Skip to content

Commit

Permalink
Merge pull request postcode-nl#80 from JerrySmidt/master
Browse files Browse the repository at this point in the history
3.1.10
  • Loading branch information
JerrySmidt authored Jun 6, 2023
2 parents e3a9a89 + 8fa3f34 commit e864bf8
Show file tree
Hide file tree
Showing 57 changed files with 214 additions and 192 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gitattributes export-ignore
.gitignore export-ignore
3 changes: 1 addition & 2 deletions Api/Data/Autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Autocomplete implements AutocompleteInterface
*/
public function __construct(array $response)
{
foreach ($response['matches'] ?? [] as $match)
{
foreach ($response['matches'] ?? [] as $match) {
$this->matches[] = new Autocomplete\AutocompleteMatch($match);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Api/Data/Autocomplete/AutocompleteMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AutocompleteMatch implements MatchInterface
public $highlights;

/**
* __construct function.
* Constructor
*
* @access public
* @param array $match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

interface HighlightInterface
{
/**
/**
* @return int[]
*/
*/
public function getOffsets(): array;
}
4 changes: 0 additions & 4 deletions Api/PostcodeModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ interface PostcodeModelInterface
*/
public function getAddressAutocomplete(string $context, string $term): \Flekto\Postcode\Api\Data\AutocompleteInterface;


/**
* @access public
* @param string $context
* @return string[][]
*/
public function getAddressDetails(String $context): array;


/**
* @access public
* @param string $context
Expand All @@ -32,13 +30,11 @@ public function getAddressDetails(String $context): array;
*/
public function getAddressDetailsCountry(String $context, String $dispatchCountry): array;


/**
* @access public
* @param string $zipCode
* @param string $houseNumber
* @return string[][]
*/
public function getNlAddress(String $zipCode, String $houseNumber): array;

}
2 changes: 1 addition & 1 deletion Block/Customer/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
class Address extends \Magento\Framework\View\Element\Template
{

}
}
9 changes: 5 additions & 4 deletions Block/Onepage/LayoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class LayoutProcessor extends AbstractBlock implements LayoutProcessorInterface
protected $scopeConfig;

/**
* __construct function.
* Constructor
*
* @access public
* @param Context $context
Expand All @@ -26,7 +26,7 @@ public function __construct(Context $context, array $data = [])
}

/**
* process function.
* Process Javascript layout of block.
*
* @access public
* @param mixed $jsLayout
Expand Down Expand Up @@ -70,8 +70,8 @@ public function process($jsLayout)
['payments-list']['children'];

if (isset($billingConfiguration)) {
foreach($billingConfiguration as $key => &$billingForm) {
if (!strpos($key, '-form')) {
foreach ($billingConfiguration as $key => &$billingForm) {
if (false === strpos($key, '-form')) {
continue;
}

Expand Down Expand Up @@ -145,6 +145,7 @@ private function _updateCustomScope($fields, $dataScope)

/**
* Find and update dataScope
*
* The default dataScope is 'shippingAddress.item-name'. But, it needs to be '$dataScope.item-name' for the billingAddress and billingAddressshared
*
* @access private
Expand Down
34 changes: 17 additions & 17 deletions Block/System/Config/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function __construct(
}

/**
* Render template.
*
* @param AbstractElement $element
*
* @return string
Expand Down Expand Up @@ -69,23 +71,21 @@ public function getConfig(): array
*
* @return string
*/
public function getApiStatusDescription(): string
{
public function getApiStatusDescription(): string
{
$status = $this->_storeConfigHelper->getValue(StoreConfigHelper::PATH['account_status']);

switch ($status)
{
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_NEW:
return __('not connected');
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_ACTIVE:
return __('active');
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_INVALID_CREDENTIALS:
return __('invalid key and/or secret');
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_INACTIVE:
return __('inactive');
default:
throw new \Exception('Invalid account status value.');
}
}

switch ($status) {
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_NEW:
return __('not connected');
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_ACTIVE:
return __('active');
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_INVALID_CREDENTIALS:
return __('invalid key and/or secret');
case \Flekto\Postcode\Helper\ApiClientHelper::API_ACCOUNT_STATUS_INACTIVE:
return __('inactive');
default:
throw new Status\Exception(__('Invalid account status value.'));
}
}
}
7 changes: 7 additions & 0 deletions Block/System/Config/Status/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Flekto\Postcode\Block\System\Config\Status;

class Exception extends \Magento\Framework\Exception\LocalizedException
{
}
1 change: 0 additions & 1 deletion Cron/UpdateApiData.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ public function execute()

$this->_logger->info(__('Postcode.eu API data update complete'));
}

}
39 changes: 11 additions & 28 deletions Helper/ApiClientHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;


class ApiClientHelper extends AbstractHelper
{
const API_ACCOUNT_STATUS_NEW = 'new';
const API_ACCOUNT_STATUS_INVALID_CREDENTIALS = 'invalid_credentials';
const API_ACCOUNT_STATUS_INACTIVE = 'inactive';
const API_ACCOUNT_STATUS_ACTIVE = 'active';
public const API_ACCOUNT_STATUS_NEW = 'new';
public const API_ACCOUNT_STATUS_INVALID_CREDENTIALS = 'invalid_credentials';
public const API_ACCOUNT_STATUS_INACTIVE = 'inactive';
public const API_ACCOUNT_STATUS_ACTIVE = 'active';

protected $_modules;
protected $_moduleList;
Expand All @@ -36,7 +35,6 @@ class ApiClientHelper extends AbstractHelper
protected $_countryCodeMap = [];
protected $_storeConfigHelper;


/**
* __construct function.
*
Expand Down Expand Up @@ -142,9 +140,8 @@ public function getAddressAutocomplete(string $context, string $term): array
}
}


/**
* Get address details
* Get address details.
*
* @access public
* @param string $context
Expand All @@ -169,9 +166,8 @@ public function getAddressDetails(string $context): array
}
}


/**
* getNlAddress function.
* Get Dutch address.
*
* @access public
* @param string $zipCode
Expand All @@ -186,7 +182,7 @@ public function getNlAddress(string $zipCode, string $houseNumber): array
$houseNumber = isset($matches[1]) ? (int)$matches[1] : null;
$houseNumberAddition = isset($matches[2]) ? trim($matches[2]) : null;

if (is_null($houseNumber)) {
if (null === $houseNumber) {
return ['error' => true, 'message_details' => __('Invalid house number.')];
}

Expand All @@ -197,10 +193,9 @@ public function getNlAddress(string $zipCode, string $houseNumber): array
$address = $this->_prepareResponse($address, $client);
$status = 'valid';

if (
(strcasecmp($address['houseNumberAddition'] ?? '', $houseNumberAddition ?? '') != 0)
if ((strcasecmp($address['houseNumberAddition'] ?? '', $houseNumberAddition ?? '') != 0)
||
(!empty($address['houseNumberAdditions']) && is_null($address['houseNumberAddition']))
(!empty($address['houseNumberAdditions']) && null === $address['houseNumberAddition'])
) {
$status = 'houseNumberAdditionIncorrect';
}
Expand Down Expand Up @@ -235,7 +230,6 @@ public function getNlAddress(string $zipCode, string $houseNumber): array
return $out;
}


/**
* _generateSessionString function.
*
Expand All @@ -247,7 +241,6 @@ private function _generateSessionString(): string
return bin2hex(random_bytes(8));
}


/**
* _handleClientException function.
*
Expand Down Expand Up @@ -282,7 +275,6 @@ private function _handleClientException(\Exception $exception): array
return $response;
}


/**
* _prepareResponse function.
*
Expand Down Expand Up @@ -314,7 +306,6 @@ private function _prepareResponse(array $apiResult, PostcodeApiClient $client):
return $apiResult;
}


/**
* Get supported countries from API.
*
Expand All @@ -330,7 +321,6 @@ public function getSupportedCountries(): array
}
}


/**
* Get country ISO3 code from ISO2 code, or NULL if not found.
*
Expand All @@ -354,9 +344,8 @@ public function getCountryIso3Code(string $iso2Code): ?string
return $this->_countryCodeMap[$mapKey][strtoupper($iso2Code)] ?? null;
}


/**
* isDebugging function.
* Check if debugging is active.
*
* @access public
* @return bool
Expand All @@ -366,7 +355,6 @@ public function isDebugging(): bool
return $this->_storeConfigHelper->isSetFlag(StoreConfigHelper::PATH['api_debug'], ScopeInterface::SCOPE_STORE) && $this->_developerHelper->isDevAllowed();
}


/**
* Get API key.
*
Expand All @@ -378,7 +366,6 @@ protected function _getKey(): string
return trim($this->_storeConfigHelper->getValue(StoreConfigHelper::PATH['api_key']) ?? '');
}


/**
* Get API secret.
*
Expand All @@ -390,7 +377,6 @@ protected function _getSecret(): string
return trim($this->_storeConfigHelper->getValue(StoreConfigHelper::PATH['api_secret']) ?? '');
}


/**
* _getModuleInfo function.
*
Expand All @@ -409,7 +395,6 @@ protected function _getModuleInfo($moduleName): ?array
return $modules[$moduleName];
}


/**
* _getMagentoModules function.
*
Expand All @@ -436,7 +421,6 @@ private function _getMagentoModules(): array
return $this->_modules;
}


/**
* Get fixed country (ISO2) if there's only one allowed country.
*
Expand All @@ -454,7 +438,6 @@ private function _getFixedCountry(): ?string
return null;
}


/**
* _getDebugInfo function.
*
Expand All @@ -477,7 +460,7 @@ private function _getDebugInfo(): array

// Magento version
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface');
$productMetadata = $objectManager->get(Magento\Framework\App\ProductMetadataInterface::class);
$version = $productMetadata->getVersion();

$debug['magentoVersion'] = 'Magento/' . $version;
Expand Down
Loading

0 comments on commit e864bf8

Please sign in to comment.