diff --git a/alma/controllers/front/cmsdataexport.php b/alma/controllers/front/cmsdataexport.php index bde92d0f..f4f773a7 100644 --- a/alma/controllers/front/cmsdataexport.php +++ b/alma/controllers/front/cmsdataexport.php @@ -89,7 +89,7 @@ public function postProcess() $cmsFeature = new CmsFeatures($this->cmsDataHelper->getCmsFeatureArray()); $payload = $this->payloadFormatter->formatConfigurationPayload($cmsInfo, $cmsFeature); - $this->ajaxRenderAndExit(json_encode(['success' => $payload])); + $this->ajaxRenderAndExit(json_encode($payload)); } /** diff --git a/alma/lib/Helpers/CmsDataHelper.php b/alma/lib/Helpers/CmsDataHelper.php index b762f065..70d12a10 100644 --- a/alma/lib/Helpers/CmsDataHelper.php +++ b/alma/lib/Helpers/CmsDataHelper.php @@ -140,12 +140,11 @@ public function getCmsFeatureArray() 'alma_enabled' => (bool) (int) $this->settingsHelper->getKey(SettingsHelper::ALMA_FULLY_CONFIGURED), // clef fully configured 'widget_cart_activated' => (bool) (int) $this->settingsHelper->getKey(CartEligibilityAdminFormBuilder::ALMA_SHOW_ELIGIBILITY_MESSAGE), 'widget_product_activated' => (bool) (int) $this->settingsHelper->getKey(ProductEligibilityAdminFormBuilder::ALMA_SHOW_PRODUCT_ELIGIBILITY), - 'used_fee_plans' => json_decode($this->settingsHelper->getKey(PnxAdminFormBuilder::ALMA_FEE_PLANS), true), + 'used_fee_plans' => $this->getUsedFeePlans(), //'payment_method_position' => null, // not applicable - position is set in the used_fee_plans 'in_page_activated' => (bool) (int) $this->settingsHelper->getKey(InpageAdminFormBuilder::ALMA_ACTIVATE_INPAGE), 'log_activated' => (bool) (int) $this->settingsHelper->getKey(DebugAdminFormBuilder::ALMA_ACTIVATE_LOGGING), 'excluded_categories' => $this->settingsHelper->getCategoriesExcludedNames(), - //'excluded_categories_activated' => '',// not applicable - it's not possible to disable the exclusion 'specific_features' => [], // no specific features in Prestashop 'country_restriction' => $this->getCountriesRestrictions(), 'custom_widget_css' => (bool) $this->settingsHelper->getKey(ProductEligibilityAdminFormBuilder::ALMA_WIDGET_POSITION_SELECTOR), @@ -158,7 +157,20 @@ public function getCmsFeatureArray() */ private function getCountriesRestrictions() { - // TODO : Need to implement this method with the db ps_module_country return []; } + + /** + * @return array|null + */ + private function getUsedFeePlans() + { + $feePlans = json_decode($this->settingsHelper->getKey(PnxAdminFormBuilder::ALMA_FEE_PLANS), true); + + if (empty($feePlans)) { + return null; + } + + return $feePlans; + } } diff --git a/alma/tests/Unit/Helper/CmsDataHelperTest.php b/alma/tests/Unit/Helper/CmsDataHelperTest.php index a4c3bdc1..d9540f0d 100644 --- a/alma/tests/Unit/Helper/CmsDataHelperTest.php +++ b/alma/tests/Unit/Helper/CmsDataHelperTest.php @@ -116,4 +116,38 @@ public function testGetCmsFeatureArray() $this->assertEquals($expected, $this->cmsDataHelper->getCmsFeatureArray()); } + + /** + * @return void + */ + public function testGetCmsFeatureArrayWithFeePlansEmptyReturnNull() + { + $this->settingsHelper->method('getKey')->willReturnMap( + [ + [SettingsHelper::ALMA_FULLY_CONFIGURED, null, false], + [CartEligibilityAdminFormBuilder::ALMA_SHOW_ELIGIBILITY_MESSAGE, null, false], + [ProductEligibilityAdminFormBuilder::ALMA_SHOW_PRODUCT_ELIGIBILITY, null, false], + [PnxAdminFormBuilder::ALMA_FEE_PLANS, null, '{}'], + [InpageAdminFormBuilder::ALMA_ACTIVATE_INPAGE, null, true], + [DebugAdminFormBuilder::ALMA_ACTIVATE_LOGGING, null, true], + [ProductEligibilityAdminFormBuilder::ALMA_WIDGET_POSITION_SELECTOR, null, '#selectorCss'], + ] + ); + $this->shopModel->method('isMultisite')->willReturn(false); + $expected = [ + 'alma_enabled' => false, + 'widget_cart_activated' => false, + 'widget_product_activated' => false, + 'used_fee_plans' => null, + 'in_page_activated' => true, + 'log_activated' => true, + 'excluded_categories' => null, + 'specific_features' => [], + 'country_restriction' => [], + 'custom_widget_css' => (bool) '#selectorCss', + 'is_multisite' => false, + ]; + + $this->assertEquals($expected, $this->cmsDataHelper->getCmsFeatureArray()); + } } diff --git a/alma/upgrade/upgrade-4.6.0.php b/alma/upgrade/upgrade-4.6.0.php index 39caae29..85a8b377 100644 --- a/alma/upgrade/upgrade-4.6.0.php +++ b/alma/upgrade/upgrade-4.6.0.php @@ -22,7 +22,13 @@ * @license https://opensource.org/licenses/MIT The MIT License */ +use Alma\API\Lib\IntegrationsConfigurationsUtils; +use Alma\PrestaShop\Builders\Helpers\ApiHelperBuilder; +use Alma\PrestaShop\Builders\Helpers\ContextHelperBuilder; +use Alma\PrestaShop\Builders\Helpers\SettingsHelperBuilder; +use Alma\PrestaShop\Helpers\CmsDataHelper; use Alma\PrestaShop\Helpers\ConstantsHelper; +use Alma\PrestaShop\Logger; if (!defined('_PS_VERSION_')) { exit; @@ -30,7 +36,18 @@ function upgrade_module_4_6_0() { - // TODO : Add Send url for CmsData + $settingsHelper = (new SettingsHelperBuilder())->getInstance(); + $contextHelper = (new ContextHelperBuilder())->getInstance(); + $apiHelper = (new ApiHelperBuilder())->getInstance(); + + try { + if (IntegrationsConfigurationsUtils::isUrlRefreshRequired($settingsHelper->getKey(CmsDataHelper::ALMA_CMSDATA_DATE))) { + $apiHelper->sendUrlForGatherCmsData($contextHelper->getModuleLink('cmsdataexport', [], true)); + $settingsHelper->updateKey(CmsDataHelper::ALMA_CMSDATA_DATE, time()); + } + } catch (\Alma\PrestaShop\Exceptions\AlmaException $e) { + Logger::instance()->error('Failed to send URL for CMS data gathering', ['exception' => $e]); + } if (version_compare(_PS_VERSION_, ConstantsHelper::PRESTASHOP_VERSION_1_7_0_2, '>')) { Tools::clearAllCache();