Option Quantity

  • Posts: 51
  • Thank you received: 3
  • Hikashop Business
4 years 3 months ago #327003

-- HikaShop version -- : 4.4.0
-- Joomla version -- : 3.9.23
-- PHP version -- : 7.4

Hello,

Is there a way to offer an option to the product with its own quantity field?

For example:
I have a product that is sold by the unit and I want to add an option that has a set price.
I noticed when I add an option to the product the quantity of the product gets used for the quantity of the option when it is added to the cart.
I need to be able to limit the quantity of the option to 1 unit and allow the product quantity to be multiple units.

Another example:
I have a product that is sold by a quantity pack and I want to offer add-ons to the unit it multiple quantities and prices.
For instance, The customer wants to buy 1 unit of a 50 pack at a certain set price and buy one or more optional add-on packs sold in quantities of 10 at a different price. I do not want the customer to be able buy the add-on packs unless they first bought the main product.

For either of these scenarios i would need to set the quantity of the option separate from the main product. The way it works now, when the customer buys 50 of the product units they also get 50 of the option added as well. I have set the option to not be grouped with the product and that allows the quantity of the options to be changed in the cart view but I need a way to set it on the product page.

I hope this is possible.

Thank You

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

  • Posts: 83404
  • Thank you received: 13498
  • MODERATOR
4 years 3 months ago #327034

Hi,

There is no option or interface to allow for that.
However, the add to wart system is supposed to handle it on the server side thanks to the code:

$options = hikaInput::get()->get('hikashop_product_option', array(), 'array');
		$options_qty = hikaInput::get()->get('hikashop_product_option_qty', array(), 'array');
		if(!empty($options) && is_array($options)) {
			$data[0]['options'] = array();
			foreach($options as $k => $option) {
				if(empty($option) || (int)$option == 0)
					continue;
				if(isset($options_qty[$k]) && empty($options_qty[$k]))
					continue;
				if(!isset($options_qty[$k]) || (int)$options_qty[$k] < 0) $options_qty[$k] = 0;
				$qty = !empty($options_qty[$k]) ? (int)$options_qty[$k] : $quantity;
				$coef = !empty($options_qty[$k]) ? 0 : 1;
				$data[0]['options'][] = array(
					'id' => (int)$option,
					'qty' => $qty,
					'coef' => $coef
				);
			}
			if(empty($data[0]['options']))
				unset($data[0]['options']);
		}
in administrator/components/com_hikashop/classes/cart.php
So if you're a developer, you should be able to edit the view file product / option.php to add the corresponding input fields so that the user could select the quantity he wants for the options.
There, you can see the name of the input for the options being:
$map = 'hikashop_product_option[]';
	if($selectionMethod == 'radio')
		$map = 'hikashop_product_option['.$i.']';
So you would need to have:
$qty_name = 'hikashop_product_option_qty[]';
	if($selectionMethod == 'radio')
		$qty_name = 'hikashop_product_option_qty['.$i.']';
for your quantity inputs.

The following user(s) said Thank You: jfischer_hika

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

Time to create page: 0.055 seconds
Powered by Kunena Forum