Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1029998
in-commerce
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 16, 12:15 AM
Size
7 KB
Mime Type
text/x-diff
Expires
Wed, Jun 18, 12:15 AM (1 h, 41 m)
Engine
blob
Format
Raw Data
Handle
665056
Attached To
rMINC Modules.In-Commerce
in-commerce
View Options
Index: branches/RC/in-commerce/units/order_items/order_items_event_handler.php
===================================================================
--- branches/RC/in-commerce/units/order_items/order_items_event_handler.php (revision 11566)
+++ branches/RC/in-commerce/units/order_items/order_items_event_handler.php (revision 11567)
@@ -1,211 +1,217 @@
<?php
class OrderItemsEventHandler extends kDBEventHandler
{
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnSaveItems' => Array('subitem' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Processes item selection from popup item selector
*
* @param kEvent $event
*/
function OnProcessSelected(&$event)
{
$object =& $event->getObject( Array('skip_autoload' => true) );
$selected_ids = $this->Application->GetVar('selected_ids');
$product_ids = $selected_ids['p'];
if ($product_ids) {
//after adding Options Selection during adding products to order in admin, selector is in single mode
// = allows selecting one item at a time, but we leave this code just in case :)
$product_ids = explode(',', $product_ids);
$product_object =& $this->Application->recallObject('p.-item', null, array('skip_autoload' => true));
- $orders_h =& $this->Application->recallObject('ord_EventHandler');
- /* @var $orders_h OrdersEventHandler */
foreach ($product_ids as $product_id) {
$product_object->Load($product_id);
- if ($product_object->GetDBField('HasRequiredOptions')) {
+
+ $sql = 'SELECT COUNT(*)
+ FROM ' . $this->Application->getUnitOption('po', 'TableName') . '
+ WHERE (Required = 1) AND (ProductId = ' . $product_id . ')';
+
+ if ( $this->Conn->GetOne($sql) ) {
$event->SetRedirectParam('opener', 'u');
$current_stack_name = rtrim('opener_stack_'.$this->Application->GetVar('m_wid'), '_');
$current_opener_stack = $this->Application->RecallVar($current_stack_name);
$current_opener_stack = $current_opener_stack ? unserialize($current_opener_stack) : Array();
// actually it should be real parent_wid for the thing to work in popups mode
// but currently there is no way to get that here
$parent_wid = '';
$parent_stack_name = rtrim('opener_stack_'.$parent_wid, '_');
$parent_opener_stack = $this->Application->RecallVar($parent_stack_name);
$parent_opener_stack = $parent_opener_stack ? unserialize($parent_opener_stack) : Array();
$current_url = preg_replace('/(:m[0-9]+-[^-]*-[^-]*-[^-]*-)(s)(-.*)/', '\1u\3', array_pop($current_opener_stack));
array_push($parent_opener_stack, $current_url);
$new_level = $this->Application->BuildEnv(
'in-commerce/orders/order_product_edit',
Array($event->Prefix.'_event' => 'OnNew', 'm_wid' => $parent_wid, 'p_id' => $product_id, 'm_opener' => 's'),
'm,ord,p',
true
);
array_push($current_opener_stack, 'index.php|'.ltrim($new_level, ENV_VAR_NAME.'=') );
$this->Application->StoreVar($current_stack_name, serialize($current_opener_stack));
$this->Application->StoreVar($parent_stack_name, serialize($parent_opener_stack));
return ;
}
else {
+ $orders_h =& $this->Application->recallObject('ord_EventHandler');
+ /* @var $orders_h OrdersEventHandler */
+
// 1 for PacakgeNum - temporary solution to overcome splitting into separate sub-orders
// of orders with items added through admin when approving them
$orders_h->AddItemToOrder($event, $product_id, null, 1);
}
}
}
$this->finalizePopup($event);
}
/**
* Updates subtotal field in order record.
* Only for "Items" tab in "Orders -> Order Edit" in Admin
*
* @param kEvent $event
*/
function OnUpdate(&$event)
{
parent::OnUpdate($event);
if ( ($this->Application->GetVar('t') != 'in-commerce/orders/orders_edit_items') ) {
return true;
}
$object =& $event->getObject();
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if (!$items_info) {
return ;
}
$sub_total = $this->getSubTotal($items_info);
$return_total = $this->getReturnTotal($items_info);
$table_info = $object->getLinkedInfo();
$main_object =& $this->Application->recallObject($table_info['ParentPrefix']);
if ($sub_total !== false) {
$main_object->SetDBField('SubTotal', $sub_total);
}
$main_object->SetDBField('ReturnTotal', $return_total);
$main_object->Update();
}
/**
* Returns subtotal
*
* @param Array $items_info
* @return float
*/
function getSubTotal($items_info)
{
$sub_total = 0;
foreach ($items_info as $id => $field_values) {
if (!array_key_exists('Price', $field_values)) {
return false;
}
$sub_total += $field_values['Quantity'] * $field_values['Price'];
}
return $sub_total;
}
/**
* Returns total returned amount (refund)
*
* @param Array $items_info
* @return float
*/
function getReturnTotal($items_info)
{
$return_total = 0;
foreach ($items_info as $id => $field_values) {
$return_total += $field_values['ReturnAmount'];
}
return $return_total;
}
/**
* Saves selected items
*
* @param kEvent $event
*/
function OnSaveItems(&$event)
{
$event->CallSubEvent('OnUpdate');
$event->redirect = false;
$event->redirect_params = Array('opener'=>'s','pass'=>'all');
}
/**
* Occures after an item has been cloned
* Id of newly created item is passed as event' 'id' param
*
* @param kEvent $event
*/
function OnAfterClone(&$event)
{
$id = $event->getEventParam('id');
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$id_field = $this->Application->getUnitOption($event->Prefix,'IDField');
$sql = 'UPDATE '.$table.' SET QuantityReserved = NULL WHERE '.$id_field.' = '.$id;
$this->Conn->Query($sql);
}
function OnAfterItemLoad(&$event)
{
$object =& $event->getObject();
if( $item_info = $object->GetDBField('ItemData') )
{
$item_info = unserialize($item_info);
$object->SetDBField('DiscountType', getArrayValue($item_info, 'DiscountType'));
$object->SetDBField('DiscountId', getArrayValue($item_info, 'DiscountId'));
}
}
function SetCustomQuery(&$event)
{
parent::SetCustomQuery($event);
$object =& $event->getObject();
$package_num = $event->getEventParam('package_num');
if ($package_num) $object->addFilter('package_num', 'PackageNum = '.$package_num);
$type = $event->getEventParam('product_type');
if ($type) {
$object->addFilter('product_type', 'p.Type ='.$type);
}
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/in-commerce/units/order_items/order_items_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.17.2.1
\ No newline at end of property
+1.17.2.2
\ No newline at end of property
Event Timeline
Log In to Comment