Ejemplo n.º 1
0
 /**
  * Query db
  * @param string $alias
  * @return array
  */
 protected function query($alias = null)
 {
     //force 'from' source
     $this->query->from($this->tableName(), $alias);
     $sql = $this->query->build();
     $data = Db::getInstance()->executeS($sql);
     $map = array();
     foreach ($data as $index => $item) {
         list($new_index, $new_item, $reserve_index) = $this->map($index, $item);
         //allow 2-level depth in mapped result (for ProductAttribute)
         if ($reserve_index) {
             $map[$new_index][$reserve_index] = $new_item;
         } else {
             $map[$new_index] = $new_item;
         }
     }
     return $map;
 }
Ejemplo n.º 2
0
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 *
 *  @author    PrestaShop SA <*****@*****.**>
 *  @copyright 2007-2015 PrestaShop SA
 *  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 *  International Registered Trademark & Property of PrestaShop SA
 */
include '../../config/config.inc.php';
$id_cart = Tools::getValue('id_cart');
$secure_key = Tools::getValue('key');
$sql = new DbQueryCore();
$sql->select('o.id_order');
$sql->from('orders', 'o');
$sql->where('id_cart=' . (int) $id_cart . ' AND secure_key = "' . pSQL($secure_key) . '"');
$result = Db::getInstance()->getValue($sql);
if ($result) {
    die('ok');
} else {
    die('ko');
}
Ejemplo n.º 3
0
    public static function getCustomersEmailRequest($campaign_id, $checked_langs, $checked_groups, $checked_campaign_optin, $checked_campaign_newsletter, $checked_campaign_active, $checked_campaign_guest, $checked_products, $checked_categories, $checked_shops, $paying_filters = array(), $extended = false, $limit = 0, &$list_total = null)
    {
        $sql_calc_found = is_null($list_total) ? '' : 'SQL_CALC_FOUND_ROWS ';
        $req = new DbQueryCore();
        $req->select($sql_calc_found . (int) $campaign_id . ' as campaign_id, customer.id_customer, customer.id_lang,
						customer.firstname, customer.lastname, customer.email,
						INET_NTOA(connections.ip_address) as ip_address,
						country.iso_code, address.postcode as zip, address.city,
						UNIX_TIMESTAMP(MAX(connections.date_add)) as last_connexion_date, \'prestashop\' as source,
						group_lang.name as group_name');
        $req->from('customer', 'customer');
        $req->leftJoin('customer_group', 'customer_group', 'customer_group.id_customer = customer.id_customer');
        $req->leftJoin('group_lang', 'group_lang', 'group_lang.id_group = customer_group.id_group AND customer.id_lang = group_lang.id_lang');
        $req->leftJoin('guest', 'guest', 'guest.id_customer = customer.id_customer');
        $req->leftJoin('connections', 'connections', 'connections.id_guest = guest.id_guest');
        $req->leftJoin('address', 'address', 'address.id_customer = customer.id_customer');
        $req->leftJoin('country', 'country', 'address.id_country = country.id_country');
        if (!empty($checked_langs)) {
            $req->where('customer.id_lang IN(' . implode(', ', array_map('intval', $checked_langs)) . ')');
        }
        if (!empty($checked_groups)) {
            $req->where('customer_group.id_group IN(' . implode(', ', array_map('intval', $checked_groups)) . ')');
        }
        if ($checked_campaign_optin) {
            $req->where('customer.optin = 1');
        }
        if ($checked_campaign_newsletter) {
            $req->where('customer.newsletter = 1');
        }
        if ($checked_campaign_active) {
            $req->where('customer.active = 1');
        }
        if (!empty($checked_products) || !empty($checked_categories)) {
            $where_products_categories = array();
            $req->leftJoin('cart', 'cart', 'cart.id_customer = customer.id_customer');
            $req->leftJoin('cart_product', 'cart_product', 'cart_product.id_cart = cart.id_cart');
            if (!empty($checked_products)) {
                $where_products_categories[] = 'cart_product.id_product IN(' . implode(', ', array_map('intval', $checked_products)) . ')';
            }
            if (!empty($checked_categories)) {
                $req->leftJoin('category_product', 'category_product', 'category_product.id_product = cart_product.id_product');
                $where_products_categories[] = 'category_product.id_category IN(' . implode(', ', array_map('intval', $checked_categories)) . ')';
            }
            $req->where(implode(' OR ', $where_products_categories));
        }
        if (!empty($checked_shops)) {
            $req->where('customer.id_shop IN (' . implode(', ', array_map('intval', $checked_shops)) . ')');
        }
        if (isset($paying_filters['birthday'])) {
            if ($birthday_sql = self::generateSQLWhereBirthday($paying_filters['birthday'])) {
                $req->where($birthday_sql);
            }
        }
        if (isset($paying_filters['civilities']) && !empty($paying_filters['civilities'])) {
            $req->where('customer.id_gender IN (' . implode(', ', array_map('intval', $paying_filters['civilities'])) . ')');
        }
        if (isset($paying_filters['countries']) && !empty($paying_filters['countries'])) {
            $req->where('country.id_country IN (' . implode(', ', array_map('intval', $paying_filters['countries'])) . ')');
        }
        if (isset($paying_filters['postcodes']) && !empty($paying_filters['postcodes'])) {
            $where_or = array();
            foreach ($paying_filters['postcodes'] as $value) {
                $where_or[] = 'address.id_country = ' . (int) $value['country_id'] . ' AND address.postcode LIKE "' . pSQL($value['postcode']) . '%"';
            }
            $req->where('(' . implode(' OR ', $where_or) . ')');
        }
        if (isset($paying_filters['buyingdates']) && !empty($paying_filters['buyingdates'])) {
            $req->innerJoin('orders', 'orders', 'orders.id_customer = customer.id_customer AND (orders.date_add BETWEEN \'' . pSQL($paying_filters['buyingdates']['min_buyingdate']) . '\' AND \'' . pSQL($paying_filters['buyingdates']['max_buyingdate']) . '\' OR orders.date_upd BETWEEN \'' . pSQL($paying_filters['buyingdates']['min_buyingdate']) . '\' AND \'' . pSQL($paying_filters['buyingdates']['max_buyingdate']) . '\')');
        }
        if (isset($paying_filters['accountdates']) && !empty($paying_filters['accountdates'])) {
            $req->where('customer.date_add BETWEEN \'' . pSQL($paying_filters['accountdates']['min_accountdate']) . '\' AND \'' . pSQL($paying_filters['accountdates']['max_accountdate']) . '\'');
        }
        if (isset($paying_filters['promocodes']) && !empty($paying_filters['promocodes'])) {
            $req->leftJoin('orders', 'orders2', 'orders2.id_customer = customer.id_customer');
            $req->leftJoin('cart', 'cart', 'orders2.id_cart = cart.id_cart');
            $req->leftJoin('cart_cart_rule', 'cart_cart_rule', 'cart_cart_rule.id_cart = cart.id_cart');
            $req->leftJoin('cart_rule', 'cart_rule', 'cart_rule.id_cart_rule = cart_cart_rule.id_cart_rule');
            $codes = array();
            foreach ($paying_filters['promocodes'] as $value) {
                if ($value['promocode_type'] == 'specific') {
                    $codes[] = pSQL($value['promocode']);
                } elseif ($value['promocode_type'] == 'any') {
                    $req->where('(cart_rule.code IS NOT NULL OR cart_rule.code <> \'\')');
                    break;
                } elseif ($value['promocode_type'] == 'never') {
                    $req->orderBy('cart_rule.code');
                    $req->select('cart_rule.code');
                    $req->having('cart_rule.code IS NULL OR cart_rule.code = \'\'');
                    break;
                }
            }
            if (!empty($codes)) {
                $req->where('cart_rule.code in (\'' . implode('\', \'', $codes) . '\')');
            }
        }
        if (Tools::strpos($req->build(), 'WHERE') === false) {
            $req->where('0 = 1');
        }
        if (!$extended) {
            $req->where('connections.ip_address IS NOT NULL');
        }
        $req->groupby('customer.id_customer');
        $limit = (int) $limit;
        // Guest newsletter subscribers
        if ($checked_campaign_guest) {
            $req_guest = new DbQuery();
            $req_guest->select((int) $campaign_id . ' as campaign_id, null, null,
							null, null, newsletter.email, newsletter.ip_registration_newsletter as ip_address,
							null, null as zip, null,
							UNIX_TIMESTAMP(newsletter.newsletter_date_add) as last_connexion_date, \'prestashop newsletter\' as source,
							\'Newsletter\' as group_name');
            $req_guest->from('newsletter', 'newsletter');
            $req_guest->where('newsletter.active = 1');
            $req .= ' UNION (' . $req_guest;
            $req .= ' HAVING email IS NOT NULL)';
            if ($limit) {
                $req .= ' LIMIT ' . $limit;
            }
        } else {
            if ($limit) {
                $req->limit($limit);
            }
        }
        $req = 'SELECT campaign_id, id_customer, id_lang, firstname, lastname, email, ip_address, iso_code, 
			zip, city, last_connexion_date, source, group_name
			FROM (' . $req . ') as rcpt';
        return $req;
    }
Ejemplo n.º 4
0
 /**
  * @return bool
  */
 public function verifyDupplicates()
 {
     $sql = new DbQueryCore();
     $sql->select('an.notify_id, an.sign');
     $sql->from('alipay_notification', 'an');
     $sql->where('an.notify_id="' . pSQL($this->notify_id) . '" AND an.sign="' . pSQL($this->sign) . '"');
     $result = Db::getInstance()->getRow($sql);
     if ($result) {
         return false;
     }
     return true;
 }