public static function getAjaxProduct($id_referrer, $id_product, $employee = null) { $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT')); $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); $referrer = new Referrer($id_referrer); $statsVisits = $referrer->getStatsVisits($id_product, $employee); $registrations = $referrer->getRegistrations($id_product, $employee); $statsSales = $referrer->getStatsSales($id_product, $employee); // If it's a product and it has no visits nor orders if ((int) $id_product and !$statsVisits['visits'] and !$statsSales['orders']) { exit; } $jsonArray = array(); $jsonArray[] = '"id_product":"' . (int) $product->id . '"'; $jsonArray[] = '"product_name":"' . addslashes($product->name) . '"'; $jsonArray[] = '"uniqs":"' . (int) $statsVisits['uniqs'] . '"'; $jsonArray[] = '"visitors":"' . (int) $statsVisits['visitors'] . '"'; $jsonArray[] = '"visits":"' . (int) $statsVisits['visits'] . '"'; $jsonArray[] = '"pages":"' . (int) $statsVisits['pages'] . '"'; $jsonArray[] = '"registrations":"' . (int) $registrations . '"'; $jsonArray[] = '"orders":"' . (int) $statsSales['orders'] . '"'; $jsonArray[] = '"sales":"' . Tools::displayPrice($statsSales['sales'], $currency) . '"'; $jsonArray[] = '"cart":"' . Tools::displayPrice((int) $statsSales['orders'] ? $statsSales['sales'] / (int) $statsSales['orders'] : 0, $currency) . '"'; $jsonArray[] = '"reg_rate":"' . number_format((int) $statsVisits['uniqs'] ? (int) $registrations / (int) $statsVisits['uniqs'] : 0, 4, '.', '') . '"'; $jsonArray[] = '"order_rate":"' . number_format((int) $statsVisits['uniqs'] ? (int) $statsSales['orders'] / (int) $statsVisits['uniqs'] : 0, 4, '.', '') . '"'; $jsonArray[] = '"click_fee":"' . Tools::displayPrice((int) $statsVisits['visits'] * $referrer->click_fee, $currency) . '"'; $jsonArray[] = '"base_fee":"' . Tools::displayPrice($statsSales['orders'] * $referrer->base_fee, $currency) . '"'; $jsonArray[] = '"percent_fee":"' . Tools::displayPrice($statsSales['sales'] * $referrer->percent_fee / 100, $currency) . '"'; die('[{' . implode(',', $jsonArray) . '}]'); }
public static function getAjaxProduct($id_referrer, $id_product, $employee = null) { $context = Context::getContext(); $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT')); $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); $referrer = new Referrer($id_referrer); $stats_visits = $referrer->getStatsVisits($id_product, $employee); $registrations = $referrer->getRegistrations($id_product, $employee); $stats_sales = $referrer->getStatsSales($id_product, $employee); // If it's a product and it has no visits nor orders if ((int) $id_product && !$stats_visits['visits'] && !$stats_sales['orders']) { exit; } $json_array = array('id_product' => (int) $product->id, 'product_name' => addslashes($product->name), 'uniqs' => (int) $stats_visits['uniqs'], 'visitors' => (int) $stats_visits['visitors'], 'visits' => (int) $stats_visits['visits'], 'pages' => (int) $stats_visits['pages'], 'registrations' => (int) $registrations, 'orders' => (int) $stats_sales['orders'], 'sales' => Tools::displayPrice($stats_sales['sales'], $currency), 'cart' => Tools::displayPrice((int) $stats_sales['orders'] ? $stats_sales['sales'] / (int) $stats_sales['orders'] : 0, $currency), 'reg_rate' => number_format((int) $stats_visits['uniqs'] ? (int) $registrations / (int) $stats_visits['uniqs'] : 0, 4, '.', ''), 'order_rate' => number_format((int) $stats_visits['uniqs'] ? (int) $stats_sales['orders'] / (int) $stats_visits['uniqs'] : 0, 4, '.', ''), 'click_fee' => Tools::displayPrice((int) $stats_visits['visits'] * $referrer->click_fee, $currency), 'base_fee' => Tools::displayPrice($stats_sales['orders'] * $referrer->base_fee, $currency), 'percent_fee' => Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency)); die('[' . Tools::jsonEncode($json_array) . ']'); }
public static function getAjaxProduct($id_referrer, $id_product, $employee = null) { $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT')); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $referrer = new Referrer($id_referrer); $statsVisits = $referrer->getStatsVisits($id_product, $employee); $registrations = $referrer->getRegistrations($id_product, $employee); $statsSales = $referrer->getStatsSales($id_product, $employee); // If it's a product and it has no visits nor orders if (intval($id_product) and !$statsVisits['visits'] and !$statsSales['orders']) { exit; } $jsonArray = array(); $jsonArray[] = 'id_product:\'' . intval($product->id) . '\''; $jsonArray[] = 'product_name:\'' . addslashes($product->name) . '\''; $jsonArray[] = 'uniqs:\'' . intval($statsVisits['uniqs']) . '\''; $jsonArray[] = 'visitors:\'' . intval($statsVisits['visitors']) . '\''; $jsonArray[] = 'visits:\'' . intval($statsVisits['visits']) . '\''; $jsonArray[] = 'pages:\'' . intval($statsVisits['pages']) . '\''; $jsonArray[] = 'registrations:\'' . intval($registrations) . '\''; $jsonArray[] = 'orders:\'' . intval($statsSales['orders']) . '\''; $jsonArray[] = 'sales:\'' . Tools::displayPrice($statsSales['sales'], $currency) . '\''; $jsonArray[] = 'cart:\'' . Tools::displayPrice(intval($statsSales['orders']) ? $statsSales['sales'] / intval($statsSales['orders']) : 0, $currency) . '\''; $jsonArray[] = 'reg_rate:\'' . number_format(intval($statsVisits['uniqs']) ? intval($registrations) / intval($statsVisits['uniqs']) : 0, 4, '.', '') . '\''; $jsonArray[] = 'order_rate:\'' . number_format(intval($statsVisits['uniqs']) ? intval($statsSales['orders']) / intval($statsVisits['uniqs']) : 0, 4, '.', '') . '\''; $jsonArray[] = 'click_fee:\'' . Tools::displayPrice(intval($statsVisits['visits']) * $referrer->click_fee, $currency) . '\''; $jsonArray[] = 'base_fee:\'' . Tools::displayPrice($statsSales['orders'] * $referrer->base_fee, $currency) . '\''; $jsonArray[] = 'percent_fee:\'' . Tools::displayPrice($statsSales['sales'] * $referrer->percent_fee / 100, $currency) . '\''; die('[{' . implode(',', $jsonArray) . '}]'); }