commit
97cb751c56
|
|
@ -53,7 +53,7 @@ Bagisto is using power of both of these frameworks and making best out of it out
|
|||
|
||||
* **OS**: Ubuntu 16.04 LTS or higher.
|
||||
* **SERVER**: Apache 2 or NGINX
|
||||
* **RAM**: 2 GB or higer.
|
||||
* **RAM**: 2 GB or higher.
|
||||
* **PHP**: 7.1.17 or higher.
|
||||
* **Processor**: Clock Cycle 1Ghz or higher.
|
||||
* **Mysql**: 5.7.23 or higher.
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ return [
|
|||
'editor' =>'vscode',
|
||||
|
||||
/**
|
||||
* Debug blacklisting
|
||||
* Blacklisting attributes while debugging
|
||||
*/
|
||||
'debug_blacklist' => [
|
||||
'_ENV' => [
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"/js/admin.js": "/js/admin.js?id=da5ebef9c25a064e7ed6",
|
||||
"/js/admin.js": "/js/admin.js?id=7683c8f127f6ad2ac3ce",
|
||||
"/css/admin.css": "/css/admin.css?id=3e790c2215bf5c60ac21"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,13 +48,13 @@ class CustomerGroupDataGrid extends DataGrid
|
|||
public function prepareActions() {
|
||||
$this->addAction([
|
||||
'type' => 'Edit',
|
||||
'route' => 'admin.customer.edit',
|
||||
'route' => 'admin.groups.edit',
|
||||
'icon' => 'icon pencil-lg-icon'
|
||||
]);
|
||||
|
||||
$this->addAction([
|
||||
'type' => 'Delete',
|
||||
'route' => 'admin.customer.delete',
|
||||
'route' => 'admin.groups.delete',
|
||||
'icon' => 'icon trash-icon'
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class OrderShipmentsDataGrid extends DataGrid
|
|||
public function prepareActions() {
|
||||
$this->addAction([
|
||||
'type' => 'View',
|
||||
'route' => 'admin.sales.orders.view',
|
||||
'route' => 'admin.sales.shipments.view',
|
||||
'icon' => 'icon eye-icon'
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@ class TaxRateDataGrid extends DataGrid
|
|||
public function prepareActions() {
|
||||
$this->addAction([
|
||||
'type' => 'Edit',
|
||||
'route' => 'admin.tax-categories.edit',
|
||||
'route' => 'admin.tax-rates.store',
|
||||
'icon' => 'icon pencil-lg-icon'
|
||||
]);
|
||||
|
||||
$this->addAction([
|
||||
'type' => 'Delete',
|
||||
'route' => 'admin.tax-categories.delete',
|
||||
'route' => 'admin.tax-rates.delete',
|
||||
'icon' => 'icon trash-icon'
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class UserDataGrid extends DataGrid
|
|||
public function prepareActions() {
|
||||
$this->addAction([
|
||||
'type' => 'Edit',
|
||||
'route' => 'admin.roles.edit',
|
||||
'route' => 'admin.users.edit',
|
||||
'icon' => 'icon pencil-lg-icon'
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ Route::group(['middleware' => ['web']], function () {
|
|||
|
||||
// Admin Routes
|
||||
Route::group(['middleware' => ['admin']], function () {
|
||||
Route::get('testev', 'Webkul\Product\Http\Controllers\ProductController@testProductFlat');
|
||||
|
||||
Route::get('/logout', 'Webkul\User\Http\Controllers\SessionController@destroy')->defaults('_config', [
|
||||
'redirect' => 'admin.session.create'
|
||||
])->name('admin.session.destroy');
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Webkul\Admin\Listeners;
|
|||
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Product\Repositories\ProductGridRepository;
|
||||
use Webkul\Product\Repositories\ProductFlatRepository;
|
||||
use Webkul\Product\Helpers\Price;
|
||||
|
||||
/**
|
||||
|
|
@ -23,19 +24,28 @@ class Product {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
Protected $price;
|
||||
protected $price;
|
||||
|
||||
/**
|
||||
* Product Flat Object
|
||||
*
|
||||
* Repository Object
|
||||
*/
|
||||
protected $productFlat;
|
||||
|
||||
/**
|
||||
* Product Grid Repository Object
|
||||
*/
|
||||
protected $productGrid;
|
||||
|
||||
public function __construct(ProductRepository $product, ProductGridRepository $productGrid, Price $price)
|
||||
public function __construct(ProductRepository $product, ProductGridRepository $productGrid, ProductFlatRepository $productFlat, Price $price)
|
||||
{
|
||||
$this->product = $product;
|
||||
|
||||
$this->productGrid = $productGrid;
|
||||
|
||||
$this->productFlat = $productFlat;
|
||||
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +101,7 @@ class Product {
|
|||
'name' => $variant->name,
|
||||
'quantity' => 0,
|
||||
'status' => $variant->status,
|
||||
'price' => $variant->price,
|
||||
'price' => $variant->price
|
||||
];
|
||||
|
||||
$this->productGrid->create($variantObj);
|
||||
|
|
@ -268,4 +278,6 @@ class Product {
|
|||
public function findRepeated() {
|
||||
//find if there is duplicacy in the products grid here
|
||||
}
|
||||
|
||||
public function syncFlat() {}
|
||||
}
|
||||
|
|
@ -75,7 +75,11 @@ class AttributeController extends Controller
|
|||
'type' => 'required'
|
||||
]);
|
||||
|
||||
$attribute = $this->attribute->create(request()->all());
|
||||
$data = request()->all();
|
||||
|
||||
$data['is_user_defined'] = 1;
|
||||
|
||||
$attribute = $this->attribute->create($data);
|
||||
|
||||
Event::fire('after.attribute.created', $attribute);
|
||||
|
||||
|
|
@ -114,7 +118,7 @@ class AttributeController extends Controller
|
|||
|
||||
$attribute = $this->attribute->update(request()->all(), $id);
|
||||
|
||||
Event::fire('after.attribute.updated', $attribute);
|
||||
// Event::fire('after.attribute.updated', $attribute);
|
||||
|
||||
session()->flash('success', 'Attribute updated successfully.');
|
||||
|
||||
|
|
@ -135,11 +139,12 @@ 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.');
|
||||
|
||||
Event::fire(after.attribute.deleted, $attribute);
|
||||
} catch(\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.attribute-error', ['name' => 'Attribute']));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -775,5 +775,15 @@ class Core
|
|||
}
|
||||
|
||||
return $merged;
|
||||
}
|
||||
}
|
||||
|
||||
public function convertEmptyStringsToNull($array) {
|
||||
foreach($array as $key => $value) {
|
||||
if($value == "" || $value == "null") {
|
||||
$array[$key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
@ -40,12 +40,12 @@ class FilterByAttributesCriteria extends AbstractProduct implements CriteriaInte
|
|||
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_'
|
||||
];
|
||||
'products' => 'filter_',
|
||||
'variants' => 'variant_filter_'
|
||||
];
|
||||
|
||||
foreach ($aliases as $table => $alias) {
|
||||
$query1 = $query1->orWhere(function($query2) use($model, $table, $alias) {
|
||||
|
|
@ -58,8 +58,9 @@ class FilterByAttributesCriteria extends AbstractProduct implements CriteriaInte
|
|||
$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);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
<?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');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,10 +8,11 @@ use Illuminate\Support\Facades\Event;
|
|||
use Webkul\Product\Http\Requests\ProductForm;
|
||||
use Webkul\Product\Repositories\ProductRepository as Product;
|
||||
use Webkul\Product\Repositories\ProductGridRepository as ProductGrid;
|
||||
use Webkul\Product\Repositories\ProductFlatRepository as ProductFlat;
|
||||
use Webkul\Product\Repositories\ProductAttributeValueRepository as ProductAttributeValue;
|
||||
use Webkul\Attribute\Repositories\AttributeFamilyRepository as AttributeFamily;
|
||||
use Webkul\Category\Repositories\CategoryRepository as Category;
|
||||
use Webkul\Inventory\Repositories\InventorySourceRepository as InventorySource;
|
||||
use Webkul\Admin\DataGrids\TestDataGrid;
|
||||
|
||||
/**
|
||||
* Product controller
|
||||
|
|
@ -62,6 +63,8 @@ class ProductController extends Controller
|
|||
* @var array
|
||||
*/
|
||||
protected $productGrid;
|
||||
protected $productFlat;
|
||||
protected $productAttributeValue;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
|
@ -77,7 +80,9 @@ class ProductController extends Controller
|
|||
Category $category,
|
||||
InventorySource $inventorySource,
|
||||
Product $product,
|
||||
ProductGrid $productGrid)
|
||||
ProductGrid $productGrid,
|
||||
ProductFlat $productFlat,
|
||||
ProductAttributeValue $productAttributeValue)
|
||||
{
|
||||
$this->attributeFamily = $attributeFamily;
|
||||
|
||||
|
|
@ -89,6 +94,10 @@ class ProductController extends Controller
|
|||
|
||||
$this->productGrid = $productGrid;
|
||||
|
||||
$this->productFlat = $productFlat;
|
||||
|
||||
$this->productAttributeValue = $productAttributeValue;
|
||||
|
||||
$this->_config = request('_config');
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +136,7 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function store()
|
||||
{
|
||||
if (! request()->get('family') && request()->input('type') == 'configurable' && request()->input('sku') != '') {
|
||||
if (!request()->get('family') && request()->input('type') == 'configurable' && request()->input('sku') != '') {
|
||||
return redirect(url()->current() . '?family=' . request()->input('attribute_family_id') . '&sku=' . request()->input('sku'));
|
||||
}
|
||||
|
||||
|
|
@ -225,11 +234,11 @@ class ProductController extends Controller
|
|||
{
|
||||
$data = request()->all();
|
||||
|
||||
if (! isset($data['massaction-type'])) {
|
||||
if (!isset($data['massaction-type'])) {
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
if (! $data['massaction-type'] == 'update') {
|
||||
if (!$data['massaction-type'] == 'update') {
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
|
@ -237,10 +246,10 @@ class ProductController extends Controller
|
|||
|
||||
foreach ($productIds as $productId) {
|
||||
$this->product->update([
|
||||
'channel' => null,
|
||||
'locale' => null,
|
||||
'status' => $data['update-options']
|
||||
], $productId);
|
||||
'channel' => null,
|
||||
'locale' => null,
|
||||
'status' => $data['update-options']
|
||||
], $productId);
|
||||
}
|
||||
|
||||
session()->flash('success', trans('admin::app.catalog.products.mass-update-success'));
|
||||
|
|
@ -257,4 +266,160 @@ class ProductController extends Controller
|
|||
|
||||
return redirect()->route('admin.catalog.products.index');
|
||||
}
|
||||
|
||||
// public function testProductFlat() {
|
||||
// $product = $this->product->find(2);
|
||||
// $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']);
|
||||
|
||||
// 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';
|
||||
// }
|
||||
}
|
||||
|
|
@ -5,6 +5,8 @@ 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
|
||||
*
|
||||
|
|
@ -13,6 +15,23 @@ use Illuminate\Database\Schema\Blueprint;
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
|
@ -20,8 +39,48 @@ class ProductsFlat
|
|||
*/
|
||||
public function afterAttributeCreated($attribute)
|
||||
{
|
||||
return true;
|
||||
dd('after attribute is created');
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -32,14 +91,180 @@ class ProductsFlat
|
|||
public function afterAttributeUpdated($attribute)
|
||||
{
|
||||
return true;
|
||||
|
||||
dd('after attribute is updated', $attribute);
|
||||
}
|
||||
|
||||
public function afterAttributeDeleted()
|
||||
public function afterAttributeDeleted($attribute)
|
||||
{
|
||||
return true;
|
||||
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));
|
||||
|
||||
dd('after attribute is deleted');
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
|
@ -28,19 +28,19 @@ class ProductAttributeValue extends Model
|
|||
];
|
||||
|
||||
protected $fillable = [
|
||||
'product_id',
|
||||
'attribute_id',
|
||||
'channel_id',
|
||||
'locale',
|
||||
'channel',
|
||||
'text_value',
|
||||
'boolean_value',
|
||||
'integer_value',
|
||||
'float_value',
|
||||
'datetime_value',
|
||||
'date_value',
|
||||
'json_value'
|
||||
];
|
||||
'product_id',
|
||||
'attribute_id',
|
||||
'channel_id',
|
||||
'locale',
|
||||
'channel',
|
||||
'text_value',
|
||||
'boolean_value',
|
||||
'integer_value',
|
||||
'float_value',
|
||||
'datetime_value',
|
||||
'date_value',
|
||||
'json_value'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attribute that owns the attribute value.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
protected $table = 'product_flat';
|
||||
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
|
|
@ -14,10 +14,15 @@ class EventServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot()
|
||||
{
|
||||
Event::listen('after.attribute.updated', 'Webkul\Product\Listeners\ProductsFlat@afterAttributeUpdated');
|
||||
// Event::listen('after.attribute.updated', 'Webkul\Product\Listeners\ProductsFlat@afterAttributeUpdated');
|
||||
|
||||
Event::listen('after.attribute.created', 'Webkul\Product\Listeners\ProductsFlat@afterAttributeCreated');
|
||||
|
||||
Event::listen('after.attribute.deleted', 'Webkul\Product\Listeners\ProductsFlat@afterAttributeDeleted');
|
||||
|
||||
Event::listen('after.product.created', 'Webkul\Product\Listeners\ProductsFlat@afterProductCreatedOrUpdated');
|
||||
|
||||
Event::listen('after.product.updated', 'Webkul\Product\Listeners\ProductsFlat@afterProductCreatedOrUpdated');
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
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\Helpers\Price;
|
||||
|
||||
/**
|
||||
* Product Repository
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class ProductFlatRepository extends Repository
|
||||
{
|
||||
protected $product;
|
||||
|
||||
/**
|
||||
* Price Object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $price;
|
||||
|
||||
public function __construct(
|
||||
Product $product,
|
||||
Price $price,
|
||||
App $app
|
||||
) {
|
||||
$this->product = $product;
|
||||
|
||||
$this->price = $price;
|
||||
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
public function model()
|
||||
{
|
||||
return 'Webkul\Product\Models\ProductFlat';
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ class ProductGridRepository extends Repository
|
|||
return $this->getModel()->where('product_id', $variant->id)->update($gridObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -144,7 +144,6 @@ class ProductRepository extends Repository
|
|||
//after store of the product
|
||||
Event::fire('catalog.product.create.after', $product);
|
||||
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
|
|
@ -233,6 +232,9 @@ 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;
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +245,7 @@ class ProductRepository extends Repository
|
|||
public function delete($id)
|
||||
{
|
||||
Event::fire('catalog.product.delete.before', $id);
|
||||
|
||||
|
||||
parent::delete($id);
|
||||
|
||||
Event::fire('catalog.product.delete.after', $id);
|
||||
|
|
@ -512,14 +514,4 @@ class ProductRepository extends Repository
|
|||
return $query->distinct()->addSelect('products.*')->where('pav.text_value', 'like', '%'.$term.'%');
|
||||
})->paginate(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* break the search term into explode by using space and tell which exploded item is attribute
|
||||
* , category, super attribute or combination of them.
|
||||
*/
|
||||
public function breakTheTerm($term) {
|
||||
$explodedTerm = (explode(" ", $term));
|
||||
|
||||
dd($term);
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"/js/shop.js": "/js/shop.js?id=e25827d4b84cbe5d76fb",
|
||||
"/js/shop.js": "/js/shop.js?id=0076f480705e7ce1f8e0",
|
||||
"/css/shop.css": "/css/shop.css?id=064ee767a010fa58727e"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"/js/ui.js": "/js/ui.js?id=711bb1082d5b116e929f",
|
||||
"/css/ui.css": "/css/ui.css?id=384d20a09ced97996829"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@
|
|||
<th colspan="100%">
|
||||
<div class="mass-action-wrapper" style="display: flex; flex-direction: row; align-items: center; justify-content: flex-start;">
|
||||
|
||||
<span class="massaction-remove" v-on:click="removeMassActions" style="margin-right: 10px;">
|
||||
<span class="massaction-remove" v-on:click="removeMassActions" style="margin-right: 10px; margin-top: 3px;">
|
||||
<span class="icon checkbox-dash-icon"></span>
|
||||
</span>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue