Flat rate implemented

This commit is contained in:
jitendra 2019-01-25 17:24:48 +05:30
parent 9a577c4d0e
commit 6fff4701a6
33 changed files with 399 additions and 43957 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/admin.js": "/js/admin.js?id=7683c8f127f6ad2ac3ce",
"/js/admin.js": "/js/admin.js?id=da5ebef9c25a064e7ed6",
"/css/admin.css": "/css/admin.css?id=3e790c2215bf5c60ac21"
}
}

View File

@ -15,7 +15,7 @@ class ProductDataGrid extends DataGrid
{
protected $paginate = true;
protected $itemsPerPage = 5; //overriding the default items per page
protected $itemsPerPage = 10; //overriding the default items per page
protected $index = 'product_id';

View File

@ -81,8 +81,6 @@ class AttributeController extends Controller
$attribute = $this->attribute->create($data);
Event::fire('after.attribute.created', $attribute);
session()->flash('success', 'Attribute created successfully.');
return redirect()->route($this->_config['redirect']);
@ -118,8 +116,6 @@ class AttributeController extends Controller
$attribute = $this->attribute->update(request()->all(), $id);
// Event::fire('after.attribute.updated', $attribute);
session()->flash('success', 'Attribute updated successfully.');
return redirect()->route($this->_config['redirect']);
@ -139,8 +135,6 @@ class AttributeController extends Controller
session()->flash('error', trans('admin::app.response.user-define-error', ['name' => 'attribute']));
} else {
try {
Event::fire('after.attribute.deleted', $attribute);
$this->attribute->delete($id);
session()->flash('success', 'Attribute deleted successfully.');

View File

@ -1,52 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Helpers\AbstractProduct;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class FeaturedProductsCriteria extends AbstractProduct implements CriteriaInterface
{
/**
* @var AttributeRepository
*/
protected $attribute;
/**
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @return void
*/
public function __construct(AttributeRepository $attribute)
{
$this->attribute = $attribute;
}
/**
* Apply criteria in query repository
*
* @param string $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
$attribute = $this->attribute->findOneByField('code', 'featured');
$model = $model->leftJoin('product_attribute_values as filter_featured', 'products.id', '=', 'filter_featured.product_id');
$model = $this->applyChannelLocaleFilter($attribute, $model, 'filter_featured');
$model->where('filter_featured.boolean_value', 1)
->where('filter_featured.attribute_id', $attribute->id);
return $model;
}
}

View File

@ -1,84 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Webkul\Product\Models\ProductAttributeValue;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Helpers\AbstractProduct;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class FilterByAttributesCriteria extends AbstractProduct implements CriteriaInterface
{
/**
* @var AttributeRepository
*/
protected $attribute;
/**
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @return void
*/
public function __construct(AttributeRepository $attribute)
{
$this->attribute = $attribute;
}
/**
* Apply criteria in query repository
*
* @param string $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
$model = $model->leftJoin('products as variants', 'products.id', '=', 'variants.parent_id');
$model = $model->where(function($query1) use($model) {
$aliases = [
'products' => 'filter_',
'variants' => 'variant_filter_'
];
foreach ($aliases as $table => $alias) {
$query1 = $query1->orWhere(function($query2) use($model, $table, $alias) {
foreach ($this->attribute->getProductDefaultAttributes(array_keys(request()->input())) as $code => $attribute) {
$aliasTemp = $alias . $attribute->code;
$model = $model->leftJoin('product_attribute_values as ' . $aliasTemp, $table . '.id', '=', $aliasTemp . '.product_id');
$query2 = $this->applyChannelLocaleFilter($attribute, $query2, $aliasTemp);
$column = ProductAttributeValue::$attributeTypeFields[$attribute->type];
$temp = explode(',', request()->get($attribute->code));
if ($attribute->type != 'price') {
$query2 = $query2->where($aliasTemp . '.attribute_id', $attribute->id);
$query2 = $query2->where(function($query3) use($aliasTemp, $column, $temp) {
foreach ($temp as $code => $filterValue) {
$query3 = $query3->orWhere($aliasTemp . '.' . $column, $filterValue);
}
});
} else {
$query2 = $query2->where($aliasTemp . '.' . $column, '>=', current($temp))
->where($aliasTemp . '.' . $column, '<=', end($temp))
->where($aliasTemp . '.attribute_id', $attribute->id);
}
}
});
}
});
return $model;
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class FilterByCategoryCriteria implements CriteriaInterface
{
/**
* @var integer
*/
protected $categoryId;
/**
* @param integer $categoryId
* @return void
*/
public function __construct($categoryId)
{
$this->categoryId = $categoryId;
}
/**
* Apply criteria in query repository
*
* @param string $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
$model = $model->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id')
->where('product_categories.category_id', $this->categoryId);
return $model;
}
}

View File

@ -1,52 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Helpers\AbstractProduct;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class NewProductsCriteria extends AbstractProduct implements CriteriaInterface
{
/**
* @var AttributeRepository
*/
protected $attribute;
/**
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @return void
*/
public function __construct(AttributeRepository $attribute)
{
$this->attribute = $attribute;
}
/**
* Apply criteria in query repository
*
* @param string $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
$attribute = $this->attribute->findOneByField('code', 'new');
$model = $model->leftJoin('product_attribute_values as filter_new', 'products.id', '=', 'filter_new.product_id');
$model = $this->applyChannelLocaleFilter($attribute, $model, 'filter_featured');
$model->where('filter_new.boolean_value', 1)
->where('filter_new.attribute_id', $attribute->id);
return $model;
}
}

View File

@ -1,45 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Helpers\AbstractProduct;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class SearchByAttributeCriteria extends AbstractProduct implements CriteriaInterface
{
/**
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @return void
*/
public function __construct(AttributeRepository $attribute)
{
$this->attribute = $attribute;
}
/**
* Apply criteria in query repository
*
* @param string $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
$attribute = $this->attribute->findOneByField('code', 'name');
return $model
->leftJoin('product_attribute_values as pav', 'products.id', '=', 'pav.product_id')
->where('pav.attribute_id', '=', $attribute->id)
->where('products.parent_id', '=', null);
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Helpers\AbstractProduct;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class SearchByCategoryCriteria extends AbstractProduct implements CriteriaInterface
{
/**
* Apply criteria in query repository
*
* @param string $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
//->leftJoin('category_translations', 'categories.id', '=', 'category_translations.id')->addSelect('category_translations.name')
$model = $model->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id')->leftJoin('categories', 'product_categories.category_id', '=', 'categories.id')->leftJoin('category_translations', 'categories.id', '=', 'category_translations.id');
return $model;
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Helpers\AbstractProduct;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class SearchBySuperAttributeCriteria extends AbstractProduct implements CriteriaInterface
{
}

View File

@ -1,71 +0,0 @@
<?php
namespace Webkul\Product\Contracts\Criteria;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Webkul\Product\Models\ProductAttributeValue;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Helpers\AbstractProduct;
/**
* Class MyCriteria.
*
* @package namespace App\Criteria;
*/
class SortCriteria extends AbstractProduct implements CriteriaInterface
{
/**
* @var AttributeRepository
*/
protected $attribute;
/**
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @return void
*/
public function __construct(AttributeRepository $attribute)
{
$this->attribute = $attribute;
}
/**
* Apply criteria in query repository
*
* @param string $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
$params = request()->input();
if (isset($params['sort'])) {
if ($params['sort'] == 'name' || $params['sort'] == 'price') {
$attribute = $this->attribute->findOneByField('code', $params['sort']);
$alias = 'sort_' . $params['sort'];
$model = $model->leftJoin('product_attribute_values as ' . $alias, function($qb) use($attribute, $alias) {
$qb = $this->applyChannelLocaleFilter($attribute, $qb, $alias);
$qb->on('products.id', $alias . '.product_id')
->where($alias . '.attribute_id', $attribute->id);
});
$model = $model->addSelect($alias . '.' . ProductAttributeValue::$attributeTypeFields[$attribute->type] . ' as ' . $attribute->code);
$model = $model->orderBy($attribute->code, $params['order']);
} else {
$model = $model->orderBy($params['sort'], $params['order']);
}
} else {
$model = $model->orderBy('created_at', 'desc');
}
return $model;
}
}

View File

@ -21,7 +21,6 @@ class CreateProductFlatTable extends Migration
$table->string('url_key')->nullable();
$table->boolean('new')->nullable();
$table->boolean('featured')->nullable();
$table->boolean('visibility')->nullable();
$table->boolean('status')->nullable();
$table->string('thumbnail')->nullable();

View File

@ -1,40 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddNewFromToColumnsInProductFlat extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('product_flat')) {
Schema::table('product_flat', function (Blueprint $table) {
$table->date('new_to')->after('new');
$table->date('new_from')->after('new');
$table->unique(['product_id', 'channel', 'locale'], 'product_flat_unique_index');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable('product_flat')) {
Schema::table('product_flat', function (Blueprint $table) {
$table->dropColumn('new_from');
$table->dropColumn('new_to');
$table->dropIndex('product_flat_unique_index');
});
}
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUpdatedAtColumnInProductFlatTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('product_flat', function (Blueprint $table) {
$table->datetime('created_at')->change();
$table->string('size_label')->change();
$table->datetime('updated_at')->nullable();
$table->integer('parent_id')->unsigned()->nullable();
$table->boolean('visible_individually')->nullable();
$table->foreign('parent_id')->references('id')->on('product_flat')->onDelete('cascade');
$table->unique(['product_id', 'channel', 'locale'], 'product_flat_unique_index');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@ -0,0 +1,218 @@
<?php
namespace Webkul\Product\Listeners;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Webkul\Attribute\Repositories\AttributeOptionRepository;
use Webkul\Product\Repositories\ProductFlatRepository;
use Webkul\Product\Repositories\ProductAttributeValueRepository;
use Webkul\Product\Models\ProductAttributeValue;
/**
* Product Flat Event handler
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductFlat
{
/**
* AttributeOptionRepository Repository Object
*
* @var object
*/
protected $attributeOptionRepository;
/**
* ProductFlatRepository Repository Object
*
* @var object
*/
protected $productFlatRepository;
/**
* ProductAttributeValueRepository Repository Object
*
* @var object
*/
protected $productAttributeValueRepository;
/**
* Attribute Object
*
* @var object
*/
protected $attribute;
/**
* @var object
*/
public $attributeTypeFields = [
'text' => 'text',
'textarea' => 'text',
'price' => 'float',
'boolean' => 'boolean',
'select' => 'integer',
'multiselect' => 'text',
'datetime' => 'datetime',
'date' => 'date',
];
/**
* Create a new listener instance.
*
* @param Webkul\Attribute\Repositories\AttributeOptionRepository $attributeOptionRepository
* @param Webkul\Product\Repositories\ProductFlatRepository $productFlatRepository
* @param Webkul\Product\Repositories\ProductAttributeValueRepository $productAttributeValueRepository
* @return void
*/
public function __construct(
AttributeOptionRepository $attributeOptionRepository,
ProductFlatRepository $productFlatRepository,
ProductAttributeValueRepository $productAttributeValueRepository
)
{
$this->attributeOptionRepository = $attributeOptionRepository;
$this->productAttributeValueRepository = $productAttributeValueRepository;
$this->productFlatRepository = $productFlatRepository;
}
/**
* After the attribute is created
*
* @return void
*/
public function afterAttributeCreatedUpdated($attribute)
{
if(!$attribute->is_user_defined) {
return false;
}
if (Schema::hasTable('product_flat')) {
if (!Schema::hasColumn('product_flat', $attribute->code)) {
Schema::table('product_flat', function (Blueprint $table) use($attribute) {
$table->{$this->attributeTypeFields[$attribute->type]}($attribute->code)->nullable();
if ($attribute->type == 'select' || $attribute->type == 'multiselect') {
$table->string($attribute->code . '_label')->nullable();
}
});
}
}
}
public function afterAttributeDeleted($attribute)
{
if (Schema::hasTable('product_flat')) {
if (Schema::hasColumn('product_flat', strtolower($attribute->code))) {
Schema::table('product_flat', function (Blueprint $table) use($attribute) {
$table->dropColumn($attribute->code);
if ($attribute->type == 'select' || $attribute->type == 'multiselect') {
$table->dropColumn($attribute->code . '_label');
}
});
}
}
}
/**
* Creates product flat
*
* @param Product $product
* @return void
*/
public function afterProductCreatedUpdated($product)
{
$this->createFlat($product);
if ($product->type == 'configurable') {
foreach ($product->variants()->get() as $variant) {
$this->createFlat($variant, $product);
}
}
}
/**
* Creates product flat
*
* @param Product $product
* @param Product $parentProduct
* @return void
*/
public function createFlat($product, $parentProduct = null)
{
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 (!$productFlat) {
$productFlat = $this->productFlatRepository->create([
'product_id' => $product->id,
'channel' => $channel->code,
'locale' => $locale->code
]);
}
foreach ($product->attribute_family->custom_attributes as $attribute) {
if (!Schema::hasTable('product_flat') || !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();
}
}
$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;
}
}
}
}
$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();
}
}
}
}

View File

@ -1,270 +0,0 @@
<?php
namespace Webkul\Product\Listeners;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Webkul\Product\Repositories\ProductFlatRepository as ProductFlat;
use Webkul\Product\Repositories\ProductAttributeValueRepository as ProductAttributeValue;
/**
* Products Flat Event handler
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductsFlat
{
/**
* ProductFlat Repository Object
*
* @vatr array
*/
protected $productFlat;
protected $productAttributeValue;
protected $attribute;
public function __construct(ProductFlat $productFlat, ProductAttributeValue $productAttributeValue) {
$this->productAttributeValue = $productAttributeValue;
$this->productFlat = $productFlat;
}
/**
* After the attribute is created
*
* @return void
*/
public function afterAttributeCreated($attribute)
{
if(!$attribute->is_user_defined) {
return false;
}
$attributeType = $attribute->type;
$attributeCode = $attribute->code;
if ($attributeType == 'text' || $attributeType == 'textarea') {
$columnType = 'text';
} else if ($attributeType == 'price') {
$columnType = 'decimal';
} else if ($attributeType == 'boolean') {
$columnType = 'boolean';
} else if ($attributeType == 'select' || $attributeType == 'multiselect') {
if ($attributeType == 'multiselect') {
$columnType = 'text';
} else {
$columnType = 'integer';
}
} else if ($attributeType == 'datetime') {
$columnType = 'dateTime';
} else if ($attributeType == 'date') {
$columnType = 'date';
} else {
return false;
}
if (Schema::hasTable('product_flat')) {
if (!Schema::hasColumn('product_flat', strtolower($attribute->code))) {
Schema::table('product_flat', function (Blueprint $table) use($columnType, $attributeCode, $attributeType) {
$table->{$columnType}(strtolower($attributeCode))->nullable();
if($attributeType == 'select' || $attributeType == 'multiselect') {
$table->string(strtolower($attributeCode).'_label')->nullable();
}
});
return true;
} else {
return false;
}
}
}
/**
* After the attribute is updated
*
* @return void
*/
public function afterAttributeUpdated($attribute)
{
return true;
}
public function afterAttributeDeleted($attribute)
{
if (Schema::hasTable('product_flat')) {
if (Schema::hasColumn('product_flat', strtolower($attribute->code))) {
Schema::table('product_flat', function (Blueprint $table) use($attribute){
$table->dropColumn(strtolower($attribute->code));
if ($attribute->type == 'select' || $attribute->type == 'multiselect') {
$table->dropColumn(strtolower($attribute->code).'_label');
}
});
return true;
} else {
return false;
}
}
}
public function afterProductCreatedOrUpdated($ProductFlat) {
$product = $ProductFlat;
$productAttributes = $product->attribute_family->custom_attributes;
$allLocales = core()->getAllLocales();
$productsFlat = array();
$channelLocaleMap = array();
$nonDependentAttributes = array();
$localeDependentAttributes = array();
$channelDependentAttributes = array();
$channelLocaleDependentAttributes = array();
foreach($productAttributes as $key => $productAttribute) {
if($productAttribute->value_per_channel) {
if($productAttribute->value_per_locale) {
array_push($channelLocaleDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
} else {
array_push($channelDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
}
} else if($productAttribute->value_per_locale && !$productAttribute->value_per_channel) {
array_push($localeDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
} else {
array_push($nonDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
}
}
foreach(core()->getAllChannels() as $channel) {
$dummy = [
'product_id' => $product->id,
'channel' => $channel->code,
'locale' => null,
'data' => $channelDependentAttributes
];
array_push($channelLocaleMap, $dummy);
$dummy = [];
foreach($channel->locales as $locale) {
$dummy = [
'product_id' => $product->id,
'channel' => $channel->code,
'locale' => $locale->code,
'data' => $channelLocaleDependentAttributes
];
array_push($channelLocaleMap, $dummy);
$dummy = [];
}
}
$dummy = [
'product_id' => $product->id,
'channel' => null,
'locale' => null,
'data' => $nonDependentAttributes
];
array_push($channelLocaleMap, $dummy);
$dummy = [];
foreach($allLocales as $key => $allLocale) {
$dummy = [
'product_id' => $product->id,
'channel' => null,
'locale' => $allLocale->code,
'data' => $localeDependentAttributes
];
array_push($channelLocaleMap, $dummy);
$dummy = [];
}
$productFlatObjects = $channelLocaleMap;
$keyOfNonDependentAttributes = null;
foreach($productAttributes as $productAttribute) {
foreach($productFlatObjects as $flatKey => $productFlatObject) {
if($productFlatObject['channel'] == null && $productFlatObject['locale'] == null) {
$keyOfNonDependentAttributes = $flatKey;
}
foreach($productFlatObject['data'] as $key => $value) {
if($productAttribute->code == $value['code']) {
$valueOf = $this->productAttributeValue->findOneWhere([
'product_id' => $product->id,
'channel' => $productFlatObject['channel'],
'locale' => $productFlatObject['locale'],
'attribute_id' => $productAttribute->id
]);
if($valueOf != null) {
$productAttributeColumn = $this->productAttributeValue->model()::$attributeTypeFields[$productAttribute->type];
$valueOf = $valueOf->{$productAttributeColumn};
$productFlatObjects[$flatKey][$productAttribute->code] = $valueOf;
} else {
$productFlatObjects[$flatKey][$productAttribute->code] = 'null';
}
}
}
}
}
$nonDependentAttributes = $productFlatObjects[$keyOfNonDependentAttributes];
array_forget($nonDependentAttributes, ['product_id', 'channel', 'locale', 'data', 'visible_individually', 'width', 'height', 'depth', 'tax_category_id']);
unset($productFlatObjects[$keyOfNonDependentAttributes]);
$productFlatEntryObject = array();
$tempFlatObject = array();
foreach($productFlatObjects as $flatKey => $productFlatObject) {
unset($productFlatObject['data']);
if(isset($productFlatObject['short_description'])) {
$productFlatObject['description'] = $productFlatObject['short_description'];
unset($productFlatObject['short_description']);
}
if(isset($productFlatObject['meta_title'])) {
unset($productFlatObject['meta_title']);
unset($productFlatObject['meta_description']);
unset($productFlatObject['meta_keywords']);
}
$tempFlatObject = array_merge($productFlatObject, $nonDependentAttributes);
$tempFlatObject = core()->convertEmptyStringsToNull($tempFlatObject);
$exists = $this->productFlat->findWhere([
'product_id' => $product->id,
'channel' => $tempFlatObject['channel'],
'locale' => $tempFlatObject['locale']
]);
if($exists->count() == 0) {
$result = $this->productFlat->create($tempFlatObject);
} else {
$result = $exists->first();
$result->update($tempFlatObject);
}
unset($tempFlatObject);
}
return 'true';
}
}

View File

@ -3,14 +3,6 @@
namespace Webkul\Product\Models;
use Illuminate\Database\Eloquent\Model;
// use Webkul\Attribute\Models\AttributeFamily;
// use Webkul\Category\Models\Category;
// use Webkul\Attribute\Models\Attribute;
// use Webkul\Product\Models\ProductAttributeValue;
// use Webkul\Product\Models\ProductInventory;
// use Webkul\Product\Models\ProductImage;
// use Webkul\Inventory\Models\InventorySource;
// use Webkul\Product\Models\ProductReview;
class ProductFlat extends Model
{
@ -19,4 +11,12 @@ class ProductFlat extends Model
protected $guarded = ['id', 'created_at', 'updated_at'];
public $timestamps = false;
/**
* Get the product that owns the attribute value.
*/
public function product()
{
return $this->belongsTo(Product::class);
}
}

View File

@ -14,15 +14,14 @@ class EventServiceProvider extends ServiceProvider
*/
public function boot()
{
// Event::listen('after.attribute.updated', 'Webkul\Product\Listeners\ProductsFlat@afterAttributeUpdated');
Event::listen('catalog.attribute.create.after', 'Webkul\Product\Listeners\ProductFlat@afterAttributeCreatedUpdated');
Event::listen('after.attribute.created', 'Webkul\Product\Listeners\ProductsFlat@afterAttributeCreated');
Event::listen('catalog.attribute.update.after', 'Webkul\Product\Listeners\ProductFlat@afterAttributeCreatedUpdated');
Event::listen('after.attribute.deleted', 'Webkul\Product\Listeners\ProductsFlat@afterAttributeDeleted');
Event::listen('catalog.attribute.delete.before', 'Webkul\Product\Listeners\ProductFlat@afterAttributeDeleted');
Event::listen('after.product.created', 'Webkul\Product\Listeners\ProductsFlat@afterProductCreatedOrUpdated');
Event::listen('after.product.updated', 'Webkul\Product\Listeners\ProductsFlat@afterProductCreatedOrUpdated');
Event::listen('catalog.product.create.after', 'Webkul\Product\Listeners\ProductFlat@afterProductCreatedUpdated');
Event::listen('catalog.product.update.after', 'Webkul\Product\Listeners\ProductFlat@afterProductCreatedUpdated');
}
}

View File

@ -7,19 +7,9 @@ use Illuminate\Support\Facades\Event;
use Webkul\Core\Eloquent\Repository;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Attribute\Repositories\AttributeOptionRepository;
use Webkul\Product\Repositories\ProductAttributeValueRepository;
use Webkul\Product\Repositories\ProductInventoryRepository;
use Webkul\Product\Repositories\ProductImageRepository;
use Webkul\Product\Models\ProductAttributeValue;
use Webkul\Product\Contracts\Criteria\SortCriteria;
use Webkul\Product\Contracts\Criteria\ActiveProductCriteria;
use Webkul\Product\Contracts\Criteria\AttributeToSelectCriteria;
use Webkul\Product\Contracts\Criteria\FilterByAttributesCriteria;
use Webkul\Product\Contracts\Criteria\FilterByCategoryCriteria;
use Webkul\Product\Contracts\Criteria\NewProductsCriteria;
use Webkul\Product\Contracts\Criteria\FeaturedProductsCriteria;
use Webkul\Product\Contracts\Criteria\SearchByAttributeCriteria;
use Webkul\Product\Contracts\Criteria\SearchByCategoryCriteria;
use Illuminate\Database\Eloquent\ModelNotFoundException;
/**
@ -52,7 +42,7 @@ class ProductRepository extends Repository
protected $attributeValue;
/**
* ProductInventoryRepository object
* ProductFlatRepository object
*
* @var array
*/
@ -70,8 +60,8 @@ class ProductRepository extends Repository
*
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @param Webkul\Attribute\Repositories\AttributeOptionRepository $attributeOption
* @param Webkul\Attribute\Repositories\AttributeOptionRepository $attributeOption
* @param Webkul\Product\Repositories\ProductAttributeValueRepository $attributeValue
* @param Webkul\Product\Repositories\ProductInventoryRepository $productInventory
* @param Webkul\Product\Repositories\ProductImageRepository $productImage
* @return void
*/
@ -232,9 +222,6 @@ class ProductRepository extends Repository
Event::fire('catalog.product.update.after', $product);
//correct it after making sure which event to use.
Event::fire('after.product.updated', $product);
return $product;
}
@ -415,25 +402,68 @@ class ProductRepository extends Repository
*/
public function findAllByCategory($categoryId = null)
{
$this->pushCriteria(app(ActiveProductCriteria::class));
$this->pushCriteria(app(SortCriteria::class));
$this->pushCriteria(app(FilterByAttributesCriteria::class));
$this->pushCriteria(new FilterByCategoryCriteria($categoryId));
$this->pushCriteria(app(AttributeToSelectCriteria::class)->addAttribueToSelect([
'name',
'description',
'short_description',
'price',
'special_price',
'special_price_from',
'special_price_to'
]));
$params = request()->input();
return $this->scopeQuery(function($query) {
return $query->distinct()->addSelect('products.*');
})->paginate(isset($params['limit']) ? $params['limit'] : 9, ['products.id']);
$results = app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function($query) use($params, $categoryId) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale();
$qb = $query->distinct()
->addSelect('product_flat.*')
->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id')
->where('product_flat.visible_individually', 1)
->where('product_flat.status', 1)
->where('product_flat.channel', $channel)
->where('product_flat.locale', $locale)
->whereNotNull('product_flat.url_key')
->where('product_categories.category_id', $categoryId);
$queryBuilder = $qb->leftJoin('product_flat as flat_variants', function($qb) use($channel, $locale) {
$qb->on('product_flat.id', '=', 'flat_variants.parent_id')
->where('flat_variants.channel', $channel)
->where('flat_variants.locale', $locale);
});
if (isset($params['sort'])) {
$attribute = $this->attribute->findOneByField('code', $params['sort']);
if ($params['sort'] == 'price') {
$qb->orderBy($attribute->code, $params['order']);
} else {
$qb->orderBy($params['sort'] == 'created_at' ? 'product_flat.created_at' : $attribute->code, $params['order']);
}
}
$qb = $qb->where(function($query1) {
foreach (['product_flat', 'flat_variants'] as $alias) {
$query1 = $query1->orWhere(function($query2) use($alias) {
$attributes = $this->attribute->getProductDefaultAttributes(array_keys(request()->input()));
foreach ($attributes as $attribute) {
$column = $alias . '.' . $attribute->code;
$queryParams = explode(',', request()->get($attribute->code));
if ($attribute->type != 'price') {
$query2 = $query2->where(function($query3) use($column, $queryParams) {
foreach ($queryParams as $filterValue) {
$query3 = $query3->orWhere($column, $filterValue);
}
});
} else {
$query2 = $query2->where($column, '>=', current($queryParams))->where($column, '<=', end($queryParams));
}
}
});
}
});
return $qb;
})->paginate(isset($params['limit']) ? $params['limit'] : 9);
return $results;
}
/**
@ -472,15 +502,21 @@ class ProductRepository extends Repository
*/
public function getNewProducts()
{
$this->pushCriteria(app(ActiveProductCriteria::class));
$this->pushCriteria(app(NewProductsCriteria::class));
$this->pushCriteria(app(AttributeToSelectCriteria::class));
$results = app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$params = request()->input();
$locale = request()->get('locale') ?: app()->getLocale();
return $this->scopeQuery(function($query) {
return $query->distinct()->addSelect('products.*')->orderBy('id', 'desc');
})->paginate(4, ['products.id']);
return $query->distinct()
->addSelect('product_flat.*')
->where('product_flat.status', 1)
->where('product_flat.new', 1)
->where('product_flat.channel', $channel)
->where('product_flat.locale', $locale)
->orderBy('product_id', 'desc');
})->paginate(4);
return $results;
}
/**
@ -490,15 +526,21 @@ class ProductRepository extends Repository
*/
public function getFeaturedProducts()
{
$this->pushCriteria(app(ActiveProductCriteria::class));
$this->pushCriteria(app(FeaturedProductsCriteria::class));
$this->pushCriteria(app(AttributeToSelectCriteria::class));
$results = app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$params = request()->input();
$locale = request()->get('locale') ?: app()->getLocale();
return $this->scopeQuery(function($query) {
return $query->distinct()->addSelect('products.*')->orderBy('id', 'desc');
})->paginate(4, ['products.id']);
return $query->distinct()
->addSelect('product_flat.*')
->where('product_flat.status', 1)
->where('product_flat.featured', 1)
->where('product_flat.channel', $channel)
->where('product_flat.locale', $locale)
->orderBy('product_id', 'desc');
})->paginate(4);
return $results;
}
/**
@ -507,11 +549,21 @@ class ProductRepository extends Repository
* @return Collection
*/
public function searchProductByAttribute($term) {
$this->pushCriteria(app(ActiveProductCriteria::class));
$this->pushCriteria(app(SearchByAttributeCriteria::class));
$results = app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function($query) use($term) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
return $this->scopeQuery(function($query) use($term) {
return $query->distinct()->addSelect('products.*')->where('pav.text_value', 'like', '%'.$term.'%');
})->paginate(4);
$locale = request()->get('locale') ?: app()->getLocale();
return $query->distinct()
->addSelect('product_flat.*')
->where('product_flat.status', 1)
->where('product_flat.channel', $channel)
->where('product_flat.locale', $locale)
->whereNotNull('product_flat.url_key')
->where('product_flat.name', 'like', '%' . $term . '%')
->orderBy('product_id', 'desc');
})->paginate(16);
return $results;
}
}

View File

@ -3,13 +3,9 @@
namespace Webkul\Product\Repositories;
use Illuminate\Container\Container as App;
use Webkul\Core\Eloquent\Repository;
use Webkul\Product\Repositories\ProductRepository as Product;
// use Webkul\Product\Contracts\Criteria\searchByAttributeCriteria;
/**
* Search Reposotory
*
@ -38,7 +34,6 @@ class SearchRepository extends Repository
}
public function searchAttributes() {
// $this->pushCriteria(app(searchByAttributeCriteria::class));
}
public function search($data) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,4 @@
{
<<<<<<< HEAD
"/js/shop.js": "/js/shop.js",
"/css/shop.css": "/css/shop.css"
=======
"/js/shop.js": "/js/shop.js?id=0076f480705e7ce1f8e0",
"/css/shop.css": "/css/shop.css?id=064ee767a010fa58727e"
>>>>>>> 97cb751c56e436baed6fe43c0e0fccfbf726334d
}
"/js/shop.js": "/js/shop.js?id=e25827d4b84cbe5d76fb",
"/css/shop.css": "/css/shop.css?id=7991a1cc49d8b6ef3949"
}

View File

@ -299,7 +299,7 @@ return [
'newest-first' => 'Newest First',
'oldest-first' => 'Oldest First',
'cheapest-first' => 'Cheapest First',
'expansive-first' => 'Expensive First',
'expensive-first' => 'Expensive First',
'show' => 'Show',
'pager-info' => 'Showing :showing of :total Items',
'description' => 'Description',

View File

@ -9,9 +9,9 @@
<div class="featured-grid product-grid-4">
@foreach ($products as $product)
@foreach ($products as $productFlat)
@include ('shop::products.list.card', ['product' => $product])
@include ('shop::products.list.card', ['product' => $productFlat->product])
@endforeach

View File

@ -9,9 +9,9 @@
<div class="product-grid-4">
@foreach ($products as $product)
@foreach ($products as $productFlat)
@include ('shop::products.list.card', ['product' => $product])
@include ('shop::products.list.card', ['product' => $productFlat->product])
@endforeach

View File

@ -38,14 +38,18 @@
@if ($toolbarHelper->getCurrentMode() == 'grid')
<div class="product-grid-3">
@foreach ($products as $product)
@include ('shop::products.list.card', ['product' => $product])
@foreach ($products as $productFlat)
@include ('shop::products.list.card', ['product' => $productFlat->product])
@endforeach
</div>
@else
<div class="product-list">
@foreach ($products as $product)
@include ('shop::products.list.card', ['product' => $product])
@include ('shop::products.list.card', ['product' => $productFlat->product])
@endforeach
</div>
@endif

View File

@ -28,10 +28,6 @@
</a>
</div>
<div class="product-description">
{{ $product->short_description }}
</div>
@include ('shop::products.price', ['product' => $product])
@if (Route::currentRouteName() == "shop.products.index")

View File

@ -26,12 +26,12 @@
<span><b>{{ $results->count() }} </b>{{ __('shop::app.search.found-results') }}</span>
</div>
@endif
{{-- @include ('shop::products.list.toolbar')
@inject ('toolbarHelper', 'Webkul\Product\Helpers\Toolbar') --}}
<div class="product-grid-4">
@foreach ($results as $product)
@include('shop::products.list.card', ['product' => $product])
@foreach ($results as $productFlat)
@include('shop::products.list.card', ['product' => $productFlat->product])
@endforeach
</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,4 @@
{
<<<<<<< HEAD
"/js/ui.js": "/js/ui.js",
"/css/ui.css": "/css/ui.css"
=======
"/js/ui.js": "/js/ui.js?id=711bb1082d5b116e929f",
"/css/ui.css": "/css/ui.css?id=384d20a09ced97996829"
>>>>>>> 97cb751c56e436baed6fe43c0e0fccfbf726334d
}
}