From a4d565e46ecef62fe41460c0f3b0097674a097b9 Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Thu, 20 Feb 2020 12:24:38 +0530 Subject: [PATCH] Improved shipping package code style --- .../Webkul/Shipping/src/Carriers/FlatRate.php | 3 +- .../Webkul/Shipping/src/Carriers/Free.php | 3 +- .../Webkul/Shipping/src/Config/carriers.php | 24 +-- .../Webkul/Shipping/src/Config/system.php | 148 +++++++++--------- packages/Webkul/Shipping/src/Shipping.php | 20 ++- 5 files changed, 102 insertions(+), 96 deletions(-) diff --git a/packages/Webkul/Shipping/src/Carriers/FlatRate.php b/packages/Webkul/Shipping/src/Carriers/FlatRate.php index 2cc7fc34c..5cbf59083 100755 --- a/packages/Webkul/Shipping/src/Carriers/FlatRate.php +++ b/packages/Webkul/Shipping/src/Carriers/FlatRate.php @@ -27,8 +27,9 @@ class FlatRate extends AbstractShipping */ public function calculate() { - if (! $this->isAvailable()) + if (! $this->isAvailable()) { return false; + } $cart = Cart::getCart(); diff --git a/packages/Webkul/Shipping/src/Carriers/Free.php b/packages/Webkul/Shipping/src/Carriers/Free.php index 69a5f1012..f03247c94 100755 --- a/packages/Webkul/Shipping/src/Carriers/Free.php +++ b/packages/Webkul/Shipping/src/Carriers/Free.php @@ -26,8 +26,9 @@ class Free extends AbstractShipping */ public function calculate() { - if (! $this->isAvailable()) + if (! $this->isAvailable()) { return false; + } $object = new CartShippingRate; diff --git a/packages/Webkul/Shipping/src/Config/carriers.php b/packages/Webkul/Shipping/src/Config/carriers.php index 209658b15..ad47266b6 100755 --- a/packages/Webkul/Shipping/src/Config/carriers.php +++ b/packages/Webkul/Shipping/src/Config/carriers.php @@ -2,21 +2,21 @@ return [ 'flatrate' => [ - 'code' => 'flatrate', - 'title' => 'Flat Rate', - 'description' => 'Flat Rate Shipping', - 'active' => true, + 'code' => 'flatrate', + 'title' => 'Flat Rate', + 'description' => 'Flat Rate Shipping', + 'active' => true, 'default_rate' => '10', - 'type' => 'per_unit', - 'class' => 'Webkul\Shipping\Carriers\FlatRate' + 'type' => 'per_unit', + 'class' => 'Webkul\Shipping\Carriers\FlatRate' ], - 'free' => [ - 'code' => 'free', - 'title' => 'Free Shipping', - 'description' => 'Free Shipping', - 'active' => true, + 'free' => [ + 'code' => 'free', + 'title' => 'Free Shipping', + 'description' => 'Free Shipping', + 'active' => true, 'default_rate' => '0', - 'class' => 'Webkul\Shipping\Carriers\Free' + 'class' => 'Webkul\Shipping\Carriers\Free' ] ]; \ No newline at end of file diff --git a/packages/Webkul/Shipping/src/Config/system.php b/packages/Webkul/Shipping/src/Config/system.php index 9d88463d4..8e85260dc 100755 --- a/packages/Webkul/Shipping/src/Config/system.php +++ b/packages/Webkul/Shipping/src/Config/system.php @@ -2,70 +2,70 @@ return [ [ - 'key' => 'sales', + 'key' => 'sales', 'name' => 'admin::app.admin.system.sales', 'sort' => 5 ], [ - 'key' => 'sales.carriers', + 'key' => 'sales.carriers', 'name' => 'admin::app.admin.system.shipping-methods', 'sort' => 1, ], [ - 'key' => 'sales.carriers.free', - 'name' => 'admin::app.admin.system.free-shipping', - 'sort' => 1, + 'key' => 'sales.carriers.free', + 'name' => 'admin::app.admin.system.free-shipping', + 'sort' => 1, 'fields' => [ [ - 'name' => 'title', - 'title' => 'admin::app.admin.system.title', - 'type' => 'text', - 'validation' => 'required', + 'name' => 'title', + 'title' => 'admin::app.admin.system.title', + 'type' => 'text', + 'validation' => 'required', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true ], [ - 'name' => 'description', - 'title' => 'admin::app.admin.system.description', - 'type' => 'textarea', + 'name' => 'description', + 'title' => 'admin::app.admin.system.description', + 'type' => 'textarea', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true ], [ - 'name' => 'active', - 'title' => 'admin::app.admin.system.status', - 'type' => 'boolean', - 'validation' => 'required', + 'name' => 'active', + 'title' => 'admin::app.admin.system.status', + 'type' => 'boolean', + 'validation' => 'required', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true ] ] ], [ - 'key' => 'sales.carriers.flatrate', - 'name' => 'admin::app.admin.system.flate-rate-shipping', - 'sort' => 2, + 'key' => 'sales.carriers.flatrate', + 'name' => 'admin::app.admin.system.flate-rate-shipping', + 'sort' => 2, 'fields' => [ [ - 'name' => 'title', - 'title' => 'admin::app.admin.system.title', - 'type' => 'text', - 'validation' => 'required', + 'name' => 'title', + 'title' => 'admin::app.admin.system.title', + 'type' => 'text', + 'validation' => 'required', 'channel_based' => true, - 'locale_based' => true + 'locale_based' => true ], [ - 'name' => 'description', - 'title' => 'admin::app.admin.system.description', - 'type' => 'textarea', + 'name' => 'description', + 'title' => 'admin::app.admin.system.description', + 'type' => 'textarea', 'channel_based' => true, - 'locale_based' => false + 'locale_based' => false ], [ - 'name' => 'default_rate', - 'title' => 'admin::app.admin.system.rate', - 'type' => 'text', - 'validation' => 'required', + 'name' => 'default_rate', + 'title' => 'admin::app.admin.system.rate', + 'type' => 'text', + 'validation' => 'required', 'channel_based' => true, - 'locale_based' => false + 'locale_based' => false ], [ - 'name' => 'type', - 'title' => 'admin::app.admin.system.type', - 'type' => 'select', - 'options' => [ + 'name' => 'type', + 'title' => 'admin::app.admin.system.type', + 'type' => 'select', + 'options' => [ [ 'title' => 'Per Unit', 'value' => 'per_unit' @@ -76,58 +76,58 @@ return [ ], 'validation' => 'required' ], [ - 'name' => 'active', - 'title' => 'admin::app.admin.system.status', - 'type' => 'boolean', - 'validation' => 'required', + 'name' => 'active', + 'title' => 'admin::app.admin.system.status', + 'type' => 'boolean', + 'validation' => 'required', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true ] ] ], [ - 'key' => 'sales.shipping', + 'key' => 'sales.shipping', 'name' => 'admin::app.admin.system.shipping', 'sort' => 0 ], [ - 'key' => 'sales.shipping.origin', - 'name' => 'admin::app.admin.system.origin', - 'sort' => 0, + 'key' => 'sales.shipping.origin', + 'name' => 'admin::app.admin.system.origin', + 'sort' => 0, 'fields' => [ [ - 'name' => 'country', - 'title' => 'admin::app.admin.system.country', - 'type' => 'country', - 'validation' => 'required', + 'name' => 'country', + 'title' => 'admin::app.admin.system.country', + 'type' => 'country', + 'validation' => 'required', 'channel_based' => true, - 'locale_based' => true + 'locale_based' => true ], [ - 'name' => 'state', - 'title' => 'admin::app.admin.system.state', - 'type' => 'state', - 'validation' => 'required', + 'name' => 'state', + 'title' => 'admin::app.admin.system.state', + 'type' => 'state', + 'validation' => 'required', 'channel_based' => true, - 'locale_based' => true + 'locale_based' => true ], [ - 'name' => 'address1', - 'title' => 'admin::app.admin.system.street-address', - 'type' => 'text', - 'validation' => 'required', + 'name' => 'address1', + 'title' => 'admin::app.admin.system.street-address', + 'type' => 'text', + 'validation' => 'required', 'channel_based' => true, - 'locale_based' => false + 'locale_based' => false ], [ - 'name' => 'zipcode', - 'title' => 'admin::app.admin.system.zip', - 'type' => 'text', - 'validation' => 'required', + 'name' => 'zipcode', + 'title' => 'admin::app.admin.system.zip', + 'type' => 'text', + 'validation' => 'required', 'channel_based' => true, - 'locale_based' => false + 'locale_based' => false ], [ - 'name' => 'city', - 'title' => 'admin::app.admin.system.city', - 'type' => 'text', - 'validation' => 'required', + 'name' => 'city', + 'title' => 'admin::app.admin.system.city', + 'type' => 'text', + 'validation' => 'required', 'channel_based' => true, - 'locale_based' => false + 'locale_based' => false ] ] ] diff --git a/packages/Webkul/Shipping/src/Shipping.php b/packages/Webkul/Shipping/src/Shipping.php index a012b1843..c989d9a0e 100755 --- a/packages/Webkul/Shipping/src/Shipping.php +++ b/packages/Webkul/Shipping/src/Shipping.php @@ -25,8 +25,9 @@ class Shipping */ public function collectRates() { - if (! $cart = Cart::getCart()) + if (! $cart = Cart::getCart()) { return false; + } $this->removeAllShippingRates(); @@ -47,7 +48,7 @@ class Shipping return [ 'jump_to_section' => 'shipping', 'shippingMethods' => $this->getGroupedAllShippingRates(), - 'html' => view('shop::checkout.onepage.shipping', ['shippingRateGroups' => $this->getGroupedAllShippingRates()])->render() + 'html' => view('shop::checkout.onepage.shipping', ['shippingRateGroups' => $this->getGroupedAllShippingRates()])->render() ]; } @@ -58,8 +59,9 @@ class Shipping */ public function removeAllShippingRates() { - if (! $cart = Cart::getCart()) + if (! $cart = Cart::getCart()) { return; + } foreach ($cart->shipping_rates()->get() as $rate) { $rate->delete(); @@ -73,8 +75,9 @@ class Shipping */ public function saveAllShippingRates() { - if (! $cart = Cart::getCart()) + if (! $cart = Cart::getCart()) { return; + } $shippingAddress = $cart->shipping_address; @@ -98,7 +101,7 @@ class Shipping if (! isset($rates[$rate->carrier])) { $rates[$rate->carrier] = [ 'carrier_title' => $rate->carrier_title, - 'rates' => [] + 'rates' => [] ]; } @@ -120,13 +123,14 @@ class Shipping foreach (Config::get('carriers') as $shippingMethod) { $object = new $shippingMethod['class']; - if (! $object->isAvailable()) + if (! $object->isAvailable()) { continue; + } $methods[] = [ - 'method' => $object->getCode(), + 'method' => $object->getCode(), 'method_title' => $object->getTitle(), - 'description' => $object->getDescription() + 'description' => $object->getDescription() ]; }