onHikashopBeforeDisplayView in checkout address

  • Posts: 120
  • Thank you received: 2
5 years 5 months ago #299850

-- HikaShop version -- : 4.0.0
-- Joomla version -- : 3.8.10
-- PHP version -- : 7

Hi dear
1: I need developing custom hikashop plugin an using onHikashopBeforeDisplayView trigger for display my data so I need if view is checkout address part display my data but can't found which code using in onHikashopBeforeDisplayView for recognition address view. How can do it?
2: If add custom text input in checkout form by using onHikashopBeforeDisplayView or onCheckoutStepDisplay after submit checkout form which plugin trigger I can get my input data?
thank you.

Last edit: 5 years 5 months ago by kaya.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
5 years 5 months ago #299861

Hi,

The trigger onHikashopBeforeDisplayView has a variable &$view
To get the current controller, you can use $view->ctrl
To get the current task, you can use $view->getLayout()
To get the current step, you can use $view->step
To get the current position, you can use $view->module_position
To get the options of the current view, you can use $view->options
So basically, you can have such code so that you skip your code if you're not in the checkout:
if($view->ctrl != 'checkout' || $view->getLayout() != 'show') return;

Supposing that you add your input fields in the address view form, you can use the onAfterAddressCreate and the onAfterAddressUpdate triggers to check the data in $_POST.

We use something similar with the recaptcha plugin which adds the catpcha in the registration form of the "login" view with the onHikashopBeforeDisplayView trigger and then checks the captcha in the onUserBeforeSave trigger called before the new user is being created.
www.hikashop.com/support/documentation/7...-with-recaptcha.html

The following user(s) said Thank You: kaya, oxido

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

  • Posts: 120
  • Thank you received: 2
5 years 5 months ago #299904

thank you dear Nicolas
we add custom input in checkout page using onCheckoutStepDisplay and can not get $_POST data in any plugin trigger after submit checkout form. only when add input in address part get data whit onAfterAddressCreate or onAfterAddressUpdate but my input not in address I need get value in another plugin trigger to save data in database and use my data in my project after submit order.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
5 years 5 months ago #299908

Hi,

Well, I still don't know what goal you have in doing that. So I can't say for sure what would be the best.
Alternatively, if you don't want to attach your input field to any pre existing form of the checkout, you can use the checkout API of HikaShop to create your own view that you can add to the checkout workflow.
www.hikashop.com/support/documentation/6...tation.html#checkout
You can use the plugins/hikashop/user_points/ plugin as an example as it implements that API to add its own user points view to the checkout. Thanks to that API, you'll be able to display whatever you want, and you'll also be called by the checkout system when the block or the page where the block is are submitted so that you'll be able to find your input data in $_POST.

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

  • Posts: 120
  • Thank you received: 2
5 years 5 months ago #299936

Than you Dear Nicolas
I can get my data but we have a problem in each checkout step trigger onAfterCheckoutStep called twice my controller. we add this code top of onAfterCheckoutStep

if($controllerName != 'plg.shop.mycontroller') return false;
but my controller called twice in each step. How can called only once? I checked user_points plugin on this plugin controller called once in each checkout step.what is my problem?

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
5 years 5 months ago #299938

Hi,

When the view is submitted in ajax it is called once so that it can get the data from the view.
When the whole step is submitted, it is called once so that it can get the data from the view. Also, if all the views of the step tell the checkout that it's ok and it can move to the next step, the checkout will call again that trigger on the views of all the steps prior to the new current step so that they can check that they have the correct data.
So the user_points plugin should also be called twice when you click on the "next" or "finish" button on a step where this plugin displays its view.
So there is no problem. It's just the normal way it works.

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

Time to create page: 0.065 seconds
Powered by Kunena Forum