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

Remove the akeneo auth from the construct #45

Merged
merged 1 commit into from
Aug 2, 2024
Merged
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
13 changes: 5 additions & 8 deletions Job/ImportMetricUnits.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@ 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(
Authenticator $authenticator,
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('<error>Akeneo client not configured!</error>');
}
Expand Down Expand Up @@ -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'] ?? [];
}
}
Loading