Skip to content

Commit

Permalink
feat: Changes required by Prestashop Validator (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmolinacano authored Jan 14, 2025
1 parent db0de5f commit 0924751
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Autoloader
*/
public static function register()
{
spl_autoload_register(function ($class) {
return spl_autoload_register(function ($class) {
$file = sprintf('%1$sdoofinder/%2$s', _PS_MODULE_DIR_, self::pathFromNamespace($class));
if (file_exists($file)) {
require_once $file;
Expand Down
16 changes: 7 additions & 9 deletions feeds/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function arrayMergeByIdProduct($array1 = [], $array2 = [])

$limit_group_attributes = false;
if (
isset($cfg_group_attributes_shown)
is_array($cfg_group_attributes_shown)
&& count($cfg_group_attributes_shown) > 0
&& $cfg_group_attributes_shown[0] !== ''
) {
Expand Down Expand Up @@ -236,7 +236,7 @@ function arrayMergeByIdProduct($array1 = [], $array2 = [])
$all_feature_keys = DfTools::getFeatureKeysForShopAndLang($shop->id, $lang->id);

if (
isset($cfg_features_shown)
is_array($cfg_features_shown)
&& count($cfg_features_shown) > 0
&& $cfg_features_shown[0] !== ''
) {
Expand Down Expand Up @@ -272,9 +272,8 @@ function arrayMergeByIdProduct($array1 = [], $array2 = [])
'limit' => $limit,
'offset' => $offset,
]);
if (!empty($extra_header)) {
$header = array_merge($header, $extra_header);
}

$header = array_merge($header, $extra_header);

if (!$limit || ($offset !== false && (int) $offset === 0)) {
echo implode(DfTools::TXT_SEPARATOR, $header) . PHP_EOL;
Expand All @@ -283,9 +282,8 @@ function arrayMergeByIdProduct($array1 = [], $array2 = [])

// PRODUCTS
$rows = DfTools::getAvailableProductsForLanguage($lang->id, $shop->id, $limit, $offset);
if (!empty($extra_rows)) {
$rows = arrayMergeByIdProduct($rows, $extra_rows);
}

$rows = arrayMergeByIdProduct($rows, $extra_rows);

// In case there is no need to display prices, avoid calculating the mins by variant
$min_price_variant_by_product_id = $cfg_display_prices ? DfTools::getMinVariantPrices($rows, $cfg_prices_w_taxes, $currencies) : [];
Expand Down Expand Up @@ -394,7 +392,7 @@ function arrayMergeByIdProduct($array1 = [], $array2 = [])
$row['id_product_attribute']
);

if (isset($id_image)) {
if (!empty($id_image)) {
$image_link = DfTools::cleanURL(
DfTools::getImageLink(
$row['id_product_attribute'],
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/DfCategoryBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function build($json = true)
{
$this->assign();

$payload = [];

foreach ($this->categories as $category) {
if (\Category::categoryExists($category)) {
$payload[] = $this->buildCategory($category);
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/DfCmsBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function build($json = true)
{
$this->assign();

$payload = [];

foreach ($this->cmsPages as $cms) {
$payload[] = $this->buildCms($cms);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/DfProductBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function build()
{
$this->assign();

$payload = [];

$products = $this->getProductData();

foreach ($products as $product) {
Expand Down Expand Up @@ -223,7 +225,7 @@ private function getImageLink($product)
if ($this->haveVariations($product)) {
$idImage = DfTools::getVariationImg($product['id_product'], $product['id_product_attribute']);

if (isset($idImage)) {
if (!empty($idImage)) {
$imageLink = DfTools::cleanURL(
DfTools::getImageLink(
$product['id_product_attribute'],
Expand Down Expand Up @@ -355,7 +357,7 @@ private function getFeaturesKeys()
$cfgFeaturesShown = explode(',', \Configuration::get('DF_FEATURES_SHOWN'));
$allFeatureKeys = DfTools::getFeatureKeysForShopAndLang($this->idShop, $this->idLang);

if (isset($cfgFeaturesShown) && count($cfgFeaturesShown) > 0 && $cfgFeaturesShown[0] !== '') {
if (is_array($cfgFeaturesShown) && count($cfgFeaturesShown) > 0 && $cfgFeaturesShown[0] !== '') {
return DfTools::getSelectedFeatures($allFeatureKeys, $cfgFeaturesShown);
} else {
return $allFeatureKeys;
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/DfTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DfTools

public static function isBasicValue($v)
{
return $v && !empty($v) && \Validate::isGenericName($v);
return $v && \Validate::isGenericName($v);
}

//
Expand Down Expand Up @@ -342,7 +342,7 @@ public static function getFeaturesForProduct($idProduct, $idLang, $featureKeys)
*/
public static function getAttributesForProductVariation($variationId, $idLang, $attributeKeys)
{
if (isset($variationId) && $variationId > 0) {
if (is_numeric($variationId) && $variationId > 0) {
$sql = '
SELECT pc.id_product_attribute,
pal.name,
Expand Down
1 change: 1 addition & 0 deletions src/Entity/DoofinderApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ public function setRange($filterName, $from = null, $to = null)
*/
public function toQuerystring($page = null)
{
$toParams = [];
foreach ($this->searchOptions as $paramName => $paramValue) {
if ($paramName == 'query') {
$toParams[$this->queryParameter] = $paramValue;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/DoofinderApiLanding.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public function searchOnApi($searchString, $module, $page = 1, $pageSize = 12, $

if ($hashid && $apiKey) {
$fail = false;
$df = new DoofinderApi($hashid, $apiKey, false, ['apiVersion' => '5']);
try {
$df = new DoofinderApi($hashid, $apiKey, false, ['apiVersion' => '5']);
$queryParams = [
'rpp' => $pageSize, // results per page
'timeout' => $timeout,
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/DoofinderConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function debug($message, $logFile = 'doofinder.log')
}

$debug = \Configuration::get('DF_DEBUG');
if (isset($debug) && $debug) {
if (!empty($debug) && $debug) {
error_log("$message\n", 3, _PS_MODULE_DIR_ . DIRECTORY_SEPARATOR . 'doofinder' . DIRECTORY_SEPARATOR . $logFile);
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public static function getConfigFormValuesStoreInfo()
*/
public static function checkOutsideConnection()
{
$client = new EasyREST(true, 3);
$client = new EasyREST(true);
$doomanangerRegionlessUrl = sprintf(DoofinderConstants::DOOMANAGER_REGION_URL, '');
$result = $client->get(sprintf('%s/auth/login', $doomanangerRegionlessUrl));

Expand Down
4 changes: 0 additions & 4 deletions src/Entity/FormManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ public function postProcess()
$formValues = array_merge($formValues, DoofinderConfig::getConfigFormValuesDataFeed());
$formUpdated = 'data_feed_tab';
}
if (((bool) \Tools::isSubmit('submitDoofinderModuleSearchLayer')) == true) {
$formValues = array_merge($formValues, DoofinderConfig::getConfigFormValuesSearchLayer());
$formUpdated = 'search_layer_tab';
}

if (((bool) \Tools::isSubmit('submitDoofinderModuleAdvanced')) == true) {
$formValues = array_merge($formValues, DoofinderConfig::getConfigFormValuesAdvanced());
Expand Down
2 changes: 1 addition & 1 deletion views/js/plugins/bootstrap.min.js

Large diffs are not rendered by default.

0 comments on commit 0924751

Please sign in to comment.