Changeset View
Changeset View
Standalone View
Standalone View
modules/in-commerce/units/orders/orders_event_handler.php
Show First 20 Lines • Show All 1687 Lines • ▼ Show 20 Line(s) | |||||
if (!$product_object->GetDBField('InventoryStatus')) { | if (!$product_object->GetDBField('InventoryStatus')) { | ||||
$order_items->GoNext(); | $order_items->GoNext(); | ||||
continue; | continue; | ||||
} | } | ||||
$inv_object =& $this->getInventoryObject($product_object, $combination_item, $combinations[ $rec['ProductId'].'_'.$rec['OptionsSalt'] ]); | $inv_object =& $this->getInventoryObject($product_object, $combination_item, $combinations[ $rec['ProductId'].'_'.$rec['OptionsSalt'] ]); | ||||
$lack = $rec['Quantity'] - $rec['QuantityReserved']; | $lack = $rec['Quantity'] - $rec['QuantityReserved']; | ||||
if ($lack > 0) { | if ( $lack > 0 ) { | ||||
// reserve lack or what is available (in case if we need to reserve anything, by Alex) | // Reserve lack or what is available (in case if we need to reserve anything, by Alex). | ||||
$to_reserve = min($lack, $inv_object->GetDBField('QtyInStock') - $product_object->GetDBField('QtyInStockMin')); | $to_reserve = min( | ||||
$lack, | |||||
$inv_object->GetDBField('QtyInStock') - $product_object->GetDBField('QtyInStockMin') | |||||
); | |||||
if ($to_reserve < $lack) $event->status = kEvent::erFAIL; // if we can't reserve the full lack | // If we can't reserve the full lack. | ||||
if ( $to_reserve < $lack ) { | |||||
$event->status = kEvent::erFAIL; | |||||
} | |||||
//reserve in order | // Reserve in order. | ||||
$order_item->SetDBFieldsFromHash($rec); | $order_item->SetDBFieldsFromHash($rec); | ||||
$order_item->SetDBField('QuantityReserved', $rec['QuantityReserved'] + $to_reserve); | $order_item->SetDBField('QuantityReserved', $rec['QuantityReserved'] + $to_reserve); | ||||
$new_lack = $order_item->GetDBField('Quantity') - $order_item->GetDBField('QuantityReserved'); | |||||
$order_item->SetDBField('BackOrderFlag', abs($new_lack) <= 0.0001 ? 0 : 1); | |||||
alex: These are the only changed lines. Other lines are CS fixes. | |||||
$order_item->SetId($rec['OrderItemId']); | $order_item->SetId($rec['OrderItemId']); | ||||
$order_item->Update(); | $order_item->Update(); | ||||
//update product - increase reserved, decrease in stock | // Update product - increase reserved, decrease in stock. | ||||
$inv_object->SetDBField('QtyReserved', $inv_object->GetDBField('QtyReserved') + $to_reserve); | $inv_object->SetDBField('QtyReserved', $inv_object->GetDBField('QtyReserved') + $to_reserve); | ||||
$inv_object->SetDBField('QtyInStock', $inv_object->GetDBField('QtyInStock') - $to_reserve); | $inv_object->SetDBField('QtyInStock', $inv_object->GetDBField('QtyInStock') - $to_reserve); | ||||
$inv_object->SetDBField('QtyBackOrdered', $inv_object->GetDBField('QtyBackOrdered') - $to_reserve); | $inv_object->SetDBField('QtyBackOrdered', $inv_object->GetDBField('QtyBackOrdered') - $to_reserve); | ||||
$inv_object->Update(); | $inv_object->Update(); | ||||
if ($product_object->GetDBField('InventoryStatus') == 2) { | if ( $product_object->GetDBField('InventoryStatus') == 2 ) { | ||||
// inventory by options, then restore changed combination values back to common $combinations array !!! | // Inventory by options, then restore changed combination | ||||
// values back to common $combinations array !!! | |||||
$combinations[ $rec['ProductId'].'_'.$rec['OptionsSalt'] ] = $inv_object->GetFieldValues(); | $combinations[$rec['ProductId'] . '_' . $rec['OptionsSalt']] = $inv_object->GetFieldValues(); | ||||
} | } | ||||
} | } | ||||
$order_items->GoNext(); | $order_items->GoNext(); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
function OnOrderPrint($event) | function OnOrderPrint($event) | ||||
▲ Show 20 Lines • Show All 2284 Lines • Show Last 20 Lines |
These are the only changed lines. Other lines are CS fixes.