Skip to content

Commit

Permalink
Merge pull request #612 from alma/feature/ecom-2240-ps-send-the-endpo…
Browse files Browse the repository at this point in the history
…int_url-during-the-upgrade-of-the-module

feat: Send the endpoint_url during the upgrade
  • Loading branch information
Benjamin-Freoua-Alma authored Dec 6, 2024
2 parents 7e1d999 + 19462d8 commit ba60095
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
2 changes: 1 addition & 1 deletion alma/controllers/front/cmsdataexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
18 changes: 15 additions & 3 deletions alma/lib/Helpers/CmsDataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
}
}
34 changes: 34 additions & 0 deletions alma/tests/Unit/Helper/CmsDataHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
19 changes: 18 additions & 1 deletion alma/upgrade/upgrade-4.6.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,32 @@
* @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;
}

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();
Expand Down

0 comments on commit ba60095

Please sign in to comment.