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

Get booked Features from Makaira and Store them in Database Configura… #63

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/Admin/CronJobs/MakairaConnectCronjobTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use GXModules\MakairaIO\MakairaConnect\App\GambioConnectService\GambioConnectManufacturerService;
use GXModules\MakairaIO\MakairaConnect\App\GambioConnectService\GambioConnectProductService;
use GXModules\MakairaIO\MakairaConnect\App\GambioConnectService\GambioConnectPublicFieldsService;
use GXModules\MakairaIO\MakairaConnect\App\MakairaClient;

class MakairaConnectCronjobTask extends AbstractCronjobTask
{
Expand All @@ -22,6 +23,8 @@ class MakairaConnectCronjobTask extends AbstractCronjobTask

protected ModuleConfigService $moduleConfigService;

protected MakairaClient $makairaClient;


public function getCallback($cronjobStartAsMicrotime): \Closure
{
Expand Down Expand Up @@ -83,6 +86,8 @@ public function getCallback($cronjobStartAsMicrotime): \Closure

$this->completePublicFieldsSetup();
}

$this->updateBookedFeatures();
};
}
return function () {
Expand Down Expand Up @@ -155,4 +160,15 @@ public function completeImporterSetup(): void
{
$this->moduleConfigService->setMakairaImporterSetupDone();
}

private function updateBookedFeatures(): void
{
$features = $this->makairaClient->getFeatures();

$this->moduleConfigService->setMakairaSearchBooked(in_array('search', $features));

$this->moduleConfigService->setMakairaPromotionBooked(in_array('promotion', $features));

$this->moduleConfigService->setMakairaRecommendationsBooked(in_array('recommendations', $features));
}
}
39 changes: 39 additions & 0 deletions src/Admin/Services/ModuleConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class ModuleConfigService

public const CONFIG_MAKAIRA_STATUS = 'status';

public const CONFIG_MAKAIRA_SEARCH_BOOKED = 'search_booked';

public const CONFIG_MAKAIRA_RECOMMENDATION_BOOKED = 'recommendation_booked';

public const CONFIG_MAKAIRA_PROMOTION_BOOKED = 'promotion_booked';

public const CONFIG_MAKAIRA_PUBLICFIELDS_SETUP_DONE = 'publicFieldsSetupDone';

public const CONFIG_MAKAIRA_IMPORTER_SETUP_DONE = 'makairaImporterSetupDone';
Expand Down Expand Up @@ -149,6 +155,36 @@ public function setMakairaCronJobInterval(): void
$this->configurationService->save(self::CONFIG_MAKAIRA_CRONJOB_INTERVAL, '*/1 * * * *');
}

public function isMakairaSearchBooked(): bool
{
return (bool)$this->getConfigValue(self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_SEARCH_BOOKED);
}

public function isMakairaRecommendationBooked(): bool
{
return (bool)$this->getConfigValue(self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_RECOMMENDATION_BOOKED);
}

public function isMakairaPromotionBooked(): bool
{
return (bool)$this->getConfigValue(self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_PROMOTION_BOOKED);
}

public function setMakairaSearchBooked(bool $booked): void
{
$this->setConfigValue(self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_SEARCH_BOOKED, $booked);
}

public function setMakairaRecommendationsBooked(bool $booked): void
{
$this->setConfigValue(self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_RECOMMENDATION_BOOKED, $booked);
}

public function setMakairaPromotionBooked(bool $booked): void
{
$this->setConfigValue(self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_PROMOTION_BOOKED, $booked);
}

private function getConfigValue(string $key): string
{
return $this->configurationService->find($key)?->value() ?? '';
Expand All @@ -169,6 +205,9 @@ public static function getModuleConfigKeys(): array
self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_INSTALLATION_SERVICE_CALLED,
self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_RECO_CROSS_SELLING,
self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_RECO_REVERSE_CROSS_SELLING,
self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_SEARCH_BOOKED,
self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_PROMOTION_BOOKED,
self::CONFIG_PREFIX . self::CONFIG_MAKAIRA_RECOMMENDATION_BOOKED,
self::CONFIG_MAKAIRA_CRONJOB_ACTIVE,
self::CONFIG_MAKAIRA_CRONJOB_INTERVAL
];
Expand Down
7 changes: 7 additions & 0 deletions src/App/MakairaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,11 @@ public function search(
$url = $this->makairaUrl . '/search/';
return json_decode($this->doRequest('POST', $url, $body)->getBody()->getContents());
}

public function getFeatures()
{
$response = $this->doRequest('GET', $this->makairaUrl . '/features');

return json_decode($response->getBody()->getContents());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function __construct()
// phpcs:ignore
protected function get_data(): array
{
if(!$this->moduleConfigService->isMakairaRecommendationBooked()) {
return parent::get_data() ?? [];
}

if (
$this->moduleStatusService->isSetUp()
&& $this->moduleStatusService->isActive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function proceed()

$moduleConfigService = new \GXModules\MakairaIO\MakairaConnect\Admin\Services\ModuleConfigService($configurationService);

if(!$moduleConfigService->isMakairaImporterSetupDone() || !$moduleConfigService->isPublicFieldsSetupDone()) {
if(!$moduleConfigService->isMakairaSearchBooked() || !$moduleConfigService->isMakairaImporterSetupDone() || !$moduleConfigService->isPublicFieldsSetupDone()) {
return parent::proceed();
}

Expand Down