// Multishop for referrers

This commit is contained in:
rMalie
2011-07-11 13:03:26 +00:00
parent 9b288cecf5
commit 55007357e1
11 changed files with 239 additions and 144 deletions
+1
View File
@@ -25,6 +25,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
define('PS_ADMIN_DIR', getcwd());
include_once(dirname(__FILE__).'/../config/config.inc.php');
$cookie = new Cookie('psAdmin');
+5 -4
View File
@@ -287,9 +287,7 @@ class AdminCustomers extends AdminTab
}
else
$countBetterCustomers = '-';
$shop = new Shop((int)$customer->id_shop);
echo '
<fieldset style="width:400px;float: left"><div style="float: right"><a href="'.$currentIndex.'&addcustomer&id_customer='.$customer->id.'&token='.$this->token.'"><img src="../img/admin/edit.gif" /></a></div>
<span style="font-weight: bold; font-size: 14px;">'.$customer->firstname.' '.$customer->lastname.'</span>
@@ -299,7 +297,7 @@ class AdminCustomers extends AdminTab
'.$this->l('Registration date:').' '.Tools::displayDate($customer->date_add, (int)($cookie->id_lang), true).'<br />
'.$this->l('Last visit:').' '.($customerStats['last_visit'] ? Tools::displayDate($customerStats['last_visit'], (int)($cookie->id_lang), true) : $this->l('never')).'<br />
'.($countBetterCustomers != '-' ? $this->l('Rank: #').' '.(int)$countBetterCustomers.'<br />' : '')
.(Tools::isMultiShopActivated() ? '<br />'.$this->l('Shop:').' '.$shop->name : '').'
.(Tools::isMultiShopActivated() ? '<br />'.$this->l('Shop:').' '.Shop::getInstance($customer->id_shop)->name : '').'
</fieldset>
<fieldset style="width:300px;float:left;margin-left:50px">
<div style="float: right">
@@ -662,6 +660,7 @@ class AdminCustomers extends AdminTab
</tr>';
echo '</table><div class="clear">&nbsp;</div>';
}
if (sizeof($referrers))
{
echo '<h2>'.$this->l('Referrers').'</h2>
@@ -669,11 +668,13 @@ class AdminCustomers extends AdminTab
<tr>
<th style="width: 200px">'.$this->l('Date').'</th>
<th style="width: 200px">'.$this->l('Name').'</th>
'.((Tools::isMultiShopActivated())? '<th style="width: 200px">'.$this->l('Shop').'</th>' : '').'
</tr>';
foreach ($referrers as $referrer)
echo '<tr>
<td>'.Tools::displayDate($referrer['date_add'], (int)($cookie->id_lang), true).'</td>
<td>'.$referrer['name'].'</td>
'.((Tools::isMultiShopActivated())? '<td>'.$referrer['shop_name'].'</td>' : '').'
</tr>';
echo '</table><div class="clear">&nbsp;</div>';
}
+15 -3
View File
@@ -59,7 +59,12 @@ class AdminReferrers extends AdminTab
$this->edit = true;
$this->delete = true;
$this->_select = 'IF(cache_orders > 0, ROUND(cache_sales/cache_orders, 2), 0) as cart, (cache_visits*click_fee) as fee0, (cache_orders*base_fee) as fee1, (cache_sales*percent_fee/100) as fee2';
$this->_select = 'SUM(rs.cache_visitors) AS cache_visitors, SUM(rs.cache_visits) AS cache_visits, SUM(rs.cache_pages) AS cache_pages,
SUM(rs.cache_registrations) AS cache_registrations, SUM(rs.cache_orders) AS cache_orders, SUM(rs.cache_sales) AS cache_sales,
IF(rs.cache_orders > 0, ROUND(rs.cache_sales/rs.cache_orders, 2), 0) as cart, (rs.cache_visits*click_fee) as fee0,
(rs.cache_orders*base_fee) as fee1, (rs.cache_sales*percent_fee/100) as fee2';
$this->_join = 'LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON a.id_referrer = rs.id_referrer '.Shop::sqlRestriction(false, 'rs');
$this->_group = 'GROUP BY rs.id_referrer';
$this->fieldsDisplay = array(
'id_referrer' => array('title' => $this->l('ID'), 'width' => 25, 'align' => 'center'),
'name' => array('title' => $this->l('Name'), 'width' => 80),
@@ -263,8 +268,14 @@ class AdminReferrers extends AdminTab
<div class="margin-form">
<input type="text" size="8" name="percent_fee" value="'.number_format((float)($this->getFieldValue($obj, 'percent_fee')), 2).'" />
<p>'.$this->l('Percent of the sales.').'</p>
</div>
</fieldset>
</div>';
if (Tools::isMultiShopActivated())
{
echo '<label>'.$this->l('Shop association:').'</label><div class="margin-form">';
$this->displayAssoShop();
echo '</div>';
}
echo '</fieldset>
<br class="clear" />
<fieldset><legend onclick="$(\'#tracking_help\').slideToggle();" style="cursor: pointer;"><img src="../img/admin/help.png" /> '.$this->l('Help').'</legend>
<div id="tracking_help" style="display: none;">
@@ -363,6 +374,7 @@ class AdminReferrers extends AdminTab
</div>
</div>
</fieldset>
<br class="clear" />
</form>';
}
+1 -1
View File
@@ -2053,7 +2053,7 @@ abstract class AdminTabCore
$html = '<table class="table" cellpadding="0" cellspacing="0">
<tr><th>'.$this->l('Shop').'</th><th>'.$this->l('Association').'</th></tr>';
foreach ($shops AS $shop)
$html .= '<tr><td>'.$shop['name'].'</td><td><input type="checkbox" name="checkBoxShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$shop['id_shop'].'" id="checkedBox_'.$shop['id_shop'].'" '.((isset($assos[$shop['id_shop']]) AND in_array($this->id, $assos[$shop['id_shop']])) ? 'checked="checked"' : '').'></td></tr>';
$html .= '<tr><td>'.$shop['name'].'</td><td><input type="checkbox" name="checkBoxShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$shop['id_shop'].'" id="checkedBox_'.$shop['id_shop'].'" '.(((isset($assos[$shop['id_shop']]) AND in_array($this->_object->id, $assos[$shop['id_shop']])) || !$this->_object->id) ? 'checked="checked"' : '').'></td></tr>';
$html .= '</table>';
}
echo $html;
+1 -3
View File
@@ -54,7 +54,7 @@ class ConnectionsSourceCore extends ObjectModel
public function add($autodate = true, $nullValues = false)
{
if($result = parent::add($autodate, $nullValues))
if ($result = parent::add($autodate, $nullValues))
Referrer::cacheNewSource($this->id);
return $result;
}
@@ -108,5 +108,3 @@ class ConnectionsSourceCore extends ObjectModel
ORDER BY cos.date_add DESC');
}
}
+9 -8
View File
@@ -51,15 +51,16 @@ class PageCore extends ObjectModel
*/
public static function getCurrentId()
{
$phpSelf = isset($_SERVER['PHP_SELF']) ? substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)) : '';
$pageTypeID = Page::getPageTypeByName($phpSelf);
$controller = Dispatcher::$controller;
$pageTypeID = Page::getPageTypeByName($controller);
// Some pages must be distinguished in order to record exactly what is being seen
// @todo dispatcher module
$specialArray = array(
'product.php' => 'id_product',
'category.php' => 'id_category',
'order.php' => 'step',
'manufacturer.php' => 'id_manufacturer',
'product' => 'id_product',
'category' => 'id_category',
'order' => 'step',
'manufacturer' => 'id_manufacturer',
);
$where = '';
@@ -67,9 +68,9 @@ class PageCore extends ObjectModel
'id_page_type' => $pageTypeID,
);
if (array_key_exists($phpSelf, $specialArray))
if (array_key_exists($controller, $specialArray))
{
$objectID = Tools::getValue($specialArray[$phpSelf]);
$objectID = Tools::getValue($specialArray[$controller]);
$where = ' AND `id_object` = '.(int)$objectID;
$insertData['id_object'] = $objectID;
}
+164 -116
View File
@@ -27,6 +27,7 @@
class ReferrerCore extends ObjectModel
{
public $id_shop;
public $name;
public $passwd;
@@ -43,26 +44,16 @@ class ReferrerCore extends ObjectModel
public $percent_fee;
public $click_fee;
public $cache_visitors;
public $cache_visits;
public $cache_pages;
public $cache_registrations;
public $cache_orders;
public $cache_sales;
public $cache_reg_rate;
public $cache_order_rate;
public $date_add;
protected $fieldsRequired = array('name');
protected $fieldsSize = array('name' => 64, 'http_referer_regexp' => 64, 'request_uri_regexp' => 64, 'http_referer_like' => 64, 'request_uri_like' => 64, 'passwd' => 32);
protected $fieldsValidate = array(
'id_shop' => 'isUnsignedInt',
'name' => 'isGenericName', 'passwd' => 'isPasswd',
'http_referer_regexp' => 'isCleanHtml', 'request_uri_regexp' => 'isCleanHtml', 'http_referer_like' => 'isCleanHtml', 'request_uri_like' => 'isCleanHtml',
'http_referer_regexp_not' => 'isCleanHtml', 'request_uri_regexp_not' => 'isCleanHtml', 'http_referer_like_not' => 'isCleanHtml', 'request_uri_like_not' => 'isCleanHtml',
'base_fee' => 'isFloat', 'percent_fee' => 'isFloat', 'click_fee' => 'isFloat',
'cache_visitors' => 'isUnsignedInt', 'cache_visits' => 'isUnsignedInt', 'cache_pages' => 'isUnsignedInt', 'cache_registrations' => 'isUnsignedInt',
'cache_orders' => 'isUnsignedInt', 'cache_sales' => 'isOptFloat', 'cache_reg_rate' => 'isOptFloat', 'cache_order_rate' => 'isOptFloat');
'base_fee' => 'isFloat', 'percent_fee' => 'isFloat', 'click_fee' => 'isFloat');
protected $table = 'referrer';
protected $identifier = 'id_referrer';
@@ -79,6 +70,8 @@ class ReferrerCore extends ObjectModel
public function getFields()
{
parent::validateFields();
$fields['id_shop'] = (!$this->id_shop) ? Shop::getCurrentShop(true) : (int)$this->id_shop;
$fields['name'] = pSQL($this->name);
$fields['passwd'] = pSQL($this->passwd);
$fields['http_referer_regexp'] = pSQL($this->http_referer_regexp, true);
@@ -92,14 +85,6 @@ class ReferrerCore extends ObjectModel
$fields['base_fee'] = number_format($this->base_fee, 2, '.', '');
$fields['percent_fee'] = number_format($this->percent_fee, 2, '.', '');
$fields['click_fee'] = number_format($this->click_fee, 2, '.', '');
$fields['cache_visitors'] = (int)($this->cache_visitors);
$fields['cache_visits'] = (int)($this->cache_visits);
$fields['cache_pages'] = (int)($this->cache_pages);
$fields['cache_registrations'] = (int)($this->cache_registrations);
$fields['cache_orders'] = (int)($this->cache_orders);
$fields['cache_sales'] = number_format($this->cache_sales, 2, '.', '');
$fields['cache_reg_rate'] = $this->cache_reg_rate > 1 ? 1 : number_format((float)($this->cache_reg_rate), 4, '.', '');
$fields['cache_order_rate'] = $this->cache_order_rate > 1 ? 1 : number_format((float)($this->cache_order_rate), 4, '.', '');
$fields['date_add'] = pSQL($this->date_add);
return $fields;
}
@@ -108,109 +93,152 @@ class ReferrerCore extends ObjectModel
{
if (!($result = parent::add($autodate, $nullValues)))
return false;
$this->refreshCache(array(array('id_referrer' => $this->id)));
$this->refreshIndex(array(array('id_referrer' => $this->id)));
Referrer::refreshCache(array(array('id_referrer' => $this->id)));
Referrer::refreshIndex(array(array('id_referrer' => $this->id)));
return $result;
}
public static function cacheNewSource($id_connections_source)
{
Db::getInstance()->Execute('
INSERT INTO '._DB_PREFIX_.'referrer_cache (id_referrer, id_connections_source) (
SELECT id_referrer, id_connections_source
FROM '._DB_PREFIX_.'referrer r
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON ('.self::$_join.')
WHERE id_connections_source = '.(int)($id_connections_source).'
)');
if (!$id_connections_source)
return;
$sql = 'INSERT INTO '._DB_PREFIX_.'referrer_cache (id_referrer, id_connections_source) (
SELECT id_referrer, id_connections_source
FROM '._DB_PREFIX_.'referrer r
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON ('.self::$_join.')
WHERE id_connections_source = '.(int)($id_connections_source).'
)';
Db::getInstance()->Execute($sql);
}
/**
* Get list of referrers connections of a customer
*
* @param int $id_customer
*/
public static function getReferrers($id_customer)
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT DISTINCT c.date_add, r.name
FROM '._DB_PREFIX_.'guest g
LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON c.id_connections = cs.id_connections
LEFT JOIN '._DB_PREFIX_.'referrer r ON ('.self::$_join.')
WHERE g.id_customer = '.(int)($id_customer).'
AND r.name IS NOT NULL');
$sql = 'SELECT DISTINCT c.date_add, r.name, s.name AS shop_name
FROM '._DB_PREFIX_.'guest g
LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON c.id_connections = cs.id_connections
LEFT JOIN '._DB_PREFIX_.'referrer r ON ('.self::$_join.')
LEFT JOIN '._DB_PREFIX_.'shop s ON s.id_shop = c.id_shop
WHERE g.id_customer = '.(int)($id_customer).'
AND r.name IS NOT NULL
ORDER BY c.date_add DESC';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
}
public function getStatsVisits($id_product = null, $employee = null)
/**
* Get some statistics on visitors connection for current referrer
*
* @param int $id_product
* @param int $employee
* @param int $shopID Since 1.5.0
*/
public function getStatsVisits($id_product = null, $employee = null, $shopID = null)
{
list($join, $where) = array('','');
if ((int)($id_product))
$join = $where = '';
if ($id_product)
{
$join = 'LEFT JOIN `'._DB_PREFIX_.'page` p ON cp.`id_page` = p.`id_page`
LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`';
$where = 'AND pt.`name` = \'product.php\'
$where = ' AND pt.`name` = \'product\'
AND p.`id_object` = '.(int)($id_product);
}
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(DISTINCT cs.id_connections_source) AS visits,
COUNT(DISTINCT cs.id_connections) as visitors,
COUNT(DISTINCT c.id_guest) as uniqs,
COUNT(DISTINCT cp.time_start) as pages
FROM '._DB_PREFIX_.'referrer_cache rc
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON rc.id_connections_source = cs.id_connections_source
LEFT JOIN '._DB_PREFIX_.'connections c ON cs.id_connections = c.id_connections
LEFT JOIN '._DB_PREFIX_.'connections_page cp ON cp.id_connections = c.id_connections
'.$join.'
WHERE cs.date_add BETWEEN '.ModuleGraph::getDateBetween($employee).'
AND rc.id_referrer = '.(int)($this->id).'
'.$where);
$sql = 'SELECT COUNT(DISTINCT cs.id_connections_source) AS visits,
COUNT(DISTINCT cs.id_connections) as visitors,
COUNT(DISTINCT c.id_guest) as uniqs,
COUNT(DISTINCT cp.time_start) as pages
FROM '._DB_PREFIX_.'referrer_cache rc
LEFT JOIN '._DB_PREFIX_.'referrer r ON rc.id_referrer = r.id_referrer
LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON r.id_referrer = rs.id_referrer
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON rc.id_connections_source = cs.id_connections_source
LEFT JOIN '._DB_PREFIX_.'connections c ON cs.id_connections = c.id_connections
LEFT JOIN '._DB_PREFIX_.'connections_page cp ON cp.id_connections = c.id_connections
'.$join.'
WHERE cs.date_add BETWEEN '.ModuleGraph::getDateBetween($employee).'
'.Shop::sqlRestriction(false, 'rs', $shopID).'
'.Shop::sqlRestriction(false, 'c', $shopID).'
AND rc.id_referrer = '.(int)$this->id
.$where;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
}
public function getRegistrations($id_product = null, $employee = null)
/**
* Get some statistics on customers registrations for current referrer
*
* @param int $id_product
* @param int $employee
* @param int $shopID Since 1.5.0
*/
public function getRegistrations($id_product = null, $employee = null, $shopID = null)
{
list($join, $where) = array('','');
if ((int)($id_product))
$join = $where = '';
if ($id_product)
{
$join = 'LEFT JOIN '._DB_PREFIX_.'connections_page cp ON cp.id_connections = c.id_connections
LEFT JOIN `'._DB_PREFIX_.'page` p ON cp.`id_page` = p.`id_page`
LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`';
$where = 'AND pt.`name` = \'product.php\'
$where = ' AND pt.`name` = \'product\'
AND p.`id_object` = '.(int)($id_product);
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(DISTINCT cu.id_customer) AS registrations
FROM '._DB_PREFIX_.'referrer_cache rc
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON rc.id_connections_source = cs.id_connections_source
LEFT JOIN '._DB_PREFIX_.'connections c ON cs.id_connections = c.id_connections
LEFT JOIN '._DB_PREFIX_.'guest g ON g.id_guest = c.id_guest
LEFT JOIN '._DB_PREFIX_.'customer cu ON cu.id_customer = g.id_customer
'.$join.'
WHERE cu.date_add BETWEEN '.ModuleGraph::getDateBetween($employee).'
AND cu.date_add > cs.date_add
AND rc.id_referrer = '.(int)($this->id).'
'.$where);
return $result['registrations'];
$sql = 'SELECT COUNT(DISTINCT cu.id_customer) AS registrations
FROM '._DB_PREFIX_.'referrer_cache rc
LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON rc.id_referrer = rs.id_referrer
LEFT JOIN '._DB_PREFIX_.'connections_source cs ON rc.id_connections_source = cs.id_connections_source
LEFT JOIN '._DB_PREFIX_.'connections c ON cs.id_connections = c.id_connections
LEFT JOIN '._DB_PREFIX_.'guest g ON g.id_guest = c.id_guest
LEFT JOIN '._DB_PREFIX_.'customer cu ON cu.id_customer = g.id_customer
'.$join.'
WHERE cu.date_add BETWEEN '.ModuleGraph::getDateBetween($employee).'
'.Shop::sqlRestriction(false, 'rs', $shopID).'
'.Shop::sqlRestriction(false, 'c', $shopID).'
'.Shop::sqlRestriction(true, 'cu', $shopID).'
AND cu.date_add > cs.date_add
AND rc.id_referrer = '.(int)($this->id)
.$where;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
return (int)$result['registrations'];
}
public function getStatsSales($id_product = null, $employee = null)
/**
* Get some statistics on orders for current referrer
*
* @param int $id_product
* @param int $employee
* @param int $shopID Since 1.5.0
*/
public function getStatsSales($id_product = null, $employee = null, $shopID = null)
{
list($join, $where) = array('','');
if ((int)($id_product))
$join = $where = '';
if ($id_product)
{
$join = 'LEFT JOIN '._DB_PREFIX_.'order_detail od ON oo.id_order = od.id_order';
$where = 'AND od.product_id = '.(int)($id_product);
$where = ' AND od.product_id = '.(int)($id_product);
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT oo.id_order
FROM '._DB_PREFIX_.'referrer_cache rc
INNER JOIN '._DB_PREFIX_.'connections_source cs ON rc.id_connections_source = cs.id_connections_source
INNER JOIN '._DB_PREFIX_.'connections c ON cs.id_connections = c.id_connections
INNER JOIN '._DB_PREFIX_.'guest g ON g.id_guest = c.id_guest
LEFT JOIN '._DB_PREFIX_.'orders oo ON oo.id_customer = g.id_customer
'.$join.'
WHERE oo.invoice_date BETWEEN '.ModuleGraph::getDateBetween($employee).'
AND oo.date_add > cs.date_add
AND rc.id_referrer = '.(int)($this->id).'
AND oo.valid = 1
'.$where);
$sql = 'SELECT oo.id_order
FROM '._DB_PREFIX_.'referrer_cache rc
LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON rc.id_referrer = rs.id_referrer
INNER JOIN '._DB_PREFIX_.'connections_source cs ON rc.id_connections_source = cs.id_connections_source
INNER JOIN '._DB_PREFIX_.'connections c ON cs.id_connections = c.id_connections
INNER JOIN '._DB_PREFIX_.'guest g ON g.id_guest = c.id_guest
LEFT JOIN '._DB_PREFIX_.'orders oo ON oo.id_customer = g.id_customer
'.$join.'
WHERE oo.invoice_date BETWEEN '.ModuleGraph::getDateBetween($employee).'
'.Shop::sqlRestriction(false, 'rs', $shopID).'
'.Shop::sqlRestriction(false, 'c', $shopID).'
'.Shop::sqlRestriction(true, 'oo', $shopID).'
AND oo.date_add > cs.date_add
AND rc.id_referrer = '.(int)($this->id).'
AND oo.valid = 1'
.$where;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
$implode = array();
foreach ($result as $row)
@@ -218,41 +246,63 @@ class ReferrerCore extends ObjectModel
$implode[] = (int)$row['id_order'];
if ($implode)
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(o.id_order) AS orders, SUM(o.total_paid_real / o.conversion_rate) AS sales
FROM '._DB_PREFIX_.'orders o
WHERE o.id_order IN ('.implode($implode, ',').')
AND o.valid = 1');
{
$sql = 'SELECT COUNT(id_order) AS orders, SUM(total_paid_real / conversion_rate) AS sales
FROM '._DB_PREFIX_.'orders
WHERE id_order IN ('.implode($implode, ',').')
'.Shop::sqlRestriction(true, '', $shopID).'
AND valid = 1';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
}
else
return array('orders' => 0, 'sales' => 0);
}
/**
* Refresh cache data of referrer statistics in referrer_shop table
*
* @param array $referrers
* @param int $employee
*/
public static function refreshCache($referrers = null, $employee = null)
{
if (!$referrers OR !is_array($referrers))
$referrers = Db::getInstance()->ExecuteS('SELECT id_referrer FROM '._DB_PREFIX_.'referrer');
foreach ($referrers as $row)
{
$referrer = new Referrer((int)($row['id_referrer']));
$statsVisits = $referrer->getStatsVisits(null, $employee);
$referrer->cache_visitors = $statsVisits['uniqs'];
$referrer->cache_visits = $statsVisits['visits'];
$referrer->cache_pages = $statsVisits['pages'];
$registrations = $referrer->getRegistrations(null, $employee);
$referrer->cache_registrations = (int)($registrations);
$statsSales = $referrer->getStatsSales(null, $employee);
$referrer->cache_orders = (int)($statsSales['orders']);
$referrer->cache_sales = number_format($statsSales['sales'], 2, '.', '');
$referrer->cache_reg_rate = $statsVisits['uniqs'] ? (int)($registrations) / $statsVisits['uniqs'] : 0;
$referrer->cache_order_rate = $statsVisits['uniqs'] ? (int)($statsSales['orders']) / $statsVisits['uniqs'] : 0;
if (!$referrer->update())
Tools::dieObject(mysql_error());
Configuration::updateValue('PS_REFERRERS_CACHE_LIKE', ModuleGraph::getDateBetween($employee));
Configuration::updateValue('PS_REFERRERS_CACHE_DATE', date('Y-m-d H:i:s'));
$referrer = new Referrer($row['id_referrer']);
foreach (Shop::getShops(true, null, true) as $shopID)
{
if (!$referrer->isAssociatedToShop($shopID))
continue;
$statsVisits = $referrer->getStatsVisits(null, $employee, $shopID);
$registrations = $referrer->getRegistrations(null, $employee, $shopID);
$statsSales = $referrer->getStatsSales(null, $employee, $shopID);
Db::getInstance()->autoExecute(_DB_PREFIX_.'referrer_shop', array(
'cache_visitors' => $statsVisits['uniqs'],
'cache_visits' => $statsVisits['visits'],
'cache_pages' => $statsVisits['pages'],
'cache_registrations' =>$registrations,
'cache_orders' => $statsSales['orders'],
'cache_sales' => number_format($statsSales['sales'], 2, '.', ''),
'cache_reg_rate' => $statsVisits['uniqs'] ? $registrations / $statsVisits['uniqs'] : 0,
'cache_order_rate' => $statsVisits['uniqs'] ? $statsSales['orders'] / $statsVisits['uniqs'] : 0,
), 'UPDATE', 'id_referrer = '.$referrer->id.' AND id_shop = '.$shopID);
}
}
Configuration::updateValue('PS_REFERRERS_CACHE_LIKE', ModuleGraph::getDateBetween($employee));
Configuration::updateValue('PS_REFERRERS_CACHE_DATE', date('Y-m-d H:i:s'));
return true;
}
/**
* Cache liaison between connections_source data and referrers data
*
* @param array $referrers
*/
public static function refreshIndex($referrers = null)
{
if (!$referrers OR !is_array($referrers))
@@ -310,6 +360,4 @@ class ReferrerCore extends ObjectModel
$jsonArray[] = '"percent_fee":"'.Tools::displayPrice($statsSales['sales'] * $referrer->percent_fee / 100, $currency).'"';
die ('[{'.implode(',', $jsonArray).'}]');
}
}
}
+12
View File
@@ -71,6 +71,7 @@ class ShopCore extends ObjectModel
'stock' => array('type' => 'fk_shop', 'primary' => 'id_stock'),
'product' => array('type' => 'shop'),
'product_lang' => array('type' => 'fk_shop'),
'referrer' => array('type' => 'shop'),
'store' => array('type' => 'shop'),
'webservice_account' => array('type' => 'shop'),
);
@@ -103,6 +104,17 @@ class ShopCore extends ObjectModel
return $fields;
}
/**
* Get an instance of a shop
*
* @param int $id shop ID
* @return Shop
*/
public static function getInstance($id)
{
return new Shop($id);
}
public static function getAssoTables()
{
return self::$assoTables;
+1 -1
View File
@@ -915,7 +915,7 @@ table.permissions td {
}
#header_shoplist select.shopList{
background-image: url("../../../img/t/AdminShop.gif");
background-image: url("../img/t/AdminShop.gif");
background-position: 1px 50%;
background-repeat: no-repeat;
padding: 1px 1px 1px 14px;
+14 -8
View File
@@ -1313,14 +1313,6 @@ CREATE TABLE `PREFIX_referrer` (
`base_fee` decimal(5,2) NOT NULL default '0.00',
`percent_fee` decimal(5,2) NOT NULL default '0.00',
`click_fee` decimal(5,2) NOT NULL default '0.00',
`cache_visitors` int(11) default NULL,
`cache_visits` int(11) default NULL,
`cache_pages` int(11) default NULL,
`cache_registrations` int(11) default NULL,
`cache_orders` int(11) default NULL,
`cache_sales` decimal(17,2) default NULL,
`cache_reg_rate` decimal(5,4) default NULL,
`cache_order_rate` decimal(5,4) default NULL,
`date_add` datetime NOT NULL,
PRIMARY KEY (`id_referrer`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
@@ -1331,6 +1323,20 @@ CREATE TABLE `PREFIX_referrer_cache` (
PRIMARY KEY (`id_connections_source`, `id_referrer`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_referrer_shop` (
`id_referrer` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL default '1',
`cache_visitors` int(11) default NULL,
`cache_visits` int(11) default NULL,
`cache_pages` int(11) default NULL,
`cache_registrations` int(11) default NULL,
`cache_orders` int(11) default NULL,
`cache_sales` decimal(17,2) default NULL,
`cache_reg_rate` decimal(5,4) default NULL,
`cache_order_rate` decimal(5,4) default NULL,
PRIMARY KEY (`id_referrer`, `id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_scene` (
`id_scene` int(10) unsigned NOT NULL auto_increment,
`active` tinyint(1) NOT NULL default '1',
+16
View File
@@ -284,4 +284,20 @@ INSERT INTO PREFIX_stock (id_product, id_product_attribute, id_group_shop, id_sh
UPDATE PREFIX_stock_mvt sm SET sm.id_stock = (SELECT s.id_stock FROM PREFIX_stock s WHERE s.id_product = sm.id_product AND s.id_product_attribute = sm.id_product_attribute);
ALTER TABLE PREFIX_stock_mvt DROP id_product, DROP id_product_attribute;
CREATE TABLE `PREFIX_referrer_shop` (
`id_referrer` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL default '1',
`cache_visitors` int(11) default NULL,
`cache_visits` int(11) default NULL,
`cache_pages` int(11) default NULL,
`cache_registrations` int(11) default NULL,
`cache_orders` int(11) default NULL,
`cache_sales` decimal(17,2) default NULL,
`cache_reg_rate` decimal(5,4) default NULL,
`cache_order_rate` decimal(5,4) default NULL,
PRIMARY KEY (`id_referrer`, `id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
INSERT INTO `PREFIX_referrer_shop` (`id_referrer`, `id_shop`) SELECT `id_referrer`, 1 FROM `PREFIX_referrer`;
ALTER TABLE `PREFIX_referrer` DROP `cache_visitors`, DROP `cache_visits`, DROP `cache_pages`, DROP `cache_registrations`, DROP `cache_orders`, DROP `cache_sales`, DROP `cache_reg_rate`, DROP `cache_order_rate`;
/* PHP:create_multistore(); */