Post by ianhaney50 » Mon Dec 16, 2024 1:31 am

I am trying to display the text out of stock if the product quantity is 0 or if there is stock quantity greater than 0 then to display the stock number and the words in stock after the number on the product page

I have the following so far but it's only partly working, it's outputting out of stock if the quantity is 0 and 24 if the product is in stock but not outputting in stock after the number

Code: Select all

{% if stock > 0 %}
<li class="stocknumber">{{ stock }}</li>
{% else %}
<li class="stocknumber">{{ stock }} in stock</li>
{% endif %}
I'm using 3.0.4.0
Last edited by ianhaney50 on Mon Dec 16, 2024 3:27 am, edited 1 time in total.

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by Cue4cheap » Mon Dec 16, 2024 3:17 am

ianhaney50 wrote:
Mon Dec 16, 2024 1:31 am
I am trying to display the text out of stock if the product quantity is 0 or if there is stock quantity greater than 0 then to display the stock number and the words in stock after the number on the product page

I have the following so far but it's only partly working, it's outputting out of stock if the quantity is 0 and 24 if the product is in stock but not outputting in stock after the number

Code: Select all

{% if stock > 0 %}
<li class="stocknumber">{{ stock }}</li>
{% else %}
<li class="stocknumber">{{ stock }} in stock</li>
{% endif %}
I'm using 3.0.4.0
So you have items in stock so "if stock > 0 " it'll put out this line: <li class="stocknumber">{{ stock }}</li>
I don't see your "out of stock" code.
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by ianhaney50 » Mon Dec 16, 2024 3:22 am

Cue4cheap wrote:
Mon Dec 16, 2024 3:17 am
ianhaney50 wrote:
Mon Dec 16, 2024 1:31 am
I am trying to display the text out of stock if the product quantity is 0 or if there is stock quantity greater than 0 then to display the stock number and the words in stock after the number on the product page

I have the following so far but it's only partly working, it's outputting out of stock if the quantity is 0 and 24 if the product is in stock but not outputting in stock after the number

Code: Select all

{% if stock > 0 %}
<li class="stocknumber">{{ stock }}</li>
{% else %}
<li class="stocknumber">{{ stock }} in stock</li>
{% endif %}
I'm using 3.0.4.0
So you have items in stock so "if stock > 0 " it'll put out this line: <li class="stocknumber">{{ stock }}</li>
I don't see your "out of stock" code.
Mike
Just managed to solve it with the following code

In catalog/controller/product/product.php, I added

Code: Select all

$data['quantity'] = $product_info['quantity'];

Code: Select all

'quantity'    => $result['quantity'],
In catalog/view/theme/electronic/template/product/product.twig, I added the following

Code: Select all

{% if quantity <= 0 %}
                                    <li class="stocknumber">Out of stock</li>
                                    {% else %}
                                    <li class="instocknumber">{{ stock }} in stock</li>
                                    {% endif %}

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am
Who is online

Users browsing this forum: No registered users and 17 guests