commit
3984d92fad
|
|
@ -54,185 +54,6 @@ class Product {
|
|||
$this->price = $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new entry in the product grid whenever a new product is created.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function afterProductCreated($product) {
|
||||
$result = $this->productCreated($product);
|
||||
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the product to the product as the product data grid instance
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function productCreated($product) {
|
||||
$gridObject = [
|
||||
'product_id' => $product->id,
|
||||
'sku' => $product->sku,
|
||||
'type' => $product->type,
|
||||
'attribute_family_name' => $product->toArray()['attribute_family']['name'],
|
||||
'name' => $product->name,
|
||||
'quantity' => 0,
|
||||
'status' => $product->status,
|
||||
'price' => $product->price
|
||||
];
|
||||
|
||||
$variants = [];
|
||||
|
||||
$found = $this->productGrid->findOneByField('product_id', $product->id);
|
||||
|
||||
//extra measure to stop duplicate entries
|
||||
if ($found == null) {
|
||||
$this->productGrid->create($gridObject);
|
||||
|
||||
if ($product->type == 'configurable') {
|
||||
$variants = $product->variants()->get();
|
||||
|
||||
foreach ($variants as $variant) {
|
||||
$variantObj = [
|
||||
'product_id' => $variant->id,
|
||||
'sku' => $variant->sku,
|
||||
'type' => $variant->type,
|
||||
'attribute_family_name' => $variant->toArray()['attribute_family']['name'],
|
||||
'name' => $variant->name,
|
||||
'quantity' => 0,
|
||||
'status' => $variant->status,
|
||||
'price' => $variant->price
|
||||
];
|
||||
|
||||
$this->productGrid->create($variantObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event before the product update
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
// public function beforeProductUpdate($productId) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Event handle for after.product.update
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function afterProductUpdate($product) {
|
||||
$result = $this->productUpdated($product);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will be invoked from afterProductUpdate
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function productUpdated($product) {
|
||||
$productGridObject = $this->productGrid->findOneByField('product_id', $product->id);
|
||||
|
||||
if (! $productGridObject) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$gridObject = [
|
||||
'product_id' => $product->id,
|
||||
'sku' => $product->sku,
|
||||
'type' => $product->type,
|
||||
'attribute_family_name' => $product->toArray()['attribute_family']['name'],
|
||||
'name' => $product->name,
|
||||
'status' => $product->status,
|
||||
];
|
||||
|
||||
if ($product->type == 'configurable') {
|
||||
$gridObject['quantity'] = 0;
|
||||
$gridObject['price'] = 0;
|
||||
} else {
|
||||
$qty = 0;
|
||||
//inventories and inventory sources relation for the variants return empty or null collection objects only
|
||||
foreach ($product->inventories()->get() as $inventory_source) {
|
||||
$qty = $qty + $inventory_source->qty;
|
||||
}
|
||||
|
||||
$gridObject['quantity'] = $qty;
|
||||
$gridObject['price'] = $product->price;
|
||||
}
|
||||
|
||||
$this->productGrid->update($gridObject, $productGridObject->id);
|
||||
|
||||
if ($product->type == 'configurable') {
|
||||
$variants = $product->variants()->get();
|
||||
|
||||
foreach ($variants as $variant) {
|
||||
$variantObj = [
|
||||
'product_id' => $variant->id,
|
||||
'sku' => $variant->sku,
|
||||
'type' => $variant->type,
|
||||
'attribute_family_name' => $variant->toArray()['attribute_family']['name'],
|
||||
'name' => $variant->name,
|
||||
'status' => $variant->status,
|
||||
'price' => $variant->price,
|
||||
];
|
||||
|
||||
$qty = 0;
|
||||
|
||||
//inventories and inventory sources relation for the variants return empty or null collection objects only
|
||||
foreach ($variant->inventories()->get() as $inventory_source) {
|
||||
$qty = $qty + $inventory_source->qty;
|
||||
}
|
||||
|
||||
$variantObj['quantity'] = $qty;
|
||||
|
||||
$qty = 0;
|
||||
|
||||
$productGridVariant = $this->productGrid->findOneByField('product_id', $variant->id);
|
||||
|
||||
if (isset($productGridVariant)) {
|
||||
$this->productGrid->update($variantObj, $productGridVariant->id);
|
||||
} else {
|
||||
$variantObj = [
|
||||
'product_id' => $variant->id,
|
||||
'sku' => $variant->sku,
|
||||
'type' => $variant->type,
|
||||
'attribute_family_name' => $variant->toArray()['attribute_family']['name'],
|
||||
'name' => $variant->name,
|
||||
'status' => $variant->status,
|
||||
'price' => $variant->price,
|
||||
];
|
||||
|
||||
$qty = 0;
|
||||
|
||||
//inventories and inventory sources relation for the variants return empty or null collection objects only
|
||||
foreach ($variant->inventories()->get() as $inventory_source) {
|
||||
$qty = $qty + $inventory_source->qty;
|
||||
}
|
||||
|
||||
$variantObj['quantity'] = $qty;
|
||||
|
||||
$qty = 0;
|
||||
|
||||
$this->productGrid->create($variantObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually invoke this function when you have created the products by importing or seeding or factory.
|
||||
*/
|
||||
|
|
@ -279,10 +100,4 @@ class Product {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function findRepeated() {
|
||||
//find if there is duplicacy in the products grid here
|
||||
}
|
||||
|
||||
public function syncFlat() {}
|
||||
}
|
||||
|
|
@ -23,9 +23,5 @@ class EventServiceProvider extends ServiceProvider
|
|||
Event::listen('checkout.order.save.after', 'Webkul\Admin\Listeners\Order@updateProductInventory');
|
||||
|
||||
Event::listen('products.datagrid.sync', 'Webkul\Admin\Listeners\Product@sync');
|
||||
|
||||
Event::listen('catalog.product.create.after', 'Webkul\Admin\Listeners\Product@afterProductCreated');
|
||||
|
||||
Event::listen('catalog.product.update.after', 'Webkul\Admin\Listeners\Product@afterProductUpdate');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Product\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Contracts;
|
||||
|
||||
interface TaxCategory
|
||||
{
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Contracts;
|
||||
|
||||
interface TaxMap
|
||||
{
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Contracts;
|
||||
|
||||
interface TaxRate
|
||||
{
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Core\Models\TaxRate;
|
||||
use Webkul\Core\Models\TaxMap;
|
||||
use Webkul\Core\Contracts\TaxCategory as TaxCategoryContract;
|
||||
|
||||
class TaxCategory extends Model implements TaxCategoryContract
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $table = 'tax_categories';
|
||||
|
||||
protected $fillable = [
|
||||
'channel_id' ,'code', 'name' ,'description'
|
||||
];
|
||||
|
||||
//for joining the two way pivot table
|
||||
public function tax_rates() {
|
||||
return $this->belongsToMany(TaxRateProxy::modelClass(), 'tax_categories_tax_rates', 'tax_category_id')->withPivot('id');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class TaxCategoryProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Core\Models\TaxCategory;
|
||||
use Webkul\Core\Models\TaxRate;
|
||||
use Webkul\Core\Contracts\TaxMap as TaxMapContract;
|
||||
|
||||
class TaxMap extends Model implements TaxMapContract
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $table = 'tax_categories_tax_rates';
|
||||
|
||||
protected $fillable = [
|
||||
'tax_category_id', 'tax_rate_id'
|
||||
];
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class TaxMapProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Core\Models\TaxCategory;
|
||||
use Webkul\Core\Contracts\TaxRate as TaxRateContract;
|
||||
|
||||
class TaxRate extends Model implements TaxRateContract
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $table = 'tax_rates';
|
||||
|
||||
protected $fillable = [
|
||||
'identifier', 'is_zip_from', 'zip_code', 'zip_from', 'zip_to', 'state', 'country', 'tax_rate'
|
||||
];
|
||||
|
||||
public function tax_categories() {
|
||||
return $this->belongsToMany(TaxCategoryProxy::modelClass(), 'tax_categories_tax_rates', 'tax_rate_id', 'id');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class TaxRateProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue