Jump to content

Hide out of stock products on prices-drop page only


maelstrom06

Recommended Posts

Hello, I'm using Prestashop 1.7 and I edited the file PricesDropController.php to change the order of the product list (I wanted to use "date_add").

Now I'm trying to hide out of stock products from this page but I can't find any info and I searched a lot in the code without any result.

Is there a way to do that? I don't want to hide all the out of stock products from the entire shop, only on prices drop page. Is that possible?

Thank you.

Link to comment
Share on other sites

If you are using prestashop classic theme you can do it like this:

Open file YOUR_STORE_NAME/themes/classic/templates/catalog/_partials/productlist.tpl

Change this:

<div class="products{if !empty($cssClass)} {$cssClass}{/if}" itemscope itemtype="http://schema.org/ItemList">
    {foreach from=$products item="product" key="position"}
        {include file="catalog/_partials/miniatures/product.tpl" product=$product position=$position}
    {/foreach}
</div>

To this:

<div class="products{if !empty($cssClass)} {$cssClass}{/if}" itemscope itemtype="http://schema.org/ItemList">
    {foreach from=$products item="product" key="position"}
        {if $product.quantity > 0 && $page.page_name == "prices-drop"} {* crezzur.com: add check if product has quantity, if not do not display product *}
            {include file="catalog/_partials/miniatures/product.tpl" product=$product position=$position}
        {else}
            {include file="catalog/_partials/miniatures/product.tpl" product=$product position=$position}
        {/if}
    {/foreach}
</div>

 

Now only products with stock will be displayed.

Edited by Crezzur (see edit history)
Link to comment
Share on other sites

18 minutes ago, Crezzur said:

If you are using prestashop classic theme you can do it like this:

Open file YOUR_STORE_NAME/themes/classic/templates/catalog/_partials/productlist.tpl

Change this:

<div class="products{if !empty($cssClass)} {$cssClass}{/if}" itemscope itemtype="http://schema.org/ItemList">
    {foreach from=$products item="product" key="position"}
        {include file="catalog/_partials/miniatures/product.tpl" product=$product position=$position}
    {/foreach}
</div>

To this:

<div class="products{if !empty($cssClass)} {$cssClass}{/if}" itemscope itemtype="http://schema.org/ItemList">
    {foreach from=$products item="product" key="position"}
        {if $product.quantity > 0 && $page.page_name == "prices-drop"} {* crezzur.com: add check if product has quantity, if not do not display product *}
            {include file="catalog/_partials/miniatures/product.tpl" product=$product position=$position}
        {/if}
    {/foreach}
</div>

 

Now only products with stock will be displayed.

Thank you @Crezzur. I'm using a commercial theme with a lot of custom code.

Your code has some problems, it breaks other listing pages (categories, new products, etc.) because that condition will not be met, generating empty list pages. It is easy to fix, but the main problem is that this is a change in the interface and does not take into account the SQL query, resulting in the wrong number of products per page and pagination.

I think I need to change the main query for prices-drop to make it work.
Thanks anyway :)

Link to comment
Share on other sites

Just now, Crezzur said:

I have updated my code, now it only works when on the "prices-drop" page.

Thanks, but like I said in my previous reply, that code hide the products out of stock but doesn't fix the number of products shown per page and make the pagination wrong.

Example:

Total of products = 24
Products per page = 10
Number of pages = 3 (10, 10, 4)
Products out of stock = 5

If there are 3 products out of stock on the first page, that page will only show 7 products instead of 10.
And if there are 4 out of stock products on the last page, this page will be empty.

I have a lot of products in price-drop page and I can't do that, it will be a mess for the users :S

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...