Exemple #1
0
    private function getOrigins($dateBetween)
    {
        $directLink = $this->l('Direct link');
        $sql = 'SELECT http_referer
				FROM ' . _DB_PREFIX_ . 'connections
				WHERE 1
					' . Shop::addSqlRestriction() . '
					AND date_add BETWEEN ' . $dateBetween;
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
        $websites = array($directLink => 0);
        while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result)) {
            if (!isset($row['http_referer']) || empty($row['http_referer'])) {
                ++$websites[$directLink];
            } else {
                $website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST));
                if (!isset($websites[$website])) {
                    $websites[$website] = 1;
                } else {
                    ++$websites[$website];
                }
            }
        }
        arsort($websites);
        return $websites;
    }
    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'group';
        $this->className = 'Group';
        $this->list_id = 'group';
        $this->lang = true;
        $this->addRowAction('edit');
        $this->addRowAction('view');
        $this->addRowAction('delete');
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
        $groups_to_keep = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP'));
        $this->fields_list = array('id_group' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'name' => array('title' => $this->l('Group name'), 'filter_key' => 'b!name'), 'reduction' => array('title' => $this->l('Discount (%)'), 'align' => 'right', 'type' => 'percent'), 'nb' => array('title' => $this->l('Members'), 'align' => 'center', 'havingFilter' => true), 'show_prices' => array('title' => $this->l('Show prices'), 'align' => 'center', 'type' => 'bool', 'callback' => 'printShowPricesIcon', 'orderby' => false), 'date_add' => array('title' => $this->l('Creation date'), 'type' => 'date', 'align' => 'right'));
        $this->addRowActionSkipList('delete', $groups_to_keep);
        parent::__construct();
        $this->_select .= '(SELECT COUNT(jcg.`id_customer`)
		FROM `' . _DB_PREFIX_ . 'customer_group` jcg
		LEFT JOIN `' . _DB_PREFIX_ . 'customer` jc ON (jc.`id_customer` = jcg.`id_customer`)
		WHERE jc.`deleted` != 1
		' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
		AND jcg.`id_group` = a.`id_group`) AS nb';
        $groups = Group::getGroups(Context::getContext()->language->id, true);
        if (Shop::isFeatureActive()) {
            $this->fields_options = array('general' => array('title' => $this->l('Default groups options'), 'fields' => array('PS_UNIDENTIFIED_GROUP' => array('title' => $this->l('Visitors group'), 'desc' => $this->l('The group defined for your un-identified visitors.'), 'cast' => 'intval', 'type' => 'select', 'list' => $groups, 'identifier' => 'id_group'), 'PS_GUEST_GROUP' => array('title' => $this->l('Guests group'), 'desc' => $this->l('The group defined for your identified guest customers (used in guest checkout).'), 'cast' => 'intval', 'type' => 'select', 'list' => $groups, 'identifier' => 'id_group'), 'PS_CUSTOMER_GROUP' => array('title' => $this->l('Customers group'), 'desc' => $this->l('The group defined for your identified registered customers.'), 'cast' => 'intval', 'type' => 'select', 'list' => $groups, 'identifier' => 'id_group')), 'submit' => array('title' => $this->l('Save'))));
        }
    }
    public function __construct()
    {
        $this->bootstrap = true;
        $this->required_database = true;
        $this->required_fields = array('company', 'address2', 'postcode', 'other', 'phone', 'phone_mobile', 'vat_number', 'dni');
        $this->table = 'address';
        $this->className = 'Address';
        $this->lang = false;
        $this->addressType = 'customer';
        $this->explicitSelect = true;
        $this->context = Context::getContext();
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
        $this->allow_export = true;
        if (!Tools::getValue('realedit')) {
            $this->deleted = true;
        }
        $countries = Country::getCountries($this->context->language->id);
        foreach ($countries as $country) {
            $this->countries_array[$country['id_country']] = $country['name'];
        }
        $this->fields_list = array('id_address' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'firstname' => array('title' => $this->l('First Name'), 'filter_key' => 'a!firstname'), 'lastname' => array('title' => $this->l('Last Name'), 'filter_key' => 'a!lastname'), 'address1' => array('title' => $this->l('Address')), 'postcode' => array('title' => $this->l('Zip/Postal Code'), 'align' => 'right'), 'city' => array('title' => $this->l('City')), 'country' => array('title' => $this->l('Country'), 'type' => 'select', 'list' => $this->countries_array, 'filter_key' => 'cl!id_country'));
        parent::__construct();
        $this->_select = 'cl.`name` as country';
        $this->_join = '
			LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = ' . (int) $this->context->language->id . ')
			LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON a.id_customer = c.id_customer
		';
        $this->_where = 'AND a.id_customer != 0 ' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'c');
    }
    public function getData()
    {
        $this->_totalCount = $this->getTotalCount();
        $this->query = 'SELECT m.name, SUM(od.product_quantity) as quantity, ROUND(SUM(od.product_quantity * od.product_price) / c.conversion_rate, 2) as sales
				FROM ' . _DB_PREFIX_ . 'order_detail od
				LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = od.product_id)
				LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.id_order = od.id_order)
				LEFT JOIN ' . _DB_PREFIX_ . 'currency c ON (c.id_currency = o.id_currency)
				LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer)
				WHERE o.invoice_date BETWEEN ' . $this->getDate() . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
					AND o.valid = 1
					AND m.id_manufacturer IS NOT NULL
				GROUP BY p.id_manufacturer';
        if (Validate::IsName($this->_sort)) {
            $this->query .= ' ORDER BY `' . bqSQL($this->_sort) . '`';
            if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) {
                $this->query .= ' ' . $this->_direction;
            }
        }
        if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) {
            $this->query .= ' LIMIT ' . (int) $this->_start . ', ' . (int) $this->_limit;
        }
        $this->_values = Db::getInstance()->executeS($this->query);
    }
    public function getData()
    {
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $this->query = 'SELECT SQL_CALC_FOUND_ROWS cr.code, ocr.name, COUNT(ocr.id_cart_rule) as total, ROUND(SUM(o.total_paid_real) / o.conversion_rate,2) as ca
				FROM ' . _DB_PREFIX_ . 'order_cart_rule ocr
				LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_order = ocr.id_order
				LEFT JOIN ' . _DB_PREFIX_ . 'cart_rule cr ON cr.id_cart_rule = ocr.id_cart_rule
				WHERE o.valid = 1
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
					AND o.invoice_date BETWEEN ' . $this->getDate() . '
				GROUP BY ocr.id_cart_rule';
        if (Validate::IsName($this->_sort)) {
            $this->query .= ' ORDER BY `' . bqSQL($this->_sort) . '`';
            if (isset($this->_direction) && (Tools::strtoupper($this->_direction) == 'ASC' || Tools::strtoupper($this->_direction) == 'DESC')) {
                $this->query .= ' ' . pSQL($this->_direction);
            }
        }
        if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) {
            $this->query .= ' LIMIT ' . (int) $this->_start . ', ' . (int) $this->_limit;
        }
        $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query);
        foreach ($values as &$value) {
            $value['ca'] = Tools::displayPrice($value['ca'], $currency);
        }
        $this->_values = $values;
        $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
    }
Exemple #6
0
    private function ModuleHookExec($moduleName, $hook_name)
    {
        $output = '';
        $moduleInstance = Module::getInstanceByName($moduleName);
        if (Validate::isLoadedObject($moduleInstance) && $moduleInstance->id) {
            $altern = 0;
            $id_hook = Hook::getIdByName($hook_name);
            $retro_hook_name = Hook::getRetroHookName($hook_name);
            $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
            if ($disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($moduleInstance->name, self::$native_module)) {
                return '';
            }
            //check disable module
            $device = (int) $this->context->getDevice();
            if (Db::getInstance()->getValue('
			SELECT COUNT(`id_module`) FROM ' . _DB_PREFIX_ . 'module_shop
			WHERE enable_device & ' . (int) $device . ' AND id_module=' . (int) $moduleInstance->id . Shop::addSqlRestriction()) == 0) {
                return '';
            }
            // Check permissions
            $exceptions = $moduleInstance->getExceptions($id_hook);
            $controller = Dispatcher::getInstance()->getController();
            $controller_obj = Context::getContext()->controller;
            //check if current controller is a module controller
            if (isset($controller_obj->module) && Validate::isLoadedObject($controller_obj->module)) {
                $controller = 'module-' . $controller_obj->module->name . '-' . $controller;
            }
            if (in_array($controller, $exceptions)) {
                return '';
            }
            //retro compat of controller names
            $matching_name = array('authentication' => 'auth', 'productscomparison' => 'compare');
            if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) {
                return '';
            }
            if (Validate::isLoadedObject($this->context->employee) && !$moduleInstance->getPermission('view', $this->context->employee)) {
                return '';
            }
            if (!isset($hook_args['cookie']) or !$hook_args['cookie']) {
                $hook_args['cookie'] = $this->context->cookie;
            }
            if (!isset($hook_args['cart']) or !$hook_args['cart']) {
                $hook_args['cart'] = $this->context->cart;
            }
            $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
            $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
            if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) {
                $hook_args['altern'] = ++$altern;
                // Call hook method
                if ($hook_callable) {
                    $display = $moduleInstance->{'hook' . $hook_name}($hook_args);
                } elseif ($hook_retro_callable) {
                    $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args);
                }
                $output .= $display;
            }
        }
        return $output;
    }
Exemple #7
0
    public static function getCustomers()
    {
        $sql = 'SELECT `id_customer`, `email`, `firstname`, `lastname`, `fax`, `details_website`
				FROM `' . _DB_PREFIX_ . 'customer`
				WHERE 1 ' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
				ORDER BY `id_customer` ASC';
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
    }
    public function renderList()
    {
        $this->_select = 'cl.`name` as country';
        $this->_join = '
			LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = ' . (int) $this->context->language->id . ')
			LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON a.id_customer = c.id_customer
		';
        $this->_where = 'AND a.id_customer != 0 ' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'c');
        return parent::renderList();
    }
    public function __construct()
    {
        $this->bootstrap = true;
        $this->required_database = true;
        $this->required_fields = array('newsletter', 'optin');
        $this->table = 'customer';
        $this->className = 'Customer';
        $this->lang = false;
        $this->deleted = true;
        $this->explicitSelect = true;
        $this->allow_export = true;
        $this->addRowAction('edit');
        $this->addRowAction('view');
        $this->addRowAction('delete');
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
        $this->context = Context::getContext();
        $this->default_form_language = $this->context->language->id;
        $titles_array = array();
        $genders = Gender::getGenders($this->context->language->id);
        foreach ($genders as $gender) {
            /** @var Gender $gender */
            $titles_array[$gender->id_gender] = $gender->name;
        }
        $this->_select = '
		a.date_add, gl.name as title, (
			SELECT SUM(total_paid_real / conversion_rate)
			FROM ' . _DB_PREFIX_ . 'orders o
			WHERE o.id_customer = a.id_customer
			' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
			AND o.valid = 1
		) as total_spent, (
			SELECT c.date_add FROM ' . _DB_PREFIX_ . 'guest g
			LEFT JOIN ' . _DB_PREFIX_ . 'connections c ON c.id_guest = g.id_guest
			WHERE g.id_customer = a.id_customer
			ORDER BY c.date_add DESC
			LIMIT 1
		) as connect';
        $this->_join = 'LEFT JOIN ' . _DB_PREFIX_ . 'gender_lang gl ON (a.id_gender = gl.id_gender AND gl.id_lang = ' . (int) $this->context->language->id . ')';
        $this->_use_found_rows = false;
        $this->fields_list = array('id_customer' => array('title' => $this->l('ID'), 'align' => 'text-center', 'class' => 'fixed-width-xs'), 'title' => array('title' => $this->l('Social title'), 'filter_key' => 'a!id_gender', 'type' => 'select', 'list' => $titles_array, 'filter_type' => 'int', 'order_key' => 'gl!name'), 'firstname' => array('title' => $this->l('First name')), 'lastname' => array('title' => $this->l('Last name')), 'email' => array('title' => $this->l('Email address')));
        if (Configuration::get('PS_B2B_ENABLE')) {
            $this->fields_list = array_merge($this->fields_list, array('company' => array('title' => $this->l('Company'))));
        }
        $this->fields_list = array_merge($this->fields_list, array('total_spent' => array('title' => $this->l('Sales'), 'type' => 'price', 'search' => false, 'havingFilter' => true, 'align' => 'text-right', 'badge_success' => true), 'active' => array('title' => $this->l('Enabled'), 'align' => 'text-center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'a!active'), 'newsletter' => array('title' => $this->l('Newsletter'), 'align' => 'text-center', 'type' => 'bool', 'callback' => 'printNewsIcon', 'orderby' => false), 'optin' => array('title' => $this->l('Opt-in'), 'align' => 'text-center', 'type' => 'bool', 'callback' => 'printOptinIcon', 'orderby' => false), 'date_add' => array('title' => $this->l('Registration'), 'type' => 'date', 'align' => 'text-right'), 'connect' => array('title' => $this->l('Last visit'), 'type' => 'datetime', 'search' => false, 'havingFilter' => true)));
        $this->shopLinkType = 'shop';
        $this->shopShareDatas = Shop::SHARE_CUSTOMER;
        parent::__construct();
        // Check if we can add a customer
        if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) {
            $this->can_add_customer = false;
        }
        self::$meaning_status = array('open' => $this->l('Open'), 'closed' => $this->l('Closed'), 'pending1' => $this->l('Pending 1'), 'pending2' => $this->l('Pending 2'));
    }
 public function __construct()
 {
     $this->table = 'order_slip';
     $this->className = 'OrderSlip';
     $this->_select = ' o.`id_shop`';
     $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.`id_order` = a.`id_order`)';
     $this->_group = ' GROUP BY o.`id_order`';
     $this->fields_list = array('id_order_slip' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'id_order' => array('title' => $this->l('ID Order'), 'align' => 'left'), 'date_add' => array('title' => $this->l('Date issued'), 'width' => 150, 'type' => 'date', 'align' => 'right'), 'id_pdf' => array('title' => $this->l('PDF'), 'width' => 35, 'align' => 'center', 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false, 'remove_onclick' => true));
     $this->_select = 'a.id_order_slip AS id_pdf';
     $this->optionTitle = $this->l('Slip');
     $this->fields_options = array('general' => array('title' => $this->l('Credit slip options'), 'fields' => array('PS_CREDIT_SLIP_PREFIX' => array('title' => $this->l('Credit slip prefix:'), 'desc' => $this->l('Prefix used for credit slips'), 'size' => 6, 'type' => 'textLang')), 'submit' => array()));
     parent::__construct();
     $this->_where = Shop::addSqlRestriction(false, 'o');
 }
Exemple #11
0
    public function getData()
    {
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $date_between = $this->getDate();
        $array_date_between = explode(' AND ', $date_between);
        $this->query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name,
				ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold,
				IFNULL(stock.quantity, 0) as quantity,
				IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold,
				ROUND(IFNULL(IFNULL(SUM(od.product_quantity), 0) / (1 + LEAST(TO_DAYS(' . $array_date_between[1] . '), TO_DAYS(NOW())) - GREATEST(TO_DAYS(' . $array_date_between[0] . '), TO_DAYS(product_shop.date_add))), 0), 2) as averageQuantitySold,
				ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold,
				(
					SELECT IFNULL(SUM(pv.counter), 0)
					FROM ' . _DB_PREFIX_ . 'page pa
					LEFT JOIN ' . _DB_PREFIX_ . 'page_viewed pv ON pa.id_page = pv.id_page
					LEFT JOIN ' . _DB_PREFIX_ . 'date_range dr ON pv.id_date_range = dr.id_date_range
					WHERE pa.id_object = p.id_product AND pa.id_page_type = ' . (int) Page::getPageTypeByName('product') . '
					AND dr.time_start BETWEEN ' . $date_between . '
					AND dr.time_end BETWEEN ' . $date_between . '
				) AS totalPageViewed,
				product_shop.active
				FROM ' . _DB_PREFIX_ . 'product p
				' . Shop::addSqlAssociation('product', 'p') . '
				LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = ' . (int) $this->getLang() . ' ' . Shop::addSqlRestrictionOnLang('pl') . ')
				LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON od.product_id = p.id_product
				LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON od.id_order = o.id_order
				' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				' . Product::sqlStock('p', 0) . '
				WHERE o.valid = 1
				AND o.invoice_date BETWEEN ' . $date_between . '
				GROUP BY od.product_id';
        if (Validate::IsName($this->_sort)) {
            $this->query .= ' ORDER BY `' . bqSQL($this->_sort) . '`';
            if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) {
                $this->query .= ' ' . $this->_direction;
            }
        }
        if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) {
            $this->query .= ' LIMIT ' . (int) $this->_start . ', ' . (int) $this->_limit;
        }
        $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query);
        foreach ($values as &$value) {
            $value['avgPriceSold'] = Tools::displayPrice($value['avgPriceSold'], $currency);
            $value['totalPriceSold'] = Tools::displayPrice($value['totalPriceSold'], $currency);
        }
        unset($value);
        $this->_values = $values;
        $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
    }
 public function __construct()
 {
     $this->bootstrap = true;
     $this->table = 'order_slip';
     $this->className = 'OrderSlip';
     $this->_select = ' o.`id_shop`';
     $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.`id_order` = a.`id_order`)';
     $this->_group = ' GROUP BY a.`id_order_slip`';
     parent::__construct();
     $this->fields_list = array('id_order_slip' => array('title' => $this->trans('ID', array(), 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'id_order' => array('title' => $this->trans('Order ID', array(), 'Admin.OrdersCustomers.Feature'), 'align' => 'left', 'class' => 'fixed-width-md'), 'date_add' => array('title' => $this->trans('Date issued', array(), 'Admin.OrdersCustomers.Feature'), 'type' => 'date', 'align' => 'right', 'filter_key' => 'a!date_add', 'havingFilter' => true), 'id_pdf' => array('title' => $this->trans('PDF', array(), 'Admin.Global'), 'align' => 'center', 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false, 'remove_onclick' => true));
     $this->_select = 'a.id_order_slip AS id_pdf';
     $this->optionTitle = $this->trans('Slip', array(), 'Admin.OrdersCustomers.Feature');
     $this->fields_options = array('general' => array('title' => $this->trans('Credit slip options', array(), 'Admin.OrdersCustomers.Feature'), 'fields' => array('PS_CREDIT_SLIP_PREFIX' => array('title' => $this->trans('Credit slip prefix', array(), 'Admin.OrdersCustomers.Feature'), 'desc' => $this->trans('Prefix used for credit slips.', array(), 'Admin.OrdersCustomers.Help'), 'size' => 6, 'type' => 'textLang')), 'submit' => array('title' => $this->trans('Save', array(), 'Admin.Actions'))));
     $this->_where = Shop::addSqlRestriction(false, 'o');
 }
    public static function customerHasAmazonCustomerId($id_customer)
    {
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
				SELECT ac.*
				  FROM `' . _DB_PREFIX_ . 'customer` c
                  JOIN `' . _DB_PREFIX_ . 'amz_customer` ac ON c.`id_customer` = ac.`id_customer`
				 WHERE c.`id_customer` = \'' . pSQL($id_customer) . '\'
				    ' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
				   AND c.`deleted` = 0');
        if (!$result) {
            return false;
        } else {
            return $result['amazon_customer_id'] ? $result['amazon_customer_id'] : false;
        }
    }
 public function __construct()
 {
     $this->bootstrap = true;
     $this->context = Context::getContext();
     $this->table = 'order_return';
     $this->className = 'OrderReturn';
     $this->colorOnBackground = true;
     $this->_select = 'orsl.`name`, o.`id_shop`';
     $this->_join = 'LEFT JOIN ' . _DB_PREFIX_ . 'order_return_state_lang orsl ON (orsl.`id_order_return_state` = a.`state` AND orsl.`id_lang` = ' . (int) $this->context->language->id . ')';
     $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.`id_order` = a.`id_order`)';
     $this->fields_list = array('id_order_return' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'a!id_order' => array('title' => $this->l('Order ID'), 'width' => 100, 'align' => 'center'), 'name' => array('title' => $this->l('Status'), 'width' => 'auto', 'align' => 'left'), 'a!date_add' => array('title' => $this->l('Date issued'), 'width' => 150, 'type' => 'date', 'align' => 'right'));
     $this->fields_options = array('general' => array('title' => $this->l('Merchandise return (RMA) options'), 'fields' => array('PS_ORDER_RETURN' => array('title' => $this->l('Enable returns'), 'desc' => $this->l('Would you like to allow merchandise returns in your shop?'), 'cast' => 'intval', 'type' => 'bool'), 'PS_ORDER_RETURN_NB_DAYS' => array('title' => $this->l('Time limit of validity'), 'desc' => $this->l('How many days after the delivery date does the customer have to return a product?'), 'cast' => 'intval', 'type' => 'text', 'size' => '2')), 'submit' => array('title' => $this->l('Save'))));
     parent::__construct();
     $this->_where = Shop::addSqlRestriction(false, 'o');
 }
Exemple #15
0
    public static function getTotalCustomerMessages($where = null)
    {
        if (is_null($where)) {
            return (int) Db::getInstance()->getValue('
				SELECT COUNT(*)
				FROM ' . _DB_PREFIX_ . 'customer_message
				LEFT JOIN `' . _DB_PREFIX_ . 'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`)
				WHERE 1' . Shop::addSqlRestriction());
        } else {
            return (int) Db::getInstance()->getValue('
				SELECT COUNT(*)
				FROM ' . _DB_PREFIX_ . 'customer_message cm
				LEFT JOIN `' . _DB_PREFIX_ . 'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`)
				WHERE ' . $where . Shop::addSqlRestriction());
        }
    }
Exemple #16
0
    public function __construct()
    {
        $this->name = 'sekeywords';
        $this->tab = 'analytics_stats';
        $this->version = 1.0;
        $this->author = 'PrestaShop';
        $this->need_instance = 0;
        parent::__construct();
        $this->_query = 'SELECT `keyword`, COUNT(TRIM(`keyword`)) as occurences
				FROM `' . _DB_PREFIX_ . 'sekeyword`
				WHERE ' . (Configuration::get('SEK_FILTER_KW') == '' ? '1' : '`keyword` REGEXP \'' . pSQL(Configuration::get('SEK_FILTER_KW')) . '\'') . Shop::addSqlRestriction() . ' AND `date_add` BETWEEN ';
        $this->_query2 = 'GROUP BY TRIM(`keyword`)
				HAVING occurences > ' . (int) Configuration::get('SEK_MIN_OCCURENCES') . '
				ORDER BY occurences DESC';
        $this->displayName = $this->l('Search engine keywords');
        $this->description = $this->l('Display which keywords have led visitors to your website.');
    }
Exemple #17
0
    /**
     * getLastElementsIdsByType return all the element ids to show (order, customer registration, and customer message)
     * Get all the element ids
     *
     * @param string $type contains the field name of the Employee table
     * @param int $id_last_element contains the id of the last seen element
     * @return array containing the notifications
     */
    public static function getLastElementsIdsByType($type, $id_last_element)
    {
        switch ($type) {
            case 'order':
                $sql = '
					SELECT SQL_CALC_FOUND_ROWS o.`id_order`, o.`id_customer`, o.`total_paid`, o.`id_currency`, o.`date_upd`, c.`firstname`, c.`lastname`
					FROM `' . _DB_PREFIX_ . 'orders` as o
					LEFT JOIN `' . _DB_PREFIX_ . 'customer` as c ON (c.`id_customer` = o.`id_customer`)
					WHERE `id_order` > ' . (int) $id_last_element . Shop::addSqlRestriction(false, 'o') . '
					ORDER BY `id_order` DESC
					LIMIT 5';
                break;
            case 'customer_message':
                $sql = '
					SELECT SQL_CALC_FOUND_ROWS c.`id_customer_message`, ct.`id_customer`, ct.`id_customer_thread`, ct.`email`, c.`date_add` as date_upd
					FROM `' . _DB_PREFIX_ . 'customer_message` as c
					LEFT JOIN `' . _DB_PREFIX_ . 'customer_thread` as ct ON (c.`id_customer_thread` = ct.`id_customer_thread`)
					WHERE c.`id_customer_message` > ' . (int) $id_last_element . '
						AND c.`id_employee` = 0
						AND ct.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
					ORDER BY c.`id_customer_message` DESC
					LIMIT 5';
                break;
            default:
                $sql = '
					SELECT SQL_CALC_FOUND_ROWS t.`id_' . bqSQL($type) . '`, t.*
					FROM `' . _DB_PREFIX_ . bqSQL($type) . '` t
					WHERE t.`deleted` = 0 AND t.`id_' . bqSQL($type) . '` > ' . (int) $id_last_element . Shop::addSqlRestriction(false, 't') . '
					ORDER BY t.`id_' . bqSQL($type) . '` DESC
					LIMIT 5';
                break;
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false);
        $total = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()', false);
        $json = array('total' => $total, 'results' => array());
        foreach ($result as $value) {
            $customer_name = '';
            if (isset($value['firstname']) && isset($value['lastname'])) {
                $customer_name = Tools::safeOutput($value['firstname'] . ' ' . $value['lastname']);
            } elseif (isset($value['email'])) {
                $customer_name = Tools::safeOutput($value['email']);
            }
            $json['results'][] = array('id_order' => !empty($value['id_order']) ? (int) $value['id_order'] : 0, 'id_customer' => !empty($value['id_customer']) ? (int) $value['id_customer'] : 0, 'id_customer_message' => !empty($value['id_customer_message']) ? (int) $value['id_customer_message'] : 0, 'id_customer_thread' => !empty($value['id_customer_thread']) ? (int) $value['id_customer_thread'] : 0, 'total_paid' => !empty($value['total_paid']) ? Tools::displayPrice((double) $value['total_paid'], (int) $value['id_currency'], false) : 0, 'customer_name' => $customer_name, 'update_date' => isset($value['date_upd']) ? (int) strtotime($value['date_upd']) * 1000 : 0);
        }
        return $json;
    }
Exemple #18
0
    public static function setNewConnection($cookie)
    {
        if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/BotLink|ahoy|AlkalineBOT|anthill|appie|arale|araneo|AraybOt|ariadne|arks|ATN_Worldwide|Atomz|bbot|Bjaaland|Ukonline|borg\\-bot\\/0\\.9|boxseabot|bspider|calif|christcrawler|CMC\\/0\\.01|combine|confuzzledbot|CoolBot|cosmos|Internet Cruiser Robot|cusco|cyberspyder|cydralspider|desertrealm, desert realm|digger|DIIbot|grabber|downloadexpress|DragonBot|dwcp|ecollector|ebiness|elfinbot|esculapio|esther|fastcrawler|FDSE|FELIX IDE|ESI|fido|H�m�h�kki|KIT\\-Fireball|fouineur|Freecrawl|gammaSpider|gazz|gcreep|golem|googlebot|griffon|Gromit|gulliver|gulper|hambot|havIndex|hotwired|htdig|iajabot|INGRID\\/0\\.1|Informant|InfoSpiders|inspectorwww|irobot|Iron33|JBot|jcrawler|Teoma|Jeeves|jobo|image\\.kapsi\\.net|KDD\\-Explorer|ko_yappo_robot|label\\-grabber|larbin|legs|Linkidator|linkwalker|Lockon|logo_gif_crawler|marvin|mattie|mediafox|MerzScope|NEC\\-MeshExplorer|MindCrawler|udmsearch|moget|Motor|msnbot|muncher|muninn|MuscatFerret|MwdSearch|sharp\\-info\\-agent|WebMechanic|NetScoop|newscan\\-online|ObjectsSearch|Occam|Orbsearch\\/1\\.0|packrat|pageboy|ParaSite|patric|pegasus|perlcrawler|phpdig|piltdownman|Pimptrain|pjspider|PlumtreeWebAccessor|PortalBSpider|psbot|Getterrobo\\-Plus|Raven|RHCS|RixBot|roadrunner|Robbie|robi|RoboCrawl|robofox|Scooter|Search\\-AU|searchprocess|Senrigan|Shagseeker|sift|SimBot|Site Valet|skymob|SLCrawler\\/2\\.0|slurp|ESI|snooper|solbot|speedy|spider_monkey|SpiderBot\\/1\\.0|spiderline|nil|suke|http:\\/\\/www\\.sygol\\.com|tach_bw|TechBOT|templeton|titin|topiclink|UdmSearch|urlck|Valkyrie libwww\\-perl|verticrawl|Victoria|void\\-bot|Voyager|VWbot_K|crawlpaper|wapspider|WebBandit\\/1\\.0|webcatcher|T\\-H\\-U\\-N\\-D\\-E\\-R\\-S\\-T\\-O\\-N\\-E|WebMoose|webquest|webreaper|webs|webspider|WebWalker|wget|winona|whowhere|wlm|WOLP|WWWC|none|XGET|Nederland\\.zoek|AISearchBot|woriobot|NetSeer|Nutch|YandexBot/i', $_SERVER['HTTP_USER_AGENT'])) {
            // This is a bot and we have to retrieve its connection ID
            $sql = 'SELECT SQL_NO_CACHE `id_connections` FROM `' . _DB_PREFIX_ . 'connections`
					WHERE ip_address = ' . (int) ip2long(Tools::getRemoteAddr()) . '
						AND `date_add` > \'' . pSQL(date('Y-m-d H:i:00', time() - 1800)) . '\'
						' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
					ORDER BY `date_add` DESC';
            if ($id_connections = Db::getInstance()->getValue($sql, false)) {
                $cookie->id_connections = (int) $id_connections;
                return Page::getCurrentId();
            }
        }
        // A new connection is created if the guest made no actions during 30 minutes
        $sql = 'SELECT SQL_NO_CACHE `id_guest`
				FROM `' . _DB_PREFIX_ . 'connections`
				WHERE `id_guest` = ' . (int) $cookie->id_guest . '
					AND `date_add` > \'' . pSQL(date('Y-m-d H:i:00', time() - 1800)) . '\'
					' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
				ORDER BY `date_add` DESC';
        $result = Db::getInstance()->getRow($sql, false);
        if (!$result['id_guest'] && (int) $cookie->id_guest) {
            // The old connections details are removed from the database in order to spare some memory
            Connection::cleanConnectionsPages();
            $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
            $array_url = parse_url($referer);
            if (!isset($array_url['host']) || preg_replace('/^www./', '', $array_url['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false))) {
                $referer = '';
            }
            $connection = new Connection();
            $connection->id_guest = (int) $cookie->id_guest;
            $connection->id_page = Page::getCurrentId();
            $connection->ip_address = Tools::getRemoteAddr() ? (int) ip2long(Tools::getRemoteAddr()) : '';
            $connection->id_shop = Context::getContext()->shop->id;
            $connection->id_shop_group = Context::getContext()->shop->id_shop_group;
            $connection->date_add = $cookie->date_add;
            if (Validate::isAbsoluteUrl($referer)) {
                $connection->http_referer = substr($referer, 0, 254);
            }
            $connection->add();
            $cookie->id_connections = $connection->id;
            return $connection->id_page;
        }
    }
    public static function getFavoriteProducts($id_customer, $id_lang)
    {
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT DISTINCT p.`id_product`, fp.`id_shop`, pl.`description_short`, pl.`link_rewrite`,
				pl.`name`, i.`id_image`, CONCAT(p.`id_product`, \'-\', i.`id_image`) as image
			FROM `' . _DB_PREFIX_ . 'favorite_product` fp
			LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.`id_product` = fp.`id_product`)
			' . Shop::addSqlAssociation('product', 'p') . '
			LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
				ON p.`id_product` = pl.`id_product`
				AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
			LEFT OUTER JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
			' . Shop::addSqlAssociation('product_attribute', 'pa', false) . '
			LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
			LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
			WHERE product_shop.`active` = 1
			' . ($id_customer ? ' AND fp.id_customer = ' . (int) $id_customer : '') . '
			' . Shop::addSqlRestriction(false, 'fp'));
    }
Exemple #20
0
    public function __construct()
    {
        $this->name = 'statssearch';
        $this->tab = 'analytics_stats';
        $this->version = 1.0;
        $this->author = 'PrestaShop';
        $this->need_instance = 0;
        parent::__construct();
        $this->query = 'SELECT `keywords`, COUNT(TRIM(`keywords`)) as occurences, MAX(results) as total
				FROM `' . _DB_PREFIX_ . 'statssearch`
				WHERE 1
					' . Shop::addSqlRestriction() . '
					AND `date_add` BETWEEN ';
        $this->query_group_by = 'GROUP BY `keywords`
				HAVING occurences > 1
				ORDER BY occurences DESC';
        $this->displayName = $this->l('Shop search');
        $this->description = $this->l('Adds a tab showing which keywords have been searched by your store\'s visitors.');
    }
Exemple #21
0
    public function getCustomers($count = false, $start = 0, $limit = 0, $shop_filtering = false)
    {
        if ($count) {
            return Db::getInstance()->getValue('
			SELECT COUNT(*)
			FROM `' . _DB_PREFIX_ . 'customer_group` cg
			LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (cg.`id_customer` = c.`id_customer`)
			WHERE cg.`id_group` = ' . (int) $this->id . '
			' . ($shop_filtering ? Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) : '') . '
			AND c.`deleted` != 1');
        }
        return Db::getInstance()->executeS('
		SELECT cg.`id_customer`, c.*
		FROM `' . _DB_PREFIX_ . 'customer_group` cg
		LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (cg.`id_customer` = c.`id_customer`)
		WHERE cg.`id_group` = ' . (int) $this->id . '
		AND c.`deleted` != 1
		' . ($shop_filtering ? Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) : '') . '
		ORDER BY cg.`id_customer` ASC
		' . ($limit > 0 ? 'LIMIT ' . (int) $start . ', ' . (int) $limit : ''));
    }
    public function getData()
    {
        $this->_query = 'SELECT SQL_CALC_FOUND_ROWS ocr.name as name, COUNT(ocr.id_cart_rule) as total, ROUND(SUM(o.total_paid_real) / o.conversion_rate, 2) as ca
				FROM ' . _DB_PREFIX_ . 'order_cart_rule ocr
				LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_order = ocr.id_order
				WHERE o.valid = 1
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
					AND o.invoice_date BETWEEN ' . $this->getDate() . '
				GROUP BY ocr.id_cart_rule';
        if (Validate::IsName($this->_sort)) {
            $this->_query .= ' ORDER BY `' . $this->_sort . '`';
            if (isset($this->_direction) && (strtoupper($this->_direction) == 'ASC' || strtoupper($this->_direction) == 'DESC')) {
                $this->_query .= ' ' . pSQL($this->_direction);
            }
        }
        if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) {
            $this->_query .= ' LIMIT ' . $this->_start . ', ' . $this->_limit;
        }
        $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query);
        $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
    }
    private function getPages()
    {
        $sql = 'SELECT http_referer, request_uri, COUNT(*) as nb
				FROM `' . _DB_PREFIX_ . 'pagenotfound`
				WHERE date_add BETWEEN ' . ModuleGraph::getDateBetween() . Shop::addSqlRestriction() . 'GROUP BY http_referer, request_uri';
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
        $pages = array();
        foreach ($result as $row) {
            $row['http_referer'] = parse_url($row['http_referer'], PHP_URL_HOST) . parse_url($row['http_referer'], PHP_URL_PATH);
            if (!isset($row['http_referer']) || empty($row['http_referer'])) {
                $row['http_referer'] = '--';
            }
            if (!isset($pages[$row['request_uri']])) {
                $pages[$row['request_uri']] = array('nb' => 0);
            }
            $pages[$row['request_uri']][$row['http_referer']] = $row['nb'];
            $pages[$row['request_uri']]['nb'] += $row['nb'];
        }
        uasort($pages, 'pnfSort');
        return $pages;
    }
Exemple #24
0
    public function getData()
    {
        $this->_totalCount = $this->getTotalCount();
        $this->query = 'SELECT s.name, SUM(od.product_quantity) as quantity, ROUND(SUM(od.product_quantity * od.product_price) / o.conversion_rate, 2) as sales
				FROM ' . _DB_PREFIX_ . 'order_detail od
				LEFT JOIN ' . _DB_PREFIX_ . 'product p ON p.id_product = od.product_id
				LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_order = od.id_order
				LEFT JOIN ' . _DB_PREFIX_ . 'supplier s ON s.id_supplier = p.id_supplier
				WHERE o.invoice_date BETWEEN ' . $this->getDate() . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
					AND o.valid = 1
					AND s.id_supplier IS NOT NULL
				GROUP BY p.id_supplier';
        if (Validate::IsName($this->_sort)) {
            $this->query .= ' ORDER BY `' . $this->_sort . '`';
            if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) {
                $this->query .= ' ' . $this->_direction;
            }
        }
        if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) {
            $this->query .= ' LIMIT ' . $this->_start . ', ' . $this->_limit;
        }
        $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query);
    }
Exemple #25
0
    public static function lastNoneOrderedCart($id_customer)
    {
        $sql = 'SELECT c.`id_cart`
				FROM ' . _DB_PREFIX_ . 'cart c
				WHERE c.`id_cart` NOT IN (SELECT o.`id_cart` FROM ' . _DB_PREFIX_ . 'orders o WHERE o.`id_customer` = ' . (int) $id_customer . ')
				AND c.`id_customer` = ' . (int) $id_customer . '
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'c') . '
				ORDER BY c.`date_upd` DESC';
        if (!($id_cart = Db::getInstance()->getValue($sql))) {
            return false;
        }
        return (int) $id_cart;
    }
Exemple #26
0
    protected function getData($layers)
    {
        if ($this->_option == 3) {
            return $this->getStatesData();
        }
        $this->_query = '
			SELECT o.`invoice_date`, o.`total_paid_real` / o.conversion_rate AS total_paid_real, SUM(od.product_quantity) as product_quantity
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` od ON od.`id_order` = o.`id_order`
			' . ((int) $this->id_country ? 'LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON o.id_address_delivery = a.id_address' : '') . '
			WHERE o.valid = 1
				' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				' . ((int) $this->id_country ? 'AND a.id_country = ' . (int) $this->id_country : '') . '
				AND o.`invoice_date` BETWEEN ';
        $this->_query2 = ' GROUP BY o.id_order';
        $this->setDateGraph($layers, true);
    }
    /**
     * @see FrontController::initContent()
     */
    public function initContent()
    {
        parent::initContent();
        if (!$this->context->customer->isLogged()) {
            $back = $this->context->link->getModuleLink('fbconnect_psb', 'link', array(), TRUE, $this->context->language->id);
            Tools::redirect('index.php?controller=authentication&back=' . urlencode($back));
        }
        $fb_connect_appid = Configuration::get('FB_CONNECT_APPID');
        $fb_connect_appkey = Configuration::get('FB_CONNECT_APPKEY');
        require_once _PS_ROOT_DIR_ . '/modules/fbconnect_psb/fb_sdk/facebook.php';
        $facebook = new Facebook(array('appId' => $fb_connect_appid, 'secret' => $fb_connect_appkey));
        // Get User ID
        $user = $facebook->getUser();
        if ($user) {
            try {
                // Proceed knowing you have a logged in user who's authenticated.
                $fb_user_profile = $facebook->api('/me');
            } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
            }
        } else {
            // Get new Access tokens
            Tools::redirect($facebook->getLoginUrl(array('scope' => 'email')));
        }
        // current user state Logged In with FB
        if (!$user || !$fb_user_profile['id']) {
            // Get new Access tokens
            Tools::redirect($facebook->getLoginUrl(array('scope' => 'email')));
        }
        $sql = 'SELECT `id_customer`
				FROM `' . _DB_PREFIX_ . 'customer_profile_connect`
				WHERE `facebook_id` = \'' . (int) $fb_user_profile['id'] . '\'' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER);
        $customer_id = Db::getInstance()->getValue($sql);
        if ($customer_id > 0 && $customer_id != $this->context->customer->id) {
            $this->context->smarty->assign(array('fbconnect_psb_status' => 'error', 'fbconnect_psb_massage' => 'The Facebook account is already linked to another account.', 'fbconnect_psb_fb_picture' => 'https://graph.facebook.com/' . $fb_user_profile['username'] . '/picture', 'fbconnect_psb_fb_name' => $fb_user_profile['name']));
        } else {
            if ($customer_id == $this->context->customer->id) {
                $this->context->smarty->assign(array('fbconnect_psb_status' => 'linked', 'fbconnect_psb_massage' => 'The Facebook account is already linked to your account.', 'fbconnect_psb_fb_picture' => 'https://graph.facebook.com/' . $fb_user_profile['username'] . '/picture', 'fbconnect_psb_fb_name' => $fb_user_profile['name']));
            } else {
                if ($fb_user_profile['email'] != $this->context->customer->email) {
                    // The message
                    $message = 'Email address on files was not the same as the Facebook account.';
                    $message .= 'customer ID: ' . print_r($this->context->customer->id, true);
                    $message .= "\n\n";
                    $message .= 'user info:' . print_r($fb_user_profile, true);
                    $message .= "\n\n";
                    // In case any of our lines are larger than 70 characters, we should use wordwrap()
                    $message = wordwrap($message, 70, "\r\n");
                    @mail(Configuration::get('PS_SHOP_EMAIL'), 'fbconnect_psb: error #1 log', $message);
                }
                $sql = 'SELECT `facebook_id`
				FROM `' . _DB_PREFIX_ . 'customer_profile_connect`
				WHERE `id_customer` = \'' . (int) $this->context->customer->id . '\' AND `id_shop` = ' . (int) $this->context->getContext()->shop->id;
                $facebook_id = Db::getInstance()->getValue($sql);
                if (!$facebook_id) {
                    Db::getInstance()->insert('customer_profile_connect', array('id_customer' => (int) $this->context->customer->id, 'facebook_id' => (int) $fb_user_profile['id']));
                    $this->context->smarty->assign(array('fbconnect_psb_status' => 'conform', 'fbconnect_psb_massage' => 'Your Facebook account has been linked to account.', 'fbconnect_psb_fb_picture' => 'https://graph.facebook.com/' . $fb_user_profile['username'] . '/picture', 'fbconnect_psb_fb_name' => $fb_user_profile['name']));
                } else {
                    // This could happen if the user logged off from FB but not the prestashop
                    // And 2nd user logs in to facebook than opens this page.
                    $this->context->smarty->assign(array('fbconnect_psb_status' => 'error', 'fbconnect_psb_massage' => 'Sorry, there was a error when we tried to link your account with Facebook. Our Site admin has been notified of error, once it\'s resolved you will be sent a email notice.'));
                    // The message
                    $message = 'customer ID: ' . print_r($this->context->customer->id, true);
                    $message .= "\n\n";
                    $message .= 'user info:' . print_r($fb_user_profile, true);
                    $message .= "\n\n";
                    // In case any of our lines are larger than 70 characters, we should use wordwrap()
                    $message = wordwrap($message, 70, "\r\n");
                    @mail(Configuration::get('PS_SHOP_EMAIL'), 'fbconnect_psb: error #2 log', $message);
                }
            }
        }
        $this->setTemplate('link_fb.tpl');
    }
Exemple #28
0
    /**
     * @since 1.5.0.3
     * @param $date_from
     * @param $date_to
     * @return array collection of invoice
     */
    public static function getByDeliveryDateInterval($date_from, $date_to)
    {
        $order_invoice_list = Db::getInstance()->executeS('
			SELECT oi.*
			FROM `' . _DB_PREFIX_ . 'order_invoice` oi
			LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_order` = oi.`id_order`)
			WHERE DATE_ADD(oi.delivery_date, INTERVAL -1 DAY) <= \'' . pSQL($date_to) . '\'
			AND oi.delivery_date >= \'' . pSQL($date_from) . '\'
			' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
			ORDER BY oi.delivery_date ASC
		');
        return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list);
    }
    public function setOption($option, $layers = 1)
    {
        switch ($option) {
            case 3:
                $this->_titles['main'][0] = $this->l('Number of visits and unique visitors');
                $this->_titles['main'][1] = $this->l('Visits');
                $this->_titles['main'][2] = $this->l('Visitors');
                $this->query[0] = 'SELECT date_add, COUNT(`date_add`) as total
					FROM `' . _DB_PREFIX_ . 'connections`
					WHERE 1
						' . Shop::addSqlRestriction() . '
						AND `date_add` BETWEEN ';
                $this->query[1] = 'SELECT date_add, COUNT(DISTINCT `id_guest`) as total
					FROM `' . _DB_PREFIX_ . 'connections`
					WHERE 1
						' . Shop::addSqlRestriction() . '
						AND `date_add` BETWEEN ';
                break;
        }
    }
Exemple #30
0
    public function setOption($option, $layers = 1)
    {
        switch ($option) {
            case 'wb':
                $this->_titles['main'] = $this->l('Web browser use');
                $this->_query = 'SELECT wb.`name`, COUNT(g.`id_web_browser`) AS total
						FROM `' . _DB_PREFIX_ . 'web_browser` wb
						LEFT JOIN `' . _DB_PREFIX_ . 'guest` g ON g.`id_web_browser` = wb.`id_web_browser`
						LEFT JOIN `' . _DB_PREFIX_ . 'connections` c ON g.`id_guest` = c.`id_guest`
						WHERE 1
							' . Shop::addSqlRestriction(false, 'c') . '
							AND c.`date_add` BETWEEN ';
                $this->_query2 = ' GROUP BY g.`id_web_browser`';
                break;
            case 'os':
                $this->_titles['main'] = $this->l('Operating systems use');
                $this->_query = 'SELECT os.`name`, COUNT(g.`id_operating_system`) AS total
						FROM `' . _DB_PREFIX_ . 'operating_system` os
						LEFT JOIN `' . _DB_PREFIX_ . 'guest` g ON g.`id_operating_system` = os.`id_operating_system`
						LEFT JOIN `' . _DB_PREFIX_ . 'connections` c ON g.`id_guest` = c.`id_guest`
						WHERE 1
							' . Shop::addSqlRestriction(false, 'c') . '
							AND c.`date_add` BETWEEN ';
                $this->_query2 = ' GROUP BY g.`id_operating_system`';
                break;
        }
    }