From 33f882209ad96e28979031b21ff56668ab359a6d Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Wed, 19 Feb 2020 15:32:52 +0530 Subject: [PATCH 1/3] code improvement --- .../Repositories/ProductFlatRepository.php | 34 ++++++++++++++++++- .../list/layered-navigation.blade.php | 18 +--------- .../list/layered-navigation.blade.php | 30 +++++++--------- 3 files changed, 47 insertions(+), 35 deletions(-) diff --git a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php index ee937894e..2d2295854 100644 --- a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php @@ -35,8 +35,9 @@ class ProductFlatRepository extends Repository } /** - * get Category Product + * get Category Product Attribute * + * @param CategoryId $categoryId * @return array */ public function getCategoryProductAttribute($categoryId) @@ -61,4 +62,35 @@ class ProductFlatRepository extends Repository return $productCategoryArrributes; } + + /** + * get Filterable Attributes. + * + * @param array $category + * @param array $products + * @return collection + */ + public function getFilterableAttributes($category, $products) { + $filterAttributes = []; + + if (count($category->filterableAttributes) > 0 && count($products)) { + $filterAttributes = $category->filterableAttributes; + } else { + $categoryProductAttributes = $this->getCategoryProductAttribute($category->id); + + if ($categoryProductAttributes) { + foreach (app('Webkul\Attribute\Repositories\AttributeRepository')->getFilterAttributes() as $filterAttribute) { + if (in_array($filterAttribute->id, $categoryProductAttributes)) { + $filterAttributes[] = $filterAttribute; + } else if ($filterAttribute ['code'] == 'price') { + $filterAttributes[] = $filterAttribute; + } + } + + $filterAttributes = collect($filterAttributes); + } + } + + return $filterAttributes; + } } \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php index 995727f94..6cd7262b9 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php @@ -10,23 +10,7 @@ if (isset($category)) { $products = $productRepository->getAll($category->id); - if (count($category->filterableAttributes) > 0 && count($products)) { - $filterAttributes = $category->filterableAttributes; - } else { - $categoryProductAttributes = $productFlatRepository->getCategoryProductAttribute($category->id); - - if ($categoryProductAttributes) { - foreach ($attributeRepository->getFilterAttributes() as $filterAttribute) { - if (in_array($filterAttribute->id, $categoryProductAttributes)) { - $filterAttributes[] = $filterAttribute; - } else if ($filterAttribute ['code'] == 'price') { - $filterAttributes[] = $filterAttribute; - } - } - - $filterAttributes = collect($filterAttributes); - } - } + $filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products); } else { $filterAttributes = $attributeRepository->getFilterAttributes(); } diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php index 015826c4e..632bdfaaa 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php @@ -8,26 +8,22 @@ if (isset($category)) { $products = $productRepository->getAll($category->id); - if (count($category->filterableAttributes) > 0 && count($products)) { - $filterAttributes = $category->filterableAttributes; - } else { - $categoryProductAttributes = $productFlatRepository->getCategoryProductAttribute($category->id); - - if ($categoryProductAttributes) { - foreach ($attributeRepository->getFilterAttributes() as $filterAttribute) { - if (in_array($filterAttribute->id, $categoryProductAttributes)) { - $filterAttributes[] = $filterAttribute; - } else if ($filterAttribute ['code'] == 'price') { - $filterAttributes[] = $filterAttribute; - } - } - - $filterAttributes = collect($filterAttributes); - } - } + $filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products); } else { $filterAttributes = $attributeRepository->getFilterAttributes(); } + + foreach ($filterAttributes as $attribute) { + if ($attribute->code <> 'price') { + if (! $attribute->options->isEmpty()) { + $attributes[] = $attribute; + } + } else { + $attributes[] = $attribute; + } + } + + $filterAttributes = collect($attributes); ?>
From d62b61b19ce820379beccfe6b29eb77e17eb61b2 Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Wed, 19 Feb 2020 16:12:54 +0530 Subject: [PATCH 2/3] Issue #2463 --- packages/Webkul/Checkout/src/Cart.php | 29 ++++++++++++------- .../views/checkout/onepage.blade.php | 4 +++ .../views/shop/checkout/onepage.blade.php | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 1309b9839..f293aea7f 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -738,8 +738,11 @@ class Cart { foreach ($taxRates as $rate) { $haveTaxRate = false; - if ($rate->state != '' && $rate->state != $address->state) + if ($rate->state != '' && $rate->state != $address->state) { + $this->setItemTaxToZero($item); + continue; + } if (! $rate->is_zip) { if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode) @@ -757,24 +760,30 @@ class Cart { $item->save(); break; } else { - $item->tax_percent = 0; - $item->tax_amount = 0; - $item->base_tax_amount = 0; + $this->setItemTaxToZero($item); - $item->save(); break; } } } else { - $item->tax_percent = 0; - $item->tax_amount = 0; - $item->base_tax_amount = 0; - - $item->save(); + $this->setItemTaxToZero($item); } } } + /** + * Set Item tax to zero. + * + * @return void + */ + protected function setItemTaxToZero($item) { + $item->tax_percent = 0; + $item->tax_amount = 0; + $item->base_tax_amount = 0; + + $item->save(); + } + /** * Checks if cart has any error * 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 300287d2b..1e61fa347 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -289,6 +289,8 @@ this.disable_button = true; + console.log(this.address); + this.$http.post("{{ route('shop.checkout.save-address') }}", this.address) .then(function(response) { this_this.disable_button = false; @@ -404,10 +406,12 @@ newBillingAddress: function() { this.new_billing_address = true; + this.address.billing.address_id = null; }, newShippingAddress: function() { this.new_shipping_address = true; + this.address.shipping.address_id = null; }, backToSavedBillingAddress: function() { diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/checkout/onepage.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/checkout/onepage.blade.php index f7b563ddd..184323563 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/checkout/onepage.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/checkout/onepage.blade.php @@ -478,7 +478,7 @@ newBillingAddress: function() { this.new_billing_address = true; this.isPlaceOrderEnabled = false; - this.address.shipping.address_id = null; + this.address.billing.address_id = null; }, newShippingAddress: function() { From 86e31346d0ea1530c7f190a843fef82146bd5263 Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Wed, 19 Feb 2020 16:17:31 +0530 Subject: [PATCH 3/3] remove console --- .../Webkul/Shop/src/Resources/views/checkout/onepage.blade.php | 2 -- 1 file changed, 2 deletions(-) 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 1e61fa347..a133d353c 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -289,8 +289,6 @@ this.disable_button = true; - console.log(this.address); - this.$http.post("{{ route('shop.checkout.save-address') }}", this.address) .then(function(response) { this_this.disable_button = false;