filterable attribute for category, tax price update on cart and issue #1234

This commit is contained in:
rahul shukla 2019-07-31 17:44:29 +05:30
parent 3a7e481d01
commit 561803cd3c
14 changed files with 150 additions and 49 deletions

View File

@ -52,11 +52,11 @@ class LocalesDataGrid extends DataGrid
'sortable' => true,
'filterable' => true
]);
$this->addColumn([
'index' => 'direction',
'label' => trans('admin::app.datagrid.direction'),
'type' => 'select',
'type' => 'string',
'searchable' => true,
'sortable' => true,
'filterable' => true

View File

@ -449,7 +449,7 @@ return [
'image' => 'Image',
'file' => 'File',
'checkbox' => 'Checkbox',
'use_in_flat' => "Create in Product Flat Table"
'use_in_flat' => "Create in Product Flat Table",
],
'families' => [
'title' => 'Families',
@ -493,6 +493,8 @@ return [
'meta_description' => 'Meta Description',
'meta_keywords' => 'Meta Keywords',
'image' => 'Image',
'filterable-attributes' => 'Filterable Attributes',
'attributes' => 'Attributes',
]
],

View File

@ -136,6 +136,23 @@
@endif
<accordian :title="'{{ __('admin::app.catalog.categories.filterable-attributes') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('attributes[]') ? 'has-error' : '']">
<label for="attributes" class="required">{{ __('admin::app.catalog.categories.attributes') }}</label>
<select class="control" name="attributes[]" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.catalog.categories.attributes') }}&quot;" multiple>
@foreach ($attributes as $attribute)
<option value="{{ $attribute->id }}">
{{ $attribute->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('attributes[]')">
@{{ errors.first('attributes[]') }}
</span>
</div>
</div>
</accordian>
{!! view_render_event('bagisto.admin.catalog.category.create_form_accordian.seo.before') !!}

View File

@ -148,6 +148,23 @@
@endif
<accordian :title="'{{ __('admin::app.catalog.categories.filterable-attributes') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('attributes[]') ? 'has-error' : '']">
<label for="attributes" class="required">{{ __('admin::app.catalog.categories.attributes') }}</label>
<select class="control" name="attributes[]" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.catalog.categories.attributes') }}&quot;" multiple>
@foreach ($attributes as $attribute)
<option value="{{ $attribute->id }}" {{ in_array($attribute->id, $category->filterableAttributes->pluck('id')->toArray()) ? 'selected' : ''}}>
{{ $attribute->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('attributes[]')">
@{{ errors.first('attributes[]') }}
</span>
</div>
</div>
</accordian>
{!! view_render_event('bagisto.admin.catalog.category.edit_form_accordian.seo.before', ['category' => $category]) !!}

View File

@ -1,7 +1,3 @@
@php
$locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
@endphp
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
@ -71,7 +67,7 @@
{!! view_render_event('bagisto.admin.layout.head') !!}
</head>
<body @if ($locale->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
<body @if (core()->getCurrentLocale()->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
<div id="app" class="container">
<flash-wrapper ref='flashes'></flash-wrapper>

View File

@ -1,7 +1,3 @@
@php
$locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
@endphp
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
@ -23,7 +19,7 @@
</head>
<body @if ($locale->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
<body @if (core()->getCurrentLocale()->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
{!! view_render_event('bagisto.admin.layout.body.before') !!}
<div id="app">

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoryFilterableAttributesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('category_filterable_attributes', function (Blueprint $table) {
$table->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');
}
}

View File

@ -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'));
}
/**

View File

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

View File

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

View File

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

View File

@ -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;
}

View File

@ -1,7 +1,3 @@
@php
$locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
@endphp
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
@ -34,7 +30,8 @@
</head>
<body @if ($locale->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
<body @if (core()->getCurrentLocale()->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
{!! view_render_event('bagisto.shop.layout.body.before') !!}

View File

@ -2,24 +2,26 @@
@inject ('productFlatRepository', 'Webkul\Product\Repositories\ProductFlatRepository')
@inject ('productAttributeValueRepository', 'Webkul\Product\Repositories\ProductAttributeValueRepository')
<?php
$filterAttributes = [];
if (isset($category)) {
$categoryProductAttributes = $productFlatRepository->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();