$this->Conn->Query('UPDATE '.$object->TableName.' SET IsPrimary = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
$this->Conn->Query('UPDATE '.$object->TableName.' SET IsPrimary = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (PriceId = '.$id.')');
}
$event->SetRedirectParam('opener','s');
}
/**
* Resets primary mark for other prices of given product, when current pricing is primary
*
* @param kEvent $event
* @return void
* @access protected
*/
protectedfunctionOnBeforeItemUpdate(kEvent$event)
{
parent::OnBeforeItemUpdate($event);
/** @var kDBItem $object */
$object=$event->getObject();
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().')';
//$cheapest_group = $this->Conn->GetOne('SELECT GroupId FROM '.$object->TableName.' WHERE ProductId='.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.') AND MinQty = 1 GROUP BY GroupId ORDER BY Price ASC');
$sql='SELECT PriceId, Price, GroupId
FROM '.$object->TableName.'
WHERE ProductId = '.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.')