Post by OCCL » Thu Apr 20, 2023 4:21 am

Hello there,
I need to let the 0 stock products or the out of stock products to be hidden,
I tried what the other threads said, but with no luck. extensions did not help as well.
using OC 3, with the Devman opt. comb. extension
Last edited by OCCL on Wed Apr 26, 2023 7:38 pm, edited 1 time in total.

New member

Posts

Joined
Sat Feb 26, 2022 3:09 pm

Post by straightlight » Thu Apr 20, 2023 7:58 am


Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by OCCL » Thu Apr 20, 2023 5:04 pm

Thank you for your reply, I tried what that thread said, it disabled the products but I still can see them on the website (when I click on it, it says product is unavailbe but its still there)
As for the extensions, do you have any recommendations? have you tried any of them?

Thank you.

New member

Posts

Joined
Sat Feb 26, 2022 3:09 pm

Post by by mona » Thu Apr 20, 2023 5:22 pm

If you disable a product it is not available for view in the front end.
Zero quantity (out of stock) and disable are not the same things.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by OCCL » Thu Apr 20, 2023 5:32 pm

by mona wrote:
Thu Apr 20, 2023 5:22 pm
If you disable a product it is not available for view in the front end.
Zero quantity (out of stock) and disable are not the same things.
Thank you for your reply.
The thing I did from that thread, kept the product in the front end, but when I click on it it says product not found,
I need to hide it from the front end in the first place. (I dont't want people to see a product, click on it and it shows an empty page)

New member

Posts

Joined
Sat Feb 26, 2022 3:09 pm

Post by by mona » Thu Apr 20, 2023 9:22 pm

You do not use an extension if you just intend to disable a product. If it is disabled in admin, then it does not appear by default in the front end. If you have an extension that effects that behaviour you just need to disable the extension. Products which are disabled have no link to click, if there is, that means that it is in extension that is effecting the behaviour. or you have caching which is old data still showing (the link) but the product is not actually there. For that you will have to refresh all cache.

If, as your title post suggests you want to hide products that are with a quantity of zero without disabling the product, as I said, that is different.
An example of an easy way to do that :

config.php:
add:

Code: Select all

// switch to hide or show products with zero stock
define('HIDE_ZERO_STOCK', true);
catalog/model/catalog/product.php in functions getProducts(...) and getTotalProducts(...)
before:

Code: Select all

if (!empty($data['filter_manufacturer_id'])) {
add:

Code: Select all

if (HIDE_ZERO_STOCK) {
$sql .= " AND p.quantity > 0 ";
}

for a module like latest products you would have to split the query in function getLatestProducts(...)
from:

Code: Select all

$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit);
to:

Code: Select all

$sql = "SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1'";
if (HIDE_ZERO_STOCK) $sql .= " AND p.quantity > 0 ";
$sql .= " AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit;
$query = $this->db->query($sql);
Same principle for bestsellers and popular products, just add the p.quantity > 0 condition if set by the switch.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by OCCL » Tue Apr 25, 2023 5:32 pm

by mona wrote:
Thu Apr 20, 2023 9:22 pm
You do not use an extension if you just intend to disable a product. If it is disabled in admin, then it does not appear by default in the front end. If you have an extension that effects that behaviour you just need to disable the extension. Products which are disabled have no link to click, if there is, that means that it is in extension that is effecting the behaviour. or you have caching which is old data still showing (the link) but the product is not actually there. For that you will have to refresh all cache.

If, as your title post suggests you want to hide products that are with a quantity of zero without disabling the product, as I said, that is different.
An example of an easy way to do that :

config.php:
add:

Code: Select all

// switch to hide or show products with zero stock
define('HIDE_ZERO_STOCK', true);
catalog/model/catalog/product.php in functions getProducts(...) and getTotalProducts(...)
before:

Code: Select all

if (!empty($data['filter_manufacturer_id'])) {
add:

Code: Select all

if (HIDE_ZERO_STOCK) {
$sql .= " AND p.quantity > 0 ";
}

for a module like latest products you would have to split the query in function getLatestProducts(...)
from:

Code: Select all

$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit);
to:

Code: Select all

$sql = "SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1'";
if (HIDE_ZERO_STOCK) $sql .= " AND p.quantity > 0 ";
$sql .= " AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit;
$query = $this->db->query($sql);
Same principle for bestsellers and popular products, just add the p.quantity > 0 condition if set by the switch.
Thank you for your reply,
I tried your solution on a vanila OC I have on a localhost, it worked fine,
but when I tried it on my OC site it didnt work, I cleared chache and made sure no other extensions were enabled. I can still see those out of stock products.
I also see them in my search results page and in catagory page, I dont know if that woudl require other steps.

New member

Posts

Joined
Sat Feb 26, 2022 3:09 pm

Post by straightlight » Wed Apr 26, 2023 12:43 am

Not sure why a constant key has been created in this example, since alias names can also be used while using an SQL query...

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by OCCL » Wed Apr 26, 2023 1:46 pm

straightlight wrote:
Wed Apr 26, 2023 12:43 am
Not sure why a constant key has been created in this example, since alias names can also be used while using an SQL query...
Thank you for your reply,
Can you please advise?
Thanks.

New member

Posts

Joined
Sat Feb 26, 2022 3:09 pm

Post by pprmkr » Wed Apr 26, 2023 2:58 pm

Out of stock products with notice 'Out of stock' and add to cart button disabled ? The notice is whatever 'Out Of Stock Status' is set.
Demo PprMkr Soldcorners for OC 4.0.2.1
Image
When 'Hide product' is enabled, product is invisible for visitor.

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by OCCL » Wed Apr 26, 2023 3:15 pm

pprmkr wrote:
Wed Apr 26, 2023 2:58 pm
Out of stock products with notice 'Out of stock' and add to cart button disabled ? The notice is whatever 'Out Of Stock Status' is set.
Demo PprMkr Soldcorners for OC 4.0.2.1
Image
When 'Hide product' is enabled, product is invisible for visitor.
That looks really great,
where can I find that?

New member

Posts

Joined
Sat Feb 26, 2022 3:09 pm

Post by pprmkr » Wed Apr 26, 2023 3:27 pm

It is an experiment for latest version 4.0.2.1.
I try to understand and use events to replace the ocMods created for OC 3.*

SoldCorners for OC 3.0.2.* and 3.0.3.* has no 'Hide' option. It is 1 ocMod.xml file with stylesheet and image.
Demo for 3.0.2.0 version

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by OCCL » Wed Apr 26, 2023 7:09 pm

Found this extension and it worked perfectly.
Great support as well.

https://www.opencart.com/index.php?rout ... n_id=39066

New member

Posts

Joined
Sat Feb 26, 2022 3:09 pm
Who is online

Users browsing this forum: No registered users and 103 guests