Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F860192
in-commerce
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Apr 30, 9:53 AM
Size
17 KB
Mime Type
text/x-diff
Expires
Fri, May 2, 9:53 AM (11 h, 58 m)
Engine
blob
Format
Raw Data
Handle
611878
Attached To
rMINC Modules.In-Commerce
in-commerce
View Options
Index: branches/5.1.x/units/shipping_quote_engines/shipping_quote_collector.php
===================================================================
--- branches/5.1.x/units/shipping_quote_engines/shipping_quote_collector.php (revision 13163)
+++ branches/5.1.x/units/shipping_quote_engines/shipping_quote_collector.php (revision 13164)
@@ -1,137 +1,133 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ShippingQuoteCollector extends ShippingQuoteEngine {
function GetShippingQuotes($params)
{
if(!$params['dest_city'] || !$params['dest_country'] ||
(($params['dest_country'] == 'US' || $params['dest_country'] == 'CA') && !$params['dest_state']) ||
!$params['dest_postal'] || !$params['packages'])
{
return Array();
}
$db =& $this->Application->GetADODBConnection();
$cached_var_name = 'ShippingQuotes'.crc32(serialize($params));
- $day_ago = adodb_mktime() - 3600*24;
- $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$cached_var_name.'"
- AND Cached > '.$day_ago;
- if($shipping_types = $db->GetOne($sql))
- {
+
+ $shipping_types = $this->Application->getDBCache($cached_var_name);
+
+ if ($shipping_types) {
return unserialize($shipping_types);
}
$sql = 'SELECT Classname FROM '.$this->Application->getUnitOption('sqe', 'TableName').' WHERE Status = 1';
$classes = $db->GetCol($sql);
$classes[] = 'CustomShippingQuoteEngine'; // always persists
$shipping_types = Array();
foreach($classes as $class)
{
$object =& $this->Application->recallObject($class);
$new_shipping_types = $object->GetShippingQuotes($params);
$shipping_types = array_merge($shipping_types, $new_shipping_types);
}
uasort($shipping_types, Array(&$this, 'price_sort'));
//exclude not available shipping quotes by products
$limit_types = unserialize($params['limit_types']);
if (is_array($limit_types) && !in_array('ANY', $limit_types)) {
if (count($limit_types) == 0) break;
$available_types = array();
foreach ($shipping_types as $a_type)
{
$include = false; //exclude by default
foreach ($limit_types as $limit)
{
$include = $include || preg_match("/^$limit/", $a_type['ShippingId']);
if ($include) break;
}
if (!$include) continue;
$available_types[$a_type['ShippingId']] = $a_type;
}
$shipping_types = $available_types;
}
//exclude Selected Products Only shipping types, not matching products
$available_types = array();
foreach ($shipping_types as $a_type) {
if (getArrayValue($a_type, 'SelectedOnly')) {
if (!is_array($limit_types) || !in_array($a_type['ShippingId'], $limit_types)) continue;
}
$available_types[$a_type['ShippingId']] = $a_type;
}
$shipping_types = $available_types;
- $sql = 'DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName LIKE "ShippingQuotes%" AND Cached < '.$day_ago;
- $db->Query($sql);
- $sql = 'INSERT INTO '.TABLE_PREFIX.'Cache(VarName, Data, Cached)
- VALUES("'.$cached_var_name.'", '.$db->qstr(serialize($shipping_types)).', '.adodb_mktime().')';
- $db->Query($sql);
+ $this->Application->setDBCache($cached_var_name, serialize($shipping_types), 24 * 3600);
+
return $shipping_types;
}
function GetAvailableShippingTypes()
{
$db =& $this->Application->GetADODBConnection();
$sql = 'SELECT Classname FROM '.$this->Application->getUnitOption('sqe', 'TableName').' WHERE Status = 1';
$classes = $db->GetCol($sql);
$classes[] = 'CustomShippingQuoteEngine'; // always persists
$shipping_types = Array();
foreach($classes as $class)
{
$object =& $this->Application->recallObject($class);
$new_shipping_types = $object->GetAvailableTypes();
$shipping_types = array_merge($shipping_types, $new_shipping_types);
}
uasort($shipping_types, Array(&$this, 'SortShippingTypes'));
return $shipping_types;
}
function SortShippingTypes($elem1, $elem2)
{
if($elem1['_Name'] < $elem2['_Name'])
{
return -1;
}
elseif($elem1['_Name'] > $elem2['_Name'])
{
return 1;
}
else
{
return 0;
}
}
function price_sort($elem1, $elem2)
{
if($elem1['TotalCost'] < $elem2['TotalCost'])
{
return -1;
}
elseif($elem1['TotalCost'] > $elem2['TotalCost'])
{
return 1;
}
else
{
return 0;
}
}
}
\ No newline at end of file
Index: branches/5.1.x/units/currencies/currency_rates.php
===================================================================
--- branches/5.1.x/units/currencies/currency_rates.php (revision 13163)
+++ branches/5.1.x/units/currencies/currency_rates.php (revision 13164)
@@ -1,285 +1,280 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class kCurrencyRates extends kBase {
var $RateSource;
var $ExchangeRates = Array();
- var $PrimaryCurrency;
function kCurrencyRates()
{
- $this->Application =& kApplication::Instance();
+ parent::kBase();
+
$this->GetRatesData();
}
function GetRatesData()
{
- // written :) just check that it's correct
- $conn =& $this->Application->GetADODBConnection();
- $table = $this->Application->getUnitOption('curr', 'TableName');
- $primary = $this->GetPrimaryCurrency();
- $sql = 'SELECT "'.$primary.'" AS TARGET, ISO AS ID, RateToPrimary As RATE, 1 AS UNITS FROM '.$table.' WHERE 1';
- $rates = $conn->Query($sql);
- foreach ($rates as $a_rate) {
- $this->SetRate($primary, $a_rate['ID'], $a_rate['RATE']);
+ $cache_key = 'currency_rates[%CurrSerial%]';
+ $rates = $this->Application->getCache($cache_key);
+ $primary = $this->Application->GetPrimaryCurrency();
+
+ if ($rates === false) {
+ $conn =& $this->Application->GetADODBConnection();
+
+ $conn->nextQueryCachable = true;
+ $sql = 'SELECT ISO, RateToPrimary
+ FROM ' . $this->Application->getUnitOption('curr', 'TableName') . '
+ WHERE Status = ' . STATUS_ACTIVE;
+ $rates = $conn->Query($sql);
+
+ $this->Application->setCache($cache_key, $rates);
+ }
+
+ foreach ($rates as $rate) {
+ $this->SetRate($primary, $rate['ISO'], $rate['RateToPrimary']);
}
}
function GetRate($source_cur, $target_cur, $units = 1)
{
- $source_cur = ($source_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $source_cur;
- $target_cur = ($target_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $target_cur;
+ $source_cur = ($source_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $source_cur;
+ $target_cur = ($target_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $target_cur;
if($source_cur == $target_cur)
{
return 1;
}
if($this->ExchangeRates[$target_cur]['TARGET'] == $source_cur)
{
$rate = ($this->ExchangeRates[$target_cur]['RATE'] == 0) ? false : 1 / $this->ExchangeRates[$target_cur]['RATE'];
}
elseif($this->ExchangeRates[$source_cur]['TARGET'] == $target_cur)
{
$rate = $this->ExchangeRates[$source_cur]['RATE'];
}
else
{
$rate = ($this->ExchangeRates[$target_cur]['RATE'] == 0) ? false : $this->ExchangeRates[$source_cur]['RATE'] / $this->ExchangeRates[$target_cur]['RATE'];
}
$rate *= $units;
return $rate;
}
function Convert($amount, $source_cur, $target_cur)
{
return $amount * $this->GetRate($source_cur, $target_cur);
}
function SetRate($source_cur, $target_cur, $rate, $units = 1)
{
$this->ExchangeRates[$target_cur]['TARGET'] = $source_cur;
$this->ExchangeRates[$target_cur]['ID'] = $target_cur;
$this->ExchangeRates[$target_cur]['RATE'] = $rate;
$this->ExchangeRates[$target_cur]['UNITS'] = $units;
}
- function GetPrimaryCurrency()
- {
- if(!$this->PrimaryCurrency)
- {
- $conn =& $this->Application->GetADODBConnection();
- $table = $this->Application->getUnitOption('curr', 'TableName');
- $sql = 'SELECT ISO FROM '.$table.' WHERE IsPrimary = 1';
- $this->PrimaryCurrency = $conn->GetOne($sql);
- }
- return $this->PrimaryCurrency;
- }
-
function StoreRates($currencies=null)
{
$curr_object =& $this->Application->recallObject('curr', null, Array ('skip_autoload' => true));
/* @var $curr_object kDBItem */
if ($currencies) {
if (!is_array($currencies)) {
$currencies = explode(',', $currencies);
}
}
else {
$currencies = array_keys($this->ExchangeRates);
}
foreach ($currencies as $id) {
$rate = $this->GetRate($id, 'PRIMARY');
if ($rate) {
$curr_object->Clear();
$curr_object->Load($id, 'ISO');
$curr_object->SetDBField('RateToPrimary', $rate);
$curr_object->SetDBField('Modified_date', adodb_mktime());
$curr_object->SetDBField('Modified_time', adodb_mktime());
$curr_object->Update();
}
}
}
}
class kBankLVCurrencyRates extends kCurrencyRates {
function kBankLVCurrencyRates()
{
$this->RateSource = 'http://www.bank.lv/ValutuKursi/XML/xml.cfm';
parent::kCurrencyRates();
}
function GetRatesData()
{
- $this->GetPrimaryCurrency();
$xml_parser = xml_parser_create();
$curl_helper =& $this->Application->recallObject('CurlHelper');
/* @var $curl_helper kCurlHelper */
$xml = $curl_helper->Send($this->RateSource);
xml_parse_into_struct($xml_parser, $xml, $struct, $index);
$data_res = Array();
$currency = '';
foreach($struct as $element)
{
switch($element['tag'])
{
case 'ID':
$currency = $element['value'];
$data_res[$currency]['ID'] = $currency;
$data_res[$currency]['TARGET'] = 'LVL';
break;
case 'UNITS':
$data_res[$currency]['UNITS'] = $element['value'];
break;
case 'RATE':
$data_res[$currency]['RATE'] = $element['value'];
break;
default:
}
}
if(!$data_res['LVL'])
{
$data_res['LVL']['ID'] = 'LVL';
$data_res['LVL']['UNITS'] = 1;
$data_res['LVL']['TARGET'] = 'LVL';
$data_res['LVL']['RATE'] = 1;
}
$this->ExchangeRates = $data_res;
}
}
class kECBCurrencyRates extends kCurrencyRates {
function kECBCurrencyRates()
{
$this->RateSource = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml';
parent::kCurrencyRates();
}
function GetRatesData()
{
- $this->GetPrimaryCurrency();
$xml_parser = xml_parser_create();
$curl_helper =& $this->Application->recallObject('CurlHelper');
/* @var $curl_helper kCurlHelper */
$xml = $curl_helper->Send($this->RateSource);
xml_parse_into_struct($xml_parser, $xml, $struct, $index);
$data_res = Array();
foreach($struct as $element)
{
if(isset($element['attributes']) && isset($element['attributes']['CURRENCY']))
{
$currency = $element['attributes']['CURRENCY'];
$data_res[$currency]['ID'] = $currency;
$data_res[$currency]['TARGET'] = 'EUR';
$data_res[$currency]['UNITS'] = 1;
$data_res[$currency]['RATE'] = ($element['attributes']['RATE'] == 0) ? 0 : 1 / $element['attributes']['RATE'];
}
}
if(!$data_res['EUR'])
{
$data_res['EUR']['ID'] = 'EUR';
$data_res['EUR']['UNITS'] = 1;
$data_res['EUR']['TARGET'] = 'EUR';
$data_res['EUR']['RATE'] = 1;
}
$this->ExchangeRates = $data_res;
}
}
class kFRNYCurrencyRates extends kCurrencyRates {
function kFRNYCurrencyRates()
{
$this->RateSource = 'http://www.ny.frb.org/markets/fxrates/FXtoXML.cfm?FEXdate=%s&FEXtime=1200';
parent::kCurrencyRates();
}
function GetRatesData()
{
$curl_helper =& $this->Application->recallObject('CurlHelper');
/* @var $curl_helper kCurlHelper */
- $this->GetPrimaryCurrency();
for($i = 0; $i < 10; $i++)
{
$time = adodb_mktime() - $i * 3600 * 24;
$source_file = sprintf($this->RateSource, adodb_date('Y-m-d', $time));
$xml = $curl_helper->Send($source_file);
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $xml, $struct, $index);
foreach($struct as $element)
{
if($element['tag'] == 'FRBNY:DATASET')
{
break;
}
}
if($element['type'] == 'open')
{
break;
}
}
if($element['type'] != 'open')
{
return false;
}
foreach($struct as $element)
{
switch($element['tag'])
{
case 'FRBNY:SERIES':
$currency = $element['attributes']['UNIT'];
if($currency)
{
$data_res[$currency]['ID'] = $currency;
$data_res[$currency]['UNITS'] = 1;
}
break;
case 'FRBNY:CURR':
$data_res[$currency]['TARGET'] = $element['value'];
break;
case 'FRBNY:OBS_VALUE':
$data_res[$currency]['RATE'] = ($element['value'] == 0) ? 0 : 1 / $element['value'];
break;
default:
}
}
if(!$data_res['USD'])
{
$data_res['USD']['ID'] = 'USD';
$data_res['USD']['UNITS'] = 1;
$data_res['USD']['TARGET'] = 'USD';
$data_res['USD']['RATE'] = 1;
}
$this->ExchangeRates = $data_res;
}
}
\ No newline at end of file
Index: branches/5.1.x/units/products/products_item.php
===================================================================
--- branches/5.1.x/units/products/products_item.php (revision 13163)
+++ branches/5.1.x/units/products/products_item.php (revision 13164)
@@ -1,67 +1,84 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ProductsItem extends kCatDBItem
{
function GetPackageContentIds()
{
$ids_string = trim($this->GetDBField('PackageContent'), '|');
if ($ids_string) {
$ids_array = explode('|', $ids_string);
return $ids_array;
}
else {
return array();
}
}
/**
* Returns field values from primary pricing for product
*
* @return array
*/
function getPrimaryPricing()
{
- if (!$this->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);
+
+ $this->Application->setCache($cache_key, $price_info);
+ }
- return $this->Conn->GetRow($sql);
+ return $price_info;
}
}
\ No newline at end of file
Event Timeline
Log In to Comment