Index: branches/5.2.x/units/pricing/pricing_event_handler.php =================================================================== diff -u -r14436 -r14569 --- branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14436) +++ branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14569) @@ -1,6 +1,6 @@ Array('subitem' => 'add|edit'), - 'OnInfinity' => Array('subitem' => 'add|edit'), - 'OnArrange' => Array('subitem' => 'add|edit'), + 'OnMoreBrackets' => Array('subitem' => 'add|edit'), + 'OnInfinity' => Array('subitem' => 'add|edit'), + 'OnArrange' => Array('subitem' => 'add|edit'), + 'OnDeleteBrackets' => Array('subitem' => 'add|edit'), ); $this->permMapping = array_merge($this->permMapping, $permissions); } function mapEvents() { parent::mapEvents(); // ensure auto-adding of approve/decine and so on events - $brackets_events = Array( 'OnMoreBrackets' => 'PricingBracketsAction', - 'OnArrange' => 'PricingBracketsAction', - 'OnInfinity' => 'PricingBracketsAction'); + $brackets_events = Array( + 'OnMoreBrackets' => 'PricingBracketsAction', + 'OnArrange' => 'PricingBracketsAction', + 'OnInfinity' => 'PricingBracketsAction', + 'OnDeleteBrackets' => 'PricingBracketsAction', + ); $this->eventMethods = array_merge($this->eventMethods, $brackets_events); } @@ -98,8 +102,6 @@ $temp[$i]['Negotiated'] = '0'; $temp[$i]['IsPrimary'] = '0'; $temp[$i]['GroupId'] = $group_id; - - } $this->Application->SetVar($event->getPrefixSpecial(true), $temp); @@ -150,50 +152,56 @@ $this->Application->SetVar($event->getPrefixSpecial(true), $temp); $event->CallSubEvent('OnPreSaveBrackets'); break; + + case 'OnDeleteBrackets': + if ($group_id) { + $temp = ''; // delete all pricings from "pr_tang" var + + $sql = 'DELETE FROM ' . $bracket->TableName . ' + WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $group_id; + $this->Conn->Query($sql); + } + break; default: } - $this->Application->SetVar($event->getPrefixSpecial(true), $temp); + $this->Application->SetVar($event->getPrefixSpecial(true), $temp); // store pr_tang var } function OnPreSaveBrackets(&$event) { - if( $this->Application->GetVar('pr_tang')) - { + if( $this->Application->GetVar('pr_tang') ) { + $object =& $event->GetObject(); /* @var $object kDBItem */ + $product_id = $this->Application->GetVar('p_id'); $group_id = $this->Application->getVar('group_id'); - if($group_id>0){ - $where_group=' AND GroupId = '.$group_id.' '; - } - $stored_ids = $this->Conn->GetCol("SELECT PriceId FROM ".$object->TableName." WHERE ProductId=".$this->Application->GetVar("p_id").' '.$where_group); - - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true)); - - + $sql = 'SELECT PriceId + FROM ' . $object->TableName . ' + WHERE ProductId = ' . $product_id . ' ' . ($group_id? 'AND GroupId = ' . $group_id : ''); + $stored_ids = $this->Conn->GetCol($sql); + + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); // get pr_tang var uasort($items_info, 'pr_bracket_comp'); + + foreach ($items_info as $item_id => $values) { - - foreach ($items_info as $item_id=>$values) - { - if (in_array($item_id, $stored_ids)) { //if it's already exist $object->Load($item_id); $object->SetFieldsFromHash($values); + if (!$object->Validate()) { unset($stored_ids[array_search($item_id, $stored_ids)]); $event->redirect = false; continue; } - if( $object->Update($item_id) ) - { + if( $object->Update($item_id) ) { $event->status=kEvent::erSUCCESS; } - else - { + else { $event->status=kEvent::erFAIL; $event->redirect=false; break; @@ -203,18 +211,17 @@ else { $object->Clear(); $object->SetFieldsFromHash($values); - $object->SetDBField('ProductId', $this->Application->GetVar("p_id")); + $object->SetDBField('ProductId', $product_id); - if( $object->Create() ) - { + if( $object->Create() ) { $event->status=kEvent::erSUCCESS; } } } // delete - foreach ($stored_ids as $stored_id){ - $this->Conn->Query("DELETE FROM ".$object->TableName." WHERE PriceId=".$stored_id); + foreach ($stored_ids as $stored_id) { + $this->Conn->Query('DELETE FROM ' . $object->TableName . ' WHERE PriceId = ' . $stored_id); } }