Custom fields in order variable

  • Posts: 71
  • Thank you received: 0
9 years 1 month ago #216446

-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.1

Hi,

I'm modifying the plugin we wrote to send order information to our invoicing platform so that discount information is also sent. To this effect I have created 2 custom fields (flo_discount and flo_originalprice) in the item table (see screenshot attached). I want to save the discount and original price information in these two fileds by setting them on the corresponding products in the order variable passed by the onBeforeOrderCreate function. When I look for these fields, they ar not found in the cart->products array, but only under cart->shipping_groups->products (see variable dump attached). Is this correct? If so, why?

Thanks for clarifying!

Michel

Attachments:

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

  • Posts: 82866
  • Thank you received: 13373
  • MODERATOR
9 years 1 month ago #216472

Hi,

That's because the "frontend" setting is disabled for these custom fields so the system is not saving them when the order is being created.
If you want to manually set them in the onBeforeOrderCreate function of a plugin, you want to set them in the cart->products array

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

  • Posts: 71
  • Thank you received: 0
9 years 1 month ago #216609

Hi Nicolas,

Thanks for the reply.
I have changed the "frontend" setting to visible and set the access level to none (because I don't want these fields to be displayed on the frontend, they only serve to keep the original price and discount info). I was now able to update the order variable in the onBeforeOrderCreate function (see order_updated_dump.txt). However I can't acces this information in the on AfterOrderUpdate, where the order information is transmitted to our invoicing platform. I get the order information as follows:

$orderClass->loadFullOrder($order->order_id, false, false)

However, here the custom fields are empty (see fullorder_dump.txt) and they are also empty in the DB. So how can I access the values of my custom fields so I can use them for transferring to our invoicing platform?

Thanks
Michel

Attachments:

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

  • Posts: 82866
  • Thank you received: 13373
  • MODERATOR
9 years 1 month ago #216615

Hi,

I don't see why that wouldn't work.
So there must be an issue with your code.
For example, if you didn't add the & before the $order parameter of the onBeforeOrderCreate function definition.
Do you get the data in the fields in the hikashop_order_product table after the order is stored in the database ?

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

  • Posts: 71
  • Thank you received: 0
9 years 1 month ago #216704

Hi Nicolas,

yes, the order variable is passed by reference. No I can't see any data stored in the DB
I have attached a code file of the onBeforeOrderCreate function (only 46 lines) and would be very grateful if you could have a look.

Many thanks,
Michel

Attachments:

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

  • Posts: 71
  • Thank you received: 0
9 years 1 month ago #216796

Hi Nicolas,

I found out, that the custom fields need to be visible on the website to be taken into account. It doesn't work if I set the "frontend" setting to visible and set the access level to none. The access level must be "all", but this causes the fields to show on the frontend and I don't want that. So back to square one... How can I save the discount and original price information for later use in the AfterOrderUpdate function?

Thanks,
Michel

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 1 month ago #216797

Hi,

That's right, the "order_product" class does not authorize the modification of custom fields like that.
There is a filtering system in the "save" function.

So I suggest you to use the "onAfterOrderCreate" trigger and update manually your "order_product" in the database.
You will find the "order_product_id" data in the $order->cart->products 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.

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

  • Posts: 71
  • Thank you received: 0
9 years 1 month ago #216825

Hi,

Yes, but is the information I need (discount und original price that was applied per product) available in he "onAfterOrderCreate" trigger? That was the whole point, why it had to be done in "onBeforeOrderCreate"...

Thanks,
Michel

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 1 month ago #216828

Hi,

I didn't tell you to not use the "onBeforeOrderCreate" trigger ; I told you to also use the "onAfterOrderCreate" to store the data in the database.
The order object will be the same, you can still put your data during the "onBeforeOrderCreate" but it won't be saved by the "order_product" class (like I explained).
So you have to use the "onAfterOrderCreate" to perform that saving operation.

Is that more clear ?

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: bmichu

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

  • Posts: 71
  • Thank you received: 0
9 years 1 month ago #216884

Hi,

Thanks, now it works!

Michel

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

Time to create page: 0.081 seconds
Powered by Kunena Forum