Array('subitem' => 'add|edit'), 'OnInfinity' => Array('subitem' => 'add|edit'), 'OnArrange' => Array('subitem' => 'add|edit'), ); $this->permMapping = array_merge($this->permMapping, $permissions); } function prepareObject(&$object, &$event) { if($this->Application->GetVar('s_id') === false) { return; } $shipping_object =& $this->Application->recallObject('s'); $lang_object =& $this->Application->recallObject('lang.current'); if($lang_object->GetDBField('UnitSystem') == 2 && $shipping_object->GetDBField('Type') == 1) { $fields = Array('Start', 'End'); $formatter =& $this->Application->recallObject('kUnitFormatter'); foreach($fields as $field) { $options = $object->GetFieldOptions($field); $options['formatter'] = 'kUnitFormatter'; $object->SetFieldOptions($field, $options); $formatter->prepareOptions($field, $options, $object); } } } function prepareBrackets(&$event) { $lang_object =& $this->Application->recallObject('lang.current'); $shipping_object =& $this->Application->recallObject('s'); if($lang_object->GetDBField('UnitSystem') != 2 || $shipping_object->GetDBField('Type') != 1) { return; } $item_info = $this->Application->GetVar( $event->Prefix_Special ); foreach($item_info as $id => $item_data) { if($item_info[$id]['Start_a'] === '' && $item_info[$id]['Start_b'] === '') { $item_info[$id]['Start'] = ''; } else { $item_info[$id]['Start'] = Pounds2Kg($item_info[$id]['Start_a'], $item_info[$id]['Start_b']); } if($item_info[$id]['End_a'] == '∞' || $item_info[$id]['End_a'] == '∞') { $item_info[$id]['End'] = '∞'; } elseif($item_info[$id]['End_a'] === '' && $item_info[$id]['End_b'] === '') { $item_info[$id]['End'] = ''; } else { $item_info[$id]['End'] = Pounds2Kg($item_info[$id]['End_a'], $item_info[$id]['End_b']); } } $this->Application->SetVar( $event->Prefix_Special, $item_info ); } /** * Adds additional 5 empty brackets * * @param kEvent $event */ function OnMoreBrackets(&$event) { $shipping_object =& $this->Application->recallObject('s'); $default_start = ($shipping_object->GetDBField('Type') == 1) ? 0 : 1; $this->prepareBrackets($event); $event->redirect = false; $brackets_helper =& $this->Application->recallObject('BracketsHelper'); $brackets_helper->InitHelper('Start', 'End', Array(), $default_start ); $brackets_helper->OnMoreBrackets($event); } /** * Arrange brackets * * @param kEvent $event */ function OnArrange(&$event) { $shipping_object =& $this->Application->recallObject('s'); $default_start = ($shipping_object->GetDBField('Type') == 1) ? 0 : 1; $this->prepareBrackets($event); $event->redirect = false; $brackets_helper =& $this->Application->recallObject('BracketsHelper'); /* @var $brackets_helper kBracketsHelper */ $brackets_helper->InitHelper('Start', 'End', Array(), $default_start); $brackets_helper->arrangeBrackets($event); $event->CallSubEvent('OnPreSaveBrackets'); } /** * Arrange infinity brackets * * @param kEvent $event */ function OnInfinity(&$event) { $shipping_object =& $this->Application->recallObject('s'); $default_start = ($shipping_object->GetDBField('Type') == 1) ? 0 : 1; $this->prepareBrackets($event); $event->redirect = false; $brackets_helper =& $this->Application->recallObject('BracketsHelper'); $brackets_helper->InitHelper('Start', 'End', Array(), $default_start ); $brackets_helper->arrangeBrackets($event); $event->CallSubEvent('OnPreSaveBrackets'); $brackets_helper->OnInfinity($event); $event->CallSubEvent('OnPreSaveBrackets'); } function OnBeforeItemUpdate(&$event) { $shipping_object =& $this->Application->recallObject('s'); $default_start = ($shipping_object->GetDBField('Type') == 1) ? 0 : 1; $object =& $event->getObject(); $linked_info = $object->getLinkedInfo(); $object->SetDBField($linked_info['ParentTableKey'], $linked_info['ParentId']); $brackets_helper =& $this->Application->recallObject('BracketsHelper'); $brackets_helper->InitHelper('Start', 'End', Array(), $default_start ); $brackets_helper->replaceInfinity($event); } /** * Enter description here... * * @param kEvent $event */ function OnPreSaveBrackets(&$event) { $lang_object =& $this->Application->recallObject('lang.current'); $shipping_object =& $this->Application->recallObject('s'); if($lang_object->GetDBField('UnitSystem') == 2 && $shipping_object->GetDBField('Type') == 1) { $item_info = $this->Application->GetVar( $event->Prefix_Special ); if(is_array($item_info)) { foreach($item_info as $id => $values) { if($values['End'] == -1) { $item_info[$id]['End_a'] = -1 / POUND_TO_KG; $item_info[$id]['End_b'] = 0; } } $this->Application->SetVar( $event->Prefix_Special, $item_info ); } } $default_start = ($shipping_object->GetDBField('Type') == 1) ? 0 : 1; $brackets_helper =& $this->Application->recallObject('BracketsHelper'); $brackets_helper->InitHelper('Start', 'End', Array(), $default_start ); $brackets_helper->OnPreSaveBrackets($event); } } ?>