From 3c5a2792e3cb1a76a4273c6fea4cbb60681f421e Mon Sep 17 00:00:00 2001 From: jitendra Date: Wed, 4 Sep 2019 16:23:05 +0530 Subject: [PATCH] Removed configurable checks and deleted unwanted files --- .../API/Http/Resources/Sales/InvoiceItem.php | 3 +- .../API/Http/Resources/Sales/OrderItem.php | 3 +- .../Http/Controllers/DashboardController.php | 1 - .../Webkul/Admin/src/Listeners/Product.php | 88 --------- packages/Webkul/Product/src/Helpers/Price.php | 167 ------------------ .../Product/src/Listeners/ProductFlat.php | 4 + .../Webkul/Product/src/Type/AbstractType.php | 2 +- .../src/Contracts/OrderItemInventory.php | 7 - .../Webkul/Sales/src/Models/InvoiceItem.php | 24 +-- .../Webkul/Sales/src/Models/OrderItem.php | 38 ---- .../Sales/src/Models/OrderItemInventory.php | 19 -- .../src/Models/OrderItemInventoryProxy.php | 10 -- .../Webkul/Sales/src/Models/ShipmentItem.php | 16 -- .../OrderItemInventoryRepository.php | 81 --------- .../customers/account/orders/pdf.blade.php | 12 +- 15 files changed, 25 insertions(+), 450 deletions(-) delete mode 100755 packages/Webkul/Admin/src/Listeners/Product.php delete mode 100755 packages/Webkul/Product/src/Helpers/Price.php delete mode 100755 packages/Webkul/Sales/src/Contracts/OrderItemInventory.php delete mode 100755 packages/Webkul/Sales/src/Models/OrderItemInventory.php delete mode 100755 packages/Webkul/Sales/src/Models/OrderItemInventoryProxy.php delete mode 100755 packages/Webkul/Sales/src/Repositories/OrderItemInventoryRepository.php diff --git a/packages/Webkul/API/Http/Resources/Sales/InvoiceItem.php b/packages/Webkul/API/Http/Resources/Sales/InvoiceItem.php index 611226cef..c5fd3d09b 100644 --- a/packages/Webkul/API/Http/Resources/Sales/InvoiceItem.php +++ b/packages/Webkul/API/Http/Resources/Sales/InvoiceItem.php @@ -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) ]; } } \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/OrderItem.php b/packages/Webkul/API/Http/Resources/Sales/OrderItem.php index cbfb19846..a6420b480 100644 --- a/packages/Webkul/API/Http/Resources/Sales/OrderItem.php +++ b/packages/Webkul/API/Http/Resources/Sales/OrderItem.php @@ -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) ]; } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Http/Controllers/DashboardController.php b/packages/Webkul/Admin/src/Http/Controllers/DashboardController.php index 13f2c19b2..6a13e69db 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/DashboardController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/DashboardController.php @@ -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) diff --git a/packages/Webkul/Admin/src/Listeners/Product.php b/packages/Webkul/Admin/src/Listeners/Product.php deleted file mode 100755 index 8d9fa5e51..000000000 --- a/packages/Webkul/Admin/src/Listeners/Product.php +++ /dev/null @@ -1,88 +0,0 @@ - @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; - } -} \ No newline at end of file diff --git a/packages/Webkul/Product/src/Helpers/Price.php b/packages/Webkul/Product/src/Helpers/Price.php deleted file mode 100755 index 0c26db2ea..000000000 --- a/packages/Webkul/Product/src/Helpers/Price.php +++ /dev/null @@ -1,167 +0,0 @@ -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; - } -} \ No newline at end of file diff --git a/packages/Webkul/Product/src/Listeners/ProductFlat.php b/packages/Webkul/Product/src/Listeners/ProductFlat.php index ff667b3df..1d30fbcf1 100644 --- a/packages/Webkul/Product/src/Listeners/ProductFlat.php +++ b/packages/Webkul/Product/src/Listeners/ProductFlat.php @@ -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, diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index 793616b6c..9185baf96 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -357,7 +357,7 @@ abstract class AbstractType */ public function getMaximamPrice() { - return $this->product->price; + return $this->getMinimalPrice(); } /** diff --git a/packages/Webkul/Sales/src/Contracts/OrderItemInventory.php b/packages/Webkul/Sales/src/Contracts/OrderItemInventory.php deleted file mode 100755 index 7e3fb76cd..000000000 --- a/packages/Webkul/Sales/src/Contracts/OrderItemInventory.php +++ /dev/null @@ -1,7 +0,0 @@ -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(); - } } \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/OrderItem.php b/packages/Webkul/Sales/src/Models/OrderItem.php index d4997e74c..93ee56ecf 100755 --- a/packages/Webkul/Sales/src/Models/OrderItem.php +++ b/packages/Webkul/Sales/src/Models/OrderItem.php @@ -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); - } } \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/OrderItemInventory.php b/packages/Webkul/Sales/src/Models/OrderItemInventory.php deleted file mode 100755 index 1d6101016..000000000 --- a/packages/Webkul/Sales/src/Models/OrderItemInventory.php +++ /dev/null @@ -1,19 +0,0 @@ -belongsTo(OrderItemProxy::modelClass()); - } -} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/OrderItemInventoryProxy.php b/packages/Webkul/Sales/src/Models/OrderItemInventoryProxy.php deleted file mode 100755 index 75a62abf4..000000000 --- a/packages/Webkul/Sales/src/Models/OrderItemInventoryProxy.php +++ /dev/null @@ -1,10 +0,0 @@ -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(); - } } \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/OrderItemInventoryRepository.php b/packages/Webkul/Sales/src/Repositories/OrderItemInventoryRepository.php deleted file mode 100755 index 44e5b4791..000000000 --- a/packages/Webkul/Sales/src/Repositories/OrderItemInventoryRepository.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @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 - ]); - } - - } -} \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php b/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php index 7d90a8096..f7b78f3e2 100755 --- a/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php @@ -176,10 +176,14 @@ {{ $item->name }} - @if ($html = $item->getOptionDetailHtml()) -

{{ $html }}

- @elseif ($item->type == 'downloadable') -

Downloads : {{ $item->getDownloadableDetailHtml() }}

+ @if (isset($item->additional['attributes'])) +
+ + @foreach ($item->additional['attributes'] as $attribute) + {{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
+ @endforeach + +
@endif {{ core()->formatPrice($item->price, $invoice->order->order_currency_code) }}