Validate a Custom Checkout Field

  • Posts: 62
  • Thank you received: 0
12 years 2 weeks ago #73186

I have created a plugin that makes use of several REST services. An additional HikaSerial generator plugin makes use of these REST services to generate serial numbers.

In the HikaShop checkout I have a custom filed which allows people to provide an existing serial number instead of generating a new one. All works except I would like to do some validation on the number provided by calling some functions from my REST service plugin at the point of entry rather than when the generator plugin is called. I am just not sure where I should be doing this validation.

Can you please provide some guidance.

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 2 weeks ago #73438

You can edit the file "fields" of the view "checkout" via the menu Display->Views and add your check on the array $this->order.

If the data is not correct, you can set the 'com_hikashop.checkout_fields_ok' and "checkout_fields" values in the session back to empty and display an error message with a $app->enqueueMessage so that your user is warned of the problem and redirect the user to the previous step of the checkout (if necessayr based on your checkout workflow).

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

  • Posts: 62
  • Thank you received: 0
12 years 2 weeks ago #73646

Thanks for your reply I just have two questions:

  1. My Checkout workflow has the fields view as a separate step as follows. login_address_shipping_coupon,fields,payment_terms_confirm_cart_status,end. If I add the check to the 'fields' view it only loads before the fields are poulated. Should I therefore add the check to the 'payment' view?
  2. How do I set the com_hikashop.checkout_fields_ok and checkout_fields values and then redirect to a previous step?.

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 2 weeks ago #73845

1. Yes, you should add your check in one of the views of the step after your fields step.

2. It's a joomla session variable. So like any joomla session variable:
$app = JFactory::getApplication();
$value = $app->getUserState('com_hikashop.checkout_fields_ok');
$value = 0;
$app->setUserState('com_hikashop.checkout_fields_ok',$value);

Redirects are also something standard in Joomla:
$app = JFactory::getApplication();
$app->redirect('URL_WHERE_TO_REDIRECT');

The following user(s) said Thank You: Devine

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

  • Posts: 62
  • Thank you received: 0
12 years 1 week ago #73910

Hello, Thanks for your help thus far but I am still not quite there yet. Because the fields view is separate from my payment view the custom fields or order class are not available. What do I need to load to have the checkout fields available in the payment view?

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 week ago #73933

You don't need the fields options in order to use them.

You can just tap directly in $_REQUEST or in the com_hikashop.checkout_fields sessions variable. For example:
$app = JFactory::getApplication();
$fields = $app->getUserState('com_hikashop.checkout_fields');
echo $fields->MY_CUSTOM_FIELD_COLUMN_NAME;

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

Time to create page: 0.060 seconds
Powered by Kunena Forum