From 8d93eb640f042b92483e976ecd6e165a4ea9bf2c Mon Sep 17 00:00:00 2001 From: Devansh Date: Tue, 11 Aug 2020 20:17:04 +0530 Subject: [PATCH 1/5] Foreign Key Cascade Removed --- .../2020_04_16_185147_add_table_addresses.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php b/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php index 8c9492954..597414d8a 100644 --- a/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php +++ b/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php @@ -267,11 +267,6 @@ SQL; ->where('order_address_id', $row->additional['old_order_address_id']) ->update(['order_address_id' => $row->id]); }); - - $table->foreign(['order_address_id']) - ->references('id') - ->on('addresses') - ->onDelete('cascade'); }); Schema::table('shipments', static function (Blueprint $table) { @@ -284,11 +279,6 @@ SQL; ->where('order_address_id', $row->additional['old_order_address_id']) ->update(['order_address_id' => $row->id]); }); - - $table->foreign(['order_address_id']) - ->references('id') - ->on('addresses') - ->onDelete('cascade'); }); } } From ea6cdd99b5a4d86f4f8bbbb9c4a7fe527b59ecc5 Mon Sep 17 00:00:00 2001 From: Devansh Date: Tue, 11 Aug 2020 20:31:38 +0530 Subject: [PATCH 2/5] Just Handled Some Exceptions --- .../views/sales/invoices/view.blade.php | 60 ++++++++++--------- .../views/sales/shipments/view.blade.php | 60 ++++++++++--------- 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php index 06fb088b8..0d392ac9b 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php @@ -107,14 +107,14 @@
{{ __('admin::app.sales.orders.customer-name') }} - {{ $invoice->address->name }} + {{ $invoice->order->customer_full_name }}
{!! view_render_event('sales.invoice.customer_name.after', ['order' => $order]) !!}
{{ __('admin::app.sales.orders.email') }} - {{ $invoice->address->email }} + {{ $invoice->order->customer_email }}
{!! view_render_event('sales.invoice.customer_email.after', ['order' => $order]) !!} @@ -124,36 +124,40 @@
- -
+ @if ($order->billing_address || $order->shipping_address) + +
-
-
- {{ __('admin::app.sales.orders.billing-address') }} -
+ @if ($order->billing_address) +
+
+ {{ __('admin::app.sales.orders.billing-address') }} +
-
- @include ('admin::sales.address', ['address' => $order->billing_address]) +
+ @include ('admin::sales.address', ['address' => $order->billing_address]) - {!! view_render_event('sales.invoice.billing_address.after', ['order' => $order]) !!} -
+ {!! view_render_event('sales.invoice.billing_address.after', ['order' => $order]) !!} +
+
+ @endif + + @if ($order->shipping_address) +
+
+ {{ __('admin::app.sales.orders.shipping-address') }} +
+ +
+ @include ('admin::sales.address', ['address' => $order->shipping_address]) + + {!! view_render_event('sales.invoice.shipping_address.after', ['order' => $order]) !!} +
+
+ @endif
- - @if ($order->shipping_address) -
-
- {{ __('admin::app.sales.orders.shipping-address') }} -
- -
- @include ('admin::sales.address', ['address' => $order->shipping_address]) - - {!! view_render_event('sales.invoice.shipping_address.after', ['order' => $order]) !!} -
-
- @endif -
-
+ + @endif
diff --git a/packages/Webkul/Admin/src/Resources/views/sales/shipments/view.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/shipments/view.blade.php index 2d21639df..ef1db5579 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/shipments/view.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/shipments/view.blade.php @@ -87,7 +87,7 @@ - {{ $shipment->address->name }} + {{ $shipment->order->customer_full_name }}
@@ -97,7 +97,7 @@ - {{ $shipment->address->email }} + {{ $shipment->order->customer_email }}
@@ -106,37 +106,41 @@
- -
+ @if ($order->billing_address || $order->shipping_address) + +
-
-
- {{ __('admin::app.sales.orders.billing-address') }} -
+ @if ($order->billing_address) +
+
+ {{ __('admin::app.sales.orders.billing-address') }} +
-
+
- @include ('admin::sales.address', ['address' => $order->billing_address]) + @include ('admin::sales.address', ['address' => $order->billing_address]) + +
+
+ @endif + + @if ($order->shipping_address) +
+
+ {{ __('admin::app.sales.orders.shipping-address') }} +
+ +
+ + @include ('admin::sales.address', ['address' => $order->shipping_address]) + +
+
+ @endif -
- - @if ($order->shipping_address) -
-
- {{ __('admin::app.sales.orders.shipping-address') }} -
- -
- - @include ('admin::sales.address', ['address' => $order->shipping_address]) - -
-
- @endif - -
-
+ + @endif
From 1f876800456030e7aa6056713768e0cef90a4004 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 12 Aug 2020 13:04:45 +0530 Subject: [PATCH 3/5] Previous One Reverted And Added New Migration --- .../2020_04_16_185147_add_table_addresses.php | 10 ++++ ...2020_08_12_114128_removing_foriegn_key.php | 53 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 packages/Webkul/Core/src/Database/Migrations/2020_08_12_114128_removing_foriegn_key.php diff --git a/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php b/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php index 597414d8a..8c9492954 100644 --- a/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php +++ b/packages/Webkul/Core/src/Database/Migrations/2020_04_16_185147_add_table_addresses.php @@ -267,6 +267,11 @@ SQL; ->where('order_address_id', $row->additional['old_order_address_id']) ->update(['order_address_id' => $row->id]); }); + + $table->foreign(['order_address_id']) + ->references('id') + ->on('addresses') + ->onDelete('cascade'); }); Schema::table('shipments', static function (Blueprint $table) { @@ -279,6 +284,11 @@ SQL; ->where('order_address_id', $row->additional['old_order_address_id']) ->update(['order_address_id' => $row->id]); }); + + $table->foreign(['order_address_id']) + ->references('id') + ->on('addresses') + ->onDelete('cascade'); }); } } diff --git a/packages/Webkul/Core/src/Database/Migrations/2020_08_12_114128_removing_foriegn_key.php b/packages/Webkul/Core/src/Database/Migrations/2020_08_12_114128_removing_foriegn_key.php new file mode 100644 index 000000000..0cbeb99e4 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Migrations/2020_08_12_114128_removing_foriegn_key.php @@ -0,0 +1,53 @@ +dropForeign(['order_address_id']); + + OrderAddress::query() + ->orderBy('id', 'asc') // for some reason each() needs an orderBy in before + ->each(static function ($row) { + Invoice::query() + ->where('order_address_id', $row->additional['old_order_address_id']) + ->update(['order_address_id' => $row->id]); + }); + }); + + Schema::table('shipments', static function (Blueprint $table) { + $table->dropForeign(['order_address_id']); + + OrderAddress::query() + ->orderBy('id', 'asc') // for some reason each() needs an orderBy in before + ->each(static function ($row) { + Shipment::query() + ->where('order_address_id', $row->additional['old_order_address_id']) + ->update(['order_address_id' => $row->id]); + }); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +} From 254020c010eec16956316ee0d0ddeb171eec4aad Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 12 Aug 2020 13:19:49 +0530 Subject: [PATCH 4/5] Handled Some Exception --- .../Admin/src/Resources/views/sales/orders/view.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php index 92b8cafeb..a7d64eaf6 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php @@ -284,6 +284,7 @@ @foreach ($order->items as $item) + {{ $item->getTypeInstance()->getOrderedItem($item)->sku }} @@ -467,13 +468,12 @@ - @foreach ($order->invoices as $invoice) #{{ $invoice->id }} {{ $invoice->created_at }} #{{ $invoice->order->increment_id }} - {{ $invoice->address->name }} + {{ $invoice->order->customer_full_name }} @if($invoice->state == "paid") {{ __('admin::app.sales.orders.invoice-status-paid') }} From 10f42eeacc106f4ec4e382b52d9ab319376b4e02 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 12 Aug 2020 14:22:48 +0530 Subject: [PATCH 5/5] Exception Handled --- .../views/sales/invoices/pdf.blade.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php index 3953c6a3d..59212d4fa 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php @@ -129,15 +129,17 @@ - -

{{ $invoice->order->billing_address->company_name ?? '' }}

-

{{ $invoice->order->billing_address->name }}

-

{{ $invoice->order->billing_address->address1 }}

-

{{ $invoice->order->billing_address->city }}

-

{{ $invoice->order->billing_address->state }}

-

{{ core()->country_name($invoice->order->billing_address->country) }} {{ $invoice->order->billing_address->postcode }}

- {{ __('shop::app.checkout.onepage.contact') }} : {{ $invoice->order->billing_address->phone }} - + @if ($invoice->order->billing_address) + +

{{ $invoice->order->billing_address->company_name ?? '' }}

+

{{ $invoice->order->billing_address->name }}

+

{{ $invoice->order->billing_address->address1 }}

+

{{ $invoice->order->billing_address->city }}

+

{{ $invoice->order->billing_address->state }}

+

{{ core()->country_name($invoice->order->billing_address->country) }} {{ $invoice->order->billing_address->postcode }}

+ {{ __('shop::app.checkout.onepage.contact') }} : {{ $invoice->order->billing_address->phone }} + + @endif @if ($invoice->order->shipping_address)