Limit order quantity to multiple of minimum order

  • Posts: 6
  • Thank you received: 1
10 years 1 month ago #146019

-- HikaShop version -- : Essential 2.2.3
-- Joomla version -- : 3.2.1
-- PHP Version 5.3.27

I have a food product priced at $20 per 100g, and the minimum order quantity is 300g. Also I need to limit the order quantity to multiples of the minimum order. i.e. customer's orders can only be 300g, 600g, 900g and up.

Setting "Price" = 20; "Minimum quantity per order" = 3 can only limit the order quantity starting at 300g. I would like to modify the "+" and "-" buttons so that each press of the buttons will increase/decrease the order quantity by the value of the "minimum quantity per order", here is 3 in this example.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
10 years 1 month ago #146045

Hi,
If you want all your product to be sold per quantity of 3, the solution will probably be to edit the file "administrator/components/com_hikashop/helpers/cart.php" and change these lines :

					function hikashopQuantityChange(field,plus,max,min){
						var fieldEl=document.getElementById(field);
						var current = fieldEl.value;
						current = parseInt(current);
						if(plus){
							if(max==0 || current<max){
								fieldEl.value=parseInt(fieldEl.value)+1;
							}else if(max && current==max){
								alert(\''.JText::_('NOT_ENOUGH_STOCK',true).'\');
							}
						}else{
							if(current>1 && current>min){
								fieldEl.value=current-1;
							}
						}
						return false;
					}
By :
					function hikashopQuantityChange(field,plus,max,min){
						var fieldEl=document.getElementById(field);
						var current = fieldEl.value;
						current = parseInt(current);
						if(plus){
							if(max==0 || current<max){
								fieldEl.value=parseInt(fieldEl.value)+3;
							}else if(max && current==max){
								alert(\''.JText::_('NOT_ENOUGH_STOCK',true).'\');
							}
						}else{
							if(current>1 && current>min){
								fieldEl.value=current-3;
							}
						}
						return false;
					}

Last edit: 10 years 1 month ago by Mohamed Thelji.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 1
10 years 1 month ago #146058

I don't need this buying restriction in quantity apply to all products.

Some products priced by boxes. Some products priced by bottles. They are fine with the default setting of increment=1. However, for products priced by weight, they are all sold by unit of 100g for comparison sake. Amongst them, some food products are weighted over 100g per piece and must be sold as a multiple of its average weight.

Will there be way to change the increment for a few products only, not the whole site.

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
10 years 1 month ago #146076

Hi there,

It's getting very picky, Hikashop doesn't propose this feature so far.
If you have knowledge in php and html, you can adapt the code mohamed give you to be applied only on specific product.
Or you can ask on our commercial job forum if someone is willing to do it.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 1
10 years 1 month ago #146114

Hi there, thank you for the prompt reply.

How can I adapt Mohamed's code to apply on a specific product. In what way can a specific product be referred to? Should all the work be done in the file administrator/components/com_hikashop/helpers/cart.php?

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
10 years 1 month ago #146132

Most of the modification will have to be done here.
You will have to change the behaviour of the funciton according to the product id so it doesn't affect every product.
You can hardcode the list of product or even had something in the Hikashop backend to select your product.
Anyway it definitely require some good php skills.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 1
10 years 1 month ago #146137

To tackle the problem in another approach. Is there a way to not allow an order to proceed to checkout if the quantity is not set at one of the allowed values, which in my case above is 3, 6, 9 and up..

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
10 years 1 month ago #146140

Same answer, you either have to edit the checkout code to check the product and the quantity or you can create a plugin to perform that check.

The following user(s) said Thank You: apeelapan

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
6 years 9 months ago #270871

Hi Mohamed,

we had modified your suggested to make the increase and decrease button always add a multiple of the min order quantity.

function hikashopQuantityChange(field, plus, max, min) {
	var d = document, fieldEl = d.getElementById(field);
	if(!fieldEl) return false;
	var current = parseInt(fieldEl.value);
	if(current === NaN) return false;
	if(plus) {
		if(max == 0 || current < max) {
			fieldEl.value = current + min;
		} else if(max && current == max) {
			alert(\''.JText::_('NOT_ENOUGH_STOCK',true).'\');
		}
	} else if(current > 1 && current > min) {
		fieldEl.value = current - min;
	}
	return false;
}

We have just run an update to v3.0.1 on our test server and this hack is no longer working. We are using the non-legacy add to cart. Is there a new function?

Thanks, James

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
6 years 9 months ago #270873

Hi,

This function is only used if you have the "add to cart legacy" setting activated (and thus using the old system).
With the new add to cart system another function is used.

Note however that since these messages, we now have the capability in HikaShop to restrict quantities to specific values without modifying any code.
For example, if you set the "quantity input" setting of the product to "show select", it will transform the quantity field into a dropdown with values automatically generated based on the minimum quantity per order configured in the product. So if you set 3 there, you'll have automatically 3, 6, 9, 12, etc and the user won't be able to select the quantities in between.

The following user(s) said Thank You: jameswadsworth

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
6 years 9 months ago #271308

Hi, so we have changed the quantity input to "show select" and now we have the dropdown with values multiples of the minimum order. The only problem is that when one selects a different characteristic, the quantity input dropdown is not populated with the complete list, just the first value. We have tried different characteristics selection method but it doesn't change anything.

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
6 years 9 months ago #271353

Hi,

The characteristics system isn't compatible with the show select system.
I've added some patches to properly support that.
If you download again the install package on our website and install it on yours, it should now work better.

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
6 years 9 months ago #271656

Hi,

we have updated to version 3.1.1. It still doesn't work with characteristics. We have some template overrides of the product view. Probably we need to update these too. Which files are to update?

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
6 years 9 months ago #271689

Hi, we have found the issue. Under Hikashop configuration > Display > General Display Options > Use Chosen Library is set to YES then the dropdown list for the quantity is not loaded correctly. Set Use Chosen Library to NO and the quantity list displays correctly when changing the characteristic.

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
6 years 2 months ago #286707

Hi, I don't know what other people think of the new system, those who were using multiples of minimum order quantity. Here are out thoughts.

1) drop down lists to achieve multiples of the minimum quantity is not a use friendly as being able to click the plus or minus button
2) being limited to a maximum 15 with the drop down lists is annoying because if the product can be bought singly you often might want more than 15 such as 100. One to a hundred in a drop down list is not very nice. Even with multiples of the minimum order 15 might not be enough. For example you have minimum order 24 pieces and you want 1152 pieces that is 48 items in the drop down list. Again not user friendly.

Just my thoughts.

Thanks, James

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
6 years 2 months ago #286711

Hi,

I indeed agree with you that an input is better than a dropdown if your products can be purchased with a lot of quantity.
In fact, the default display of the quantity fields are input fields, not dropdowns for that reason.
Being able to switch between dropdown and input with the "quantity input method" setting is great so that you can really display the quantity field the way you need it.

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
6 years 2 months ago #286795

Hi Nicolas,

while I agree entirely with you answer I was speaking specifically about cases where shop owners want to see multiples of the min quantity per order, i.e. 6, 12, 18, 24, 30 etc

With the legacy cart system (prior to hikashop 3+) it was possible to use the input field along with the modification proposed by Mohamed Thelji near the start of this thread. However with the new cart system in hikahops 3+ the only way to be able to sell multiple values of the minimum quantity is to use the dropdown input method with the inconveniences as outlined in my previous post.

So is there a way with the new cart system to sell multiples of the minimum order quantity the input field box?

James

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
6 years 1 month ago #286797

Hi,

Ah no, it's the same as before but the modification is now even easier. The change that Mohamed gave had to be done in the core file of HikaShop, and thus, you had to do it after each update.
Now, you can activate the "Display view files" setting of the HikaShop configuration to see which view file is displaying the - and + buttons of the quantity input (it's probably "show_quantity").
Then, in it, you can change the code:
data-hk-qty-mod="-1"
to:
data-hk-qty-mod="-6"
and the code:
data-hk-qty-mod="1"
to:
data-hk-qty-mod="6"
and it will increment by steps of 6 with the input field. And since it will be done with a view override, you won't loose your changes when you update.

Please Log in or Create an account to join the conversation.

  • Posts: 272
  • Thank you received: 3
6 years 3 weeks ago #288951

Cool feature "Display view files" under advanced config.

As you can imagine not all products will have same master boxes. It could be any number. You example examples works fine if they all have master box of 6.

How do you handle the situation in which for example, even the same category, a products has master box 6 and another product has master box 12?

Please Log in or Create an account to join the conversation.

  • Posts: 25994
  • Thank you received: 4004
  • MODERATOR
6 years 3 weeks ago #288954

Hello,

The product increment already have an algorithm in the view to determine its value. It's generally based on the "min quantity per order" and "max quantity per order" of the product.

Afterwards, you can use product custom fields or category custom fields to store such kind of value.
But afterwards, regarding the view override, it would require some PHP code in order to extract the data from the field (which can be more tricky when it's related to category since a product can have a lot of categories).
That kind of code is outside the limit of our support and is related to custom development ; if you cannot perform that task, I would recommend you to contact a developer/integrator.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.136 seconds
Powered by Kunena Forum