diff --git a/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php b/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php
index 47211d650..7ffa75817 100755
--- a/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php
@@ -1,7 +1,3 @@
-@php
- $locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
-@endphp
-
@@ -23,7 +19,7 @@
- direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
+ getCurrentLocale()->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
{!! view_render_event('bagisto.admin.layout.body.before') !!}
diff --git a/packages/Webkul/Admin/src/Resources/views/layouts/nav-top.blade.php b/packages/Webkul/Admin/src/Resources/views/layouts/nav-top.blade.php
index 53f228c82..3bb21692c 100755
--- a/packages/Webkul/Admin/src/Resources/views/layouts/nav-top.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/layouts/nav-top.blade.php
@@ -2,7 +2,11 @@
diff --git a/packages/Webkul/Category/src/Database/Migrations/2019_07_31_143339_create_category_filterable_attributes_table.php b/packages/Webkul/Category/src/Database/Migrations/2019_07_31_143339_create_category_filterable_attributes_table.php
new file mode 100644
index 000000000..3301581ad
--- /dev/null
+++ b/packages/Webkul/Category/src/Database/Migrations/2019_07_31_143339_create_category_filterable_attributes_table.php
@@ -0,0 +1,33 @@
+integer('category_id')->unsigned();
+ $table->integer('attribute_id')->unsigned();
+ $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
+ $table->foreign('attribute_id')->references('id')->on('attributes')->onDelete('cascade');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('category_filterable_attributes');
+ }
+}
diff --git a/packages/Webkul/Category/src/Http/Controllers/CategoryController.php b/packages/Webkul/Category/src/Http/Controllers/CategoryController.php
index 2c5a876f5..8268c2187 100755
--- a/packages/Webkul/Category/src/Http/Controllers/CategoryController.php
+++ b/packages/Webkul/Category/src/Http/Controllers/CategoryController.php
@@ -5,6 +5,7 @@ namespace Webkul\Category\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Category\Repositories\CategoryRepository as Category;
+use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
use Webkul\Category\Models\CategoryTranslation;
use Illuminate\Support\Facades\Event;
@@ -30,16 +31,26 @@ class CategoryController extends Controller
*/
protected $category;
+ /**
+ * AttributeRepository object
+ *
+ * @var array
+ */
+ protected $attribute;
+
/**
* Create a new controller instance.
*
- * @param \Webkul\Category\Repositories\CategoryRepository $category
+ * @param \Webkul\Category\Repositories\CategoryRepository $category
+ * @param use Webkul\Attribute\Repositories\AttributeRepository $attribute
* @return void
*/
- public function __construct(Category $category)
+ public function __construct(Category $category, Attribute $attribute)
{
$this->category = $category;
+ $this->attribute = $attribute;
+
$this->_config = request('_config');
}
@@ -62,7 +73,9 @@ class CategoryController extends Controller
{
$categories = $this->category->getCategoryTree(null, ['id']);
- return view($this->_config['view'], compact('categories'));
+ $attributes = $this->attribute->findWhere(['is_filterable' => 1]);
+
+ return view($this->_config['view'], compact('categories', 'attributes'));
}
/**
@@ -110,7 +123,9 @@ class CategoryController extends Controller
$category = $this->category->findOrFail($id);
- return view($this->_config['view'], compact('category', 'categories'));
+ $attributes = $this->attribute->findWhere(['is_filterable' => 1]);
+
+ return view($this->_config['view'], compact('category', 'categories', 'attributes'));
}
/**
diff --git a/packages/Webkul/Category/src/Models/Category.php b/packages/Webkul/Category/src/Models/Category.php
index 48b8e3046..8a38f7c02 100755
--- a/packages/Webkul/Category/src/Models/Category.php
+++ b/packages/Webkul/Category/src/Models/Category.php
@@ -6,6 +6,7 @@ use Webkul\Core\Eloquent\TranslatableModel;
use Kalnoy\Nestedset\NodeTrait;
use Illuminate\Support\Facades\Storage;
use Webkul\Category\Contracts\Category as CategoryContract;
+use Webkul\Attribute\Models\AttributeProxy;
class Category extends TranslatableModel implements CategoryContract
{
@@ -35,4 +36,12 @@ class Category extends TranslatableModel implements CategoryContract
{
return $this->image_url();
}
+
+ /**
+ * The filterable attributes that belong to the category.
+ */
+ public function filterableAttributes()
+ {
+ return $this->belongsToMany(AttributeProxy::modelClass(), 'category_filterable_attributes')->with('options');
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Category/src/Repositories/CategoryRepository.php b/packages/Webkul/Category/src/Repositories/CategoryRepository.php
index ccae2f210..3ddf7f649 100755
--- a/packages/Webkul/Category/src/Repositories/CategoryRepository.php
+++ b/packages/Webkul/Category/src/Repositories/CategoryRepository.php
@@ -63,6 +63,10 @@ class CategoryRepository extends Repository
$this->uploadImages($data, $category);
+ if (isset($data['attributes'])) {
+ $category->filterableAttributes()->sync($data['attributes']);
+ }
+
Event::fire('catalog.category.create.after', $category);
return $category;
@@ -163,6 +167,10 @@ class CategoryRepository extends Repository
$this->uploadImages($data, $category);
+ if (isset($data['attributes'])) {
+ $category->filterableAttributes()->sync($data['attributes']);
+ }
+
Event::fire('catalog.category.update.after', $id);
return $category;
diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php
index 523ec26c5..6bbb39e25 100755
--- a/packages/Webkul/Checkout/src/Cart.php
+++ b/packages/Webkul/Checkout/src/Cart.php
@@ -936,27 +936,35 @@ class Cart {
'country' => $shippingAddress->country,
])->orderBy('tax_rate', 'desc')->get();
- foreach ($taxRates as $rate) {
- $haveTaxRate = false;
+ if (count( $taxRates) > 0) {
+ foreach ($taxRates as $rate) {
+ $haveTaxRate = false;
- if (! $rate->is_zip) {
- if ($rate->zip_code == '*' || $rate->zip_code == $shippingAddress->postcode) {
- $haveTaxRate = true;
+ if (! $rate->is_zip) {
+ if ($rate->zip_code == '*' || $rate->zip_code == $shippingAddress->postcode) {
+ $haveTaxRate = true;
+ }
+ } else {
+ if ($shippingAddress->postcode >= $rate->zip_from && $shippingAddress->postcode <= $rate->zip_to) {
+ $haveTaxRate = true;
+ }
}
- } else {
- if ($shippingAddress->postcode >= $rate->zip_from && $shippingAddress->postcode <= $rate->zip_to) {
- $haveTaxRate = true;
+
+ if ($haveTaxRate) {
+ $item->tax_percent = $rate->tax_rate;
+ $item->tax_amount = ($item->total * $rate->tax_rate) / 100;
+ $item->base_tax_amount = ($item->base_total * $rate->tax_rate) / 100;
+
+ $item->save();
+ break;
}
}
+ } else {
+ $item->tax_percent = 0;
+ $item->tax_amount = 0;
+ $item->base_tax_amount = 0;
- if ($haveTaxRate) {
- $item->tax_percent = $rate->tax_rate;
- $item->tax_amount = ($item->total * $rate->tax_rate) / 100;
- $item->base_tax_amount = ($item->base_total * $rate->tax_rate) / 100;
-
- $item->save();
- break;
- }
+ $item->save();
}
}
}
diff --git a/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php b/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php
index 78fd9a25f..29309afab 100755
--- a/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php
+++ b/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php
@@ -52,25 +52,31 @@ class ForgotPasswordController extends Controller
*/
public function store()
{
- $this->validate(request(), [
- 'email' => 'required|email'
- ]);
+ try {
+ $this->validate(request(), [
+ 'email' => 'required|email'
+ ]);
- $response = $this->broker()->sendResetLink(
- request(['email'])
- );
- //dd($response);
- if ($response == Password::RESET_LINK_SENT) {
- session()->flash('success', trans($response));
-
- return back();
- }
-
- return back()
- ->withInput(request(['email']))
- ->withErrors(
- ['email' => trans($response)]
+ $response = $this->broker()->sendResetLink(
+ request(['email'])
);
+
+ if ($response == Password::RESET_LINK_SENT) {
+ session()->flash('success', trans($response));
+
+ return back();
+ }
+
+ return back()
+ ->withInput(request(['email']))
+ ->withErrors(
+ ['email' => trans($response)]
+ );
+ } catch (\Exception $e) {
+ session()->flash('error', trans($e->getMessage()));
+
+ return redirect()->back();
+ }
}
/**
diff --git a/packages/Webkul/Customer/src/Http/Middleware/RedirectIfNotCustomer.php b/packages/Webkul/Customer/src/Http/Middleware/RedirectIfNotCustomer.php
index 78f5c1436..38adeb4e3 100755
--- a/packages/Webkul/Customer/src/Http/Middleware/RedirectIfNotCustomer.php
+++ b/packages/Webkul/Customer/src/Http/Middleware/RedirectIfNotCustomer.php
@@ -18,7 +18,7 @@ class RedirectIfNotCustomer
public function handle($request, Closure $next, $guard = 'customer')
{
if (! Auth::guard($guard)->check()) {
- return redirect()->route('customer.profile.index');
+ return redirect()->route('customer.session.index');
} else {
if (Auth::guard($guard)->user()->status == 0) {
Auth::guard($guard)->logout();
diff --git a/packages/Webkul/Product/src/Listeners/ProductFlat.php b/packages/Webkul/Product/src/Listeners/ProductFlat.php
index d02227ddc..5cbfc80a9 100644
--- a/packages/Webkul/Product/src/Listeners/ProductFlat.php
+++ b/packages/Webkul/Product/src/Listeners/ProductFlat.php
@@ -104,6 +104,7 @@ class ProductFlat
public function afterAttributeCreatedUpdated($attribute)
{
if (! $attribute->is_user_defined || ! $attribute->use_in_flat) {
+ $this->afterAttributeDeleted($attribute->id);
return false;
}
@@ -169,100 +170,125 @@ class ProductFlat
if ($parentProduct && ! array_key_exists($parentProduct->id, $superAttributes))
$superAttributes[$parentProduct->id] = $parentProduct->super_attributes()->pluck('code')->toArray();
- foreach (core()->getAllChannels() as $channel) {
- foreach ($channel->locales as $locale) {
- $productFlat = $this->productFlatRepository->findOneWhere([
- 'product_id' => $product->id,
- 'channel' => $channel->code,
- 'locale' => $locale->code
- ]);
+ if (isset($product['channels'])) {
+ foreach ($product['channels'] as $channel) {
+ $channel = app('Webkul\Core\Repositories\ChannelRepository')->findOrFail($channel);
+ $channels[] = $channel['code'];
+ }
+ } else if (isset($parentProduct['channels'])){
+ foreach ($parentProduct['channels'] as $channel) {
+ $channel = app('Webkul\Core\Repositories\ChannelRepository')->findOrFail($channel);
+ $channels[] = $channel['code'];
+ }
+ } else {
+ $channels[] = core()->getDefaultChannelCode();
+ }
- if (! $productFlat) {
- $productFlat = $this->productFlatRepository->create([
+ foreach (core()->getAllChannels() as $channel) {
+ if (in_array($channel->code, $channels)) {
+ foreach ($channel->locales as $locale) {
+ $productFlat = $this->productFlatRepository->findOneWhere([
'product_id' => $product->id,
'channel' => $channel->code,
'locale' => $locale->code
]);
- }
- foreach ($familyAttributes[$product->attribute_family->id] as $attribute) {
- if ($parentProduct && ! in_array($attribute->code, array_merge($superAttributes[$parentProduct->id], ['sku', 'name', 'price', 'weight', 'status'])))
- continue;
-
- if (in_array($attribute->code, ['tax_category_id']))
- continue;
-
- if (! Schema::hasColumn('product_flat', $attribute->code))
- continue;
-
- if ($attribute->value_per_channel) {
- if ($attribute->value_per_locale) {
- $productAttributeValue = $product->attribute_values()->where('channel', $channel->code)->where('locale', $locale->code)->where('attribute_id', $attribute->id)->first();
- } else {
- $productAttributeValue = $product->attribute_values()->where('channel', $channel->code)->where('attribute_id', $attribute->id)->first();
- }
- } else {
- if ($attribute->value_per_locale) {
- $productAttributeValue = $product->attribute_values()->where('locale', $locale->code)->where('attribute_id', $attribute->id)->first();
- } else {
- $productAttributeValue = $product->attribute_values()->where('attribute_id', $attribute->id)->first();
- }
- }
-
- if ($product->type == 'configurable' && $attribute->code == 'price') {
- $productFlat->{$attribute->code} = app('Webkul\Product\Helpers\Price')->getVariantMinPrice($product);
- } else {
- $productFlat->{$attribute->code} = $productAttributeValue[ProductAttributeValue::$attributeTypeFields[$attribute->type]];
- }
-
- if ($attribute->type == 'select') {
- $attributeOption = $this->attributeOptionRepository->find($product->{$attribute->code});
-
- if ($attributeOption) {
- if ($attributeOptionTranslation = $attributeOption->translate($locale->code)) {
- $productFlat->{$attribute->code . '_label'} = $attributeOptionTranslation->label;
- } else {
- $productFlat->{$attribute->code . '_label'} = $attributeOption->admin_name;
- }
- }
- } elseif ($attribute->type == 'multiselect') {
- $attributeOptionIds = explode(',', $product->{$attribute->code});
-
- if (count($attributeOptionIds)) {
- $attributeOptions = $this->attributeOptionRepository->findWhereIn('id', $attributeOptionIds);
-
- $optionLabels = [];
-
- foreach ($attributeOptions as $attributeOption) {
- if ($attributeOptionTranslation = $attributeOption->translate($locale->code)) {
- $optionLabels[] = $attributeOptionTranslation->label;
- } else {
- $optionLabels[] = $attributeOption->admin_name;
- }
- }
-
- $productFlat->{$attribute->code . '_label'} = implode(', ', $optionLabels);
- }
- }
- }
-
- $productFlat->created_at = $product->created_at;
-
- $productFlat->updated_at = $product->updated_at;
-
- if ($parentProduct) {
- $parentProductFlat = $this->productFlatRepository->findOneWhere([
- 'product_id' => $parentProduct->id,
+ if (! $productFlat) {
+ $productFlat = $this->productFlatRepository->create([
+ 'product_id' => $product->id,
'channel' => $channel->code,
'locale' => $locale->code
]);
-
- if ($parentProductFlat) {
- $productFlat->parent_id = $parentProductFlat->id;
}
- }
- $productFlat->save();
+ foreach ($familyAttributes[$product->attribute_family->id] as $attribute) {
+ if ($parentProduct && ! in_array($attribute->code, array_merge($superAttributes[$parentProduct->id], ['sku', 'name', 'price', 'weight', 'status'])))
+ continue;
+
+ if (in_array($attribute->code, ['tax_category_id']))
+ continue;
+
+ if (! Schema::hasColumn('product_flat', $attribute->code))
+ continue;
+
+ if ($attribute->value_per_channel) {
+ if ($attribute->value_per_locale) {
+ $productAttributeValue = $product->attribute_values()->where('channel', $channel->code)->where('locale', $locale->code)->where('attribute_id', $attribute->id)->first();
+ } else {
+ $productAttributeValue = $product->attribute_values()->where('channel', $channel->code)->where('attribute_id', $attribute->id)->first();
+ }
+ } else {
+ if ($attribute->value_per_locale) {
+ $productAttributeValue = $product->attribute_values()->where('locale', $locale->code)->where('attribute_id', $attribute->id)->first();
+ } else {
+ $productAttributeValue = $product->attribute_values()->where('attribute_id', $attribute->id)->first();
+ }
+ }
+
+ if ($product->type == 'configurable' && $attribute->code == 'price') {
+ $productFlat->{$attribute->code} = app('Webkul\Product\Helpers\Price')->getVariantMinPrice($product);
+ } else {
+ $productFlat->{$attribute->code} = $productAttributeValue[ProductAttributeValue::$attributeTypeFields[$attribute->type]];
+ }
+
+ if ($attribute->type == 'select') {
+ $attributeOption = $this->attributeOptionRepository->find($product->{$attribute->code});
+
+ if ($attributeOption) {
+ if ($attributeOptionTranslation = $attributeOption->translate($locale->code)) {
+ $productFlat->{$attribute->code . '_label'} = $attributeOptionTranslation->label;
+ } else {
+ $productFlat->{$attribute->code . '_label'} = $attributeOption->admin_name;
+ }
+ }
+ } elseif ($attribute->type == 'multiselect') {
+ $attributeOptionIds = explode(',', $product->{$attribute->code});
+
+ if (count($attributeOptionIds)) {
+ $attributeOptions = $this->attributeOptionRepository->findWhereIn('id', $attributeOptionIds);
+
+ $optionLabels = [];
+
+ foreach ($attributeOptions as $attributeOption) {
+ if ($attributeOptionTranslation = $attributeOption->translate($locale->code)) {
+ $optionLabels[] = $attributeOptionTranslation->label;
+ } else {
+ $optionLabels[] = $attributeOption->admin_name;
+ }
+ }
+
+ $productFlat->{$attribute->code . '_label'} = implode(', ', $optionLabels);
+ }
+ }
+ }
+
+ $productFlat->created_at = $product->created_at;
+
+ $productFlat->updated_at = $product->updated_at;
+
+ if ($parentProduct) {
+ $parentProductFlat = $this->productFlatRepository->findOneWhere([
+ 'product_id' => $parentProduct->id,
+ 'channel' => $channel->code,
+ 'locale' => $locale->code
+ ]);
+
+ if ($parentProductFlat) {
+ $productFlat->parent_id = $parentProductFlat->id;
+ }
+ }
+
+ $productFlat->save();
+ }
+ } else {
+ $productFlat = $this->productFlatRepository->findOneWhere([
+ 'product_id' => $product->id,
+ 'channel' => $channel->code,
+ ]);
+
+ if ($productFlat) {
+ $this->productFlatRepository->delete($productFlat->id);
+ }
}
}
}
diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php
index c639af542..abdaf4ac5 100755
--- a/packages/Webkul/Product/src/Repositories/ProductRepository.php
+++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php
@@ -260,6 +260,10 @@ class ProductRepository extends Repository
$this->productImage->uploadImages($data, $product);
}
+ if (isset($data['channels'])) {
+ $product['channels'] = $data['channels'];
+ }
+
Event::fire('catalog.product.update.after', $product);
return $product;
diff --git a/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php b/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php
index 9248fab4c..15288f439 100644
--- a/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php
+++ b/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php
@@ -20,7 +20,7 @@ class OrderDataGrid extends DataGrid
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('orders as order')
- ->addSelect('order.id', 'order.status', 'order.created_at', 'order.grand_total')
+ ->addSelect('order.id', 'order.status', 'order.created_at', 'order.grand_total', 'order.order_currency_code')
->where('customer_id', auth()->guard('customer')->user()->id);
$this->setQueryBuilder($queryBuilder);
@@ -49,10 +49,13 @@ class OrderDataGrid extends DataGrid
$this->addColumn([
'index' => 'grand_total',
'label' => trans('shop::app.customer.account.order.index.total'),
- 'type' => 'price',
+ 'type' => 'number',
'searchable' => true,
'sortable' => true,
- 'filterable' => true
+ 'filterable' => true,
+ 'wrapper' => function ($value) {
+ return core()->formatPrice($value->grand_total, $value->order_currency_code);
+ }
]);
$this->addColumn([
diff --git a/packages/Webkul/Shop/src/Resources/views/layouts/master.blade.php b/packages/Webkul/Shop/src/Resources/views/layouts/master.blade.php
index 190b3df2e..6d01be266 100755
--- a/packages/Webkul/Shop/src/Resources/views/layouts/master.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/layouts/master.blade.php
@@ -1,7 +1,3 @@
-@php
- $locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
-@endphp
-
@@ -34,7 +30,8 @@
-direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
+
+getCurrentLocale()->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
{!! view_render_event('bagisto.shop.layout.body.before') !!}
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 7ef798090..e15147b98 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
@@ -2,24 +2,26 @@
@inject ('productFlatRepository', 'Webkul\Product\Repositories\ProductFlatRepository')
-@inject ('productAttributeValueRepository', 'Webkul\Product\Repositories\ProductAttributeValueRepository')
-
getCategoryProductAttribute($category->id);
+ if (count($category->filterableAttributes) > 0) {
+ $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;
+ 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 = collect($filterAttributes);
+ }
}
} else {
$filterAttributes = $attributeRepository->getFilterAttributes();