What's New
Tagged: hide not available products
- AuthorPosts
Hi,
how can I change the new products slider, special products slider and so on so, that the sliders don’t display the products with quantity equal 0?I made this for products pages but don’t now how I can make this for sliders.
The solution for product pages is this:
Changes on modules faceted navigation v2.1.2:
Change the file /modules/ps_facetedsearch/ps_facetedsearch.php
(added the bold writing lines):on the line 1628:
WHERE ‘ . $alias_where . ‘.
active
= 1 AND ‘ . $alias_where . ‘.visibility
IN (“both”, “catalog”)
AND (stock.quantity > 0 OR p.quantity > 0)
ORDER BY ‘ . $order_clause . ‘ , cp.id_product’ .
‘ LIMIT ‘ . (((int)$page – 1) * $products_per_page . ‘,’ . $products_per_page));on the line 1657:
WHERE ‘ . $alias_where . ‘.
active
= 1 AND ‘ . $alias_where . ‘.visibility
IN (“both”, “catalog”)
AND (stock.quantity > 0 OR p.quantity > 0)
GROUP BY product_shop.id_product
ORDER BY ‘ . $order_clause . ‘ , cp.id_product’ .
‘ LIMIT ‘ . (((int)$page – 1) * $products_per_page . ‘,’ . $products_per_page));On the file /classes/Category.php :
WHERE product_shop.
id_shop
= ‘.(int) $context->shop->id.’
AND (stock.quantity > 0 OR p.quantity > 0)
AND cp.id_category
= ‘.(int) $this->id
.($active ? ‘ AND product_shop.active
= 1′ : ”)
.($front ? ‘ AND product_shop.visibility
IN (“both”, “catalog”)’ : ”)
.($idSupplier ? ‘ AND p.id_supplier = ‘.(int)$idSupplier : ”);Now the question how can I change the
– Special Products Slider
– New Products Slider
– Top sellers Slider
– Product Slider
so that they don’t displays the products with quantity equal 0?Best regards, Viaceslav.
Hi,
Please modify the following files:
\modules\sthomenew\sthomenew.php
\modules\stspecialslider\stspecialslider.php
\modules\stbestsellers\stbestsellers.php
Add the following code to the function getProducts, see attached screenshot:$pro = new Product($rawProduct['id_product']); if ($pro->quantity <= 0) { continue; }
And modify the file: \modules\stproductcategoriesslider\stproductcategoriesslider.php, add the following code to the function _prepareHook:
$pro = new Product($product['id_product']); if ($pro->quantity <= 0) { continue; }
, see attached screenshot.
Best regards.Attachments:
Hi,
don’t work.
I tested your fix on the new products slider.
I have copied and paste the code.
Here is the new code lines:
if (is_array($newProducts)) {
$pro = new Product($rawProduct[‘id_product’]);
if ($pro->quantity <= 0) {
continue;
}
foreach ($newProducts as $rawProduct) {
$products_for_template[] = $presenter->present(
$presentationSettings,
$assembler->assembleProduct($rawProduct),
$this->context->language
);
}
}
But will be loaded the white empty page with error HTTP 500.
I have cleaned the smarty cache and browser cache and delete the /app/cache/prod directory.
Nothing help.Best regards, Viaceslav.
Hi,
So sorry the correct code as following:if (is_array($newProducts)) { foreach ($newProducts as $rawProduct) { $pro = new Product($rawProduct[‘id_product’]); if ($pro->quantity <= 0) { continue; } $products_for_template[] = $presenter->present( $presentationSettings, $assembler->assembleProduct($rawProduct), $this->context->language ); } }
Best regards.
Hi,
it also don’t work.
After this fix the new products slider say: no items.
Here is the new code:
$products_for_template = array();
if (is_array($newProducts)) {
foreach ($newProducts as $rawProduct) {
$pro = new Product($rawProduct[‘id_product’]);
if ($pro->quantity <= 0) {
continue;
}
$products_for_template[] = $presenter->present(
$presentationSettings,
$assembler->assembleProduct($rawProduct),
$this->context->language
);
}
}And if I click “New Products” on slider will be load the page with products, including “Out of stock” products.
Please see attachments.Attachments:
Hi,
Sorry, the correct code as following:if (is_array($newProducts)) { foreach ($newProducts as $rawProduct) { if ($pro->quantity <= 0) { continue; } $products_for_template[] = $presenter->present( $presentationSettings, $assembler->assembleProduct($rawProduct), $this->context->language ); } }
Best regards.
Hi,
Its work, thank you for support.
I was on vacation and as I back home, I discovered that there is one more problem with products with quantity equal 0: the search results still displays the out of stocks products (quantity = 0).Is it possible that you fix also this problem?
I can not find what file at what line and how I must change.
Best regards, Viaceslav.
Hi,
I made this but without success: the products with quantity = or < 0 are displaying on search results.
I deleted the cache and Re-build the entire index – nothing help.
Please see the attachments.Best regards, Viaceslav.
P.S. The searched word was Лермонтов
You can copy and paste this word for tests.Attachments:
Hi,
sorry but now I discovered that this these corrections introduced a side effect in the output of the search results.
Before making the corrections the search produced search results with pagination.
Making the last corrections offered by you above, fix the problem with output of only those products that have the quantity of more than 0,
but leads to the fact that the breakdown of the search results into pages disappears and only one page with the first 40 products appears.I tried to upload again back to the site the original yet unmodified PS 1.7.2.4 file /classes/Search.php and splitting the search results into pages again worked fine.
Can you please check what is wrong, to achieve that the search worked completely correctly?
Best regards, Viaceslav
Attachments:
- AuthorPosts
You must be logged in to reply to this topic.