Page 1 of 1
[SOLVED] - Quantity dropdown for Opencart v3.0.2.0
Posted: Thu Nov 02, 2017 10:08 pm
by xoxoxo
New beginner with Open Cart
Please can someone help me on how to add dropdown to Product Quantity.
Below is the code I found in my product.twig
<input type="text" name="quantity" value="{{ minimum }}" size="2" id="input-quantity" class="form-control" />
Thanks.....
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Thu Nov 02, 2017 11:25 pm
by straightlight
Replace:
Code: Select all
<input type="text" name="quantity" value="{{ minimum }}" size="2" id="input-quantity" class="form-control" />
with:
Code: Select all
<select name="quantity" id="input-quantity" class="form-control" />
<option value="{{ minimum }}">{{ minimum }}</option>
</select>
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sat Apr 11, 2020 11:40 am
by nightwing
Hey straightlight, I am using version 3.0.3.2 Default theme, this only shows the minimum quantity in the dropdown. How can I get it to display a range? Like 1 through to 10?
Thanks
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sat Apr 11, 2020 11:48 am
by nightwing
I know I am able to add
Code: Select all
<option value="2">2</option>
<option value="3">3</option>
<option value="3">3</option>
However, this would be conflicting with the minimum order amount unless I would start it at 1 and if customer try to add that, it alerts them about the minimum. Let me know if this is the ideal thing to do.
Thanks
seanstorm100 wrote: ↑Sat Apr 11, 2020 11:40 am
Hey straightlight, I am using version 3.0.3.2 Default theme, this only shows the minimum quantity in the dropdown. How can I get it to display a range? Like 1 through to 10?
Thanks
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sat Apr 11, 2020 4:33 pm
by letxobnav
you could try:
Code: Select all
{% for i in minimum..10 %}
* <option value="{{ i }}">{{ i }}</option>
{% endfor %}
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sat Apr 11, 2020 9:18 pm
by nightwing
Hey letxobnav,
Thanks I will test and get back to you!
letxobnav wrote: ↑Sat Apr 11, 2020 4:33 pm
you could try:
Code: Select all
{% for i in minimum..10 %}
* <option value="{{ i }}">{{ i }}</option>
{% endfor %}
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sat Apr 11, 2020 9:28 pm
by nightwing
Hi letxobnav,
It started at the minimum, however, the numbers are no longer in a dropdown but a printed just text on the page.
See image:
https://pasteboard.co/J3jLPv3.png
seanstorm100 wrote: ↑Sat Apr 11, 2020 9:18 pm
Hey letxobnav,
Thanks I will test and get back to you!
letxobnav wrote: ↑Sat Apr 11, 2020 4:33 pm
you could try:
Code: Select all
{% for i in minimum..10 %}
* <option value="{{ i }}">{{ i }}</option>
{% endfor %}
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sat Apr 11, 2020 10:50 pm
by letxobnav
you have to put the select around it.
Code: Select all
<select name="quantity" id="input-quantity" class="form-control" />
{% for i in minimum..10 %}
* <option value="{{ i }}">{{ i }}</option>
{% endfor %}
</select>
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sat Apr 11, 2020 11:54 pm
by nightwing
Shoots don't know how that missed me. My apologies. Thanks I will test as soon as I get home.
letxobnav wrote: ↑Sat Apr 11, 2020 10:50 pm
you have to put the select around it.
Code: Select all
<select name="quantity" id="input-quantity" class="form-control" />
{% for i in minimum..10 %}
* <option value="{{ i }}">{{ i }}</option>
{% endfor %}
</select>
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sun Apr 12, 2020 12:49 am
by nightwing
Hi letxobnav,
I haven't tested as yet, just a thought... Even though we have the drop down starting at minimum and ends at 10... The way my store was set up was to disable adding to cart what we dont have. So for example we have 3 in stock you cannot add 4. We I used custom code to display stock under 10 and counting down but over 10 it shows In Stock. My question ials, is it possible to start at minimum but if the stock is below 10 it shows the number they can add to cart? So if we have 4 in stock and order minimum is 2 the dropdown will show 2,3,4 but if we have 11 or more in stock they see minimum to 10 in quantity drop down.
Please let me know.
Thank you
seanstorm100 wrote: ↑Sat Apr 11, 2020 9:28 pm
Hi letxobnav,
It started at the minimum, however, the numbers are no longer in a dropdown but a printed just text on the page.
See image:
https://pasteboard.co/J3jLPv3.png
seanstorm100 wrote: ↑Sat Apr 11, 2020 9:18 pm
Hey letxobnav,
Thanks I will test and get back to you!
letxobnav wrote: ↑Sat Apr 11, 2020 4:33 pm
you could try:
Code: Select all
{% for i in minimum..10 %}
* <option value="{{ i }}">{{ i }}</option>
{% endfor %}
Re: Quantity dropdown for Opencart v3.0.2.0
Posted: Sun Apr 12, 2020 2:27 am
by nightwing
This worked! Thanks
letxobnav wrote: ↑Sat Apr 11, 2020 10:50 pm
you have to put the select around it.
Code: Select all
<select name="quantity" id="input-quantity" class="form-control" />
{% for i in minimum..10 %}
* <option value="{{ i }}">{{ i }}</option>
{% endfor %}
</select>
Re: [SOLVED] - Quantity dropdown for Opencart v3.0.2.0
Posted: Sun Apr 12, 2020 9:03 am
by letxobnav
good, for the maximum.
in your controller you would add a maximum variable to be passed to the view just like minimum.
Code: Select all
if ($product_info['minimum']) {
$data['minimum'] = $product_info['minimum'];
} else {
$data['minimum'] = 1;
}
Code: Select all
if ($product_info['quantity'] > 0) {
if ($product_info['quantity'] > 10) {
$data['maximum'] = 10;
} else {
$data['maximum'] = $product_info['quantity'];
}
} else {
$data['maximum'] = 1;
}
depending on what you want to display if there is no stock.
then use maximum in the view.
Re: [SOLVED] - Quantity dropdown for Opencart v3.0.2.0
Posted: Sun Apr 12, 2020 8:54 pm
by nightwing
Thank you letxobnav, I will test and let you know!
letxobnav wrote: ↑Sun Apr 12, 2020 9:03 am
good, for the maximum.
in your controller you would add a maximum variable to be passed to the view just like minimum.
Code: Select all
if ($product_info['minimum']) {
$data['minimum'] = $product_info['minimum'];
} else {
$data['minimum'] = 1;
}
Code: Select all
if ($product_info['quantity'] > 0) {
if ($product_info['quantity'] > 10) {
$data['maximum'] = 10;
} else {
$data['maximum'] = $product_info['quantity'];
}
} else {
$data['maximum'] = 1;
}
depending on what you want to display if there is no stock.
then use maximum in the view.
Re: [SOLVED] - Quantity dropdown for Opencart v3.0.2.0
Posted: Sun Apr 12, 2020 9:28 pm
by nightwing
Worked really well, thank you!
letxobnav wrote: ↑Sun Apr 12, 2020 9:03 am
good, for the maximum.
in your controller you would add a maximum variable to be passed to the view just like minimum.
Code: Select all
if ($product_info['minimum']) {
$data['minimum'] = $product_info['minimum'];
} else {
$data['minimum'] = 1;
}
Code: Select all
if ($product_info['quantity'] > 0) {
if ($product_info['quantity'] > 10) {
$data['maximum'] = 10;
} else {
$data['maximum'] = $product_info['quantity'];
}
} else {
$data['maximum'] = 1;
}
depending on what you want to display if there is no stock.
then use maximum in the view.
Re: [SOLVED] - Quantity dropdown for Opencart v3.0.2.0
Posted: Mon Apr 20, 2020 3:54 am
by nightwing
Hi letxobnav,
Is there a way to do the below:
You have 5 Shirts, 2 Red, 3 Blue, 1 Red - Medium, 1 Red - Large, 2 Blue - Small, 1 Blue - Medium
A Customer selects Blue, Small, They see Qty = 5, after added to cart successfully and they try to checkout, it says that we do not have that amount etc...
Is there any way to reveal the quantity based on option selection? So after selecting Blue, Small, Quantity would be 1, 2 (Drop Down) and if they change to lets say blue large, the quantity goes to 1.
Optionally an error can be thrown if we can't achieve this in Quantity (Dropdown) Limitation.
I am looking at this module:
https://www.opencart.com/index.php?rout ... n_id=13703
I wanted to know if there's a quick way to do this.
seanstorm100 wrote: ↑Sun Apr 12, 2020 9:28 pm
Worked really well, thank you!
letxobnav wrote: ↑Sun Apr 12, 2020 9:03 am
good, for the maximum.
in your controller you would add a maximum variable to be passed to the view just like minimum.
Code: Select all
if ($product_info['minimum']) {
$data['minimum'] = $product_info['minimum'];
} else {
$data['minimum'] = 1;
}
Code: Select all
if ($product_info['quantity'] > 0) {
if ($product_info['quantity'] > 10) {
$data['maximum'] = 10;
} else {
$data['maximum'] = $product_info['quantity'];
}
} else {
$data['maximum'] = 1;
}
depending on what you want to display if there is no stock.
then use maximum in the view.