Index: branches/5.2.x/units/products/products_event_handler.php =================================================================== diff -u -N -r16693 -r16775 --- branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 16693) +++ branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 16775) @@ -1,6 +1,6 @@ Application->RecallVar('user_id'); + /** @var UserHelper $user_helper */ + $user_helper = $this->Application->recallObject('UserHelper'); + $primary_group_id = $user_helper->getPrimaryGroup($this->Application->RecallVar('user_id')); - $sql = 'SELECT PrimaryGroupId - FROM ' . TABLE_PREFIX . 'Users - WHERE PortalUserId = ' . $user_id; - $primary_group_id = $this->Conn->GetOne($sql); - if (!$primary_group_id) { return; } Index: branches/5.2.x/units/products/products_item.php =================================================================== diff -u -N -r14258 -r16775 --- branches/5.2.x/units/products/products_item.php (.../products_item.php) (revision 14258) +++ branches/5.2.x/units/products/products_item.php (.../products_item.php) (revision 16775) @@ -1,6 +1,6 @@ Application->isAdmin && $this->Application->LoggedIn()) { // also group based - $primary_group = (int)$this->Application->Session->GetField('GroupId'); + /** @var UserHelper $user_helper */ + $user_helper = $this->Application->recallObject('UserHelper'); + $primary_group = $user_helper->getPrimaryGroup($this->Application->RecallVar('user_id')); $cache_key .= ':group=' . $primary_group; } @@ -82,4 +84,4 @@ return $price_info; } - } \ No newline at end of file + } Index: branches/5.2.x/units/orders/order_calculator.php =================================================================== diff -u -N -r16516 -r16775 --- branches/5.2.x/units/orders/order_calculator.php (.../order_calculator.php) (revision 16516) +++ branches/5.2.x/units/orders/order_calculator.php (.../order_calculator.php) (revision 16775) @@ -1,6 +1,6 @@ Application->ConfigValue('Comm_PriceBracketCalculation') == 1) { // if we have to stick to primary group, then its pricing will go first, // but if there is no pricing for primary group, then next optimal will be taken - $primary_group = $this->getUserPrimaryGroup($user_id); + /** @var UserHelper $user_helper */ + $user_helper = $this->Application->recallObject('UserHelper'); + $primary_group = $user_helper->getPrimaryGroup($user_id); + return '( IF(GroupId = ' . $primary_group . ', 1, 2) ) ASC, pp.Price ASC'; } @@ -787,24 +790,6 @@ } /** - * Returns primary group of given user - * - * @param int $user_id - * @return int - */ - protected function getUserPrimaryGroup($user_id) - { - if ($user_id > 0) { - $sql = 'SELECT PrimaryGroupId - FROM ' . TABLE_PREFIX . 'Users - WHERE PortalUserId = ' . $user_id; - return $this->Conn->GetOne($sql); - } - - return $this->Application->ConfigValue('User_LoggedInGroup'); - } - - /** * Returns ItemData associated with given order item * * @param Array $item Index: branches/5.2.x/units/pricing/pricing_event_handler.php =================================================================== diff -u -N -r16693 -r16775 --- branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 16693) +++ branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 16775) @@ -1,6 +1,6 @@ Application->ConfigValue('Comm_PriceBracketCalculation') == 1 ) { - $sql = 'SELECT PrimaryGroupId - FROM ' . TABLE_PREFIX . 'Users - WHERE PortalUserId = ' . $this->Application->GetVar('u_id'); - $pricing_group = $this->Conn->GetOne($sql); + /** @var UserHelper $user_helper */ + $user_helper = $this->Application->recallObject('UserHelper'); + $pricing_group = $user_helper->getPrimaryGroup($this->Application->RecallVar('user_id')); - if ( $pricing_group ) { + if ( $this->Application->LoggedIn() ) { $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 ) { - $pricing_group = $this->Application->ConfigValue('User_LoggedInGroup'); + if ( !$pricing_for_group_exists ) { + $pricing_group = $this->Application->ConfigValue('User_LoggedInGroup'); + } } } else {