Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read module's version from module's composer.json instead of setup_version attribute of module.xml #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 32 additions & 4 deletions Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,46 @@
use Magento\Store\Model\StoreManagerInterface;
use Signifyd\Connect\Helper\ConfigHelper;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\Component\ComponentRegistrarInterface;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Filesystem\Directory\ReadFactory;

class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
{
/**
* @var ConfigHelper
*/
public $configHelper;
protected $configHelper;

/**
* @var StoreManagerInterface
*/
public $storeManager;
protected $storeManager;

/**
* @var ModuleListInterface
*/
public $moduleListInterface;
protected $moduleListInterface;
protected ComponentRegistrarInterface $componentRegistrar;
protected ReadFactory $readFactory;

/**
* @param ConfigHelper $configHelper
* @param StoreManagerInterface $storeManager
* @param ModuleListInterface $moduleListInterface
*/
public function __construct(
ReadFactory $readFactory,
ComponentRegistrarInterface $componentRegistrar,
ConfigHelper $configHelper,
StoreManagerInterface $storeManager,
ModuleListInterface $moduleListInterface
) {
$this->storeManager = $storeManager;
$this->moduleListInterface = $moduleListInterface;
$this->configHelper = $configHelper;
$this->componentRegistrar = $componentRegistrar;
$this->readFactory = $readFactory;
}
public function getConfig()
{
Expand All @@ -55,7 +64,7 @@ public function getConfig()
$adyenModule = $this->moduleListInterface->getOne('Adyen_Payment');

if (isset($adyenModule)) {
$adyenVersion = $this->moduleListInterface->getOne('Adyen_Payment')['setup_version'];
$adyenVersion = $this->getModuleVersionFromComposer('Adyen_Payment');
$isAdyenGreaterThanEightEighteen = version_compare($adyenVersion, '8.18.0') >= 0;
$isAdyenGreaterThanEight = version_compare($adyenVersion, '8.0.0') >= 0 &&
version_compare($adyenVersion, '8.17.9') <= 0;
Expand All @@ -74,4 +83,23 @@ public function getConfig()
'isAdyenGreaterThanEight' => $isAdyenGreaterThanEight]
];
}

/**
* Get version from composer.json if it exist otherwise return empty string
* @param string $moduleName
* @return string
*/
public function getModuleVersionFromComposer(string $moduleName) : string
{
$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
$directoryRead = $this->readFactory->create($path);
$composerJsonData = $directoryRead->readFile('composer.json');
$data = json_decode($composerJsonData, true);
if (is_null($data))
{
return '';
}

return isset($data['version']) ? $data['version'] : '';
}
}