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