Reputation: 1
I tried to implement saving total price in orders but it`s returning an issue like before saving everything is good, but after it debug returning null
protected function createOrder($order_data) {
$user = user_load_by_mail($order_data['Email']);
if (!$user) {
$user = User::create([
'name' => $order_data['Customer'],
'mail' => $order_data['Email'],
'status' => 1,
]);
$user->save();
}
// Get currency code and amount
$splitAmount = $this->getCurrencyCode($order_data['Total']);
$formatted_value = number_format((float) $splitAmount['value'], 6, '.', '');
// Create the order
$order = Order::create([
'type' => 'default',
'state' => $order_data['Status'],
'uid' => $user->id(),
'order_number' => $order_data['ID'],
'mail' => $user->getEmail(),
'placed' => strtotime($order_data['Date']),
'overridden_unit_price' => TRUE,
]);
// Create a Price object and set it to the order
$amount = new Price($splitAmount['value'], $splitAmount['currency_code']);
$order->set('total_price', $amount);
dd($order->get('total_price')->getValue());
$order->save();
// $order = Order::load($order->id());
// Debug the total price after saving
dd($order->get('total_price')->getValue());
// Debug the total price to check the result
// dd($order->get('total_price')->getValue());
}
the first debug
array:1 [▼
0 => array:2 [▼
"number" => "1107000"
"currency_code" => "LBP"
]
]
the second one
[]
I tried to debug and changed the data what comes to Price
Upvotes: 0
Views: 34