From 231c17bb48781eae3b917a365702316f16c397c1 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Wed, 19 Aug 2020 16:44:24 -0400 Subject: [PATCH] Update Extension list --- .../System/Config/Field/Extensions.php | 16 +++++++++ Model/Module.php | 33 +++++++++++++++---- composer.json | 2 +- .../system/config/field/extensions.phtml | 20 ++++++++++- view/adminhtml/web/css/config.less | 6 ++++ 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/Block/Adminhtml/System/Config/Field/Extensions.php b/Block/Adminhtml/System/Config/Field/Extensions.php index abfcc1c..741acbb 100755 --- a/Block/Adminhtml/System/Config/Field/Extensions.php +++ b/Block/Adminhtml/System/Config/Field/Extensions.php @@ -56,4 +56,20 @@ public function getExtensionList() { return $this->module->getOutDatedExtension(); } + + /** + * @return array + */ + public function getRelatedProduct() + { + $result = []; + $installedExtensions = $this->module->getMyExtensionList(); + foreach ($this->module->getProductFeed() as $key => $item) { + if (isset($item['upsell']) && $item['upsell'] == 1 && !array_key_exists($key, $installedExtensions)) { + $result[$key] = $item; + } + } + + return $result; + } } diff --git a/Model/Module.php b/Model/Module.php index a9a7c7a..7db099f 100644 --- a/Model/Module.php +++ b/Model/Module.php @@ -21,7 +21,8 @@ class Module { const URL = "https://updates.magepal.com/extensions.json"; const CACHE_KEY = 'magepal_extension_installed_list'; - const DATA_VERSION = '1.0.2'; + const SESSION_KEY = 'magepal-core-notification-data'; + const DATA_VERSION = '1.0.3'; const LIFE_TIME = 604800; /** @var int $updateCounter */ @@ -67,6 +68,10 @@ class Module private $session; private $timeStamp; + /** + * @var array|mixed + */ + private $latestVersions = []; /** * @param ModuleListInterface $moduleList @@ -139,7 +144,7 @@ public function getCachedUpdateCount() { $now = $this->getTimeStamp(); $hash = $this->getHash(); - $data = (array) $this->session->getData('magepal-core-notification-data'); + $data = (array) $this->session->getData(self::SESSION_KEY); if (empty($data) || !is_array($data) || $this->getArrayKeyIfExist('hash', $data, '') !== $hash @@ -163,7 +168,7 @@ protected function setCountCache($amount) 'ttl' => $this->getTtl() ]; - $this->session->setData('magepal-core-notification-data', $data); + $this->session->setData(self::SESSION_KEY, $data); return $data; } @@ -175,6 +180,15 @@ public function getHash() return md5(json_encode($this->getPostData())); } + public function getProductFeed() + { + if (empty($this->latestVersions)) { + $this->getOutDatedExtension(); + } + + return (array) $this->latestVersions; + } + /** * @return array */ @@ -202,6 +216,10 @@ public function getOutDatedExtension() if (array_key_exists('extensions', $dataObject)) { $this->outDatedExtensionList = $dataObject['extensions']; } + + if (array_key_exists('latestVersions', $dataObject)) { + $this->latestVersions = $dataObject['latestVersions']; + } } } @@ -216,7 +234,7 @@ public function loadOutDatedExtensionCollection() try { $extensionList = $this->getMyExtensionList(); $feed = $this->callApi(self::URL, $this->getPostData()); - $latestVersions = $feed['extensions'] ?? []; + $this->latestVersions = $feed['extensions'] ?? []; $hasUpdate = false; foreach ($extensionList as $item) { @@ -225,8 +243,8 @@ public function loadOutDatedExtensionCollection() $item['url'] = 'https://www.magepal.com/extensions.com'; $item['name'] = $this->getTitleFromModuleName($item['moduleName']); - if (array_key_exists($item['composer_name'], $latestVersions)) { - $latest = $latestVersions[$item['composer_name']]; + if (array_key_exists($item['composer_name'], $this->latestVersions)) { + $latest = $this->latestVersions[$item['composer_name']]; $item['latest_version'] = $latest['latest_version']; $item['has_update'] = version_compare($item['latest_version'], $item['install_version']) > 0; $item['url'] = $latest['url']; @@ -249,7 +267,8 @@ public function loadOutDatedExtensionCollection() 'count' => $this->updateCounter, 'extensions' => $this->outDatedExtensionList, 'data_version' => self::DATA_VERSION, - 'hash' => $this->getHash() + 'hash' => $this->getHash(), + 'latestVersions' => $this->latestVersions ]; $this->cache->save(json_encode($dataObject), self::CACHE_KEY, [], self::LIFE_TIME); diff --git a/composer.json b/composer.json index 461e694..a0a6ed4 100755 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "magento/framework": "100.0.*|100.1.*|101.0.*|102.0.*|103.0.*" }, "type": "magento2-module", - "version": "1.1.7", + "version": "1.1.8", "autoload": { "files": [ "registration.php" diff --git a/view/adminhtml/templates/system/config/field/extensions.phtml b/view/adminhtml/templates/system/config/field/extensions.phtml index 87f4ca8..b40a2b6 100644 --- a/view/adminhtml/templates/system/config/field/extensions.phtml +++ b/view/adminhtml/templates/system/config/field/extensions.phtml @@ -28,7 +28,7 @@
- Learn More + Learn More
@@ -56,6 +56,24 @@ + + getRelatedProduct() as $item): ?> +
+
escapeHtml($item['name'] ?? '') ?>
+
+
+ +
+ + +
+ Get Now! +
+ +
+
+ + diff --git a/view/adminhtml/web/css/config.less b/view/adminhtml/web/css/config.less index edf2d31..5beaeea 100644 --- a/view/adminhtml/web/css/config.less +++ b/view/adminhtml/web/css/config.less @@ -105,6 +105,12 @@ color: green; } + .latest-version { + margin-top: 12px; + text-align: center; + color: red; + } + .update { color: red; }