VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Kuubs on November 12, 2020, 09:46:23 AM

Title: Out of stock, not showing products, show message
Post by: Kuubs on November 12, 2020, 09:46:23 AM
Hello,

I have a problem I cannot seem to fix. I have a couple of products which are out of stock, I configured Virtuemart to not show these products in the configuration tab. But now the page is just empty. I'd like to show a message that there are currently no products in stock.

But the products array is still populated, so I cannot use the normal template style in showing a message. Does anyone know how to tackle this problem?
Title: Re: Out of stock, not showing products, show message
Post by: Jörgen on November 12, 2020, 09:51:34 AM
This is very likely a template issue. Test with Protostar.
Jörgen
Title: Re: Out of stock, not showing products, show message
Post by: Kuubs on November 12, 2020, 15:29:04 PM
Quote from: Jörgen on November 12, 2020, 09:51:34 AM
This is very likely a template issue. Test with Protostar.
Jörgen

It's not, i tested it with protostar. In the backend you can set the products to not be shown when the stock is empty.
Title: Re: Out of stock, not showing products, show message
Post by: pinochico on November 12, 2020, 15:37:04 PM
QuoteIn the backend you can set the products to not be shown when the stock is empty.

Where?
Title: Re: Out of stock, not showing products, show message
Post by: Jörgen on November 12, 2020, 16:03:52 PM
Then I would look and see how it is handled in the view file.

Jörgen
Title: Re: Out of stock, not showing products, show message
Post by: Kuubs on November 13, 2020, 09:03:10 AM
Quote from: Jörgen on November 12, 2020, 16:03:52 PM
Then I would look and see how it is handled in the view file.

Jörgen

Yes I have selected the second option. But the $this->products array is still full of the products. I think it checks at a later stage whether or not to show the product?

Is there some sort of clean and effective option to display the message without looping through all the products to check their stock?
Title: Re: Out of stock, not showing products, show message
Post by: GJC Web Design on November 13, 2020, 10:28:21 AM
where is $this->products populated even though all are out of stock?  at the template/view?
Title: Re: Out of stock, not showing products, show message
Post by: Kuubs on November 14, 2020, 09:14:50 AM
Quote from: GJC Web Design on November 13, 2020, 10:28:21 AM
where is $this->products populated even though all are out of stock?  at the template/view?

Nope, it only checks if the products array is empty, and if not it displays the products.

This seems Virtuemart behaviour
Title: Re: Out of stock, not showing products, show message
Post by: pinochico on November 14, 2020, 10:28:53 AM
Nope, it only checks if the products array is empty, and if not it displays the products.


Your products array is not empty, you have assigned 2 keys without value.

Array ( [featured] => Array ( ) [products] => Array ( ) )

Then you must use right check in PHP for $this->products:
https://www.google.com/search?client=safari&rls=en&q=php+array+empty&ie=UTF-8&oe=UTF-8


https://joomla3.easy.minion.cz/eshop-virtuemart/headpiece -> NO PRODUCTS IN STOCK FOR HUUBS


If you need show message between different category without products and category without products in stock, you must hack model product and add error message in model where is check for stockhandle
Title: Re: Out of stock, not showing products, show message
Post by: Kuubs on November 14, 2020, 13:33:24 PM
Quote from: pinochico on November 14, 2020, 10:28:53 AM
Nope, it only checks if the products array is empty, and if not it displays the products.


Your products array is not empty, you have assigned 2 keys without value.

Array ( [featured] => Array ( ) [products] => Array ( ) )

Then you must use right check in PHP for $this->products:
https://www.google.com/search?client=safari&rls=en&q=php+array+empty&ie=UTF-8&oe=UTF-8


https://joomla3.easy.minion.cz/eshop-virtuemart/headpiece -> NO PRODUCTS IN STOCK FOR HUUBS


If you need show message between different category without products and category without products in stock, you must hack model product and add error message in model where is check for stockhandle

Ooh, i see i use the third option (can't order show the inform me button)

So that is intended behaviour. I check at the products sublayout if the product is in stock, and if not it skips the product. I am gonna add a variable that if nothing shows there it will display the message. Sorry for the confusion guys.

Code:



$productShow = false;
....

if($product->product_in_stock - $product->product_ordered < 1){
continue;
}
$productShow=true;
.....

if(!$productShow){
  echo 'No Products avaialble';
  }


Title: Re: Out of stock, not showing products, show message
Post by: pinochico on November 14, 2020, 18:28:11 PM
Now you know - if I ask you, then answer me.
Or send all information on start - You will not waste my time and yours

The only text question is not enough.

But great Congratulations


Hmmm, but for child products is other option for ordered... I think