Post by Friend » Mon Mar 19, 2018 10:21 pm

Hello, friends!
I ask you for the help. My head is already boiling :(
I can not show statuses without "out of stock". Only all are shown.

What was done:
1. Added to controller category.php

Code: Select all

'quantity' => $result['quantity'], 'status_stock' => $result['stock_status'],
2. Added the appropriate phrase to the languages.
3. In the template I add a phrase( {{status_stock}} ) and frame it in product['quantity']>1.

With this option, the status of absence in the warehouse is not displayed on goods with less than one quantity, but is displayed where the amount is greater than zero. I think it is necessary to make so that "status_id = 3"(out of stock) was not displayed in the category. But how to do that? ???

Please excuse me for my bad English.

Newbie

Posts

Joined
Mon Mar 19, 2018 9:56 pm

Post by straightlight » Wed Mar 21, 2018 5:42 am

By remaining with the {{ stock }} variable in the category TWIG file, this could be done easily. In your catalog/controller/product/category.php file,

find:

Code: Select all

if ($result['quantity'] <= 0) {
replace with:

Code: Select all

if ((int)$result['quantity'] <= 0 || (float)$result['price'] <= 0) {
This should also verify if the price is lower or equal than 0.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Friend » Wed Mar 21, 2018 8:14 pm

straightlight, thanks for your help, but I do not have this line by default "if ($ result ['quantity'] <= 0) {" in category.php :( - maybe i need to add this code to some place?
You say that it will work when the product has a number of zero or equal, but I need to display all statuses only without "out of stock" when more and less than zero.

Newbie

Posts

Joined
Mon Mar 19, 2018 9:56 pm

Post by straightlight » Wed Mar 21, 2018 8:15 pm

No OC version provided.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Friend » Wed Mar 21, 2018 8:17 pm

OC 3.0.2.0

Newbie

Posts

Joined
Mon Mar 19, 2018 9:56 pm

Post by straightlight » Wed Mar 21, 2018 8:17 pm

Then, the provided line should be showing in that file.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Friend » Wed Mar 21, 2018 8:26 pm

straightlight, friend, i do not want to upset you, but there is no line like "if ($ result ['quantity'] <= 0) {" in the original version of opencart 3.0.2.0 in the file "catalog\controller\product\category.php". Therefore, i can not replace this line with your suggested "if ((int) $ result ['quantity'] <= 0 || (float) $ result ['price'] <= 0) {". :(

Newbie

Posts

Joined
Mon Mar 19, 2018 9:56 pm

Post by Friend » Wed Mar 21, 2018 11:21 pm

Need to disable showing this status in the category:
Image

Newbie

Posts

Joined
Mon Mar 19, 2018 9:56 pm

Post by Friend » Fri Mar 23, 2018 4:29 am

Friends, help please.

Newbie

Posts

Joined
Mon Mar 19, 2018 9:56 pm

Post by Wid » Fri Mar 23, 2018 4:45 pm

it is better to show this "out of stock" products, with a label out of stock for seo reason ex. this module.

a way to do it is by altering the file: catalog/controller/product/category.php
after line:165 foreach ($results as $result) {
add

Code: Select all

product_info = $this->model_catalog_product->getProduct($result['product_id']);
$stock_status_out_of_stock = $this->model_catalog_product->getStockStatusOutOfStock('Out Of Stock');
if (!($product_info['quantity'] <= 0 && in_array($product_info['stock_status'], $stock_status_out_of_stock))) {
...
}
line:212 before "$url = '';"
file: catalog/model/catalog/product.php
add this method

Code: Select all

public function getStockStatusOutOfStock($en_out_of_stock = 'Out Of Stock') {
	$sql = "SELECT `name` FROM `" . DB_PREFIX . "stock_status` WHERE stock_status_id = (SELECT DISTINCT `stock_status_id` FROM `" . DB_PREFIX . "stock_status` WHERE `name` = '" . $en_out_of_stock . "')" ;
			
	$stock_status_out_of_stock = array();

	$query = $this->db->query($sql);

	foreach ($query->rows as $row) {
		$stock_status_out_of_stock[] = $row['name'];
	}
	return $stock_status_out_of_stock;	
}

take a visit to My Modules !


Wid
New member

Posts

Joined
Fri Feb 02, 2018 9:19 pm
Location - Athens/Greece

Post by Wid » Fri Mar 23, 2018 4:56 pm

a better way is to change the metod public function getProducts($data = array())
from catalog/model/catalog/product.php
so as not to get out of stock products in result set
replace line 202

Code: Select all

foreach ($query->rows as $result) {
	$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}
with:

Code: Select all

$stock_status_out_of_stock = $this->getStockStatusOutOfStock('Out Of Stock');
foreach ($query->rows as $result) {	
	$product_info = $this->getProduct($result['product_id']);
	if (!($product_info['quantity'] <= 0 && in_array($product_info['stock_status'], $stock_status_out_of_stock))) {
		$product_data[$result['product_id']] = $product_info;
	}
}
you have to change, public function getTotalProducts($data = array()) so as to have correct pagination

in this way all actions will not show this products
category.php
search.php
compare.php

take a visit to My Modules !


Wid
New member

Posts

Joined
Fri Feb 02, 2018 9:19 pm
Location - Athens/Greece

Post by Friend » Sat Mar 24, 2018 12:21 am

Thanks, wid ;)
But do you have a way that can apply directly to the twig template? Example wrap into the code "{{status_stock}}" that will block the id status(out of stock)?

Newbie

Posts

Joined
Mon Mar 19, 2018 9:56 pm
Who is online

Users browsing this forum: Bing [Bot] and 29 guests