From 15abe379e0425bd80454e1dc1f84267800b04dd3 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Sun, 16 Jun 2019 17:26:06 +0530 Subject: [PATCH] Changed frontend attributes and syntax fixes in checkout --- .../promotions/cart-rule/create.blade.php | 3 +- .../views/promotions/cart-rule/edit.blade.php | 28 +++- .../Webkul/Discount/src/Helpers/Discount.php | 3 + .../Http/Controllers/CartRuleController.php | 6 +- .../Http/Controllers/OnepageController.php | 20 +-- .../views/checkout/onepage.blade.php | 144 +++++++++--------- .../views/checkout/onepage/review.blade.php | 3 +- .../views/checkout/total/summary.blade.php | 13 +- .../assets/js/components/accordian.vue | 2 +- 9 files changed, 128 insertions(+), 94 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php index 0f2d6d222..e9721e456 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php @@ -476,7 +476,6 @@ this.conditions_list.push(this.cart_object); this.cart_object = { - criteria: null, attribute: null, condition: null, value: [] @@ -526,7 +525,7 @@ onSubmit: function (e) { if (this.conditions_list.length != 0) { - this.conditions_list.test_mode = this.match_criteria; + this.conditions_list.push({'criteria': this.match_criteria}); } this.all_conditions = JSON.stringify(this.conditions_list); diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php index ce21944ca..66d974f05 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php @@ -567,12 +567,32 @@ }, onSubmit: function (e) { + if (this.conditions_list.length != 0) { - // if (this.conditions_list.length != 0) { - // this.conditions_list.push(this.match_criteria); - // } + indexes = []; - console.log(JSON.stringify(this.conditions_list)); + for (i in this.conditions_list) { + if (this.conditions_list[i].hasOwnProperty('criteria') && ! this.conditions_list[i].hasOwnProperty('attribute')) { + indexes.push(i); + } + } + + if (indexes.length > 1) { + for (i in indexes) { + console.log(indexes[i]); + if (this.conditions_list.length ) + this.conditions_list.splice(indexes[i], 1); + } + } else { + + } + + return false; + + this.conditions_list.push({'criteria': this.match_criteria}); + } + + return false; this.all_conditions = JSON.stringify(this.conditions_list); diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index f48e14796..3d7b7ab39 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -502,6 +502,8 @@ class Discount } protected function testIfAllConditionAreTrue($conditions, $cart) { + array_pop($conditions); + $shipping_address = $cart->getShippingAddressAttribute() ?? ''; $shipping_method = $cart->shipping_method ?? ''; @@ -524,6 +526,7 @@ class Discount $test_conditions = config('pricerules.cart.conditions'); $result = 1; + foreach ($conditions as $condition) { $actual_value = ${$condition->attribute}; $test_value = $condition->value; diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index 6853cd9d2..d23bf0715 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -79,7 +79,7 @@ class CartRuleController extends Controller } /** - * @return Redirect + * @return redirect */ public function store() { @@ -451,7 +451,9 @@ class CartRuleController extends Controller } /** - * Delete + * Deletes the cart rule + * + * @return JSON */ public function destroy($id) { diff --git a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php index eaf2454d6..587bd800b 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php @@ -99,13 +99,13 @@ class OnepageController extends Controller $data['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1'])); $data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1'])); - if (Cart::hasError() || !Cart::saveCustomerAddress($data) || ! $rates = Shipping::collectRates()) - return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); - Cart::applyNonCoupon(); Cart::collectTotals(); + if (Cart::hasError() || !Cart::saveCustomerAddress($data) || ! $rates = Shipping::collectRates()) + return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); + return response()->json($rates); } @@ -118,13 +118,13 @@ class OnepageController extends Controller { $shippingMethod = request()->get('shipping_method'); - if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod)) - return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); - Cart::applyNonCoupon(); Cart::collectTotals(); + if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod)) + return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); + return response()->json(Payment::getSupportedPaymentMethods()); } @@ -137,15 +137,15 @@ class OnepageController extends Controller { $payment = request()->get('payment'); + Cart::applyNonCoupon(); + + Cart::collectTotals(); + if (Cart::hasError() || !$payment || !Cart::savePaymentMethod($payment)) return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); $cart = Cart::getCart(); - Cart::applyNonCoupon(); - - Cart::collectTotals(); - return response()->json([ 'jump_to_section' => 'review', 'html' => view('shop::checkout.onepage.review', compact('cart', 'rule'))->render() 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 02e593fbc..93613d39c 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -71,8 +71,12 @@ -
- +
+ +
+ +
+
- +
@@ -341,42 +345,6 @@ } }) - var summaryTemplateRenderFns = []; - - Vue.component('summary-section', { - inject: ['$validator'], - - data: function() { - return { - templateRender: null, - - code: null, - - coupon_used: false, - - hide_discount: 0 - } - }, - - staticRenderFns: summaryTemplateRenderFns, - - mounted: function() { - this.templateRender = summaryHtml.render; - - for (var i in summaryHtml.staticRenderFns) { - summaryTemplateRenderFns.push(summaryHtml.staticRenderFns[i]); - } - }, - - render: function(h) { - return h('div', [ - (this.templateRender ? - this.templateRender() : - '') - ]); - } - }) - var shippingTemplateRenderFns = []; Vue.component('shipping-section', { @@ -460,40 +428,78 @@ eventBus.$emit('after-payment-method-selected'); } } - }) + }); var reviewTemplateRenderFns = []; Vue.component('review-section', { - data: function() { + props: ['active'], + + data: function () { return { templateRender: null, - code: '', - - hide_discount: 1, - - coupon_used: false, - - error_message: '' + hide_discount: null, } }, staticRenderFns: reviewTemplateRenderFns, - mounted: function() { + mounted: function () { + this.hide_discount = this.active; + this.templateRender = reviewHtml.render; + for (var i in reviewHtml.staticRenderFns) { reviewTemplateRenderFns.push(reviewHtml.staticRenderFns[i]); } - - @if ($cart->coupon_code != null) - this.code = '{{ $cart->coupon_code }}'; - this.coupon_used = true; - @endif }, render: function(h) { + return h('div', [ + (this.templateRender ? + this.templateRender() : + '') + ] + ); + } + }); + + var summaryTemplateRenderFns = []; + + Vue.component('summary-section', { + inject: ['$validator'], + props: ['active'], + + data: function () { + return { + templateRender: null, + + code: null, + + coupon_used: false, + + hide_discount: null, + + error_message: '', + + call_count: 0, + } + }, + + staticRenderFns: summaryTemplateRenderFns, + + mounted: function () { + this.hide_discount = this.active; + + this.templateRender = summaryHtml.render; + + for (var i in summaryHtml.staticRenderFns) { + summaryTemplateRenderFns.push(summaryHtml.staticRenderFns[i]); + } + }, + + render: function (h) { return h('div', [ (this.templateRender ? this.templateRender() : @@ -510,12 +516,8 @@ }).then(function(response) { this_this.coupon_used = true; - document.getElementById("discount-detail").style.display = "block"; - document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; - - document.getElementById("grand-total-amount-detail").innerHTML = response.data.result.grand_total; + this_this.getOrderSummary(); }).catch(function(error) { - console.log(error.data); }); }, @@ -527,20 +529,24 @@ this_this.coupon_used = false; this_this.code = ''; + }).catch(function(error) {}); + }, - console.log(response.data.data.grand_total); + getOrderSummary () { + var this_this = this; - document.getElementById("discount-detail").style.display = "none"; + this.$http.get("{{ route('shop.checkout.summary') }}") + .then(function(response) { + this_this.resetSummary = false; - document.getElementById("grand-total-amount-detail").innerHTML = response.data.data.grand_total; - }).catch(function(error) { - console.log(error.data); - - this_this.error_message = '{{ __('shop::app.checkout.onepage.total.cannot-apply-coupon') }}' - }); - } + summaryHtml = Vue.compile(response.data.html) + setTimeout(function() { + this_this.resetSummary = true; + }, 0); + }).catch(function (error) {}) + }, } - }); + }) @endpush \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php index 5341e42e4..d200f8a9c 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php @@ -155,7 +155,8 @@
- @include('shop::checkout.total.summary', ['cart' => $cart]) + {{-- @include('shop::checkout.total.summary', ['cart' => $cart]) --}} +
\ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index f5229a87b..678798244 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -1,4 +1,4 @@ -
+

{{ __('shop::app.checkout.total.order-summary') }}

@@ -35,7 +35,6 @@
-