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

#   Quantity Based Pricing combined with Variants

##

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

Less More

- Posts: 2
- Thank you received: 0
-
-

8 months 1 week ago [\#371017](#371017) by [rolandpb](/forum/user/84034-rolandpb "View rolandpb's Profile")  *[Quantity Based Pricing combined with Variants](/forum/25-install-update/910217-quantity-based-pricing-combined-with-variants#371017 "-- HikaShop version -- : 6.4.0 -- Joomla version -- : 5.4  Hi,  I am trying to set up differently priced product variants combined with quantity based pricing. I would like to have the following:  1. The variant being selected in a drop down menu 2. Buttons displaying different quantities, the relevant prices as well as the discounts. Upon clicking the buttons the quantity selector automatically updates to the specified quantity. 3. The main price below the product title to update based on the variant and quantity selected.  So while I get the two systems to function independently of each other, I don't manage to have them work together. Ie, when I load the page, quantity based pricing works based on the default variant. The price below the heading updates to the correct value as I click the quantity buttons (See Attachment Screenshot a - ).  As soon as I select a variant two problems arise: 1. all three prices associated with the different quantities of the selected variant show below the heading and 2. the prices displayed on the quantity buttons do not update. (See Attachment Screenshot b - )  Are there any suggestions on how to get this working?  Thanks, Roland")* was created by *[rolandpb](/forum/user/84034-rolandpb "View rolandpb's Profile")*

-- HikaShop version -- : 6.4.0
-- Joomla version -- : 5.4

Hi,

I am trying to set up differently priced product variants combined with quantity based pricing. I would like to have the following:

1. The variant being selected in a drop down menu
2. Buttons displaying different quantities, the relevant prices as well as the discounts. Upon clicking the buttons the quantity selector automatically updates to the specified quantity.
3. The main price below the product title to update based on the variant and quantity selected.

So while I get the two systems to function independently of each other, I don't manage to have them work together. Ie, when I load the page, quantity based pricing works based on the default variant. The price below the heading updates to the correct value as I click the quantity buttons (See Attachment Screenshot a -  [ ![Screenshota.png](/forum/attachment/61322) ](/forum/attachment/61322 "Screenshota.png")

).

As soon as I select a variant two problems arise: 1. all three prices associated with the different quantities of the selected variant show below the heading and 2. the prices displayed on the quantity buttons do not update. (See Attachment Screenshot b -  [ ![Screenshotb.png](/forum/attachment/61323) ](/forum/attachment/61323 "Screenshotb.png")

)

Are there any suggestions on how to get this working?

Thanks,
Roland

- [ ![Screenshota.png](/forum/attachment/61322) ](/forum/attachment/61322 "Screenshota.png") [ ](/forum/attachment/61322?download=1 "Screenshota.png")
- [ ![Screenshotb.png](/forum/attachment/61323) ](/forum/attachment/61323 "Screenshotb.png") [ ](/forum/attachment/61323?download=1 "Screenshotb.png")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkxMDIxNy1xdWFudGl0eS1iYXNlZC1wcmljaW5nLWNvbWJpbmVkLXdpdGgtdmFyaWFudHM/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: 86593
- Thank you received: 14334
-
-

8 months 1 week ago [\#371018](#371018) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Quantity Based Pricing combined with Variants](/forum/25-install-update/910217-quantity-based-pricing-combined-with-variants#371018 "-- HikaShop version -- : 6.4.0 -- Joomla version -- : 5.4  Hi,  I am trying to set up differently priced product variants combined with quantity based pricing. I would like to have the following:  1. The variant being selected in a drop down menu 2. Buttons displaying different quantities, the relevant prices as well as the discounts. Upon clicking the buttons the quantity selector automatically updates to the specified quantity. 3. The main price below the product title to update based on the variant and quantity selected.  So while I get the two systems to function independently of each other, I don't manage to have them work together. Ie, when I load the page, quantity based pricing works based on the default variant. The price below the heading updates to the correct value as I click the quantity buttons (See Attachment Screenshot a - ).  As soon as I select a variant two problems arise: 1. all three prices associated with the different quantities of the selected variant show below the heading and 2. the prices displayed on the quantity buttons do not update. (See Attachment Screenshot b - )  Are there any suggestions on how to get this working?  Thanks, Roland")*

Hi,

Without knowing the settings of your product / variants, the customization you made in the view override to get the quantity selector like this, and a link to the page with the issue so that we can analyze the situation, it will be hard to tell you exactly what you're missing.
Could you provide these ?

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

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

Less More

- Posts: 2
- Thank you received: 0
-
-

8 months 1 week ago -  8 months 1 week ago [\#371024](#371024) by [rolandpb](/forum/user/84034-rolandpb "View rolandpb's Profile")  Replied by *[rolandpb](/forum/user/84034-rolandpb "View rolandpb's Profile")* on topic *[Quantity Based Pricing combined with Variants](/forum/25-install-update/910217-quantity-based-pricing-combined-with-variants#371024 "-- HikaShop version -- : 6.4.0 -- Joomla version -- : 5.4  Hi,  I am trying to set up differently priced product variants combined with quantity based pricing. I would like to have the following:  1. The variant being selected in a drop down menu 2. Buttons displaying different quantities, the relevant prices as well as the discounts. Upon clicking the buttons the quantity selector automatically updates to the specified quantity. 3. The main price below the product title to update based on the variant and quantity selected.  So while I get the two systems to function independently of each other, I don't manage to have them work together. Ie, when I load the page, quantity based pricing works based on the default variant. The price below the heading updates to the correct value as I click the quantity buttons (See Attachment Screenshot a - ).  As soon as I select a variant two problems arise: 1. all three prices associated with the different quantities of the selected variant show below the heading and 2. the prices displayed on the quantity buttons do not update. (See Attachment Screenshot b - )  Are there any suggestions on how to get this working?  Thanks, Roland")*

Hi Nicolas,

Thanks for your message. I am still running the site on local host so cannot send you a link unfortunately.

I have created the variants by setting the following:

1. Characteristics under Components -&gt; Hikashop -&gt; Products -&gt; Products -&gt; Characteristics
2. Specifications under the product tab under Components -&gt; Hikashop -&gt; Products -&gt; my specific product (Langstroth Hive)
3. Variants under the variant tab under Components -&gt; Hikashop -&gt; Products -&gt; my specific product (Langstroth Hive). Here I have set three prices for each variant giving each price a different minimum quantity.

The quantity based pricing I have done through changes to the show_default.php file. I have used ChatGPT for assistance as I am relatively new to programming. Apologies in advance for pasting such a long code. Here are the parts I have added to the file: Code:

&lt;h4 class="quantity-title"&gt;Quantity&lt;/h4&gt; &lt;div class="bulk-row"&gt; &lt;?php $base_price = 0; if (!empty($this-&gt;element-&gt;prices[0])) { $base_price = $this-&gt;element-&gt;prices[0]-&gt;price_value_with_tax; } foreach ($this-&gt;element-&gt;prices as $price) { // Quantity $qty = $price-&gt;price_min_quantity ?: 1; // Price $value = $price-&gt;price_value_with_tax; $formatted = $this-&gt;currencyHelper-&gt;format($value, $this-&gt;currency-&gt;currency_id); // Discount $save = 0; if ($base_price &gt; 0) { $save = round((1 - ($value / $base_price)) * 100); } // Output echo '&lt;div class="bulk-option" data-qty="' . $qty . '"&gt;'; echo '&lt;div class="bulk-qty"&gt;' . $qty . '&lt;span class="unit"&gt; pcs&lt;/span&gt;&lt;/div&gt;'; echo '&lt;div class="bulk-price"&gt;' . $formatted . '&lt;/div&gt;'; if ($save &gt; 0) { echo '&lt;div class="bulk-save"&gt;' . $save . '% Discount&lt;/div&gt;'; } echo '&lt;/div&gt;'; } ?&gt; &lt;/div&gt; &lt;script&gt; document.querySelectorAll('.bulk-option').forEach(function(option) { option.addEventListener('click', function() { // === Quantity === let qty = this.getAttribute('data-qty'); let qtyInput = document.querySelector('input[name="quantity"]'); if (qtyInput) { qtyInput.value = qty; } // === Price === let price = this.querySelector('.bulk-price').innerText; let mainPrice = document.querySelector('#hikashop_product_price_main'); // === Discount === let discount = this.querySelector('.bulk-save'); let discountText = discount ? discount.innerText : ''; // === Update main price === if (mainPrice) { if (discountText) { mainPrice.innerHTML = price + ' &lt;span class="main-discount"&gt;' + discountText + '&lt;/span&gt;'; } else { mainPrice.innerHTML = price; } } // === Active state === document.querySelectorAll('.bulk-option').forEach(function(o) { o.classList.remove('active'); }); this.classList.add('active'); }); }); // === Version selection === document.querySelectorAll('.version-option').forEach(function(btn) { btn.addEventListener('click', function() { document.querySelectorAll('.version-option').forEach(function(o) { o.classList.remove('active'); }); this.classList.add('active'); }); }); &lt;/script&gt;

Hope this makes it clear? Please let me know if you need any other information.

Thanks

Last edit: 8 months 1 week ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkxMDIxNy1xdWFudGl0eS1iYXNlZC1wcmljaW5nLWNvbWJpbmVkLXdpdGgtdmFyaWFudHM/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: 86593
- Thank you received: 14334
-
-

8 months 1 week ago [\#371025](#371025) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Quantity Based Pricing combined with Variants](/forum/25-install-update/910217-quantity-based-pricing-combined-with-variants#371025 "-- HikaShop version -- : 6.4.0 -- Joomla version -- : 5.4  Hi,  I am trying to set up differently priced product variants combined with quantity based pricing. I would like to have the following:  1. The variant being selected in a drop down menu 2. Buttons displaying different quantities, the relevant prices as well as the discounts. Upon clicking the buttons the quantity selector automatically updates to the specified quantity. 3. The main price below the product title to update based on the variant and quantity selected.  So while I get the two systems to function independently of each other, I don't manage to have them work together. Ie, when I load the page, quantity based pricing works based on the default variant. The price below the heading updates to the correct value as I click the quantity buttons (See Attachment Screenshot a - ).  As soon as I select a variant two problems arise: 1. all three prices associated with the different quantities of the selected variant show below the heading and 2. the prices displayed on the quantity buttons do not update. (See Attachment Screenshot b - )  Are there any suggestions on how to get this working?  Thanks, Roland")*

Hi,

This is a view override issue, not a core bug. Two things need to be adjusted in your customization:

1. Multiple prices showing after variant selection: Your code loops over $this-&gt;element-&gt;prices which, after a variant is selected, contains the prices of all variants. You need to check if a variant is selected and use its prices instead. For example:
Code:

$prices = $this-&gt;element-&gt;prices; if(!empty($this-&gt;element-&gt;main)) { $prices = $this-&gt;element-&gt;main-&gt;prices; }

Or better, listen to the variant selection and rebuild the buttons from the selected variant's prices via JavaScript.

2. Quantity buttons stop working after variant change: When a variant is selected, HikaShop refreshes parts of the page via AJAX, which replaces the DOM elements your event listeners were attached to. You need to re-initialize your click handlers after each variant change by listening to HikaShop's content change event:
Code:

window.Oby.registerAjax(['hkContentChanged'], function() { // Re-bind your bulk-option click handlers here document.querySelectorAll('.bulk-option').forEach(function(option) { option.addEventListener('click', function() { // ... your existing click handler code }); }); });

This event fires each time a variant is selected and the page content is updated.

The following user(s) said Thank You: [rolandpb](/forum/user/84034-rolandpb "View rolandpb's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkxMDIxNy1xdWFudGl0eS1iYXNlZC1wcmljaW5nLWNvbWJpbmVkLXdpdGgtdmFyaWFudHM/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.054 seconds

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