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')) { $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 { // 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 * * @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) { $sub_total = 0; foreach($items_info as $id => $field_values) { $sub_total += $field_values['Quantity']*$field_values['Price']; } } else { return; // no need to update subtotal if there was no items_info } $table_info = $object->getLinkedInfo(); $main_object =& $this->Application->recallObject($table_info['ParentPrefix']); $main_object->SetDBField('SubTotal', $sub_total); $main_object->Update(); } /** * 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); } } } ?>