Skip to content
Merged
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
25 changes: 16 additions & 9 deletions ps_viewedproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ protected function getViewedProductIds()
$viewedProductsIds = array_diff($viewedProductsIds, [$this->currentProductId]);
}

$existingProducts = $this->getExistingProductsIds();
$viewedProductsIds = array_filter($viewedProductsIds, function ($entry) use ($existingProducts) {
return in_array($entry, $existingProducts);
$activeProducts = $this->getExistingProductsIds($viewedProductsIds);
$viewedProductsIds = array_filter($viewedProductsIds, function ($entry) use ($activeProducts) {
return in_array($entry, $activeProducts);
});

return array_slice($viewedProductsIds, 0, (int) (Configuration::get('PRODUCTS_VIEWED_NBR')));
Expand Down Expand Up @@ -321,18 +321,25 @@ protected function getViewedProducts()
}

/**
* @return array the list of active product ids
* @param array $productIds List of product IDs to check
*
* @return array the list of active product ids among those provided
*/
private function getExistingProductsIds()
private function getExistingProductsIds(array $productIds = [])
{
$existingProductsQuery = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS('
if (empty($productIds)) {
return [];
}

$activeProductsQuery = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS('
SELECT p.id_product
FROM ' . _DB_PREFIX_ . 'product p
WHERE p.active = 1'
FROM ' . _DB_PREFIX_ . 'product_shop p
WHERE p.active = 1
AND p.id_product IN (' . implode(',', array_map('intval', $productIds)) . ')' . Shop::addSqlRestriction(false, 'p')
);

return array_map(function ($entry) {
return $entry['id_product'];
}, $existingProductsQuery);
}, $activeProductsQuery);
}
}
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.1.2.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Call to method present\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter not found.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.2.5.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Call to method present\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter not found.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.3.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Call to method present\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter not found.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.4.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ parameters:
- '#Access to an undefined property Cookie::\$viewed.#'
- '#Call to method present\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter.#'
- '#Instantiated class PrestaShop\\PrestaShop\\Adapter\\Presenter\\Product\\ProductListingPresenter not found.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.5.1.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ includes:
parameters:
ignoreErrors:
- '#Access to an undefined property Cookie::\$viewed.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.6.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ includes:
parameters:
ignoreErrors:
- '#Access to an undefined property Cookie::\$viewed.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.7.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ includes:
parameters:
ignoreErrors:
- '#Access to an undefined property Cookie::\$viewed.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.8.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ includes:
parameters:
ignoreErrors:
- '#Access to an undefined property Cookie::\$viewed.#'
- '#Parameter \#1 \$share of static method ShopCore::addSqlRestriction\(\) expects int, false given.#'
Loading