Index: branches/5.1.x/units/products/products_item.php =================================================================== diff -u -N -r13100 -r13164 --- branches/5.1.x/units/products/products_item.php (.../products_item.php) (revision 13100) +++ branches/5.1.x/units/products/products_item.php (.../products_item.php) (revision 13164) @@ -1,6 +1,6 @@ Application->isAdminUser) { - $user_id = $this->Application->RecallVar('user_id'); - $primary_group = $user_id != -2 ? $this->Conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PrimaryGroup = 1 AND PortalUserId = '.$user_id) : false; + // product + pricing based + $cache_key = 'product_primary_pricing[%PIDSerial:' . $this->GetID() . '%][%PrIDSerial:ProductId:' . $this->GetID() . '%]'; - if ($primary_group) { + if (!$this->Application->isAdmin && $this->Application->LoggedIn()) { + // also group based + $primary_group = (int)$this->Application->Session->GetField('GroupId'); + $cache_key .= ':group=' . $primary_group; + } + + $price_info = $this->Application->getCache($cache_key); + + if ($price_info === false) { + if (!$this->Application->isAdmin && $this->Application->LoggedIn()) { + // logged in user on front-end + $this->Conn->nextQueryCachable = true; $sql = 'SELECT Price, Cost - FROM '.TABLE_PREFIX.'ProductsPricing - WHERE (ProductId = '.$this->GetID().') AND (GroupId = '.$primary_group.') - ORDER BY MinQty'; - $a_values = $this->Conn->GetRow($sql); + FROM ' . TABLE_PREFIX . 'ProductsPricing + WHERE (ProductId = ' . $this->GetID() . ') AND (GroupId = ' . $primary_group . ') + ORDER BY MinQty'; + $price_info = $this->Conn->GetRow($sql); - if ($a_values !== false) { - return $a_values; + if ($price_info !== false) { + $this->Application->setCache($cache_key, $price_info); + + return $price_info; } } - } - $pr_table = $this->Application->getUnitOption('pr', 'TableName'); + // not logged-in user on front-end or in administrative console + $pr_table = $this->Application->getUnitOption('pr', 'TableName'); - if ($this->mode == 't') { - $pr_table = $this->Application->GetTempName($pr_table, 'prefix:'.$this->Prefix); - } + if ($this->IsTempTable()) { + $pr_table = $this->Application->GetTempName($pr_table, 'prefix:' . $this->Prefix); + } - $sql = 'SELECT Price, Cost - FROM '.$pr_table.' - WHERE ('.$this->IDField.' = '.$this->GetID().') AND (IsPrimary = 1)'; + $this->Conn->nextQueryCachable = true; + $sql = 'SELECT Price, Cost + FROM ' . $pr_table . ' + WHERE (' . $this->IDField . ' = ' . $this->GetID() . ') AND (IsPrimary = 1)'; + $price_info = $this->Conn->GetRow($sql); - return $this->Conn->GetRow($sql); + $this->Application->setCache($cache_key, $price_info); + } + + return $price_info; } } \ No newline at end of file