Plugin trigger when moving on from basket?

  • Posts: 106
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
6 days 4 hours ago #368737

Is it possible to make a plugin trigger when moving on from the basket to the next step in the checkout ? I need an age verification plugin to trigger, I can make it work when entering the checkout, but I would like the customer to be able to remove products that needs age verification, if they regret filling them in the basket and only want products that do not need verification - is that possible ?

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

  • Posts: 84435
  • Thank you received: 13733
  • MODERATOR
4 days 13 hours ago #368742

Hi,

Before answer on what would be appropriate to do that, could you tell us what kind of age verification you wish to implement ? Someone like providing an upload field to upload a scan of an identity card / password with a manual verification of age ? Or just a checkbox with a label "I am more than XX years old", or something else ?
Or do you have some kind of Joomla age verification extension you would like to use ?
Wouldn't this make sense to have that check on the registration form ? That way the user would do it once, and then it would be automatically taken into account for orders in the future ?

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

  • Posts: 106
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
4 days 12 hours ago #368747

It is a third party privider of digital age verification that this pælugin integrates with, so nothing to upload or enter. The user just gets redirected to this verfication and then back to the same page where a session variable is then set to true.

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

  • Posts: 84435
  • Thank you received: 13733
  • MODERATOR
4 days 9 hours ago #368750

Hi,

Ok. There are several events already available on the checkout:
www.hikashop.com/support/documentation/6...tation.html#checkout
For example, with onCheckoutWorkflowLoad you can check if the age verification has been done. If not, redirect to that verification mechanism, and then redirect back to the URL you were before once done.
So it seems to me it would be the one to use in this case.

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

  • Posts: 106
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
4 days 8 hours ago #368751

Ok - and from the onCheckoutWorkflowLoad trigger - is it still possible to get all the products in the basket ? I need to check if they are in categories that needs verification (only categories selected in the plugin must be age verified)

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

  • Posts: 84435
  • Thank you received: 13733
  • MODERATOR
4 days 5 hours ago #368753

Hi,

Yes. As explained on the documentation of that event, the $cart_id is provided. So you can easily load the cart.
For example:

$cartClass = hikashop_get('class.cart');
$cart = $cartClass->getFullCart($cart_id);
Then, you'll have access to the products in the cart in the $cart->products array.

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

  • Posts: 106
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
4 days 1 hour ago #368766

Hmm.. how can I determine which workflow step I am on? I need to redirect right after moving to the next step after the basket view.

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

  • Posts: 84435
  • Thank you received: 13733
  • MODERATOR
3 days 13 hours ago #368767

Hi,

You can get the step number with this code:

$step = hikashop_getCID('step');

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

  • Posts: 106
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
3 days 2 hours ago #368790

Hmm.. I can't seem to intercept the step between step 0 and 1. If I redirect on step 1, then i cannot delete the content in the basket ?? How would I do this. I want the user to be able to delete what is in the basket, but if the user moves on to the next step, then he must be redirected to the age verification mecanism..

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

  • Posts: 84435
  • Thank you received: 13733
  • MODERATOR
2 days 13 hours ago #368801

Hi,

Check the content of $_POST. That way, you can see if the cart is being changed or not. And if not, then you can redirect.

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

  • Posts: 106
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
2 days 4 hours ago #368834

I try to use this in the onCheckoutWorkflowLoad function:

$input = Factory::getApplication()->input;
$post = $input->post->getArray()

But what should I check for to know if this is a deletion of a product and not a move to the next step ?

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

  • Posts: 84435
  • Thank you received: 13733
  • MODERATOR
1 day 23 hours ago #368835

Hi,

You want to do something like this:

// get the cart data from the POST
$data = hikaInput::get()->get('checkout', array(), 'array');
// check that the products quantities are there
if(empty($data['cart']))
	return true;
if(empty($data['cart']['item']))
	return false;
// get the cart from the database
$checkoutHelper = hikashopCheckoutHelper::get();
$cart = $checkoutHelper->getCart();

// compare the quantities from the POST in $data['cart']['item'] and the quantities in the cart in $cart->products
// if they are the same, the cart has not ben changed and thus you can redirect
// if they are not the same, and the products requiring the verification are being removed, you want to let the process continue
// if they are not the same, and the products requiring the verification are not being removed, you want to let the process continue so that the change can be taken into account, add a flag, and implement onAfterCartSave where you can then do the redirection if the flag is present

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

  • Posts: 106
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
7 hours 49 minutes ago #368864

It seems that hikaInput is not available in the onCheckoutWorkflowLoad scope?

Last edit: 7 hours 27 minutes ago by rbuelund.

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

  • Posts: 84435
  • Thank you received: 13733
  • MODERATOR
4 hours 32 minutes ago #368866

Hi,

It is. hikaInput is a class defined when the main helper file of HikaShop is loaded.
And if the hikashop plugins are loaded and the event onCheckoutWorkflowLoad is triggered, then HikaShop has to be loaded already and thus the class hikaInput exists.
However, PHP introduced namespaces a while back and many Joomla plugins use that feature.
If you do in your plugin, then you want to add a \ before hikaInput in the code. Otherwise, PHP will search the hikaInput class in your plugin namespace, not in the main namespace where HikaShop defines it.
Example 1 here www.php.net/manual/en/language.namespaces.basics.php presents this case.

Last edit: 7 hours 32 minutes ago by nicolas.

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

Time to create page: 0.077 seconds
Powered by Kunena Forum