Order creation completed for bundle product

This commit is contained in:
jitendra 2019-09-03 15:46:13 +05:30
parent 557cbb1db1
commit eafa585cb8
28 changed files with 169 additions and 102 deletions

View File

@ -143,25 +143,41 @@ class ShipmentController extends Controller
*/ */
public function isInventoryValidate(&$data) public function isInventoryValidate(&$data)
{ {
$valid = false;
if (! isset($data['shipment']['items'])) if (! isset($data['shipment']['items']))
return ; return ;
$valid = false;
$inventorySourceId = $data['shipment']['source'];
foreach ($data['shipment']['items'] as $itemId => $inventorySource) { foreach ($data['shipment']['items'] as $itemId => $inventorySource) {
if ($qty = $inventorySource[$data['shipment']['source']]) { if ($qty = $inventorySource[$inventorySourceId]) {
$orderItem = $this->orderItemRepository->find($itemId); $orderItem = $this->orderItemRepository->find($itemId);
$product = ($orderItem->type == 'configurable') if ($orderItem->qty_to_ship < $qty)
? $orderItem->child->product
: $orderItem->product;
$availableQty = $product->inventories()
->where('inventory_source_id', $data['shipment']['source'])
->sum('qty');
if ($orderItem->qty_to_ship < $qty || $availableQty < $qty) {
return false; return false;
if ($orderItem->getTypeInstance()->isComposite()) {
foreach ($orderItem->children as $child) {
if (! $child->qty_ordered)
continue;
$finalQty = ($child->qty_ordered / $orderItem->qty_ordered) * $qty;
$availableQty = $child->product->inventories()
->where('inventory_source_id', $inventorySourceId)
->sum('qty');
if ($child->qty_to_ship < $finalQty || $availableQty < $finalQty)
return false;
}
} else {
$availableQty = $orderItem->product->inventories()
->where('inventory_source_id', $inventorySourceId)
->sum('qty');
if ($orderItem->qty_to_ship < $qty || $availableQty < $qty)
return false;
} }
$valid = true; $valid = true;

View File

@ -896,4 +896,12 @@ body {
.pagination { .pagination {
margin-top: 30px; margin-top: 30px;
}
.item-options {
font-weight: 200;
b {
font-weight: 500;
}
} }

View File

@ -232,7 +232,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -182,7 +182,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -238,7 +238,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -260,7 +260,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -281,7 +281,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>
@ -308,24 +308,19 @@
</td> </td>
<td> <td>
@php
<?php
$product = $item->getTypeInstance()->getOrderedItem($item)->product; $product = $item->getTypeInstance()->getOrderedItem($item)->product;
$sourceQty = $product->inventory_source_qty($inventorySource); $sourceQty = $product->type == 'bundle' ? $item->qty_ordered : $product->inventory_source_qty($inventorySource->id);
@endphp
foreach ($product->inventories as $inventory) {
if ($inventory->inventory_source_id == $inventorySource->id) {
$sourceQty += $inventory->qty;
}
}
?>
{{ $sourceQty }} {{ $sourceQty }}
</td> </td>
<td> <td>
<?php $inputName = "shipment[items][$item->id][$inventorySource->id]"; ?> @php
$inputName = "shipment[items][$item->id][$inventorySource->id]";
@endphp
<div class="control-group" :class="[errors.has('{{ $inputName }}') ? 'has-error' : '']"> <div class="control-group" :class="[errors.has('{{ $inputName }}') ? 'has-error' : '']">

View File

@ -256,7 +256,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -870,6 +870,8 @@ class Cart {
if (isset($data['children']) && $data['children']) { if (isset($data['children']) && $data['children']) {
foreach ($data['children'] as $child) { foreach ($data['children'] as $child) {
$child['quantity'] = $child['quantity'] ? $child['quantity'] * $data['quantity'] : $child['quantity'];
$finalData['children'][] = $this->prepareDataForOrderItem($child); $finalData['children'][] = $this->prepareDataForOrderItem($child);
} }
} }

View File

@ -273,9 +273,8 @@ class ProductFlat
'locale' => $locale->code 'locale' => $locale->code
]); ]);
if ($parentProductFlat) { if ($parentProductFlat)
$productFlat->parent_id = $parentProductFlat->id; $productFlat->parent_id = $parentProductFlat->id;
}
} }
$productFlat->save(); $productFlat->save();

View File

@ -171,9 +171,8 @@ class Order extends Model implements OrderContract
return false; return false;
foreach ($this->items as $item) { foreach ($this->items as $item) {
if ($item->canShip()) { if ($item->canShip())
return true; return true;
}
} }
return false; return false;
@ -188,9 +187,8 @@ class Order extends Model implements OrderContract
return false; return false;
foreach ($this->items as $item) { foreach ($this->items as $item) {
if ($item->canInvoice()) { if ($item->canInvoice())
return true; return true;
}
} }
return false; return false;
@ -205,9 +203,8 @@ class Order extends Model implements OrderContract
return false; return false;
foreach ($this->items as $item) { foreach ($this->items as $item) {
if ($item->canCancel()) { if ($item->canCancel())
return true; return true;
}
} }
return false; return false;

View File

@ -129,6 +129,14 @@ class OrderItem extends Model implements OrderItemContract
return $this->hasOne(OrderItemProxy::modelClass(), 'parent_id'); return $this->hasOne(OrderItemProxy::modelClass(), 'parent_id');
} }
/**
* Get the parent item record associated with the order item.
*/
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
/** /**
* Get the children items. * Get the children items.
*/ */

View File

@ -138,17 +138,21 @@ class InvoiceRepository extends Repository
]); ]);
foreach ($orderItem->children as $childOrderItem) { foreach ($orderItem->children as $childOrderItem) {
$invoiceItem->child = $this->invoiceItemRepository->create([ $finalQty = $childOrderItem->qty_ordered
? ($childOrderItem->qty_ordered / $orderItem->qty_ordered) * $qty
: $child->qty_ordered;
$this->invoiceItemRepository->create([
'invoice_id' => $invoice->id, 'invoice_id' => $invoice->id,
'order_item_id' => $childOrderItem->id, 'order_item_id' => $childOrderItem->id,
'parent_id' => $invoiceItem->id, 'parent_id' => $invoiceItem->id,
'name' => $childOrderItem->name, 'name' => $childOrderItem->name,
'sku' => $childOrderItem->sku, 'sku' => $childOrderItem->sku,
'qty' => $qty, 'qty' => $finalQty,
'price' => $childOrderItem->price, 'price' => $childOrderItem->price,
'base_price' => $childOrderItem->base_price, 'base_price' => $childOrderItem->base_price,
'total' => $childOrderItem->price * $qty, 'total' => $childOrderItem->price * $finalQty,
'base_total' => $childOrderItem->base_price * $qty, 'base_total' => $childOrderItem->base_price * $finalQty,
'tax_amount' => 0, 'tax_amount' => 0,
'base_tax_amount' => 0, 'base_tax_amount' => 0,
'discount_amount' => 0, 'discount_amount' => 0,
@ -157,6 +161,8 @@ class InvoiceRepository extends Repository
'product_type' => $childOrderItem->product_type, 'product_type' => $childOrderItem->product_type,
'additional' => $childOrderItem->additional, 'additional' => $childOrderItem->additional,
]); ]);
$this->orderItemRepository->collectTotals($childOrderItem);
} }
$this->orderItemRepository->collectTotals($orderItem); $this->orderItemRepository->collectTotals($orderItem);

View File

@ -85,38 +85,34 @@ class OrderItemRepository extends Repository
*/ */
public function manageInventory($orderItem) public function manageInventory($orderItem)
{ {
if (! $orderedQuantity = $orderItem->qty_ordered) $orderItems = [];
return;
$products = [];
if ($orderItem->product->getTypeInstance()->isComposite()) { if ($orderItem->product->getTypeInstance()->isComposite()) {
foreach ($orderItem->children as $child) { foreach ($orderItem->children as $child) {
if (! $child->product) $orderItems[] = $child;
continue;
$products[] = $child->product;
} }
} else { } else {
if (! $orderItem->product) $orderItems[] = $orderItem;
return;
$products[] = $orderItem->product;
} }
foreach ($products as $product) { foreach ($orderItems as $item) {
$orderedInventory = $product->ordered_inventories() if (! $item->product)
->where('channel_id', $orderItem->order->channel->id) continue;
->first();
$orderedInventory = $item->product->ordered_inventories()
->where('channel_id', $orderItem->order->channel->id)
->first();
$qty = $item->qty_ordered ?: $item->parent->qty_ordered;
if ($orderedInventory) { if ($orderedInventory) {
$orderedInventory->update([ $orderedInventory->update([
'qty' => $orderedInventory->qty + $orderItem->qty_ordered 'qty' => $orderedInventory->qty + $qty
]); ]);
} else { } else {
$product->ordered_inventories()->create([ $item->product->ordered_inventories()->create([
'qty' => $orderItem->qty_ordered, 'qty' => $qty,
'product_id' => $product->id, 'product_id' => $item->product_id,
'channel_id' => $orderItem->order->channel->id, 'channel_id' => $orderItem->order->channel->id,
]); ]);
} }
@ -131,19 +127,15 @@ class OrderItemRepository extends Repository
*/ */
public function returnQtyToProductInventory($orderItem) public function returnQtyToProductInventory($orderItem)
{ {
if (! $product = $orderItem->product) $orderedInventory = $orderItem->product->ordered_inventories()
return;
$orderedInventory = $product->ordered_inventories()
->where('channel_id', $orderItem->order->channel->id) ->where('channel_id', $orderItem->order->channel->id)
->first(); ->first();
if (! $orderedInventory) if (! $orderedInventory)
return ; return;
if (($qty = $orderedInventory->qty - $orderItem->qty_to_cancel) < 0) { if (($qty = $orderedInventory->qty - ($orderItem->qty_ordered ? $orderItem->qty_to_cancel : $orderItem->parent->qty_ordered)) < 0)
$qty = 0; $qty = 0;
}
$orderedInventory->update([ $orderedInventory->update([
'qty' => $qty 'qty' => $qty

View File

@ -139,12 +139,37 @@ class OrderRepository extends Repository
Event::fire('sales.order.cancel.before', $order); Event::fire('sales.order.cancel.before', $order);
foreach ($order->items as $item) { foreach ($order->items as $item) {
if ($item->qty_to_cancel) { if (! $item->qty_to_cancel)
$this->orderItemRepository->returnQtyToProductInventory($item); continue;
$item->qty_canceled += $item->qty_to_cancel; $orderItems = [];
$item->save(); if ($item->product->getTypeInstance()->isComposite()) {
foreach ($item->children as $child) {
$orderItems[] = $child;
}
} else {
$orderItems[] = $item;
}
foreach ($orderItems as $orderItem) {
if (! $orderItem->product)
continue;
$this->orderItemRepository->returnQtyToProductInventory($orderItem);
if ($orderItem->qty_ordered) {
$orderItem->qty_canceled += $orderItem->qty_to_cancel;
$orderItem->save();
if ($orderItem->parent && $orderItem->parent->qty_ordered) {
$orderItem->parent->qty_canceled += $orderItem->parent->qty_to_cancel;
$orderItem->parent->save();
}
} else {
$orderItem->parent->qty_canceled += $orderItem->parent->qty_to_cancel;
$orderItem->parent->save();
}
} }
} }
@ -156,7 +181,7 @@ class OrderRepository extends Repository
} }
/** /**
* @inheritDoc * @return integer
*/ */
public function generateIncrementId() public function generateIncrementId()
{ {

View File

@ -39,9 +39,8 @@ class ShipmentItemRepository extends Repository
->first(); ->first();
if ($orderedInventory) { if ($orderedInventory) {
if (($orderedQty = $orderedInventory->qty - $data['qty']) < 0) { if (($orderedQty = $orderedInventory->qty - $data['qty']) < 0)
$orderedQty = 0; $orderedQty = 0;
}
$orderedInventory->update([ $orderedInventory->update([
'qty' => $orderedQty 'qty' => $orderedQty
@ -59,12 +58,11 @@ class ShipmentItemRepository extends Repository
->where('inventory_source_id', $data['shipment']->inventory_source_id) ->where('inventory_source_id', $data['shipment']->inventory_source_id)
->first(); ->first();
if (!$inventory) if (! $inventory)
return; return;
if (($qty = $inventory->qty - $data['qty']) < 0) { if (($qty = $inventory->qty - $data['qty']) < 0)
$qty = 0; $qty = 0;
}
$inventory->update([ $inventory->update([
'qty' => $qty 'qty' => $qty

View File

@ -115,9 +115,7 @@ class ShipmentRepository extends Repository
'shipment_id' => $shipment->id, 'shipment_id' => $shipment->id,
'order_item_id' => $orderItem->id, 'order_item_id' => $orderItem->id,
'name' => $orderItem->name, 'name' => $orderItem->name,
'sku' => ($orderItem->type == 'configurable') 'sku' => $orderItem->getTypeInstance()->getOrderedItem($orderItem)->sku,
? $orderItem->child->sku
: $orderItem->sku,
'qty' => $qty, 'qty' => $qty,
'weight' => $orderItem->weight * $qty, 'weight' => $orderItem->weight * $qty,
'price' => $orderItem->price, 'price' => $orderItem->price,
@ -129,17 +127,32 @@ class ShipmentRepository extends Repository
'additional' => $orderItem->additional, 'additional' => $orderItem->additional,
]); ]);
$product = ($orderItem->type == 'configurable') if ($orderItem->getTypeInstance()->isComposite()) {
? $orderItem->child->product foreach ($orderItem->children as $child) {
: $orderItem->product; if (! $child->qty_ordered)
continue;
$this->shipmentItemRepository->updateProductInventory([ $finalQty = ($child->qty_ordered / $orderItem->qty_ordered) * $qty;
'shipment' => $shipment,
'shipmentItem' => $shipmentItem, $this->shipmentItemRepository->updateProductInventory([
'product' => $product, 'shipment' => $shipment,
'qty' => $qty, 'shipmentItem' => $shipmentItem,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0 'product' => $child->product,
]); 'qty' => $finalQty,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
]);
$this->orderItemRepository->update(['qty_shipped' => $child->qty_shipped + $finalQty], $child->id);
}
} else {
$this->shipmentItemRepository->updateProductInventory([
'shipment' => $shipment,
'shipmentItem' => $shipmentItem,
'product' => $orderItem->product,
'qty' => $qty,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
]);
}
$this->orderItemRepository->update(['qty_shipped' => $orderItem->qty_shipped + $qty], $orderItem->id); $this->orderItemRepository->update(['qty_shipped' => $orderItem->qty_shipped + $qty], $orderItem->id);
} }

View File

@ -947,7 +947,6 @@ section.slider-block {
} }
.item-details .item-options { .item-details .item-options {
font-size: 16px;
margin-bottom: 8px; margin-bottom: 8px;
} }
@ -4364,4 +4363,13 @@ section.review {
grid-template-columns: 30% 30% 30%; grid-template-columns: 30% 30% 30%;
grid-column-gap: 4%; grid-column-gap: 4%;
} }
}
.item-options {
font-size: 14px;
font-weight: 200;
b {
font-weight: 500;
}
} }

View File

@ -56,7 +56,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -62,7 +62,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -115,7 +115,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -75,7 +75,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -44,7 +44,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -119,7 +119,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -130,7 +130,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -120,7 +120,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -121,7 +121,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>

View File

@ -131,7 +131,7 @@
<div class="item-options"> <div class="item-options">
@foreach ($item->additional['attributes'] as $attribute) @foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }} <b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach @endforeach
</div> </div>