diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 250caacd3..f95aafff7 100755 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -1137,7 +1137,7 @@ return [ 'invoice number prefix' => 'Invoice Number Prefix', 'invoice number length' => 'Invoice Number Length', 'invoice number suffix' => 'Invoice Number Suffix', - + 'default' => 'Default', ] ] ]; diff --git a/packages/Webkul/Payment/src/Config/paymentmethods.php b/packages/Webkul/Payment/src/Config/paymentmethods.php index 864751d7a..ec7ec7e56 100755 --- a/packages/Webkul/Payment/src/Config/paymentmethods.php +++ b/packages/Webkul/Payment/src/Config/paymentmethods.php @@ -6,7 +6,8 @@ return [ 'description' => 'shop::app.checkout.onepage.cash-desc', 'class' => 'Webkul\Payment\Payment\CashOnDelivery', 'active' => true, - 'sort' => 1 + 'sort' => 1, + 'default' => 'no' ], 'moneytransfer' => [ @@ -15,7 +16,8 @@ return [ 'description' => 'shop::app.checkout.onepage.money-desc', 'class' => 'Webkul\Payment\Payment\MoneyTransfer', 'active' => true, - 'sort' => 2 + 'sort' => 2, + 'default' => 'yes' ], 'paypal_standard' => [ @@ -26,6 +28,7 @@ return [ 'sandbox' => true, 'active' => true, 'business_account' => 'test@webkul.com', - 'sort' => 3 + 'sort' => 3, + 'default' => 'no' ] ]; \ No newline at end of file diff --git a/packages/Webkul/Payment/src/Config/system.php b/packages/Webkul/Payment/src/Config/system.php index 3e1b22195..beec93f54 100755 --- a/packages/Webkul/Payment/src/Config/system.php +++ b/packages/Webkul/Payment/src/Config/system.php @@ -62,7 +62,14 @@ return [ 'value' => 4 ] ], - ] + ], [ + 'name' => 'default', + 'title' => 'admin::app.admin.system.default', + 'type' => 'boolean', + 'validation' => 'required', + 'channel_based' => false, + 'locale_based' => true + ], ] ], [ 'key' => 'sales.paymentmethods.moneytransfer', @@ -117,7 +124,14 @@ return [ 'value' => 4 ] ], - ] + ], [ + 'name' => 'default', + 'title' => 'admin::app.admin.system.default', + 'type' => 'boolean', + 'validation' => 'required', + 'channel_based' => false, + 'locale_based' => true + ], ] ], [ 'key' => 'sales.paymentmethods.paypal_standard', @@ -178,7 +192,14 @@ return [ 'value' => 4 ] ], - ] + ], [ + 'name' => 'default', + 'title' => 'admin::app.admin.system.default', + 'type' => 'boolean', + 'validation' => 'required', + 'channel_based' => false, + 'locale_based' => true + ], ] ] ]; \ No newline at end of file diff --git a/packages/Webkul/Payment/src/Payment.php b/packages/Webkul/Payment/src/Payment.php index 9f56fb521..f7ba3684d 100755 --- a/packages/Webkul/Payment/src/Payment.php +++ b/packages/Webkul/Payment/src/Payment.php @@ -18,6 +18,7 @@ class Payment return [ 'jump_to_section' => 'payment', + 'paymentMethods' => $this->getPaymentMethods(), 'html' => view('shop::checkout.onepage.payment', compact('paymentMethods'))->render() ]; } @@ -40,6 +41,7 @@ class Payment 'method_title' => $object->getTitle(), 'description' => $object->getDescription(), 'sort' => $object->getSortOrder(), + 'default' => $object->getDefaultMethod(), ]; } } diff --git a/packages/Webkul/Payment/src/Payment/Payment.php b/packages/Webkul/Payment/src/Payment/Payment.php index f2acea2d1..c695f5998 100755 --- a/packages/Webkul/Payment/src/Payment/Payment.php +++ b/packages/Webkul/Payment/src/Payment/Payment.php @@ -113,10 +113,20 @@ abstract class Payment /** * Returns payment method sort order * - * @return array + * @return int */ public function getSortOrder() { return $this->getConfigData('sort'); } + + /** + * Returns default payment method. + * + * @return boolean + */ + public function getDefaultMethod() + { + return $this->getConfigData('default'); + } } \ No newline at end of file diff --git a/packages/Webkul/Shipping/src/Config/carriers.php b/packages/Webkul/Shipping/src/Config/carriers.php index d78327e75..9a1c7d05f 100755 --- a/packages/Webkul/Shipping/src/Config/carriers.php +++ b/packages/Webkul/Shipping/src/Config/carriers.php @@ -9,6 +9,7 @@ return [ 'default_rate' => '10', 'type' => 'per_unit', 'class' => 'Webkul\Shipping\Carriers\FlatRate', + 'default' => 'yes', ], 'free' => [ @@ -18,5 +19,6 @@ return [ 'active' => true, 'default_rate' => '0', 'class' => 'Webkul\Shipping\Carriers\Free', + 'default' => 'yes', ] ]; \ 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 916d61b99..3343bf7f3 100755 --- a/packages/Webkul/Shipping/src/Config/system.php +++ b/packages/Webkul/Shipping/src/Config/system.php @@ -43,7 +43,14 @@ return [ 'validation' => 'required', 'channel_based' => false, 'locale_based' => true - ] + ], [ + 'name' => 'default', + 'title' => 'admin::app.admin.system.default', + 'type' => 'boolean', + 'validation' => 'required', + 'channel_based' => false, + 'locale_based' => true + ], ] ], [ 'key' => 'sales.carriers.flatrate', @@ -99,7 +106,14 @@ return [ 'validation' => 'required', 'channel_based' => false, 'locale_based' => true - ] + ], [ + 'name' => 'default', + 'title' => 'admin::app.admin.system.default', + 'type' => 'boolean', + 'validation' => 'required', + 'channel_based' => false, + 'locale_based' => true + ], ] ], [ 'key' => 'sales.shipping', diff --git a/packages/Webkul/Shipping/src/Shipping.php b/packages/Webkul/Shipping/src/Shipping.php index 4661f59d2..f5e554e4b 100755 --- a/packages/Webkul/Shipping/src/Shipping.php +++ b/packages/Webkul/Shipping/src/Shipping.php @@ -46,6 +46,7 @@ class Shipping return [ 'jump_to_section' => 'shipping', + 'shippingMethods' => $this->getGroupedAllShippingRates(), 'html' => view('shop::checkout.onepage.shipping', ['shippingRateGroups' => $this->getGroupedAllShippingRates()])->render() ]; } @@ -97,6 +98,7 @@ class Shipping if (! isset($rates[$rate->carrier])) { $rates[$rate->carrier] = [ 'carrier_title' => $rate->carrier_title, + 'default' => core()->getConfigData('sales.carriers.' . $rate->carrier. '.default'), 'rates' => [] ]; } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 5aa62ffef..9d81d6ffc 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -103,6 +103,8 @@ var reviewHtml = ''; var summaryHtml = ''; var customerAddress = ''; + var shippingMethods = ''; + var paymentMethods = ''; @auth('customer') @if(auth('customer')->user()->addresses) @@ -230,6 +232,7 @@ if (response.data.jump_to_section == 'shipping') { shippingHtml = Vue.compile(response.data.html) + shippingMethods = response.data.shippingMethods; this_this.completedStep = 1; this_this.currentStep = 2; @@ -254,6 +257,7 @@ if (response.data.jump_to_section == 'payment') { paymentHtml = Vue.compile(response.data.html) + paymentMethods = response.data.paymentMethods; this_this.completedStep = 2; this_this.currentStep = 3; @@ -368,6 +372,16 @@ staticRenderFns: shippingTemplateRenderFns, mounted: function() { + for (method in shippingMethods) { + if (shippingMethods[method]['default'] == 'yes' || shippingMethods[method]['default'] == 1) { + for (rate in shippingMethods[method]['rates']) { + this.selected_shipping_method = shippingMethods[method]['rates'][rate]['method']; + + this.methodSelected(); + } + } + } + this.templateRender = shippingHtml.render; for (var i in shippingHtml.staticRenderFns) { shippingTemplateRenderFns.push(shippingHtml.staticRenderFns[i]); @@ -411,8 +425,15 @@ staticRenderFns: paymentTemplateRenderFns, mounted: function() { - this.templateRender = paymentHtml.render; + for (method in paymentMethods) { + if (paymentMethods[method]['default'] == 'yes' || paymentMethods[method]['default'] == 1) { + this.payment.method = paymentMethods[method]['method']; + this.methodSelected(); + } + } + + this.templateRender = paymentHtml.render; for (var i in paymentHtml.staticRenderFns) { paymentTemplateRenderFns.push(paymentHtml.staticRenderFns[i]); }