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

#   Updating Order Details Not Accurate

##

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

Less More

- Posts: 56
- Thank you received: 1
-
-

3 years 7 months ago [\#350599](#350599) by [jiawen](/forum/user/68179-jiawen "View jiawen's Profile")  *[Updating Order Details Not Accurate](/forum/35-orders-management/906177-updating-order-details-not-accurate#350599 "Using a sales component, which the new record submitted, will append a hikashop order using ($orderClass = hikashop&#95;get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true,...")* was created by *[jiawen](/forum/user/68179-jiawen "View jiawen's Profile")*

Using a sales component, which the new record submitted, will append a hikashop order using ($orderClass = hikashop_get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true, false); $orderClass-&gt;save($fullOrder)![;)](/media/kunena/emoticons/24.png ";)"). It is working fine when adding new record, but comes to edit the existing component record, the order details are updated correctly except the order_full_price. The field order_full_price not able to updated. Even there is value when running the save function. Any suggestion to solve this?

The code for update hikashop order details when editing record is as follows: Code:

if (!empty($array['custom_field5'])) { //if is update record $orderId = $array['custom_field5']; $orderClass = hikashop_get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true, false); //$orderObj = new stdClass(); $fullOrder-&gt;order_billing_address_id = $array['customer']; $fullOrder-&gt;order_shipping_address_id = $array['customer']; $fullOrder-&gt;order_user_id = $customerID; $fullOrder-&gt;order_status = 'confirmed'; $fullOrder-&gt;order_type = 'sale'; //update full price //$orderObj-&gt;order_full_price = $array['total_value']; $fullOrder-&gt;receipt = $receiptFile; $fullOrder-&gt;branch = $array['record_branch']; $fullOrder-&gt;source = $array['record_source']; foreach ($fullOrder-&gt;products as $product) { $class = hikashop_get('class.order'); JRequest::setVar('order_id', $fullOrder-&gt;order_id); JRequest::setVar('order_product_id', $product-&gt;order_product_id); $class-&gt;saveForm('product_delete'); } $productarray = array(); if (isset($array['product']) &amp;&amp; $array['product'] != "") { // calculate the order full price $finalPrice = 0; $discount = 0; foreach ($array['product'] as $key =&gt; $value) { $data = Dt_salesHelper::ProductDetail($value["productsname"]); $product = new stdClass(); $write['data'] = $data; //check if shipping item $shipping_id = $data-&gt;shipping_id; if (!empty($shipping_id)) { $write['shipping_id'] = $shipping_id; $db = JFactory::getDbo(); $query = $db-&gt;getQuery(true); $query -&gt;SELECT('shipping_name,shipping_params') -&gt;FROM($db-&gt;quoteName('#__hikashop_shipping')) -&gt;where($db-&gt;quoteName('shipping_id') . ' = ' . $db-&gt;quote($shipping_id)); $db-&gt;setQuery($query); $row = $db-&gt;loadAssoc(); $shipping_price = $value['unitprice'] * $value["quantity"]; $shipping_name = $row['shipping_name']; $shipping_params = $row['shipping_params']; $order_full_price += $shipping_price; // add shipping cost if applicable } //check if discount item else if ($data-&gt;product_id == '9'){ $discount = $value['unitprice'] * $value["quantity"]; //$total_discount = preg_replace("/[^a-zA-Z0-9]+/", "", $total_discount); $write['discount'] = gettype($discount); } //normal product add else{ $product-&gt;product_id = $value["productsname"]; $product-&gt;order_product_price = $value['unitprice']; $product-&gt;order_product_quantity = $value["quantity"]; $product-&gt;order_product_name = $data-&gt;product_name; $product-&gt;order_product_code = $data-&gt;product_code; $order_full_price += $product-&gt;order_product_price * $product-&gt;order_product_quantity; $productarray[] = $product; } } $fullPrice = $array['total_value']; $finalPrice = $fullPrice - $discount; $fullOrder-&gt;order_full_price = $order_full_price; // convert to double $fullOrder-&gt;order_discount_price = abs($discount); // remove negative sign from discount } $write['finalPrice'] = gettype($finalPrice); $write['finalPriceq'] = $finalPrice; $write['fullPrice'] = $fullPrice; $write['order_full_price'] = $fullOrder-&gt;order_full_price; $write['total_discount'] = abs($discount); if (empty($shipping_id)) { $fullOrder-&gt;order_shipping_id = ''; $fullOrder-&gt;order_shipping_method = ''; $fullOrder-&gt;order_shipping_price = ''; $fullOrder-&gt;order_shipping_params = ''; }else{ $fullOrder-&gt;order_shipping_id = $shipping_id; $fullOrder-&gt;order_shipping_method = $shipping_name; $fullOrder-&gt;order_shipping_price = $shipping_price; $fullOrder-&gt;order_shipping_params = $shipping_params; } /*if (empty($total_discount)) { $fullOrder-&gt;order_discount_price = ''; }else{ $fullOrder-&gt;order_discount_price = $total_discount; }*/ $fullOrder-&gt;cart-&gt;products = $productarray; $fullOrder-&gt;order_id = $fullOrder-&gt;order_id; $fullOrder-&gt;history = new stdClass(); $fullOrder-&gt;history-&gt;history_notified = 1; unset($fullOrder-&gt;order_subtotal); unset($fullOrder-&gt;order_subtotal_no_vat); $orderClass-&gt;save($fullOrder); $write['saved'] = $fullOrder; $myfile = fopen("aUp.txt", "w") or die("Unable to open file!"); fwrite($myfile,print_r($write,true)); fclose($myfile); }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNjE3Ny11cGRhdGluZy1vcmRlci1kZXRhaWxzLW5vdC1hY2N1cmF0ZT90bXBsPW1hcmtkb3du) 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: 86583
- Thank you received: 14324
-
-

3 years 7 months ago [\#350611](#350611) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Updating Order Details Not Accurate](/forum/35-orders-management/906177-updating-order-details-not-accurate#350611 "Using a sales component, which the new record submitted, will append a hikashop order using ($orderClass = hikashop&#95;get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true,...")*

Hi,

The save function of class.order was not meant to be used for a complete order update like this.
The $fullOrder-&gt;cart-&gt;products array is processed after the order data is saved. That's because it's meant to be used when a new order is created, and thus is needs to add the order_id in the order_product table when adding the entries, but the order_id is not known before the order data is saved to the database.
Now, when you call the save function on an existing order, the system is looking at whether you're providing things which could change the total price:
- a payment fee
- a shipping fee
- a coupon value
- a product change (in $order-&gt;product)
And in that case, it will recalculate the total amount based on these and the list of products already in the database before saving the order data.
But since it then process the products in $fullOrder-&gt;cart-&gt;products after the order data save, it doesn't take the new products data into account in your case.

Ideally, you would use the saveForm function to save all the new order data, like you did for the product deletion.
But you would have to rewrite all the code.
A simpler solution would be to have it recalculate the total after the save call, like this: Code:

$recalculateOrder = new stdClass(); $recalculateOrder-&gt;order_id = $fullOrder-&gt;order_id; $orderClass-&gt;recalculateFullPrice($recalculateOrder); $orderClass-&gt;save($recalculateOrder);

The following user(s) said Thank You: [jiawen](/forum/user/68179-jiawen "View jiawen's Profile")

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

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

Less More

- Posts: 56
- Thank you received: 1
-
-

3 years 7 months ago [\#350619](#350619) by [jiawen](/forum/user/68179-jiawen "View jiawen's Profile")  Replied by *[jiawen](/forum/user/68179-jiawen "View jiawen's Profile")* on topic *[Updating Order Details Not Accurate](/forum/35-orders-management/906177-updating-order-details-not-accurate#350619 "Using a sales component, which the new record submitted, will append a hikashop order using ($orderClass = hikashop&#95;get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true,...")*

Thank you. It works. Another issue is would like to add customer details for the order. Is it can use the $orderClass-&gt;save($fullOrder); function do this?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNjE3Ny11cGRhdGluZy1vcmRlci1kZXRhaWxzLW5vdC1hY2N1cmF0ZT90bXBsPW1hcmtkb3du) 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: 86583
- Thank you received: 14324
-
-

3 years 7 months ago [\#350620](#350620) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Updating Order Details Not Accurate](/forum/35-orders-management/906177-updating-order-details-not-accurate#350620 "Using a sales component, which the new record submitted, will append a hikashop order using ($orderClass = hikashop&#95;get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true,...")*

Hi,

What user details do you want to add exactly ?
In the order, you only have the order_user_id which links the order to a user.
So if you want to add data in custom fields of the table "user", it's the save of class.user you want to use instead.

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

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

Less More

- Posts: 56
- Thank you received: 1
-
-

3 years 7 months ago [\#350634](#350634) by [jiawen](/forum/user/68179-jiawen "View jiawen's Profile")  Replied by *[jiawen](/forum/user/68179-jiawen "View jiawen's Profile")* on topic *[Updating Order Details Not Accurate](/forum/35-orders-management/906177-updating-order-details-not-accurate#350634 "Using a sales component, which the new record submitted, will append a hikashop order using ($orderClass = hikashop&#95;get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true,...")*

Want to insert customer data for this part.  [ ![hikashoo.png](/forum/attachment/56810) ](/forum/attachment/56810 "hikashoo.png")

- [ ![hikashoo.png](/forum/attachment/56810) ](/forum/attachment/56810 "hikashoo.png") [ ](/forum/attachment/56810?download=1 "hikashoo.png")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50LzkwNjE3Ny11cGRhdGluZy1vcmRlci1kZXRhaWxzLW5vdC1hY2N1cmF0ZT90bXBsPW1hcmtkb3du) 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: 86583
- Thank you received: 14324
-
-

3 years 7 months ago [\#350637](#350637) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Updating Order Details Not Accurate](/forum/35-orders-management/906177-updating-order-details-not-accurate#350637 "Using a sales component, which the new record submitted, will append a hikashop order using ($orderClass = hikashop&#95;get('class.order'); $fullOrder = $orderClass-&gt;loadFullOrder((int)$orderId, true,...")*

Hi,

Well, there are several steps in that case:
- first, do you already have an entry for your data in the hikashop_user table ? If you do, you just have to fill the order_user_id of the order in the hikashop_order table. This can be done with the save of class.order
- if you don't have an entry for your data in the hikashop_user table, you need to create one with the save of class.user. You'll need to provide the user_email and potentially the user_cms_id provided you want to link it to a Joomla user account. In that case the user_cms_id must be the id of the user account in the users table of Joomla. If you don't provide the user_cms_id, the user entry in HikaShop will be as a guest user.
- And so if you want to have a user account, you first need to use the Joomla API to add the user account in Joomla.
It's an old page on this:
[ stackoverflow.com/questions/1904809/how-...from-within-a-script](https://stackoverflow.com/questions/1904809/how-can-i-create-a-new-joomla-user-account-from-within-a-script)
A more recent example would be in the "register" method of class.user in HikaShop but it's a lot of code as it's doing a lot more stuff than necessary for you.

The following user(s) said Thank You: [jiawen](/forum/user/68179-jiawen "View jiawen's Profile")

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

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