Index: branches/5.2.x/units/pricing/pricing_event_handler.php =================================================================== diff -u -N -r14258 -r14436 --- branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14258) +++ branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14436) @@ -1,6 +1,6 @@ Application->RecallVar('UserGroups'); + if ( $this->Application->ConfigValue('Comm_PriceBracketCalculation') == 1 ) { + $sql = 'SELECT PrimaryGroupId + FROM ' . TABLE_PREFIX . 'PortalUser + WHERE PortalUserId = ' . $this->Application->GetVar('u_id'); + $pricing_group = $this->Conn->GetOne($sql); - $pricing_method = $this->Application->ConfigValue('Comm_PriceBracketCalculation'); - if ($pricing_method == 1) { - $primary_group = $this->Conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$this->Application->GetVar('u_id').' AND PrimaryGroup=1'); - $pricing_group = $primary_group; if ($pricing_group) { - $pricing_for_group_exists = $this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'ProductsPricing WHERE ProductId='.$this->Application->GetVar('p_id').' AND GroupId='.$primary_group.' AND Price IS NOT NULL'); + $sql = 'SELECT COUNT(*) + FROM ' . TABLE_PREFIX . 'ProductsPricing + WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $pricing_group . ' AND Price IS NOT NULL'; + $pricing_for_group_exists = $this->Conn->GetOne($sql); } - if ($pricing_group && $pricing_for_group_exists > 0) { - $pricing_group = $primary_group; - } - else { + + if ( !$pricing_group || !$pricing_for_group_exists ) { $pricing_group = $this->Application->ConfigValue('User_LoggedInGroup'); } - - } else { + $user_groups = $this->Application->RecallVar('UserGroups'); + //$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'); - $effective_brackets = $this->Conn->Query('SELECT PriceId, Price, GroupId FROM '.$object->TableName.' - WHERE ProductId='.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.') ORDER BY GroupId ASC, MinQty ASC', 'PriceId'); + + $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 . ') + ORDER BY GroupId ASC, MinQty ASC'; + $effective_brackets = $this->Conn->Query($sql, 'PriceId'); + $group_prices = array(); $min_price = -1; $cheapest_group = 0;