Index: branches/5.2.x/units/pricing/pricing_event_handler.php =================================================================== diff -u -N -r14569 -r14625 --- branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14569) +++ branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14625) @@ -1,6 +1,6 @@ getObject(); switch ($type) @@ -372,19 +380,21 @@ } /** - * Resets primary mark for other pricings of given product, when current pricing is primary + * Resets primary mark for other prices of given product, when current pricing is primary * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); $object =& $event->getObject(); /* @var $object kDBItem */ - if ($object->GetDBField('IsPrimary') == 1) { - // make all pricings non primary, when this one is + if ( $object->GetDBField('IsPrimary') == 1 ) { + // make all prices non primary, when this one is $sql = 'UPDATE ' . $object->TableName . ' SET IsPrimary = 0 WHERE (ProductId = ' . $object->GetDBField('ProductId') . ') AND (' . $object->IDField . ' <> ' . $object->GetID() . ')'; @@ -393,35 +403,50 @@ } /** - * Enter description here... + * Occurs before creating item * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { + parent::OnBeforeItemCreate($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ + $table_info = $object->getLinkedInfo($event->Special); - $table_info['ParentId'] = ($table_info['ParentId']?$table_info['ParentId']:0); + $table_info['ParentId'] = ($table_info['ParentId'] ? $table_info['ParentId'] : 0); - if ( $object->GetDBField('IsPrimary') == 1 ){ - $this->Conn->Query('UPDATE '.$object->TableName.' SET IsPrimary = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); + if ( $object->GetDBField('IsPrimary') == 1 ) { + $sql = 'UPDATE ' . $object->TableName . ' + SET IsPrimary = 0 + WHERE ' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId']; + $this->Conn->Query($sql); } else { - $prices_qty = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); + $sql = 'SELECT COUNT(*) + FROM ' . $object->TableName . ' + WHERE ' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId']; + $prices_qty = $this->Conn->GetOne($sql); - if ($prices_qty == 0) { + if ( $prices_qty == 0 ) { $object->SetDBField('IsPrimary', 1); } } } /** - * Enter description here... + * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject();