diff --git a/Job/ImportMetricUnits.php b/Job/ImportMetricUnits.php index 7c85951..36c675a 100644 --- a/Job/ImportMetricUnits.php +++ b/Job/ImportMetricUnits.php @@ -18,8 +18,8 @@ class ImportMetricUnits protected const ENABLED_CONFIG_KEY = 'enablemetricunits'; protected const CHANNEL_CONFIG_KEY = 'metric_conversion_channel'; + protected Authenticator $authenticator; protected AttributeRepositoryInterface $attributeRepository; - protected ?AkeneoPimClientInterface $akeneoClient = null; protected ScopeConfigInterface $config; public function __construct( @@ -27,17 +27,14 @@ public function __construct( AttributeRepositoryInterface $attributeRepository, ScopeConfigInterface $config ) { + $this->authenticator = $authenticator; $this->attributeRepository = $attributeRepository; $this->config = $config; - - if (($client = $authenticator->getAkeneoApiClient())) { - $this->akeneoClient = $client; - } } public function execute(OutputInterface $output = null): void { - if (! $this->akeneoClient) { + if (! $this->authenticator->getAkeneoApiClient()) { if ($output) { $output->writeln('Akeneo client not configured!'); } @@ -90,13 +87,13 @@ protected function getMetricAttributes(): ResourceCursor { $search = (new SearchBuilder())->addFilter('type', 'IN', ['pim_catalog_metric']); - return $this->akeneoClient->getAttributeApi()->all(100, ['search' => $search->getFilters()]); + return $this->authenticator->getAkeneoApiClient()->getAttributeApi()->all(100, ['search' => $search->getFilters()]); } protected function getChannelConversions(): array { $channel = $this->config->getValue(static::CONFIG_PREFIX . static::CHANNEL_CONFIG_KEY); - return $this->akeneoClient->getChannelApi()->get($channel)['conversion_units'] ?? []; + return $this->authenticator->getAkeneoApiClient()->getChannelApi()->get($channel)['conversion_units'] ?? []; } }