programmatically set extra fields value

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
2 years 9 months ago #339805

-- HikaShop version -- : 4.5.0
-- Joomla version -- : 3.10.6
-- PHP version -- : 7.4.3
-- Browser(s) name and version -- : Chrome 90.0.4430.212

Hello,
is there the possibility to set the value for extra fields programmatically via php?

I have managed extra fields for order, and i want to set their value on checkout page based on the user logged in. Those data are stored for user in a third party backend.

Thank you

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
2 years 9 months ago #339806

Hi,

It's possible.
What to do exactly depends on what your goal is.
If it is to set the value of a custom field of the table "order" when the order is being created, then it's quite easy. You can implement the onBeforeOrderCreate(&$order, &$do) event in a plugin of the group "hikashop" and just add the data like so:
$order->xxx = 'yyy';
where xxx is the column name of the field and yyy the value you want to set.

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
2 years 9 months ago #339815

thank you,
the goal is to set value to custom fields (order table) while they are shown in checkout page (show_block_fields)
is it possibile?

with your code i think the value is set only after user click "Confrm button" on checkout page, but my custom fields are shown in that page and i want to set a default value for they, and let user change it if he wants to.

thank you

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

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
2 years 9 months ago #339818

Hi,

In that case, you can implement the event onAfterCartProductsLoad(&$cart)
And you can use this code:
$cart->cart_fields->xxx = 'yyy';
Note that you'll want to check if that value is not empty before doing this so that you don't overwrite what the user selected/entered in the field since this event will be called each time the cart is loaded from the database (so on every page of the checkout, and every page where the cart module is displayed).

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
2 years 9 months ago #339829

ok thank you
i tried to create a plugin w/ group "hikashop" implementing JPlugin with:

function onAfterCartProductsLoad(&$cart) {
$cart->cart_fields->xxx = 'yyy';
}

but it is never invoked! am I wrong?

thanks

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
2 years 9 months ago #339831

ok i manage to resolve my problem!
thank you very much for support

The following user(s) said Thank You: nicolas

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

Time to create page: 0.061 seconds
Powered by Kunena Forum