[Skip to main content](#vessel-content)

#   onBeforeOrderCreate plugin to add product.

##

- **[consultech](/forum/user/13290-consultech "View consultech's Profile")**
- [![consultech's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13290-consultech "View consultech's Profile") Topic Author
- [ Offline](/forum/user/13290-consultech)

Less More

- Posts: 54
- Thank you received: 2
-
-

12 years 9 months ago [\#143685](#143685) by [consultech](/forum/user/13290-consultech "View consultech's Profile")  *[onBeforeOrderCreate plugin to add product.](/forum/31-development/865801-onbeforeordercreate-plugin-to-add-product#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&#95;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-&gt;update(product&#95;id,quantity), the cart contain the new added product but not the order.  why ? it's before order create no ?  Thanks !")* was created by *[consultech](/forum/user/13290-consultech "View consultech's Profile")*

-- 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-&gt;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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2NTgwMS1vbmJlZm9yZW9yZGVyY3JlYXRlLXBsdWdpbi10by1hZGQtcHJvZHVjdD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

12 years 9 months ago [\#143755](#143755) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[onBeforeOrderCreate plugin to add product.](/forum/31-development/865801-onbeforeordercreate-plugin-to-add-product#143755 "-- 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&#95;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-&gt;update(product&#95;id,quantity), the cart contain the new added product but not the order.  why ? it's before order create no ?  Thanks !")*

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-&gt;products and recalculate the $order-&gt;order_full_price of the order yourself.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2NTgwMS1vbmJlZm9yZW9yZGVyY3JlYXRlLXBsdWdpbi10by1hZGQtcHJvZHVjdD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[consultech](/forum/user/13290-consultech "View consultech's Profile")**
- [![consultech's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13290-consultech "View consultech's Profile") Topic Author
- [ Offline](/forum/user/13290-consultech)

Less More

- Posts: 54
- Thank you received: 2
-
-

12 years 9 months ago [\#143791](#143791) by [consultech](/forum/user/13290-consultech "View consultech's Profile")  Replied by *[consultech](/forum/user/13290-consultech "View consultech's Profile")* on topic *[onBeforeOrderCreate plugin to add product.](/forum/31-development/865801-onbeforeordercreate-plugin-to-add-product#143791 "-- 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&#95;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-&gt;update(product&#95;id,quantity), the cart contain the new added product but not the order.  why ? it's before order create no ?  Thanks !")*

Thank you for your clarifications.

Regards,

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg2NTgwMS1vbmJlZm9yZW9yZGVyY3JlYXRlLXBsdWdpbi10by1hZGQtcHJvZHVjdD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.052 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
