The empty required custom fields on product not pops error when add to cart

  • Posts: 628
  • Thank you received: 18
  • Hikashop Business
4 years 4 months ago #325173

-- HikaShop version -- : 4.4.0
-- PHP version -- : 7

Hello,

I had to modify the view "product/show_quantity" to do specific things. I did that under Hikashop 3. In that version, I was able to set manually "custom fields" as required on the product pages. So, when trying to add to cart, if those fields wasn't fill, an error was shown.

To do this manually, I was adding an array containing the name of my required fields under Javascript to this variable:
window.hikashopFieldsJs

I was able to set my error message to by filling this variable:
window.hikashopFieldsJs

For now, using Hikashop 4.4.0, this is no more working. How can I achieve this now?

Thanks

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

  • Posts: 4816
  • Thank you received: 654
  • MODERATOR
4 years 4 months ago #325193

Hello,

Sorry but there are things that we didn't get, in details by default with HikaShop when a Item custom field is required, you have already a warning error if customer process without define it.

Sorry for this return, but from this we aren't sure to understand what you to achieved, and so aren't able to guide you so far.
Can you provide more elements like :
- Your custom field configuration screenshot
- A concrete example case with step by step process
- And why this popup isn't enough for your needs ?



Awaiting news from you to better help you.
Regards

Last edit: 4 years 4 months ago by Philip.

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

  • Posts: 628
  • Thank you received: 18
  • Hikashop Business
4 years 4 months ago #325221

Hello Philippe,

Yeah, it's hard to explain. There is more detail.
I created around 20 custom fields to get phone numbers. I configured these fields as NOT required on the backend configuration.



In the front-end, on the product page, I created a custom version of the view "product/show_quantity". By default, I only show the first custom field. If the user need more, he can change the quantity. If he choose 3 per example, I show two more custom fields.

So, I only want custom fields that are shown to be required. It's why I didn't set these custom fields as required into the custom field configuration. I do it manually in my custom version of "product/show_quantity".

So, when I set a field to be required:
  • I add an asterisk at the end of the textbox;
  • I add the custom field name into an array;
When all my custom fields are in the array, I assign this array to the following array variable:
window.hikashopFieldsJs['reqFieldsComp']['item']

With that, when I clic add to cart button, if one field are not feeded, Hikashop show me an alert about the required field.
It was working well on Hikashop 3, but it is no more working with Hikashop 4.4.0.

How can I achieve this?

BTW, the "HikaShop Cart notification Plugin" is disabled.

Thanks

Attachments:

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

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

Hi,

That's because with HikaShop 4.4, we removed the "add to cart legacy" setting.
And your javascript code for window.hikashopFieldsJs is only used by the legacy add to cart system, which has been removed.
So your add to cart buttons are now using the new add to cart system, and thus you need to do the check yourself.
You have two options:
- you implement the fields API as explained on our developer documentation as a custom hikashop plugin to create a new type of custom fields extending from the "text" type so that you can do your own check. You can see an example of a custom field type plugin in plugins/hikashop/datepicker_field/
I believe it will be a lot more complex for you
- you edit add_to_cart_ajax.php (for listings) and quantity.php (for the product page) to add a call to your own javascript function in the onclick attribute of the add to cart link before it calls the window.hikashop.addToCart function which will do the normal add to cart.
That second option will be way simpler to implement, especially if you're not familiar with Joomla plugins development.

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

  • Posts: 628
  • Thank you received: 18
  • Hikashop Business
4 years 4 months ago #325285

Hi Nicolas,

Thanks for the information, I did the modification and it works.

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

Time to create page: 0.073 seconds
Powered by Kunena Forum