onBeforeOrderCreate plugin to add product.

  • Posts: 54
  • Thank you received: 2
  • Hikaserial Subscription Hikashop Business
10 years 9 months ago #143685

-- HikaShop version -- : 2.2.3
-- Joomla version -- : 2.5.x
-- PHP version -- : x.x.x
-- Browser(s) name and version -- : XXXXX x.x.x
-- Error-message(debug-mod must be tuned on) -- : Error_message

Hello,

I build a plugin : the idea is to add a hidden product into the current cart when, during the checkout an option (custom field order) is checked in additonal information.

with onBeforeOrderCreate I've no problem to verify if this option is checked and in this case, add product with php code $cartClass->update(product_id,quantity), the cart contain the new added product but not the order.

why ? it's before order create no ?

Thanks !

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

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
10 years 9 months ago #143755

Hi,

The first parameter of the onBeforeOrderCreate is the content of the order which is going to be saved just after that function. At that point, the cart has already been converted into the order object of the first parameter. So changing the cart content at that point has no influence on that object as the conversion between the cart and the order object has already been done before.
So if you want to use that trigger, you'll have to add your product in $order->products and recalculate the $order->order_full_price of the order yourself.

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

  • Posts: 54
  • Thank you received: 2
  • Hikaserial Subscription Hikashop Business
10 years 9 months ago #143791

Thank you for your clarifications.

Regards,

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

Time to create page: 0.056 seconds
Powered by Kunena Forum