Improved shipping package code style

This commit is contained in:
Jitendra Singh 2020-02-20 12:24:38 +05:30
parent 7b8cf802f4
commit a4d565e46e
5 changed files with 102 additions and 96 deletions

View File

@ -27,8 +27,9 @@ class FlatRate extends AbstractShipping
*/
public function calculate()
{
if (! $this->isAvailable())
if (! $this->isAvailable()) {
return false;
}
$cart = Cart::getCart();

View File

@ -26,8 +26,9 @@ class Free extends AbstractShipping
*/
public function calculate()
{
if (! $this->isAvailable())
if (! $this->isAvailable()) {
return false;
}
$object = new CartShippingRate;

View File

@ -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'
]
];

View File

@ -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
]
]
]

View File

@ -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()
];
}