Skip to content
Merged

4.1.0 #124

Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions Api/Data/MagentoDebugInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

class MagentoDebugInfo implements MagentoDebugInfoInterface
{
/** @var string */
protected $moduleVersion;
/** @var string */
protected $magentoVersion;
/** @var string */
protected $client;
/** @var string */
protected $session;
/** @var MagentoDebugInfo\ConfigurationInterface */
protected $configuration;
/** @var MagentoDebugInfo\MagentoModuleInterface[] */
protected $modules;

/**
Expand Down
2 changes: 2 additions & 0 deletions Api/Data/MagentoDebugInfo/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

class Configuration implements ConfigurationInterface
{
/** @var string */
protected $key;
/** @var string */
protected $secret;

/**
Expand Down
2 changes: 2 additions & 0 deletions Api/Data/MagentoDebugInfo/MagentoModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

class MagentoModule implements MagentoModuleInterface
{
/** @var string */
private string $name;
/** @var string */
private string $setupVersion;

/**
Expand Down
19 changes: 17 additions & 2 deletions Block/System/Config/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,33 @@ class Status extends Template implements RendererInterface
public const CACHE_ID = 'postcode-eu-status';
public const CACHE_LIFETIME_SECONDS = 3600;

/** @var string */
protected $_template = 'PostcodeEu_AddressValidation::system/config/status.phtml';
/** @var \Magento\Framework\App\Config\ScopeConfigInterface */
protected $_scopeConfig;
/** @var StoreConfigHelper */
protected $_storeConfigHelper;
/** @var ApiClientHelper */
protected $_apiClientHelper;
/** @var ConfigInterface */
protected $_resourceConfig;
/** @var CacheTypeList */
protected $_cacheTypeList;
/** @var CacheFrontendPool */
protected $_cacheFrontendPool;
/** @var SerializerInterface */
protected $_serializer;
/** @var DataHelper */
protected $_dataHelper;
/** @var UpdateNotifier */
protected $_updateNotifier;

/** @var array|null */
private $_cachedData;

/** @var array */
public array $accountInfo;
/** @var array */
public array $moduleInfo;

/**
Expand Down Expand Up @@ -191,13 +204,15 @@ public function isStatusActive(): bool
private function _getCachedData(): array
{
$cache = $this->_cacheFrontendPool->get(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER);
$cachedData = $cache->load(self::CACHE_ID);
[$scopeType, $scopeId] = $this->_storeConfigHelper->getScopeFromRequest();
$cacheId = implode('-', [self::CACHE_ID, $scopeType, $scopeId]);
$cachedData = $cache->load($cacheId);

if ($cachedData === false) {
$data = [];
$data['accountInfo'] = $this->_getAccountInfo();
$data['moduleInfo'] = $this->_dataHelper->getModuleInfo();
$cache->save($this->_serializer->serialize($data), self::CACHE_ID, [], self::CACHE_LIFETIME_SECONDS);
$cache->save($this->_serializer->serialize($data), $cacheId, [], self::CACHE_LIFETIME_SECONDS);
return $data;
}

Expand Down
72 changes: 72 additions & 0 deletions Controller/Adminhtml/Address/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace PostcodeEu\AddressValidation\Controller\Adminhtml\Address;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Webapi\ServiceOutputProcessor;
use PostcodeEu\AddressValidation\Api\PostcodeModelInterface;

class Api extends Action implements HttpGetActionInterface
{
const ADMIN_RESOURCE = 'PostcodeEu_AddressValidation::config_postcode_eu';

/** @var JsonFactory */
protected $_resultJsonFactory;
/** @var PostcodeModelInterface */
protected $_postcodeModel;
/** @var ServiceOutputProcessor */
protected $_serviceOutputProcessor;

public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
PostcodeModelInterface $postcodeModel,
ServiceOutputProcessor $serviceOutputProcessor
) {
parent::__construct($context);
$this->_resultJsonFactory = $resultJsonFactory;
$this->_postcodeModel = $postcodeModel;
$this->_serviceOutputProcessor = $serviceOutputProcessor;
}

/**
* Call address API methods
*
* @return Json
*/
public function execute(): Json
{
$resultJson = $this->_resultJsonFactory->create();
$request = $this->getRequest();

try {
switch ($request->getParam('method')) {
case 'postcode':
$serviceMethod = 'getNlAddress';
$params = ['postcode', 'house_number'];
break;
case 'autocomplete':
$serviceMethod = 'getAddressAutocomplete';
$params = ['context', 'term'];
break;
case 'address_details':
$serviceMethod = 'getAddressDetails';
$params = ['context'];
break;
default:
throw new \Exception('Invalid service method');
}

$values = array_filter($request->getParams(), fn($key) => in_array($key, $params), ARRAY_FILTER_USE_KEY);
$result = $this->_postcodeModel->$serviceMethod(...array_values($values));
$result = $this->_serviceOutputProcessor->process($result, PostcodeModelInterface::class, $serviceMethod);
return $resultJson->setData($result);
} catch (\Exception $e) {
return $resultJson->setHttpResponseCode(400)->setData(['error' => $e->getMessage()]);
}
}
}
3 changes: 3 additions & 0 deletions Cron/NotifyModuleUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

class NotifyModuleUpdate
{
/** @var LoggerInterface */
protected $_logger;
/** @var DataHelper */
protected $_dataHelper;
/** @var UpdateNotifier */
protected $_updateNotifier;

/**
Expand Down
Loading