Skip to content

Commit 4f15752

Browse files
committed
Updated the update command
1 parent 0c6754b commit 4f15752

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/Console/LaravelCrmUpdate.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,35 @@ public function handle()
113113
$this->info('Updating Laravel CRM split orders, invoices & deliveries...');
114114

115115
foreach(Order::whereNotNull('quote_id')->get() as $order) {
116-
foreach($order->quote->quoteProducts as $quoteProduct) {
117-
if($orderProduct = $order->orderProducts()
118-
->whereNull('quote_product_id')
119-
->where([
120-
'product_id' => $quoteProduct->product_id,
121-
'price' => $quoteProduct->price,
122-
])->first()) {
123-
$orderProduct->update([
124-
'quote_product_id' => $quoteProduct->id
125-
]);
116+
if($order->quote){
117+
foreach($order->quote->quoteProducts as $quoteProduct) {
118+
if($orderProduct = $order->orderProducts()
119+
->whereNull('quote_product_id')
120+
->where([
121+
'product_id' => $quoteProduct->product_id,
122+
'price' => $quoteProduct->price,
123+
])->first()) {
124+
$orderProduct->update([
125+
'quote_product_id' => $quoteProduct->id
126+
]);
127+
}
126128
}
127129
}
128130
}
129131

130132
foreach(Invoice::whereNotNull('order_id')->get() as $invoice) {
131-
foreach($invoice->order->orderProducts as $orderProduct) {
132-
if($invoiceLine = $invoice->invoiceLines()
133-
->whereNull('order_product_id')
134-
->where([
135-
'product_id' => $orderProduct->product_id,
136-
'price' => $orderProduct->price,
137-
])->first()) {
138-
$invoiceLine->update([
139-
'order_product_id' => $orderProduct->id
140-
]);
133+
if($invoice->order){
134+
foreach($invoice->order->orderProducts as $orderProduct) {
135+
if($invoiceLine = $invoice->invoiceLines()
136+
->whereNull('order_product_id')
137+
->where([
138+
'product_id' => $orderProduct->product_id,
139+
'price' => $orderProduct->price,
140+
])->first()) {
141+
$invoiceLine->update([
142+
'order_product_id' => $orderProduct->id
143+
]);
144+
}
141145
}
142146
}
143147
}

0 commit comments

Comments
 (0)