Page 1 of 1
Hiding out of stock items on latest module [solved]
Posted: Mon Jul 06, 2015 11:07 am
by Redcomet
Hello,
I am trying to customize latest.php to make out of stock items hidden.
I have added the following line
Code: Select all
if ($result['quantity'] <= 0) { continue; }
under
Now this code does its job but the issue is when I have lets say 6 products enabled on the latest module (based on $data['limit']), only 5 show up.
Code: Select all
$data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit']
);
My thought was to somehow increment the foreach loop when quantity = 0 but every time I try, I get a syntax error.
How can I play around with latest.php to make sure 6 products show even when one is out of stock?
Thanks
Re: Hiding out of stock items on latest module
Posted: Tue Jul 07, 2015 12:47 pm
by Redcomet
I have figured it out for all those who are wondering how to skip out of stock items without losing a blank space.
I used a simple counter system with a break function. Here is the code I used
Code: Select all
$data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => 20,
);
$count = 0;
$results = $this->model_catalog_product->getProducts($data);
foreach ($results as $result) {
if ($count == 6) break;
$count++;
if ($result['quantity'] <= 0) { $count--; continue; }
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
If you want to customize it to the amount of items you want displayed for your front page, simply change
to your desired numbered.
Hope that helps everyone out there!
Re: Hiding out of stock items on latest module [solved]
Posted: Mon Aug 05, 2024 6:08 pm
by ianhaney50
Hi
I have tried this code for the latest module on the homepage and it's still showing a empty space for a out of stock product. I'm using opencart 2.3.0.2.
Should I increase the number 6 to 7 on this line
Re: Hiding out of stock items on latest module [solved]
Posted: Mon Aug 05, 2024 7:32 pm
by ADD Creative
ianhaney50 wrote: ↑Mon Aug 05, 2024 6:08 pm
Hi
I have tried this code for the latest module on the homepage and it's still showing a empty space for a out of stock product. I'm using opencart 2.3.0.2.
Should I increase the number 6 to 7 on this line
That would depend on what the module limit is set to.
Re: Hiding out of stock items on latest module [solved]
Posted: Mon Aug 05, 2024 8:10 pm
by ianhaney50
ADD Creative wrote: ↑Mon Aug 05, 2024 7:32 pm
ianhaney50 wrote: ↑Mon Aug 05, 2024 6:08 pm
Hi
I have tried this code for the latest module on the homepage and it's still showing a empty space for a out of stock product. I'm using opencart 2.3.0.2.
Should I increase the number 6 to 7 on this line
That would depend on what the module limit is set to.
It's set to 9
Re: Hiding out of stock items on latest module [solved]
Posted: Tue Aug 06, 2024 1:12 am
by ADD Creative
ianhaney50 wrote: ↑Mon Aug 05, 2024 8:10 pm
It's set to 9
Should probably check count == 9.