Post by ianhaney50 » Mon Aug 05, 2024 6:13 pm

Hi

I am trying to get the latest module to hide of stock products, I found similar code that works on opencart 1.5 but not on opencart 2.3. The forum post I found is at viewtopic.php?t=147258#p569210

I thought it did work last night but visited the site this morning and is a empty place where a out of stock product would be

I'm wondering if I should increase the number 6 to 7 on this line

Code: Select all

if ($count == 6) break;
or does anywhere have some better code to try please

New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by xxvirusxx » Tue Aug 06, 2024 1:38 am

You can add quantity in controller and here

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);

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by ianhaney50 » Tue Aug 06, 2024 2:11 am

xxvirusxx wrote:
Tue Aug 06, 2024 1:38 am
You can add quantity in controller and here

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);
I have added

Code: Select all

AND p.quantity > 0
after

Code: Select all

p.status = '1'
in catalog/model/catalog/product.php and also modified the code in catalog/controller/extension/module/latest.php so it looks like the following

Code: Select all

$filter_data = array(
            'sort'  => 'p.date_added',
            'order' => 'DESC',
            'start' => 0,
            //'limit' => $setting['limit']
            'limit' => 20,
        );

        $count = 0;
        $results = $this->model_catalog_product->getProducts($filter_data);

        if ($results) {
            foreach ($results as $result) {
                if ($count == 8) break;
                $count++;
                if ($result['quantity'] < 0) { $count--; continue; }
It has not worked I don't think as it's showing out of stock products on the latest module and also it's showing two empty spaces on the most popular module as well on the homepage

I have attached two screenshots of the latest module and most popular module on the homepage

Attachments

most-popular-module-out-of-stock-products-issue.jpg

most-popular-module-out-of-stock-products-issue.jpg (297.53 KiB) Viewed 814 times

latest-module-out-of-stock-products-issue.jpg

latest-module-out-of-stock-products-issue.jpg (387.97 KiB) Viewed 814 times


New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ADD Creative » Tue Aug 06, 2024 4:18 pm

Check your storage/modification directory in case you have extensions that are also modifying the files.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ianhaney50 » Tue Aug 06, 2024 5:47 pm

ADD Creative wrote:
Tue Aug 06, 2024 4:18 pm
Check your storage/modification directory in case you have extensions that are also modifying the files.
I just checked the storage/modification folder and is no extensions modifying the files

New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ADD Creative » Tue Aug 06, 2024 7:28 pm

If you modified the getLatestProducts query in catalog/model/catalog/product.php. You will need to make this change as 2.3.0.2 is still using the slower getProducts method.
https://github.com/opencart/opencart/pull/8178

If changing the database query and the above then shouldn't need the changes from the other forum post.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ianhaney50 » Tue Aug 06, 2024 8:34 pm

ADD Creative wrote:
Tue Aug 06, 2024 7:28 pm
If you modified the getLatestProducts query in catalog/model/catalog/product.php. You will need to make this change as 2.3.0.2 is still using the slower getProducts method.
https://github.com/opencart/opencart/pull/8178

If changing the database query and the above then shouldn't need the changes from the other forum post.
I have not modified the getLatestProducts query in catalog/model/catalog/product.php

New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ADD Creative » Tue Aug 06, 2024 9:58 pm

ianhaney50 wrote:
Tue Aug 06, 2024 8:34 pm
I have not modified the getLatestProducts query in catalog/model/catalog/product.php
If you did want to modify it, it's probably the simplest way.

Revert your changes. Make the change at https://github.com/opencart/opencart/pull/8178

Then in catalog/model/catalog/product.php chage.

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

$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.quantity > '0' 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);
You may also need to clear the files in storage/cache.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ianhaney50 » Tue Aug 06, 2024 10:35 pm

ADD Creative wrote:
Tue Aug 06, 2024 9:58 pm
ianhaney50 wrote:
Tue Aug 06, 2024 8:34 pm
I have not modified the getLatestProducts query in catalog/model/catalog/product.php
If you did want to modify it, it's probably the simplest way.

Revert your changes. Make the change at https://github.com/opencart/opencart/pull/8178

Then in catalog/model/catalog/product.php chage.

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

$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.quantity > '0' 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);
You may also need to clear the files in storage/cache.
I tried the code

Code: Select all

AND p.quantity > '0'
but don't work, on the category page it replaces the products with zero quantity with empty products that have no id numbers and no names

New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by paulfeakins » Tue Aug 06, 2024 10:41 pm

ianhaney50 wrote:
Mon Aug 05, 2024 6:13 pm
I'm wondering if I should increase the number 6 to 7 on this line

Code: Select all

if ($count == 6) break;
or does anywhere have some better code to try please
Looks like you're poking around with random bits of code, guessing what it does. This bit seems related to creating rows of 6 products, not their stock levels.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by ADD Creative » Wed Aug 07, 2024 4:15 pm

ianhaney50 wrote:
Tue Aug 06, 2024 10:35 pm
I tried the code

Code: Select all

AND p.quantity > '0'
but don't work, on the category page it replaces the products with zero quantity with empty products that have no id numbers and no names
It should not affect the category page at all. Just tested and changes worked fine. Your are can't be making the correct changes. Sounds like you have added to the wrong query.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ianhaney50 » Wed Aug 07, 2024 5:28 pm

ADD Creative wrote:
Wed Aug 07, 2024 4:15 pm
ianhaney50 wrote:
Tue Aug 06, 2024 10:35 pm
I tried the code

Code: Select all

AND p.quantity > '0'
but don't work, on the category page it replaces the products with zero quantity with empty products that have no id numbers and no names
It should not affect the category page at all. Just tested and changes worked fine. Your are can't be making the correct changes. Sounds like you have added to the wrong query.
I added it to all the queries that had

Code: Select all

p.status = '1'

New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ianhaney50 » Thu Aug 08, 2024 12:40 am

I have just managed to sort the issue on the latest module on the homepage and looks to be working all ok.

Just need to now hide the out of stock products on the category page, what coding would I need to use to hide the out of stock products that have zero quantity on the category page in opencart 2.3.0.2 please

New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ianhaney50 » Thu Aug 08, 2024 1:45 am

Think I just found a way to do it, I have modified the code on catalog/view/theme/default/template/product/category.tpl

After

Code: Select all

<?php foreach ($products as $product) { ?>
I added the following line

Code: Select all

<?php if ($product['quantity'] < "1") { ?>
                <div style="display: none;"></div>
                <?php } else { ?>
After the closing div for

Code: Select all

<div class="product-layout product-list col-xs-12">
I added the following line of code

Code: Select all

<?php } ?>
It looks to have worked and it's hidden the out of stock products on the category page

New member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by paulfeakins » Thu Aug 08, 2024 10:23 pm

ianhaney50 wrote:
Thu Aug 08, 2024 1:45 am
Think I just found a way to do it
You have found "a way" but that is what is known as a "hack".

You should prevent them being returned from the query, but if you can't do that, at least don't output them at all rather than wrap them in a div with a style that hides them.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by xxvirusxx » Sun Aug 11, 2024 4:24 pm

ianhaney50 wrote:
Thu Aug 08, 2024 12:40 am
Just need to now hide the out of stock products on the category page, what coding would I need to use to hide the out of stock products that have zero quantity on the category page in opencart 2.3.0.2 please
lol

from

Code: Select all

$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";
to

Code: Select all

$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.quantity > 0 AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";
LE. Compare my model with your model

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România
Who is online

Users browsing this forum: Google [Bot] and 4 guests