Post by romerz » Thu Mar 29, 2012 7:16 pm

I've trawled through loads of different threads reading about all sorts of different stock control requests and different things. I was recently looking to display the stock available on each of my product options, figured out a fairly simple way and thought I would share it on here - as I've used loads of things from the rest of the community.

Please note that is by no means the best method of how to do this, but it works for me.

In controller/product/product.php

On around line 246 find

Code: Select all

'name' => $option_value['name'],
and add below

Code: Select all

'quantity' => $option_value['quantity'],
In view/theme/themename/template/product/product.tpl


(I use Radio boxes to select my option, but this will work with any method)
On around line 94 find

Code: Select all

<b><?php echo $option['name']; ?>:</b><br />
<?php foreach ($option['option_value'] as $option_value) { ?>
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
<label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</label>
On the last line, you want to make it say the following

Code: Select all

<?php echo $option_value['quantity']; ?></label>
This will then display the quantity that item has in stock next to the option. You can then set it for example to only display when subtrack stock is set to yes, or add a div and give it its own style etc. There are plenty of things that can be done with this.

(What I've done for example is set it so show in Red when the stock is less than 5, and Green when the stock is more than 5)

I'm sorry my 'fix' isn't as slick as others offered, but hopefully this helps someone out at some point.

Newbie

Posts

Joined
Wed Feb 16, 2011 11:56 pm

Post by rishi » Sat Mar 31, 2012 6:48 pm

Thanks for sharing. It is really useful.

User avatar
New member

Posts

Joined
Mon May 17, 2010 5:34 am

Post by plexone » Thu Nov 01, 2012 8:19 am

quicks a treat but only in radio mode, any idea how to get it to work in image mode, as i need to display colour pictures for the items on the store

thanks

plex

Newbie

Posts

Joined
Thu Nov 01, 2012 8:16 am

Post by slimx » Tue Jul 30, 2013 10:01 pm

Hey guys, sorry revive an old thread but im stuck i've been trying to get this thing to work on 1.5.5.1 any help would be appreciated (im willing to PAY for help). (paypal)

Newbie

Posts

Joined
Fri Dec 02, 2011 8:14 am

Post by flanders » Wed Jul 31, 2013 1:28 am

Hi,

If you need this function I developed this extension:

http://www.opencart.com/index.php?route ... n_id=11877

or this with update price automatically

http://www.opencart.com/index.php?route ... n_id=11891

Regards

Color Size Table - A table for Colors and Sizes
Super Options - Options with quantities and calculate the upgrade total price automatically
Live New Price with Options - Update price product selecting options
Custom Plus Options - My Extensions


User avatar
Active Member

Posts

Joined
Sun Jun 03, 2012 11:01 pm
Location - Italy

Post by slimx » Wed Jul 31, 2013 7:29 am

Thank you, i'll be purchasing that now :) - Might need your support though, the theme im working on is just shocking lol.

Newbie

Posts

Joined
Fri Dec 02, 2011 8:14 am

Post by dlmcollection » Fri Mar 07, 2014 2:27 am

Romerz, is there any way to make the stock quantities show up based on the customer group type? In a way that stock quantities show to wholesalers clients but not for retail clients?

Thanks!

Newbie

Posts

Joined
Tue Jan 21, 2014 3:51 am

Post by dlmcollection » Mon Mar 10, 2014 10:29 pm

dlmcollection wrote:Romerz, is there any way to make the stock quantities show up based on the customer group type? In a way that stock quantities show to wholesalers clients but not for retail clients?

Thanks!
Can someone please anwser me? =(

Newbie

Posts

Joined
Tue Jan 21, 2014 3:51 am

Post by Ed_Rolla » Thu Mar 27, 2014 12:15 am

romerz wrote:I've trawled through loads of different threads reading about all sorts of different stock control requests and different things. I was recently looking to display...
Romez, I think I just love you, man! ;D
Thank you! So very much!

WIP Design Publicidade e Marketing Digital


User avatar
New member

Posts

Joined
Sun Jul 15, 2012 12:16 am
Location - Brazil, Rio de Janeiro

Post by edmundverwey » Fri Sep 05, 2014 5:27 pm

This is really very useful and helpful. Thank you.
I am not a programmer but I just added that little piece of code to all the other options and it works great.
What do you mean by "div"? you said one can change the color of the the amount to red when below 5 and green to above 5? Can you give an example please? I would really appreciate. As I said, not php friendly lol. Thanks

Newbie

Posts

Joined
Fri Aug 08, 2014 2:53 pm

Post by drest341 » Sat Jan 23, 2021 10:51 pm

FOR OC3 AROUND LINE 167 JUST REPLACE :

In view/theme/themename/template/product/product.tpl

</label>

WITH:

({{ option_value.quantity }})
</label>

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by drest341 » Mon Jan 25, 2021 5:33 am

drest341 wrote:
Sat Jan 23, 2021 10:51 pm
FOR OC3 AROUND LINE 167 JUST REPLACE :

In view/theme/themename/template/product/product.tpl

</label>

WITH:

({{ option_value.quantity }})
</label>

And for Journal 3 theme in OC3.x

in catalog/view/theme/journal3/template/product/product.twig

around line 385 replace:
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" data-toggle="tooltip" data-tooltip-class="push-tooltip" data-placement="{{ j3.settings.get(stylePrefix ~ 'PushTooltipPosition') }}" title="{{ option_value.name }} {% if option_value.price %} ({{ option_value.price_prefix }}{{ option_value.price }}) {% endif %}"/> {% endif %}

with :

{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" data-toggle="tooltip" data-tooltip-class="push-tooltip" data-placement="{{ j3.settings.get(stylePrefix ~ 'PushTooltipPosition') }}" title="{{ option_value.name }} ({{ option_value.quantity }}) {% if option_value.price %} ({{ option_value.price_prefix }}{{ option_value.price }}) {% endif %}"/> {% endif %}

and

in line 394 replace:

</span>

with:

</span>
<div style="text-align:center">{{ option_value.quantity }})</div>

Then go to system/storage and empty cache. Make refresh of product page twice to see the changes.

Attachments

quantity.jpg

quantity.jpg (68.19 KiB) Viewed 8444 times


Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by azonicdh » Mon Jan 25, 2021 1:41 pm

drest341 wrote:
Sat Jan 23, 2021 10:51 pm
FOR OC3 AROUND LINE 167 JUST REPLACE :

In view/theme/themename/template/product/product.tpl

</label>

WITH:

({{ option_value.quantity }})
</label>
I tried this but it didn't work. OC version is 3.0.3.2.
on catalog/product/product.php

Code: Select all

$product_option_value_data[] = array(
							'product_option_value_id' => $option_value['product_option_value_id'],
							'option_value_id'         => $option_value['option_value_id'],
							'name'                    => $option_value['name'],
							'quantity'                => $option_value['quantity'],
							'image'                   => $this->model_tool_image->resize($option_value['image'], 50, 50),
							'price'                   => $price,
							'price_prefix'            => $option_value['price_prefix']
						);
and on product.twig

Code: Select all

   <h3>{{ text_option }}</h3>
            {% for option in options %}
            {% if option.type == 'select' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
              <select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
                <option value="">{{ text_select }}</option>
                {% for option_value in option.product_option_value %}
                <option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
                {% if option_value.price %}
                ({{ option_value.price_prefix }}{{ option_value.price }})
                {% endif %} ({{option_value.quantity}}) </option>
                {% endfor %}
              </select>
what did I do wrong? can someone help me?

Newbie

Posts

Joined
Sat Mar 14, 2020 2:37 pm

Post by Pamella » Sat May 29, 2021 8:47 pm

It seems @azonicdh that can't work if your dashboard subtract stock option (system settings) is enabled! but I don't know how do? evenf if it's enabled

OC 3.0.3.7 EN (default theme) running on PHP 7.3 MariaDB 10.3 Linux / Apache 2.4


New member

Posts

Joined
Tue Oct 25, 2011 4:22 am
Who is online

Users browsing this forum: No registered users and 171 guests