Mandantory content in custom field on table item is not copied on renewal

  • Posts: 8
  • Thank you received: 1
2 years 11 months ago #332859

-- HikaShop version -- : 4.4.2
-- Joomla version -- : 3.1.2
-- PHP version -- : 7.4.18

We are since years a happy customer of hikashop and hikaserial :)
Lastly we added hikasubscription to our shop to provide some subscription services, obviously.

While configuring and testing the features we encountered a problen, that we could not solve so far:
We created a subscription plan and assigned it to a product.. The relation type is "creation then renewal".
Ordering a subscription of this product assignes a mandantory field (type text) to the ordered product which must be filled with licensing information by the customer.

The order and activation of this subscription works fine so far. But whenever we try to renew a subscription we face an error which states that information which is required for the product is missing. It displays the error message of our mandantory custom field.

Any idea of how to solve this?

We expect that any information (even from custom fields) gets copied to the renewal order.

Thanks in advance for your kind support and speedy help.

Sven Mitscherlich
CamModelTools

Last edit: 2 years 11 months ago by sven.mitscherlich.

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
2 years 11 months ago #332877

Hello,

What kind of "renewal" are you talking about ? An automatic (recurring) or a manual one ?

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 8
  • Thank you received: 1
2 years 11 months ago #332898

At the moment we only want to use manual renewal.
During my tests this happens when I click on Renew in frontend in subscription listing.

The problem is, that the information in the field is needed to activate a temporary license for the usage of our software.

Thanks for your support.

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
2 years 11 months ago #332915

Hello,

The manual renewal do not use the original order (or its content) ; it just list the possible products which provide renewal for a subscription.
So there is not possibility of custom field management with manual renewals.

So for such configuration, you should use two products.
One for the creation (which will have your required custom field) and another for the renewal.
During the creation of the subscription, the content of your custom field should be copy into the subscription (via a custom plugin) so the information will persist there.
And the renewal will extend the subscription without changing the content of the subscription field.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 8
  • Thank you received: 1
2 years 11 months ago #332929

Thanks so far for guiding me in the right direction :)
Before I start to write a new plugin, I want to share my idea and questions.
Is it correct if I suppose that the event onBeforeSubscriptionUpdate gets fired while renewal (just before the reneval gets executed)?
Is it correct if I suppose thate the optimal event to get the information of my custom field is onSubscriptionActivation?

Where to store this data? In hikaserial_subscription.subscription_extradata?

If I understand the event handling right, then it might be possible to save the value of our custom field when the payment gets approved and the subscription gets activated. This would also make it possible to feed the field value to the new order created for renewal ...

If these assumptions are not correct then please give me some hints on how to implement that custom plugin. I have already read the corresponding technical documentation and tried to understand the both template plugins (acymailingsubscriber and groupsubscriber) but I have to admit that my native language is not php I speak and understand much better C# ... lol ...

Thanks again for your support
Sven Mitscherlich

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
2 years 11 months ago #332938

Hello,

1 - Yes the trigger "onBeforeSubscriptionUpdate" is called before a subscription is modified.
From a manual modification in the backend, from a customer action, a renewal, etc.

2 - The trigger onSubscriptionActivation is triggered after an action on a subscription.
The trigger onAfterSubscriptionCreate will be better since it's before the creation of a subscription and you are sure that the subscription object is in creation state.
The activation trigger is made for all subscription modification on an active subscription (including renewals).

3 - Yes, the extradata is the best place to store extra information which will be kept in the subscription.
Extra data can be seen and modified in the backend and otherwise, be handled by plugins.
The system is flexible and allow you to store whatever you want.

4 - During the subscription creation, you have access to the order which made that creation possible, so you have access to its content, including the product and its custom field value.

The current subscription plugins are not working with custom field or products.
If you look at the HikaSerial order class, you will find the function "createOrderSubscription". That function create a subscription based on an order object. You'll see that the subscription receives an array of orders with just one order for its creation.
That object contains the full HikaShop order content, with the order products and custom fields.

I'm a C (and Asm) programmer at start :)


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: sven.mitscherlich

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

  • Posts: 8
  • Thank you received: 1
2 years 10 months ago #332949

Hello Jerome,
thanks for your help!! ... I think I can now start to implement my special plugin. I hope you don't mind if I continue to ask questions if any further problem comes up (hopefully not). I let you know how it works out and how far I came with my implementation.

Jerome wrote: Hello,
(...)

I'm a C (and Asm) programmer at start :)
(...)


Seems you like it the hard way ... back to the roots :))


Greets
Sven

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

  • Posts: 8
  • Thank you received: 1
2 years 10 months ago #333015

Hello Jerome,
... sorry, but I am a complet php noob :)
can you please put light on my knowledge and tell me please on how to access the order and the order_products objects within a plugin??
I tried as good as possible to find out but to no avail ... sry.

Again thanks in advance for your help
Sven

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
2 years 10 months ago #333016

Hello,

4 - During the subscription creation, you have access to the order which made that creation possible, so you have access to its content, including the product and its custom field value.

If you take the onBeforeSubscriptionCreate trigger, you have the subscription object in parameter.
CF : www.hikashop.com/support/documentation/1...resubscriptioncreate

If you want to know the full content, the easier is to use a "var_dump" on the variable and you'll see the full content of the variable (object and sub objects).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: sven.mitscherlich

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

  • Posts: 8
  • Thank you received: 1
2 years 10 months ago #333035

Hello Jerome,
thanks for the hint in the right direction. Now all is simple :) and is working like a charm!!

For the community and as a reference I share the php code of that little plugin. It is really easy to adapt it to any need.

<?php
/**
 * @author     CamModelTools
 * @copyright  (C) 2021-2021 CamModelTools. All rights reserved.
 * @license    GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');

class plgHikaserial<nameofplugin> extends hikaserialPlugin {
	protected $type = 'ext';
	protected $multiple = false;
	protected $name = '<nameofplugin>';

	public function onBeforeSubscriptionCreate(&$subscription, &$do) {
		/* echo '<pre>'; var_dump($subscription->orders[0]->cart->products[0]->name_of_extra_field); echo '</pre>'; */
		$special_data = @$subscription->orders[0]->cart->products[0]->name_of_extra_field;
		if(!empty($special_data))
		{
			if(empty($subscription->subscription_extradata))
				$subscription->subscription_extradata = array();
			$subscription->subscription_extradata['name_of_extra_field'] = $special_data;
		}
	}
}

Replace <nameofplugin> with the name of the plugin; replace name_of_extra_field with the name of your user defined field.

This boilerplate code works with user defined fields on item level.

I hope it will be of any help.
Thx
Sven

Last edit: 2 years 10 months ago by Jerome. Reason: Little improvements

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
2 years 10 months ago #333047

Hello,

Thanks for the share !
I modified just a bit your code in ordre to improve the serialization of the extra data.

Please note that by using "products[0]" you're accessing the first product of the order.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: sven.mitscherlich

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

Moderators: Obsidev
Time to create page: 0.075 seconds
Powered by Kunena Forum