[Skip to main content](#vessel-content)

#   how to automatically choose variants based on the quantity of the main product

##

- **[javabek](/forum/user/59013-javabek "View javabek's Profile")**
- [![javabek's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/59013-javabek "View javabek's Profile") Topic Author
- [ Offline](/forum/user/59013-javabek)

Less More

- Posts: 11
- Thank you received: 0
-
-

6 years 8 months ago [\#316128](#316128) by [javabek](/forum/user/59013-javabek "View javabek's Profile")  *[how to automatically choose variants based on the quantity of the main product](/forum/25-install-update/899263-how-to-automatically-choose-variants-based-on-the-quantity-of-the-main-product#316128 "-- HikaShop version -- : 4.2.2 -- Joomla version -- : 3.9.13 -- PHP version -- : 7.2.2  hello, first of all i created variants like: 2, 3, 4, 5, 6 See picture:  So, I need when you indicate the quantity of the main product - 6: (if Quantity of main product is 5, then variants should appear up to 5, like 2,3,4,5) See picture:  then the variants should appear (auto add) variants automatically as shown See picture:  Please can you write some php code to solve this")* was created by *[javabek](/forum/user/59013-javabek "View javabek's Profile")*

-- HikaShop version -- : 4.2.2
-- Joomla version -- : 3.9.13
-- PHP version -- : 7.2.2

hello, first of all i created variants like: 2, 3, 4, 5, 6
See picture:  [ ![Variants.jpg](/forum/attachment/48816) ](/forum/attachment/48816 "Variants.jpg")

So, I need when you indicate the quantity of the main product - 6: (if Quantity of main product is 5, then variants should appear up to 5, like 2,3,4,5)
See picture:  [ ![Bookquantity.jpg](/forum/attachment/48817) ](/forum/attachment/48817 "Bookquantity.jpg")

then the variants should appear (auto add) variants automatically as shown
See picture:  [ ![Copiesauto.jpg](/forum/attachment/48818) ](/forum/attachment/48818 "Copiesauto.jpg")

Please can you write some php code to solve this

- [ ![Variants.jpg](/forum/attachment/48816) ](/forum/attachment/48816 "Variants.jpg") [ ](/forum/attachment/48816?download=1 "Variants.jpg")
- [ ![Bookquantity.jpg](/forum/attachment/48817) ](/forum/attachment/48817 "Bookquantity.jpg") [ ](/forum/attachment/48817?download=1 "Bookquantity.jpg")
- [ ![Copiesauto.jpg](/forum/attachment/48818) ](/forum/attachment/48818 "Copiesauto.jpg") [ ](/forum/attachment/48818?download=1 "Copiesauto.jpg")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5OTI2My1ob3ctdG8tYXV0b21hdGljYWxseS1jaG9vc2UtdmFyaWFudHMtYmFzZWQtb24tdGhlLXF1YW50aXR5LW9mLXRoZS1tYWluLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86556
- Thank you received: 14305
-
-

6 years 8 months ago [\#316131](#316131) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[how to automatically choose variants based on the quantity of the main product](/forum/25-install-update/899263-how-to-automatically-choose-variants-based-on-the-quantity-of-the-main-product#316131 "-- HikaShop version -- : 4.2.2 -- Joomla version -- : 3.9.13 -- PHP version -- : 7.2.2  hello, first of all i created variants like: 2, 3, 4, 5, 6 See picture:  So, I need when you indicate the quantity of the main product - 6: (if Quantity of main product is 5, then variants should appear up to 5, like 2,3,4,5) See picture:  then the variants should appear (auto add) variants automatically as shown See picture:  Please can you write some php code to solve this")*

Hi,

It will be hard to do it like that.
I would recommend a simpler solution.
Just remove the variants and characteristics of your product, and instead, in the "quantity input method" setting of the product, select "show select".
That way, instead of an input field for the quantity next to the add to cart button, you'll have a dropdown starting from 1 and going up to the quantity of the product. So you won't have to code anything.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5OTI2My1ob3ctdG8tYXV0b21hdGljYWxseS1jaG9vc2UtdmFyaWFudHMtYmFzZWQtb24tdGhlLXF1YW50aXR5LW9mLXRoZS1tYWluLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[javabek](/forum/user/59013-javabek "View javabek's Profile")**
- [![javabek's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/59013-javabek "View javabek's Profile") Topic Author
- [ Offline](/forum/user/59013-javabek)

Less More

- Posts: 11
- Thank you received: 0
-
-

6 years 8 months ago [\#316137](#316137) by [javabek](/forum/user/59013-javabek "View javabek's Profile")  Replied by *[javabek](/forum/user/59013-javabek "View javabek's Profile")* on topic *[how to automatically choose variants based on the quantity of the main product](/forum/25-install-update/899263-how-to-automatically-choose-variants-based-on-the-quantity-of-the-main-product#316137 "-- HikaShop version -- : 4.2.2 -- Joomla version -- : 3.9.13 -- PHP version -- : 7.2.2  hello, first of all i created variants like: 2, 3, 4, 5, 6 See picture:  So, I need when you indicate the quantity of the main product - 6: (if Quantity of main product is 5, then variants should appear up to 5, like 2,3,4,5) See picture:  then the variants should appear (auto add) variants automatically as shown See picture:  Please can you write some php code to solve this")*

can you write code for massive adding variants by selecting its "id"

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5OTI2My1ob3ctdG8tYXV0b21hdGljYWxseS1jaG9vc2UtdmFyaWFudHMtYmFzZWQtb24tdGhlLXF1YW50aXR5LW9mLXRoZS1tYWluLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86556
- Thank you received: 14305
-
-

6 years 8 months ago [\#316140](#316140) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[how to automatically choose variants based on the quantity of the main product](/forum/25-install-update/899263-how-to-automatically-choose-variants-based-on-the-quantity-of-the-main-product#316140 "-- HikaShop version -- : 4.2.2 -- Joomla version -- : 3.9.13 -- PHP version -- : 7.2.2  hello, first of all i created variants like: 2, 3, 4, 5, 6 See picture:  So, I need when you indicate the quantity of the main product - 6: (if Quantity of main product is 5, then variants should appear up to 5, like 2,3,4,5) See picture:  then the variants should appear (auto add) variants automatically as shown See picture:  Please can you write some php code to solve this")*

Hi,

If you really want to do what you're talking about, the only solution I can see is to edit the file components/com_hikashop/views/product/view.html.php and in the "show" function, after the query to load the main details of the product, dynamically generate the variants with 2 or 3 MySQL queries based on the quantity of the product.
Or even generate them all in the backend, and remove the ones you don't want once they are loaded by the MySQL query in the "show" function, it will be simpler.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg5OTI2My1ob3ctdG8tYXV0b21hdGljYWxseS1jaG9vc2UtdmFyaWFudHMtYmFzZWQtb24tdGhlLXF1YW50aXR5LW9mLXRoZS1tYWluLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.052 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
