Removed configurable checks and deleted unwanted files
This commit is contained in:
parent
45f1ea4b83
commit
3c5a2792e3
|
|
@ -41,7 +41,8 @@ class InvoiceItem extends JsonResource
|
|||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
'child' => new self($this->child)
|
||||
'child' => new self($this->child),
|
||||
'children' => Self::collection($this->children)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +78,8 @@ class OrderItem extends JsonResource
|
|||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
'child' => new self($this->child)
|
||||
'child' => new self($this->child),
|
||||
'children' => Self::collection($this->children)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -206,7 +206,6 @@ class DashboardController extends Controller
|
|||
->leftJoin('products', 'product_inventories.product_id', 'products.id')
|
||||
->select(DB::raw('SUM(qty) as total_qty'))
|
||||
->addSelect('product_inventories.product_id')
|
||||
->where('products.type', '!=', 'configurable')
|
||||
->groupBy('product_id')
|
||||
->orderBy('total_qty', 'ASC')
|
||||
->limit(5)
|
||||
|
|
|
|||
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Admin\Listeners;
|
||||
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Product\Repositories\ProductFlatRepository;
|
||||
|
||||
/**
|
||||
* Products Event handler
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class Product {
|
||||
/**
|
||||
* Product Repository Object
|
||||
*/
|
||||
protected $product;
|
||||
|
||||
/**
|
||||
* Product Flat Object
|
||||
*
|
||||
* Repository Object
|
||||
*/
|
||||
protected $productFlat;
|
||||
|
||||
/**
|
||||
* Product Grid Repository Object
|
||||
*/
|
||||
protected $productGrid;
|
||||
|
||||
public function __construct(
|
||||
ProductRepository $product,
|
||||
ProductFlatRepository $productFlat
|
||||
)
|
||||
{
|
||||
$this->product = $product;
|
||||
|
||||
$this->productFlat = $productFlat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually invoke this function when you have created the products by importing or seeding or factory.
|
||||
*/
|
||||
public function sync() {
|
||||
$gridObject = [];
|
||||
|
||||
foreach ($this->product->all() as $product) {
|
||||
$gridObject = [
|
||||
'product_id' => $product->id,
|
||||
'sku' => $product->sku,
|
||||
'type' => $product->type,
|
||||
'name' => $product->name,
|
||||
'attribute_family_name' => $product->toArray()['attribute_family']['name'],
|
||||
'price' => $product->getTypeInstance()->getMinimalPrice(),
|
||||
'status' => $product->status
|
||||
];
|
||||
|
||||
if ($product->type == 'configurable') {
|
||||
$gridObject['quantity'] = 0;
|
||||
} else {
|
||||
$qty = 0;
|
||||
|
||||
foreach ($product->toArray()['inventories'] as $inventorySource) {
|
||||
$qty = $qty + $inventorySource['qty'];
|
||||
}
|
||||
|
||||
$gridObject['quantity'] = $qty;
|
||||
|
||||
$qty = 0;
|
||||
}
|
||||
|
||||
$oldGridObject = $this->productGrid->findOneByField('product_id', $product->id);
|
||||
|
||||
if ($oldGridObject) {
|
||||
$oldGridObject->update($gridObject);
|
||||
} else {
|
||||
$this->productGrid->create($gridObject);
|
||||
}
|
||||
|
||||
$gridObject = [];
|
||||
}
|
||||
|
||||
$this->findRepeated();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Product\Helpers;
|
||||
|
||||
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
|
||||
use Webkul\Product\Models\Product;
|
||||
use Webkul\Product\Models\ProductFlat;
|
||||
use Webkul\Discount\Repositories\CatalogRuleProductsRepository as CatalogRuleProduct;
|
||||
use Webkul\Customer\Repositories\CustomerGroupRepository as CustomerGroup;
|
||||
|
||||
class Price extends AbstractProduct
|
||||
{
|
||||
/**
|
||||
* AttributeRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attribute;
|
||||
|
||||
/**
|
||||
* CatalogRuleProductsRepository object
|
||||
*
|
||||
*/
|
||||
protected $catalogRuleProduct;
|
||||
|
||||
/**
|
||||
* CustomerGroupRepository object
|
||||
*/
|
||||
protected $customerGroup;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
Attribute $attribute,
|
||||
CatalogRuleProduct $catalogRuleProduct,
|
||||
CustomerGroup $customerGroup
|
||||
) {
|
||||
$this->attribute = $attribute;
|
||||
|
||||
$this->catalogRuleProduct = $catalogRuleProduct;
|
||||
|
||||
$this->customerGroup = $customerGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product's minimal price
|
||||
*
|
||||
* @param Product $product
|
||||
* @return float
|
||||
*/
|
||||
public function getMinimalPrice($product)
|
||||
{
|
||||
static $price = [];
|
||||
|
||||
if(array_key_exists($product->id, $price))
|
||||
return $price[$product->id];
|
||||
|
||||
if ($product->type == 'configurable') {
|
||||
return $price[$product->id] = $this->getVariantMinPrice($product);
|
||||
} else {
|
||||
if ($this->haveSpecialPrice($product)) {
|
||||
return $price[$product->id] = $product->special_price;
|
||||
}
|
||||
|
||||
return $price[$product->id] = $product->price;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product's minimal price
|
||||
*
|
||||
* @param Product $product
|
||||
* @return float
|
||||
*/
|
||||
public function getVariantMinPrice($product)
|
||||
{
|
||||
static $price = [];
|
||||
$finalPrice = [];
|
||||
|
||||
if (array_key_exists($product->id, $price))
|
||||
return $price[$product->id];
|
||||
|
||||
if ($product instanceof ProductFlat) {
|
||||
$productId = $product->product_id;
|
||||
} else {
|
||||
$productId = $product->id;
|
||||
}
|
||||
|
||||
$qb = ProductFlat::join('products', 'product_flat.product_id', '=', 'products.id')
|
||||
->where('products.parent_id', $productId);
|
||||
|
||||
$result = $qb
|
||||
->distinct()
|
||||
->selectRaw('IF( product_flat.special_price_from IS NOT NULL
|
||||
AND product_flat.special_price_to IS NOT NULL , IF( NOW( ) >= product_flat.special_price_from
|
||||
AND NOW( ) <= product_flat.special_price_to, IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , product_flat.price ) , IF( product_flat.special_price_from IS NULL , IF( product_flat.special_price_to IS NULL , IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , IF( NOW( ) <= product_flat.special_price_to, IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , product_flat.price ) ) , IF( product_flat.special_price_to IS NULL , IF( NOW( ) >= product_flat.special_price_from, IF( product_flat.special_price IS NULL OR product_flat.special_price = 0 , product_flat.price, LEAST( product_flat.special_price, product_flat.price ) ) , product_flat.price ) , product_flat.price ) ) ) AS final_price')
|
||||
->where('product_flat.channel', core()->getCurrentChannelCode())
|
||||
->where('product_flat.locale', app()->getLocale())
|
||||
->get();
|
||||
|
||||
|
||||
if (! auth()->guard('customer')->check()) {
|
||||
$groupID = $this->customerGroup->findOneWhere([
|
||||
'code' => 'guest'
|
||||
])->id;
|
||||
} else {
|
||||
$groupID = auth()->guard('customer')->user()->customer_group_id;
|
||||
}
|
||||
|
||||
if ($groupID) {
|
||||
$something = $this->catalogRuleProduct->findWhere([
|
||||
'product_id' => $productId,
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'customer_group_id' => $groupID
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($result as $price) {
|
||||
$finalPrice[] = $price->final_price;
|
||||
}
|
||||
|
||||
if (empty($finalPrice))
|
||||
return $price[$product->id] = 0;
|
||||
|
||||
return $price[$product->id] = min($finalPrice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product's minimal price
|
||||
*
|
||||
* @param Product $product
|
||||
* @return float
|
||||
*/
|
||||
public function getSpecialPrice($product)
|
||||
{
|
||||
static $price = [];
|
||||
|
||||
if(array_key_exists($product->id, $price))
|
||||
return $price[$product->id];
|
||||
|
||||
if ($this->haveSpecialPrice($product)) {
|
||||
return $price[$product->id] = $product->special_price;
|
||||
} else {
|
||||
return $price[$product->id] = $product->price;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @return boolean
|
||||
*/
|
||||
public function haveSpecialPrice($product)
|
||||
{
|
||||
if (is_null($product->special_price) || ! (float) $product->special_price)
|
||||
return false;
|
||||
|
||||
if (core()->isChannelDateInInterval($product->special_price_from, $product->special_price_to)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -266,6 +266,10 @@ class ProductFlat
|
|||
|
||||
$productFlat->updated_at = $product->updated_at;
|
||||
|
||||
$productFlat->min_price = $product->getTypeInstance()->getMinimalPrice();
|
||||
|
||||
$productFlat->max_price = $product->getTypeInstance()->getMaximamPrice();
|
||||
|
||||
if ($parentProduct) {
|
||||
$parentProductFlat = $this->productFlatRepository->findOneWhere([
|
||||
'product_id' => $parentProduct->id,
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ abstract class AbstractType
|
|||
*/
|
||||
public function getMaximamPrice()
|
||||
{
|
||||
return $this->product->price;
|
||||
return $this->getMinimalPrice();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface OrderItemInventory
|
||||
{
|
||||
}
|
||||
|
|
@ -55,6 +55,14 @@ class InvoiceItem extends Model implements InvoiceItemContract
|
|||
return $this->hasOne(InvoiceItemProxy::modelClass(), 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the children items.
|
||||
*/
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order item type
|
||||
*/
|
||||
|
|
@ -62,20 +70,4 @@ class InvoiceItem extends Model implements InvoiceItemContract
|
|||
{
|
||||
return $this->order_item->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configurable option html
|
||||
*/
|
||||
public function getOptionDetailHtml()
|
||||
{
|
||||
return $this->order_item->getOptionDetailHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configurable option html
|
||||
*/
|
||||
public function getDownloadableDetailHtml()
|
||||
{
|
||||
return $this->order_item->getDownloadableDetailHtml();
|
||||
}
|
||||
}
|
||||
|
|
@ -168,42 +168,4 @@ class OrderItem extends Model implements OrderItemContract
|
|||
{
|
||||
return $this->hasMany(DownloadableLinkPurchasedProxy::modelClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configurable option html
|
||||
*/
|
||||
public function getOptionDetailHtml()
|
||||
{
|
||||
if ($this->type != 'configurable')
|
||||
return;
|
||||
|
||||
if (isset($this->additional['attributes'])) {
|
||||
$labels = [];
|
||||
|
||||
foreach ($this->additional['attributes'] as $attribute) {
|
||||
$labels[] = $attribute['attribute_name'] . ' : ' . $attribute['option_label'];
|
||||
}
|
||||
|
||||
return implode(', ', $labels);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configurable option html
|
||||
*/
|
||||
public function getDownloadableDetailHtml()
|
||||
{
|
||||
$labels = [];
|
||||
|
||||
foreach ($this->downloadable_link_purchased as $link) {
|
||||
if (! $link->download_bought) {
|
||||
$labels[] = $link->name . ' (' . $link->download_used . ' / U)';
|
||||
} else {
|
||||
$labels[] = $link->name . ' (' . $link->download_used . ' / ' . $link->download_bought . ')';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return implode(', ', $labels);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\OrderItemInventory as OrderItemInventoryContract;
|
||||
|
||||
class OrderItemInventory extends Model implements OrderItemInventoryContract
|
||||
{
|
||||
protected $guarded = ['id', 'child', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Get the order item record associated with the order item inventory.
|
||||
*/
|
||||
public function order_item()
|
||||
{
|
||||
return $this->belongsTo(OrderItemProxy::modelClass());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class OrderItemInventoryProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -62,20 +62,4 @@ class ShipmentItem extends Model implements ShipmentItemContract
|
|||
{
|
||||
return $this->order_item->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configurable option html
|
||||
*/
|
||||
public function getOptionDetailHtml()
|
||||
{
|
||||
return $this->order_item->getOptionDetailHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configurable option html
|
||||
*/
|
||||
public function getDownloadableDetailHtml()
|
||||
{
|
||||
return $this->order_item->getDownloadableDetailHtml();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Webkul\Sales\Contracts\OrderItemInventory;
|
||||
|
||||
/**
|
||||
* Order Item Inventory Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class OrderItemInventoryRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Specify Model class name
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
|
||||
function model()
|
||||
{
|
||||
return OrderItemInventory::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$orderItem = $data['orderItem'];
|
||||
|
||||
$orderedQuantity = $orderItem->qty_ordered;
|
||||
|
||||
$product = $orderItem->type == 'configurable' ? $orderItem->child->product : $orderItem->product;
|
||||
|
||||
if (! $product)
|
||||
return ;
|
||||
|
||||
$inventories = $product->inventory_sources()->orderBy('priority', 'asc')->get();
|
||||
|
||||
foreach ($inventories as $inventorySource) {
|
||||
if (! $orderedQuantity)
|
||||
break;
|
||||
|
||||
$sourceQuantity = $inventorySource->pivot->qty;
|
||||
|
||||
if (! $inventorySource->status || !$sourceQuantity)
|
||||
continue;
|
||||
|
||||
if ($sourceQuantity >= $orderedQuantity) {
|
||||
$orderItemQuantity = $orderedQuantity;
|
||||
|
||||
$sourceQuantity -= $orderItemQuantity;
|
||||
|
||||
$orderedQuantity = 0;
|
||||
} else {
|
||||
$orderItemQuantity = $sourceQuantity;
|
||||
|
||||
$sourceQuantity = 0;
|
||||
|
||||
$orderedQuantity -= $orderItemQuantity;
|
||||
}
|
||||
|
||||
$this->model->create([
|
||||
'qty' => $orderItemQuantity,
|
||||
'order_item_id' => $orderItem->id,
|
||||
'inventory_source_id' => $inventorySource->id,
|
||||
]);
|
||||
|
||||
$inventorySource->pivot->update([
|
||||
'qty' => $sourceQuantity
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -176,10 +176,14 @@
|
|||
<td>
|
||||
{{ $item->name }}
|
||||
|
||||
@if ($html = $item->getOptionDetailHtml())
|
||||
<p>{{ $html }}</p>
|
||||
@elseif ($item->type == 'downloadable')
|
||||
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
|
||||
@if (isset($item->additional['attributes']))
|
||||
<div class="item-options">
|
||||
|
||||
@foreach ($item->additional['attributes'] as $attribute)
|
||||
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ core()->formatPrice($item->price, $invoice->order->order_currency_code) }}</td>
|
||||
|
|
|
|||
Loading…
Reference in New Issue