Want optional product to be displayed in a different way.

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 1 week ago #363040

-- HikaShop version -- : 5.1.0
-- Joomla version -- : 5.1.4
-- PHP version -- : 8.1.x

Hello,

Got a little question.
We have an optional product added to product test. But we now get a select box to select add this with it or not.. but we like to have the quantity field, so customers can select more than one of this extra optional product. How can i accomplish that?

Attachments:

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
3 months 1 week ago #363041

Hi,

You have two ways to go about it:

- You could create a characteristic with the values being the quantity you want to be selectable. Then, add that characteristic to the option product in its "characteristics" setting, and add the corresponding variants. That way, the dropdown of the option will contain one choice for each variant of the product. And then, you can adapt the price if necessary in each variant.

- You could edit the file product / option via the menu Display>Views and add this line at the beginning:

<?php $this->show_option_quantity = true; ?>
This will display a quantity input field next to each option. That's a hidden feature of HikaShop.
Now, this means that it will apply to all options of all the products on your shop. If you want this option quantity field to apply only for some options of some products, it will require further PHP code to set this variable to true only in some cases so it gets more complicated.

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

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 1 week ago #363134

Hi Nicolas,

The quantity field is super, i think i can manage to add the + and - easily to that, but what more important is, is how to change the select dropdown into a checkbox, when box is checked it will have the yes function as it already does. i can change it in a checkbox but not in the right way, because the shown optionprice will not calculate anymore..

Hope you understand,

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
3 months 6 days ago #363135

Hi,

If you want options to be displayed as checkboxes instead of dropdowns, you want to change the "product selection method" to "checkbox" in the HikaShop configuration:
www.hikashop.com/support/documentation/5...html#display_product

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

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 6 days ago #363167

super great thanks..
A little question for the quantity field. Ik have a + and - build next to it. i can increase and decrease the optional product. But i can not get it to give an announcement when maximum total items for the order.

<?php
		if($this->show_option_quantity === true || (int)$this->show_option_quantity <= 1) {
?>
			<div class="quantity-control">
    <button type="button" class="quantity-decrease" onclick="changeQuantity(-1, 'hikashop_product_option_qty_<?php echo $i; ?>')">-</button>
    <button type="button" class="quantity-increase" onclick="changeQuantity(1, 'hikashop_product_option_qty_<?php echo $i; ?>')">+</button>
</div>
<input type="text" class="hikashop_product_quantity_field" id="hikashop_product_option_qty_<?php echo $i; ?>" name="hikashop_product_option_qty[<?php echo $i; ?>]" onchange="hikaProductOptions.change();" value="1" />
<script>
    // Function to handle the increase or decrease in quantity with a max limit
    function changeQuantity(change, inputId, maxQuantity) {
        var inputField = document.getElementById(inputId);
        var currentValue = parseInt(inputField.value);

        // Ensure the current value is a number and adjust the quantity
        if (!isNaN(currentValue)) {
            var newValue = currentValue + change;
            
            // Prevent the value from going below 1
            if (newValue < 1) {
                newValue = 1;
            }

            // To Check if the new value exceeds the maximum allowed quantity
            if (newValue > maxQuantity) {
                alert('You cannot purchase more than ' + maxQuantity + ' units of this product.');
                newValue = maxQuantity; // Set the value to the max limit if exceeded
            }

            inputField.value = newValue;
            hikaProductOptions.change(); // Call the existing function to update the options/prices
        }
    }
</script>
What am i doing wrong here?

Last edit: 3 months 5 days ago by nicolas.

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
3 months 5 days ago #363170

Hi,

In your call to the changeQuantity function, you don't provide the maxQuantity in the third parameter.

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

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 5 days ago #363189

Hi Nicolas,

Tried serveral option to get the MaxQuantity from the option product, but no call to it is working on this quantity field, can you point out a direction?

Thanks

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
3 months 5 days ago #363191

Hi,

What do you mean ?
Supposing that you want to use the stock of the product as the max quantity, you want to change the lines:

    <button type="button" class="quantity-decrease" onclick="changeQuantity(-1, 'hikashop_product_option_qty_<?php echo $i; ?>')">-</button>
    <button type="button" class="quantity-increase" onclick="changeQuantity(1, 'hikashop_product_option_qty_<?php echo $i; ?>')">+</button>
to:
    <button type="button" class="quantity-decrease" onclick="changeQuantity(-1, 'hikashop_product_option_qty_<?php echo $i; ?>', <?php echo $optionInfo->product_quantity; ?>)">-</button>
    <button type="button" class="quantity-increase" onclick="changeQuantity(1, 'hikashop_product_option_qty_<?php echo $i; ?>', <?php echo $optionInfo->product_quantity; ?>)">+</button>
in your code.

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

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 4 days ago #363221

Hi Nicolas,

Thanks for your answer, with this i get the announcement "You cannot purchase more than -1 units of this product." for the + and the - ,
I see that you call the stock of the product, i need to set it to the max per order, e.g. in the product i put in as option, this product has a maximum of 3 to order per order. :)

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

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 4 days ago #363222

I got it.. Yeah.. super thanks !! I am very happy with hikashop and support.
You Rock Nicolas!

The following user(s) said Thank You: nicolas

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

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 1 day ago #363255

Hi Nicolas,

I had to set the max and min order instead of the main quantity, but when i increase the quantity to 3 i get neatly the warning, but when i want to decrease this quantity with 1 i get the warning of the minimal order and the total isn't decreased anymore, do you have a suggestion why this can be?

<div class="quantity-control">
<button type="button" class="quantity-decrease" onclick="changeQuantity(-1, 'hikashop_product_option_qty_<?php echo $i; ?>', <?php echo $optionInfo->product_min_per_order; ?>)">-</button>
<button type="button" class="quantity-increase" onclick="changeQuantity(1, 'hikashop_product_option_qty_<?php echo $i; ?>', <?php echo $optionInfo->product_max_per_order; ?>)">+</button>
</div>
<input type="text" class="hikashop_product_quantity_field" id="hikashop_product_option_qty_<?php echo $i; ?>" name="hikashop_product_option_qty[<?php echo $i; ?>]" onchange="hikaProductOptions.change();" value="1" />

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
3 months 1 day ago #363261

Hi,

Well, if you want to take into account the max per order and the stock, you need more complex PHP code.
Something like that for example:

echo min($optionInfo->product_max_per_order, $optionInfo->product_quantity);

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

  • Posts: 412
  • Thank you received: 9
  • Hikaserial Subscription Hikashop Business
3 months 6 hours ago #363287

Hi Nicolas,
I just see your message thanks..
I managed to set the alert.. but differently as you suggested.
After a little headache struggle i saw i set the newvalue=1 i tackled that one in my script.
[code
]if (newValue < minQuantity) {
alert('You cannot purchase less than ' + minQuantity + ' units of this product.');
newValue = minQuantity; // Set to min limit if below
}
// Check if the new value exceeds the maximum allowed quantity
else if (newValue > maxQuantity) {
alert('You cannot purchase more than ' + maxQuantity + ' units of this product.');
newValue = maxQuantity; // Set to max limit if exceeded
}[/code]
It now works like i want, super thanks again..

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

Time to create page: 0.088 seconds
Powered by Kunena Forum