Index: branches/5.1.x/units/pricing/pricing_event_handler.php =================================================================== diff -u -N -r13745 -r13809 --- branches/5.1.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 13745) +++ branches/5.1.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 13809) @@ -1,6 +1,6 @@ redirect_params = Array('opener' => 's'); //stay! } + /** + * Resets primary mark for other pricings of given product, when current pricing is primary + * + * @param kEvent $event + */ function OnBeforeItemUpdate(&$event) { - // TODO: during import special of product is not empty as usual and this raises problems to getLinkedInfo + parent::OnBeforeItemUpdate($event); + $object =& $event->getObject(); - $table_info = $object->getLinkedInfo(); + /* @var $object kDBItem */ - $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) { + // make all pricings non primary, when this one is + $sql = 'UPDATE ' . $object->TableName . ' + SET IsPrimary = 0 + WHERE (ProductId = ' . $object->GetDBField('ProductId') . ') AND (' . $object->IDField . ' <> ' . $object->GetID() . ')'; + $this->Conn->Query($sql); } - } /**