Post by xoxoxo » Thu Nov 02, 2017 10:08 pm

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.....

Newbie

Posts

Joined
Thu Nov 02, 2017 8:03 pm

Post by straightlight » Thu Nov 02, 2017 11:25 pm

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>

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nightwing » 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

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by nightwing » Sat Apr 11, 2020 11:48 am

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

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by letxobnav » Sat Apr 11, 2020 4:33 pm

you could try:

Code: Select all

{% for i in minimum..10 %}
    * <option value="{{ i }}">{{ i }}</option>
{% endfor %}

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by nightwing » 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 %}

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by nightwing » 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 %}

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by letxobnav » 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>

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by nightwing » Sat Apr 11, 2020 11:54 pm

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>

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by nightwing » Sun Apr 12, 2020 12:49 am

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 %}

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by nightwing » Sun Apr 12, 2020 2:27 am

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>

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by letxobnav » 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.

Code: Select all

{% for i in minimum..maximum %}

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by nightwing » Sun Apr 12, 2020 8:54 pm

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.

Code: Select all

{% for i in minimum..maximum %}

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by nightwing » 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.

Code: Select all

{% for i in minimum..maximum %}

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by nightwing » Mon Apr 20, 2020 3:54 am

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.

Code: Select all

{% for i in minimum..maximum %}

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm

Who is online

Users browsing this forum: No registered users and 9 guests