-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE][SEL-485] Added graphql support for postcode-nl/api-magento2…
…-module and removed support for experius/module-postcode
- Loading branch information
Showing
6 changed files
with
232 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## 2.0.0 (2021-09-28) | ||
|
||
[View Release]([email protected]:experius/Mage2-Module-Experius-PostcodeGraphQl.git/commits/tag/2.0.0) | ||
|
||
* [FEATURE][SEL-485] Added graphql support for postcode-nl/api-magento2-module and removed support for experius/module-postcode *(René Schep)* | ||
|
||
|
||
## 1.0.1 (2020-10-08) | ||
|
||
[View Release]([email protected]:experius/Mage2-Module-Experius-PostcodeGraphQl.git/commits/tag/1.0.1) | ||
|
||
* [BUGFIX] Fixed old reference *(René Schep)* | ||
|
||
|
||
## 1.0.0 (2020-10-02) | ||
|
||
[View Release]([email protected]:experius/Mage2-Module-Experius-PostcodeGraphQl.git/commits/tag/1.0.0) | ||
|
||
* [FEATURE] Intial commit, split from Postcode module *(René Schep)* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* A Magento 2 module named Experius/Postcode | ||
* Copyright (C) 2016 Experius | ||
* | ||
* This file included in Experius/Postcode is licensed under OSL 3.0 | ||
* | ||
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* Please see LICENSE.txt for the full text of the OSL 3.0 license | ||
*/ | ||
|
||
namespace Experius\PostcodeGraphQl\Model\Resolver; | ||
|
||
use Experius\Core\Helper\Settings; | ||
use Flekto\Postcode\Helper\PostcodeApiClient; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
class AddressDetails implements ResolverInterface | ||
{ | ||
|
||
protected $postcodeHelper; | ||
|
||
/** | ||
* PostcodeManagement constructor. | ||
* @param Settings $helper | ||
*/ | ||
public function __construct( | ||
Settings $helper | ||
) { | ||
$this->postcodeHelper = new PostcodeApiClient( | ||
$helper->getConfigValue('postcodenl_api/general/api_key'), | ||
$helper->getConfigValue('postcodenl_api/general/api_secret') | ||
); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
|
||
if (!isset($args['context']) || !$args['context']) { | ||
throw new GraphQlInputException(__('"context" should be specified')); | ||
} | ||
$result = $this->postcodeHelper->internationalGetDetails($args['context']); | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* A Magento 2 module named Experius/Postcode | ||
* Copyright (C) 2016 Experius | ||
* | ||
* This file included in Experius/Postcode is licensed under OSL 3.0 | ||
* | ||
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* Please see LICENSE.txt for the full text of the OSL 3.0 license | ||
*/ | ||
|
||
namespace Experius\PostcodeGraphQl\Model\Resolver; | ||
|
||
use Experius\Core\Helper\Settings; | ||
use Flekto\Postcode\Helper\CountryCodeConvertorHelper; | ||
use Flekto\Postcode\Helper\PostcodeApiClient; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
class Autocomplete implements ResolverInterface | ||
{ | ||
|
||
/** | ||
* @var PostcodeApiClient | ||
*/ | ||
protected $postcodeHelper; | ||
|
||
/** | ||
* PostcodeManagement constructor. | ||
* @param Settings $helper | ||
*/ | ||
public function __construct( | ||
Settings $helper | ||
) { | ||
$this->postcodeHelper = new PostcodeApiClient( | ||
$helper->getConfigValue('postcodenl_api/general/api_key'), | ||
$helper->getConfigValue('postcodenl_api/general/api_secret') | ||
); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!isset($args['countryId']) || !$args['countryId']) { | ||
throw new GraphQlInputException(__('"countryId" should be specified')); | ||
} | ||
if (!isset($args['searchTerm']) || !$args['searchTerm']) { | ||
throw new GraphQlInputException(__('"searchTerm" should be specified')); | ||
} | ||
$countryId = CountryCodeConvertorHelper::alpha2ToAlpha3($args['countryId']); | ||
if(!isset($args['xAutocompleteSession'])) { | ||
$session = bin2hex(random_bytes(8)); | ||
} else { | ||
$session = $args['xAutocompleteSession']; | ||
} | ||
|
||
$result = $this->postcodeHelper->internationalAutocomplete($countryId, $args['searchTerm'], null, 'en-US'); | ||
if (isset($result['matches'])) { | ||
foreach($result['matches'] as &$match) { | ||
if(isset($match['highlights'])) { | ||
foreach($match['highlights'] as &$highlight) { | ||
$highlight['start'] = $highlight[0]; | ||
$highlight['end'] = $highlight[1]; | ||
} | ||
} | ||
} | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
Postcode.nl GraphQl Magento 2 Module by Experius | ||
============= | ||
|
||
Adds GraphQl support to the Experius Postcode.nl module. | ||
Adds GraphQl support to the postcode-nl/api-magento2-module | ||
|
||
IMPORTANT: Version 2 only supports the postcode-nl/api-magento2-module. For graphql support the experius/module-postcode module use version 1.x. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters