How to use custom fields to modify quantity field

  • Posts: 11
  • Thank you received: 0
13 years 1 month ago #29281

Hi, I have just installed HS essentials and I am wondering if it is possible to alter the way that the product quantity input field behaves based on a custom field.

I have created a file in my template folder that overrides the default behaviour with a dropdown box containing options for fixed quantities of 50,100,150,200 ... and this works fine. But I would like to create a product custom field that defines what the incremental values would be.

If the value is for example,qty_range = "50;100;150;200", then the input would be a dropdown containing those values.

If the value is 0 or blank, it would default to a normal (ajax) input field.

Can I access the custom field from within the templates/TEMPLATE/html/hikashop_button.php ?

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
13 years 1 month ago #29308

If your quantity field is displayed on product pages (not on listings) then you can retrieve the custom field like that:

$productClass = hikashop_get('class.product');
$product = $productClass->get(JRequest::getInt('cid'));
echo $product->CUSTOM_FIELD_COLUMN_NAME;

where CUSTOM_FIELD_COLUMN_NAME is the column name of your custom field.

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

  • Posts: 11
  • Thank you received: 0
13 years 1 month ago #29313

Thanks Nicolas - that works perfectly!

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

  • Posts: 12
  • Thank you received: 0
10 years 11 months ago #139225

nicolas wrote: If your quantity field is displayed on product pages (not on listings) then you can retrieve the custom field like that:

$productClass = hikashop_get('class.product');
$product = $productClass->get(JRequest::getInt('cid'));
echo $product->CUSTOM_FIELD_COLUMN_NAME;

where CUSTOM_FIELD_COLUMN_NAME is the column name of your custom field.


When you do it like this, does the system actually use the number from the custom field as if it was input in the normal input box? For instance, if I create a custom drop down with exact predetermined quantities, will it treat the value of the selected drop down (if it's a number) as normal (that way it will calculate the weight for shipping and the total cost and all that)? To put it in programmer terminology, will it populate the quantity field for the cart DB table with the value of the custom field (again, obviously only if the value of the custom field selection is a number or integer or whatever)?

Last edit: 10 years 11 months ago by printco.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
10 years 11 months ago #139239

No it won't. If you want to replace the quantity box by a dropdown with predefined values, you should do it like that instead:
www.hikashop.com/forum/4-how-to/15254-re...uantity-ordered.html

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

  • Posts: 12
  • Thank you received: 0
10 years 11 months ago #139241

I don't want this to be a global change. We are selling different items at different preset quantities. What WOULD be helpful is if we could set up a custom field to do this for us (that way I can set up multiple custom fields with the different preset quantities), or if we could assign the different dropdown preset quantities based on categories or something along those lines.

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

  • Posts: 12
  • Thank you received: 0
10 years 11 months ago #139245

nicolas wrote: If your quantity field is displayed on product pages (not on listings) then you can retrieve the custom field like that:

$productClass = hikashop_get('class.product');
$product = $productClass->get(JRequest::getInt('cid'));
echo $product->CUSTOM_FIELD_COLUMN_NAME;

where CUSTOM_FIELD_COLUMN_NAME is the column name of your custom field.


It seems to me like you should only have to add on like one more line of code on to this ^^^ code to tell it to retrieve the value for the selected drop down choice and assign it to the quantity variable -> then add that value to the quantity column in the DB when you click on the button.

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
10 years 11 months ago #139340

You can do that with a product quantity override plugin:
www.hikashop.com/support/support/documen...tation.html#override
You can see an example of such plugin here:
demo.hikashop.com/index.php?option=com_h...ct&task=show&cid=214

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

Time to create page: 0.078 seconds
Powered by Kunena Forum