Product listing

Overrides allow you to change the foundation of your site.
Post Reply
Vaddalapam
Member
Posts: 76
Joined: Sat Feb 03, 2024 6:34 pm
Phoenix Version: v1.1.0.7
Has thanked: 20 times
Been thanked: 3 times

Product listing

Post by Vaddalapam »

Hello, Items with a stock level of "0" should be moved to the end of the list, regardless of the selected sorting option; this works in `product_listing.php`. The items in the screenshot are sorted by highest price, but the most expensive ones appear at the end of the list—which is exactly what I want. Is there a way to achieve this without modifying the core? I used a translator today to make myself understood—Vadda. :D
2.PNG
1.PNG
You do not have the required permissions to view the files attached to this post.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4546
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Product listing

Post by burt »

TY for translating @Vaddalapam.

You want all products with zero stock to be at the end of the "sorting" because you want to have your "can buy this now" products at the top of the list.

Your code works, but you have changed core code.

That is OK, no one says (and no one has ever said) you cannot change core code - this is an ongoing debate at the moment in another thread 8-) :!: :D

--

I can think of TWO ways in which this can be achieved without changing core.
I will show both and let you know which I prefer;

1. Override the file.
/templates/default/includes/components/product_listing.php
copy it to:
/templates/YOUR_LIVE_TEMPLATE/includes/components/product_listing.php

Now UNDO those changes in the core file.

You have what you need, and have not changed core code.
You have added one extra file into your template.

Upside:
No core code changes.

Downside:
If you change your template...you lose your `zero sort`, unless you override the same file into your new template.

2. A hook

Hooks are a way to change functionality with touching Core. Product Listings are hooked.

You can take your code, and plug it into a Hook at /includes/hooks/shop/filter/.
Your Hook targets the correct listen_filterStart (that is already in core). Your listings are now as you want them.

Upside:
No core code changes.
Persists across all templates, so even if you change a template, the `zero sort` will still work.

Downside
Need to understand hooks.

--

For you today, try overriding the file into your template, then undoing the changes in the original file.

However the Hook way is, I think, preferable. You could have a go at that, if you wanted. Plug this post into your preferred AI (and it might have enough info to actually make you the correct hook)...

If it does not, and you do want to see the Hook way, post back and I can find time to make it. Will be in the Co-op.
Vaddalapam
Member
Posts: 76
Joined: Sat Feb 03, 2024 6:34 pm
Phoenix Version: v1.1.0.7
Has thanked: 20 times
Been thanked: 3 times

Re: Product listing

Post by Vaddalapam »

Thank you @burt , i used option 1 because i'm far away from understanding hooks.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply