hide product quantity label when no stock

  • Posts: 101
  • Thank you received: 12
9 years 3 months ago #184736

-- HikaShop version -- : 2.3.4
-- Joomla version -- : 2.5.27

Hi,

How can I get the product quantity for the main product that has variants.
I'm in PRODUCT / SHOW_DEFAULT and I want to hide

<?php echo JText::_('PRODUCT_QUANTITY'); ?>

Otherwise you get the following on the site:

Quantity
No stock


I just want to show NO STOCK which resides in QUANTITY view if I'm not mistaken.

So I tried to use $this->row->product_quantity but this doesn't give the right quantity.
I think this has to do with the fact that the product has variants.

When I do var_dump($this->element->main) I can see the
object(stdClass)#831 (58) { ["product_id"]=> string(4) "4469" ["product_parent_id"]=> string(1) "0" ["product_name"]=> string(23) "Geschenkpapier RF12000F" ["product_description"]=> string(26) "Geschenkpapier test" ["product_quantity"]=> string(1) "0" ["product_code"]=> string(8) "RF12000F" ["product_published"]=> string(1) "1"

I just don't know how to access product_quantity.
When I try with $this->element->main->product_quantity my page isn't loaded well and the layout disapears so there seams to be an error.

So my question is:
How to get the product quantity of the main product so I can hide <?php echo JText::_('PRODUCT_QUANTITY'); ?> under <div id="hikashop_product_quantity_main" class="hikashop_product_quantity_main"> in the product view.

Thanks in advance

Last edit: 9 years 3 months ago by SG.

Please Log in or Create an account to join the conversation.

  • Posts: 101
  • Thank you received: 12
9 years 3 months ago #184785

Hi,

I apologize, it seems that $this->element->main->product_quantity DOES work.

My problem was that during testing I tried the following:

echo "prod quantity: $this->element->main->product_quantity";
With $this->element->main->product_quantity inside the double quotes.
And this gave a semi blank page and when I set the debug on maximum, I could see an error with:
object of class stdclass could not be converted to string

So when I changed the echo to:
echo "prod quantity: " . $this->element->main->product_quantity;

I did get a result for the product_quantity when it was from the product with variants.

So now I used the following test:
if (($this->element->main->product_quantity != 0 or $this->element->main->product_quantity == NULL) and ($this->row->product_quantity != 0)){
				echo JText::_('PRODUCT_QUANTITY'); 
           }

Is this the correct way of showing the Quantity Label?

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
9 years 3 months ago #184791

Hi,

Yes.
It's always best to keep the variable outside of the strings, like in any other language. Because when you deal with complex variables you need extra curly brackets to have the variables properly recognized by PHP in the strings. But if you leave them outside of the strings, you never get such problems.

Please Log in or Create an account to join the conversation.

  • Posts: 101
  • Thank you received: 12
9 years 3 months ago #184846

Thanks Nicolas for the tip.

Is the IF-structure correct? Or should I perform the test in a different way?

if (($this->element->main->product_quantity != 0 or $this->element->main->product_quantity == NULL) and ($this->row->product_quantity != 0)

Cheers

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
9 years 3 months ago #184853

Hello,
Using something like this will probably be better :

if (($this->element->main->product_quantity != 0 || $this->element->main->product_quantity == NULL) && ($this->row->product_quantity != 0)){
			
		}

Please Log in or Create an account to join the conversation.

  • Posts: 224
  • Thank you received: 26
  • Hikashop Business
1 year 11 months ago #341472

UPDATE FOR HIKASHOP v4.5.1

Display > Views > product / quantity
Around line 126 you will find this:

if(($add_to_cart || $add_to_wishlist) && $display_quantity_field)
Add one more condition "&& $in_stock", like this:
if(($add_to_cart || $add_to_wishlist) && $display_quantity_field && $in_stock)

Last edit: 1 year 11 months ago by oxido. Reason: code line correction
The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.085 seconds
Powered by Kunena Forum