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

#   order\_discount\_price not saved to db when using discount - only with coupons

##

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

Less More

- Posts: 88
- Thank you received: 20
-
-

8 years 11 months ago [\#283429](#283429) by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile")  *[order\_discount\_price not saved to db when using discount - only with coupons](/forum/31-development/892963-order-discount-price-not-saved-to-db-when-using-discount-only-with-coupons#283429 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2  Hi  I'm expanding a custom plugin that saves orders as an xml file using onAfterOrderUpdate. I would like to calculate the discount amount as a percentage of the order price. I can do that with coupon codes as order&#95;discount&#95;price is saved to the database. This is however not the case with discounts.Why this difference?  How can I access the discount information from my plugin?  Thanks")* was created by *[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")*

-- HikaShop version -- : 3.2.1
-- Joomla version -- : 3.8.2

Hi

I'm expanding a custom plugin that saves orders as an xml file using onAfterOrderUpdate. I would like to calculate the discount amount as a percentage of the order price. I can do that with coupon codes as order_discount_price is saved to the database. This is however not the case with discounts.Why this difference?

How can I access the discount information from my plugin?

Thanks

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5Mjk2My1vcmRlci1kaXNjb3VudC1wcmljZS1ub3Qtc2F2ZWQtdG8tZGItd2hlbi11c2luZy1kaXNjb3VudC1vbmx5LXdpdGgtY291cG9ucz90bXBsPW1hcmtkb3du) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14279
-
-

8 years 11 months ago [\#283437](#283437) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[order\_discount\_price not saved to db when using discount - only with coupons](/forum/31-development/892963-order-discount-price-not-saved-to-db-when-using-discount-only-with-coupons#283437 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2  Hi  I'm expanding a custom plugin that saves orders as an xml file using onAfterOrderUpdate. I would like to calculate the discount amount as a percentage of the order price. I can do that with coupon codes as order&#95;discount&#95;price is saved to the database. This is however not the case with discounts.Why this difference?  How can I access the discount information from my plugin?  Thanks")*

Hi,

The coupons are applied globally to the cart/order.
The discounts are applied to the product prices directly. So in the order you see the product prices already with the discount applied.
Storing the discount amount in order_discount_price is not possible. Imagine if you have two discounts on two different products of the order.
Even if we were to store the data of the discounts with the order, they wouldn't be stored there. They would be stored in the hikashop_order_product table along with the products on which they apply.
The name of the columns in the database use "discount" because the coupons are actually also stored in the hikashop_discount table, but that's all.

Since the discount information is not stored with the orders for now, the best would be to implement the onAfterOrderCreate trigger in your plugin in order to get the data of the discounts in the products from the $order-&gt;cart-&gt;products array and store them yourself in some column of the hikashop_order_product table.
In fact that's something we should do in a future release of HikaShop.

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

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

Less More

- Posts: 88
- Thank you received: 20
-
-

8 years 11 months ago [\#283498](#283498) by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile")  Replied by *[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")* on topic *[order\_discount\_price not saved to db when using discount - only with coupons](/forum/31-development/892963-order-discount-price-not-saved-to-db-when-using-discount-only-with-coupons#283498 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2  Hi  I'm expanding a custom plugin that saves orders as an xml file using onAfterOrderUpdate. I would like to calculate the discount amount as a percentage of the order price. I can do that with coupon codes as order&#95;discount&#95;price is saved to the database. This is however not the case with discounts.Why this difference?  How can I access the discount information from my plugin?  Thanks")*

Got it working now, thanks! ![:-)](/media/kunena/emoticons/3.png ":-)")

Only I had to use onBeforeOrderCreate instead of onAfterOrderCreate for saving into hikashop_order.
If I were to use hikashop_order_product, how do I create custom fields there?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5Mjk2My1vcmRlci1kaXNjb3VudC1wcmljZS1ub3Qtc2F2ZWQtdG8tZGItd2hlbi11c2luZy1kaXNjb3VudC1vbmx5LXdpdGgtY291cG9ucz90bXBsPW1hcmtkb3du) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14279
-
-

8 years 11 months ago [\#283502](#283502) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[order\_discount\_price not saved to db when using discount - only with coupons](/forum/31-development/892963-order-discount-price-not-saved-to-db-when-using-discount-only-with-coupons#283502 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2  Hi  I'm expanding a custom plugin that saves orders as an xml file using onAfterOrderUpdate. I would like to calculate the discount amount as a percentage of the order price. I can do that with coupon codes as order&#95;discount&#95;price is saved to the database. This is however not the case with discounts.Why this difference?  How can I access the discount information from my plugin?  Thanks")*

You can create custom fields of the table "item" via the menu Display&gt;Custom fields.

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

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

Less More

- Posts: 88
- Thank you received: 20
-
-

8 years 11 months ago [\#283574](#283574) by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile")  Replied by *[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")* on topic *[order\_discount\_price not saved to db when using discount - only with coupons](/forum/31-development/892963-order-discount-price-not-saved-to-db-when-using-discount-only-with-coupons#283574 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2  Hi  I'm expanding a custom plugin that saves orders as an xml file using onAfterOrderUpdate. I would like to calculate the discount amount as a percentage of the order price. I can do that with coupon codes as order&#95;discount&#95;price is saved to the database. This is however not the case with discounts.Why this difference?  How can I access the discount information from my plugin?  Thanks")*

I know, but what table should I select for custom fields in hikashop_order_products table? Tried order and products, but none of those adds to hikashop_order_products table.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5Mjk2My1vcmRlci1kaXNjb3VudC1wcmljZS1ub3Qtc2F2ZWQtdG8tZGItd2hlbi11c2luZy1kaXNjb3VudC1vbmx5LXdpdGgtY291cG9ucz90bXBsPW1hcmtkb3du) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14279
-
-

8 years 11 months ago [\#283576](#283576) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[order\_discount\_price not saved to db when using discount - only with coupons](/forum/31-development/892963-order-discount-price-not-saved-to-db-when-using-discount-only-with-coupons#283576 "-- HikaShop version -- : 3.2.1 -- Joomla version -- : 3.8.2  Hi  I'm expanding a custom plugin that saves orders as an xml file using onAfterOrderUpdate. I would like to calculate the discount amount as a percentage of the order price. I can do that with coupon codes as order&#95;discount&#95;price is saved to the database. This is however not the case with discounts.Why this difference?  How can I access the discount information from my plugin?  Thanks")*

Hi,

In the onBeforeOrderCreate function of your plugin, you can simply add the data of your custom item field to each product object in the array $order-&gt;cart-&gt;products using the column name of the custom field as attribute of the product object.
Note that the "frontend" display setting of the custom field needs to be activated or the field will be skipped by HikaShop.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5Mjk2My1vcmRlci1kaXNjb3VudC1wcmljZS1ub3Qtc2F2ZWQtdG8tZGItd2hlbi11c2luZy1kaXNjb3VudC1vbmx5LXdpdGgtY291cG9ucz90bXBsPW1hcmtkb3du) 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.079 seconds

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

[](#top)
