public function postProcess()
 {
     if (Tools::isSubmit('update' . $this->table)) {
         $campaign_id = (int) Tools::getValue('campaign_id');
         if ($campaign_id > 0) {
             Tools::redirectAdmin('index.php?controller=AdminMarketingFStep1&campaign_id=' . $campaign_id . '&token=' . Tools::getAdminTokenLite('AdminMarketingFStep1'));
             exit;
         }
     }
     if (Tools::isSubmit('delete' . $this->table)) {
         $campaign_id = (int) Tools::getValue('campaign_id');
         if ($campaign_id > 0) {
             // On masque la campagne via son champ 'state'
             // -------------------------------------------
             Db::getInstance()->delete('expressmailing_fax_recipients', 'campaign_id = ' . $campaign_id);
             $req = new DbQuery();
             $req->select('*');
             $req->from('expressmailing_fax_pages');
             $req->where('campaign_id = ' . $campaign_id);
             $req->orderBy('id');
             $pages_db = Db::getInstance()->executeS($req, true, false);
             foreach ($pages_db as $page) {
                 unlink($page['page_path']);
                 unlink($page['page_path_original']);
             }
             Db::getInstance()->delete('expressmailing_fax_pages', 'campaign_id = ' . $campaign_id);
             Db::getInstance()->update($this->table, array('campaign_state' => self::FINISHED, 'campaign_date_update' => date('Y-m-d H:i:s')), 'campaign_id = ' . $campaign_id);
         }
     }
 }
 public static function getLastId()
 {
     $query = new DbQuery();
     $query->select('id_stock_mvt');
     $query->from('stock_mvt');
     $query->orderBy('id_stock_mvt DESC');
     return Db::getInstance()->getValue($query);
 }
 public static function getAll()
 {
     $sql = new DbQuery();
     $sql->select('id_simpleblog_post_type, name');
     $sql->from('simpleblog_post_type', 'sbpt');
     $sql->orderBy('id_simpleblog_post_type ASC');
     return Db::getInstance()->executeS($sql);
 }
Beispiel #4
0
 public function getNextBadgeId()
 {
     $query = new DbQuery();
     $query->select('b.`id_badge`');
     $query->from('badge', 'b');
     $query->where('b.id_group = \'' . pSQL($this->id_group) . '\' AND b.validated = 0');
     $query->orderBy('b.group_position');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
 }
 public function getLastId()
 {
     // build query
     $query = new DbQuery();
     $query->select('id_erpip_inventory');
     $query->from('erpip_inventory', 'i');
     $query->orderBy('id_erpip_inventory DESC');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
 }
 public function getLastId()
 {
     // build query
     $query = new DbQuery();
     $query->select('id_stock_image');
     $query->from('stock_image', 'si');
     $query->orderBy('id_stock_image DESC');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
 }
Beispiel #7
0
    /**
     * Return suppliers
     *
     * @return array Suppliers
     */
    public static function getSuppliers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_groups = false)
    {
        if (!$id_lang) {
            $id_lang = Configuration::get('PS_LANG_DEFAULT');
        }
        $query = new DbQuery();
        $query->select('s.*, sl.`description`');
        $query->from('supplier', 's');
        $query->leftJoin('supplier_lang', 'sl', 's.`id_supplier` = sl.`id_supplier` AND sl.`id_lang` = ' . (int) $id_lang);
        $query->join(Shop::addSqlAssociation('supplier', 's'));
        if ($active) {
            $query->where('s.`active` = 1');
        }
        $query->orderBy(' s.`name` ASC');
        $query->limit($n, ($p - 1) * $n);
        $query->groupBy('s.id_supplier');
        $suppliers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
        if ($suppliers === false) {
            return false;
        }
        if ($get_nb_products) {
            $sql_groups = '';
            if (!$all_groups) {
                $groups = FrontController::getCurrentCustomerGroups();
                $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
            }
            foreach ($suppliers as $key => $supplier) {
                $sql = '
					SELECT DISTINCT(ps.`id_product`)
					FROM `' . _DB_PREFIX_ . 'product_supplier` ps
					JOIN `' . _DB_PREFIX_ . 'product` p ON (ps.`id_product`= p.`id_product`)
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE ps.`id_supplier` = ' . (int) $supplier['id_supplier'] . '
					AND ps.id_product_attribute = 0' . ($active ? ' AND product_shop.`active` = 1' : '') . ($all_groups ? '' : '
					AND ps.`id_product` IN (
						SELECT cp.`id_product`
						FROM `' . _DB_PREFIX_ . 'category_group` cg
						LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
						WHERE cg.`id_group` ' . $sql_groups . '
					)');
                $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
                $suppliers[$key]['nb_products'] = count($result);
            }
        }
        $nb_suppliers = count($suppliers);
        $rewrite_settings = (int) Configuration::get('PS_REWRITING_SETTINGS');
        for ($i = 0; $i < $nb_suppliers; $i++) {
            if ($rewrite_settings) {
                $suppliers[$i]['link_rewrite'] = Tools::link_rewrite($suppliers[$i]['name'], false);
            } else {
                $suppliers[$i]['link_rewrite'] = 0;
            }
        }
        return $suppliers;
    }
 public static function getAllById($id_simpleblog_post)
 {
     if (!Validate::isUnsignedInt($id_simpleblog_post)) {
         return Tools::displayError('getAllById - invalid ID');
     }
     $sql = new DbQuery();
     $sql->select('*');
     $sql->from('simpleblog_post_image', 'sbpi');
     $sql->where('id_simpleblog_post = ' . (int) $id_simpleblog_post);
     $sql->orderBy('position ASC');
     return Db::getInstance()->executeS($sql);
 }
Beispiel #9
0
 public static function getPosts($id_lang, $limit = 10, $id_simpleblog_category = null, $page = null, $active = true, $orderby = false, $orderway = false, $exclude = null, $featured = false, $author = false, $id_shop = null, $filter = false, $selected = array())
 {
     $context = Context::getContext();
     $start = $limit * ($page == 0 ? 0 : $page - 1);
     $sql = new DbQuery();
     $sql->select('*');
     $sql->from('simpleblog_post', 'sbp');
     if ($id_lang) {
         $sql->innerJoin('simpleblog_post_lang', 'l', 'sbp.id_simpleblog_post = l.id_simpleblog_post AND l.id_lang = ' . (int) $id_lang);
     }
     if (!$id_shop) {
         $id_shop = $context->shop->id;
     }
     $sql->innerJoin('simpleblog_post_shop', 'sbps', 'sbp.id_simpleblog_post = sbps.id_simpleblog_post AND sbps.id_shop = ' . (int) $id_shop);
     if ($active) {
         $sql->where('sbp.active = 1');
     }
     if (isset($id_simpleblog_category) && (int) $id_simpleblog_category > 0) {
         $sql->where('sbp.id_simpleblog_category = ' . (int) $id_simpleblog_category);
     }
     if ($exclude) {
         $sql->where('sbp.id_simpleblog_post != ' . (int) $exclude);
     }
     if ($featured) {
         $sql->where('sbp.is_featured = 1');
     }
     if ($author && Configuration::get('PH_BLOG_POST_BY_AUTHOR')) {
         $sql->where('sbp.author = \'' . pSQL($author) . '\'');
     }
     if ($filter) {
         $sql->where('sbp.id_simpleblog_post ' . $filter . ' (' . join(',', $selected) . ')');
     }
     if (isset($context->customer) && !$context->customer->isLogged()) {
         $sql->where('sbp.logged = 0');
     }
     if (!$orderby) {
         $orderby = 'sbp.id_simpleblog_post';
     }
     if (!$orderway) {
         $orderway = 'DESC';
     }
     $sql->orderBy($orderby . ' ' . $orderway);
     $sql->limit($limit, $start);
     $result = Db::getInstance()->executeS($sql);
     if (sizeof($result)) {
         foreach ($result as &$row) {
             $category_rewrite = SimpleBlogCategory::getRewriteByCategory($row['id_simpleblog_category'], $id_lang);
             $category_obj = new SimpleBlogCategory($row['id_simpleblog_category'], $id_lang);
             $category_url = SimpleBlogCategory::getLink($category_obj->link_rewrite, $id_lang);
             if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '.' . $row['cover'])) {
                 $row['banner'] = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '.' . $row['cover'];
                 $row['banner_thumb'] = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '-thumb.' . $row['cover'];
                 $row['banner_wide'] = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '-wide.' . $row['cover'];
             }
             if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/featured/' . $row['id_simpleblog_post'] . '.' . $row['featured'])) {
                 $row['featured'] = _MODULE_DIR_ . 'ph_simpleblog/featured/' . $row['id_simpleblog_post'] . '.' . $row['featured'];
             }
             $row['url'] = self::getLink($row['link_rewrite'], $category_obj->link_rewrite, $id_lang);
             $row['category'] = $category_obj->name;
             $row['category_url'] = $category_url;
             $tags = SimpleBlogTag::getPostTags($row['id_simpleblog_post']);
             $row['tags'] = isset($tags[$id_lang]) && sizeof($tags[$id_lang] > 0) ? $tags[$id_lang] : false;
         }
     } else {
         return;
     }
     return $result;
 }
 /**
  * AdminController::getList() override
  * @see AdminController::getList()
  */
 public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
 {
     parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
     if ($this->ajax) {
         foreach ($this->_list as &$list) {
             if (file_exists(_PS_IMG_DIR_ . $this->fieldImageSettings['dir'] . '/' . (int) $list['id_attribute'] . '.jpg')) {
                 if (!isset($list['color']) || !is_array($list['color'])) {
                     $list['color'] = array();
                 }
                 $list['color']['texture'] = '../img/' . $this->fieldImageSettings['dir'] . '/' . (int) $list['id_attribute'] . '.jpg';
             }
         }
     } else {
         $nb_items = count($this->_list);
         for ($i = 0; $i < $nb_items; ++$i) {
             $item =& $this->_list[$i];
             $query = new DbQuery();
             $query->select('COUNT(a.id_attribute) as count_values');
             $query->from('attribute', 'a');
             $query->join(Shop::addSqlAssociation('attribute', 'a'));
             $query->where('a.id_attribute_group =' . (int) $item['id_attribute_group']);
             $query->groupBy('attribute_shop.id_shop');
             $query->orderBy('count_values DESC');
             $item['count_values'] = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
             unset($query);
         }
     }
 }
Beispiel #11
0
 public function getListCaptured()
 {
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         $query = 'SELECT * FROM ' . _DB_PREFIX_ . 'paypal_capture WHERE id_order =' . $this->id_order . ' ORDER BY date_add DESC ;';
     } else {
         $query = new DbQuery();
         $query->from(self::$definition['table']);
         $query->where('id_order = ' . $this->id_order);
         $query->orderBy('date_add DESC');
     }
     $result = DB::getInstance()->executeS($query);
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         foreach ($result as &$foo) {
             $foo['date'] = Tools::displayDate($foo['date_add'], Configuration::get('PS_LANG_DEFAULT'), true);
         }
     }
     return $result;
 }
Beispiel #12
0
 /**
  * Add GROUP BY restriction on query using real SQL syntax
  *
  * @param string $sql
  * @return Collection
  */
 public function sqlGroupBy($sql)
 {
     $this->query->orderBy($this->parseFields($sql));
     return $this;
 }
 /**
  * Gets the list of supply order statuses
  *
  * @param array $ids Optional Do not include these ids in the result
  * @param int $id_lang Optional
  * @return array
  */
 public static function getStates($ids = null, $id_lang = null)
 {
     if ($id_lang == null) {
         $id_lang = Context::getContext()->language->id;
     }
     if ($ids && !is_array($ids)) {
         $ids = array();
     }
     $query = new DbQuery();
     $query->select('sl.name, s.id_supply_order_state');
     $query->from('supply_order_state', 's');
     $query->leftjoin('supply_order_state_lang', 'sl', 's.id_supply_order_state = sl.id_supply_order_state AND sl.id_lang=' . (int) $id_lang);
     if ($ids) {
         $query->where('s.id_supply_order_state NOT IN(' . implode(',', array_map('intval', $ids)) . ')');
     }
     $query->orderBy('sl.name ASC');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
 }
Beispiel #14
0
    /**
     * ONLY FOR DEVELOPMENT PURPOSE
     */
    public function getEntityContents($entity)
    {
        $xml = $this->loadEntity($entity);
        $primary = isset($xml->fields['primary']) && $xml->fields['primary'] ? (string) $xml->fields['primary'] : 'id_' . $entity;
        $is_multilang = $this->isMultilang($entity);
        // Check if current table is an association table (if multiple primary keys)
        $is_association = false;
        if (strpos($primary, ',') !== false) {
            $is_association = true;
            $primary = array_map('trim', explode(',', $primary));
        }
        // Build query
        $sql = new DbQuery();
        $sql->select('a.*');
        $sql->from($entity, 'a');
        if ($is_multilang) {
            $sql->select('b.*');
            $sql->leftJoin($entity . '_lang', 'b', 'a.' . $primary . ' = b.' . $primary);
        }
        if (isset($xml->fields['sql']) && $xml->fields['sql']) {
            $sql->where((string) $xml->fields['sql']);
        }
        if (!$is_association) {
            $sql->select('a.' . $primary);
            if (!isset($xml->fields['ordersql']) || !$xml->fields['ordersql']) {
                $sql->orderBy('a.' . $primary);
            }
        }
        if ($is_multilang && (!isset($xml->fields['ordersql']) || !$xml->fields['ordersql'])) {
            $sql->orderBy('b.id_lang');
        }
        if (isset($xml->fields['ordersql']) && $xml->fields['ordersql']) {
            $sql->orderBy((string) $xml->fields['ordersql']);
        }
        // Get multilang columns
        $alias_multilang = array();
        if ($is_multilang) {
            $columns = $this->getColumns($entity);
            $multilang_columns = $this->getColumns($entity, true);
            // If some columns from _lang table have same name than original table, rename them (E.g. value in configuration)
            foreach ($multilang_columns as $c => $is_text) {
                if (isset($columns[$c])) {
                    $alias = $c . '_alias';
                    $alias_multilang[$c] = $alias;
                    $sql->select('a.' . $c . ' as ' . $c . ', b.' . $c . ' as ' . $alias);
                }
            }
        }
        // Get all results
        $nodes = $nodes_lang = array();
        $results = Db::getInstance()->executeS($sql);
        if (Db::getInstance()->getNumberError()) {
            $this->setError($this->language->l('SQL error on query <i>%s</i>', $sql));
        } else {
            foreach ($results as $row) {
                // Store common columns
                if ($is_association) {
                    $id = $entity;
                    foreach ($primary as $key) {
                        $id .= '_' . $row[$key];
                    }
                } else {
                    $id = $this->generateId($entity, $row[$primary], $row, isset($xml->fields['id']) && $xml->fields['id'] ? (string) $xml->fields['id'] : null);
                }
                if (!isset($nodes[$id])) {
                    $node = array();
                    foreach ($xml->fields->field as $field) {
                        $column = (string) $field['name'];
                        if (isset($field['relation'])) {
                            $sql = 'SELECT `id_' . bqSQL($field['relation']) . '`
									FROM `' . bqSQL(_DB_PREFIX_ . $field['relation']) . '`
									WHERE `id_' . bqSQL($field['relation']) . '` = ' . (int) $row[$column];
                            $node[$column] = $this->generateId((string) $field['relation'], Db::getInstance()->getValue($sql));
                            // A little trick to allow storage of some hard values, like '-1' for tab.id_parent
                            if (!$node[$column] && $row[$column]) {
                                $node[$column] = $row[$column];
                            }
                        } else {
                            $node[$column] = $row[$column];
                        }
                    }
                    $nodes[$id] = $node;
                }
                // Store multilang columns
                if ($is_multilang && $row['id_lang']) {
                    $node = array();
                    foreach ($multilang_columns as $column => $is_text) {
                        $node[$column] = $row[isset($alias_multilang[$column]) ? $alias_multilang[$column] : $column];
                    }
                    $nodes_lang[$row['id_lang']][$id] = $node;
                }
            }
        }
        return array('nodes' => $nodes, 'nodes_lang' => $nodes_lang);
    }
Beispiel #15
0
    public function getProducts($refresh = false, $id_product = false, $id_country = null)
    {
        /* 
         * EU-Legal
         * 1) correct calculation of prices -> Problem with inaccuracy at high number of items 
         * 2) assign standard delivery times to products
         */
        if (!$this->id) {
            return array();
        }
        // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
        if ($this->_products !== null && !$refresh) {
            // Return product row with specified ID if it exists
            if (is_int($id_product)) {
                foreach ($this->_products as $product) {
                    if ($product['id_product'] == $id_product) {
                        return array($product);
                    }
                }
                return array();
            }
            return $this->_products;
        }
        // Build query
        $sql = new DbQuery();
        // Build SELECT
        $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
						pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`delivery_now`, pl.`delivery_later`, product_shop.`id_category_default`, p.`id_supplier`,
						p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
						product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`, 
						stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`,
						p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
						CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery,
						product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference, IFNULL(sp.`reduction_type`, 0) AS reduction_type');
        // Build FROM
        $sql->from('cart_product', 'cp');
        // Build JOIN
        $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
        $sql->innerJoin('product_shop', 'product_shop', '(product_shop.`id_shop` = cp.`id_shop` AND product_shop.`id_product` = p.`id_product`)');
        $sql->leftJoin('product_lang', 'pl', '
			p.`id_product` = pl.`id_product`
			AND pl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('pl', 'cp.id_shop'));
        $sql->leftJoin('category_lang', 'cl', '
			product_shop.`id_category_default` = cl.`id_category`
			AND cl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('cl', 'cp.id_shop'));
        $sql->leftJoin('product_supplier', 'ps', 'ps.`id_product` = cp.`id_product` AND ps.`id_product_attribute` = cp.`id_product_attribute` AND ps.`id_supplier` = p.`id_supplier`');
        $sql->leftJoin('specific_price', 'sp', 'sp.`id_product` = cp.`id_product`');
        // AND 'sp.`id_shop` = cp.`id_shop`
        // @todo test if everything is ok, then refactorise call of this method
        $sql->join(Product::sqlStock('cp', 'cp'));
        // Build WHERE clauses
        $sql->where('cp.`id_cart` = ' . (int) $this->id);
        if ($id_product) {
            $sql->where('cp.`id_product` = ' . (int) $id_product);
        }
        $sql->where('p.`id_product` IS NOT NULL');
        // Build GROUP BY
        $sql->groupBy('unique_id');
        // Build ORDER BY
        $sql->orderBy('cp.`date_add`, p.`id_product`, cp.`id_product_attribute` ASC');
        if (Customization::isFeatureActive()) {
            $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity');
            $sql->leftJoin('customization', 'cu', 'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = ' . (int) $this->id);
        } else {
            $sql->select('NULL AS customization_quantity, NULL AS id_customization');
        }
        if (Combination::isFeatureActive()) {
            $sql->select('
				product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
				IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
				(p.`weight`+ pa.`weight`) weight_attribute,
				IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
				IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
				pai.`id_image` as pai_id_image, il.`legend` as pai_legend,
				IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity,
				IF(product_attribute_shop.wholesale_price > 0,  product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price
			');
            $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
            $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');
            $sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`');
            $sql->leftJoin('image_lang', 'il', 'il.`id_image` = pai.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang);
        } else {
            $sql->select('p.`reference` AS reference, p.`ean13`,
				p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price');
        }
        $result = Db::getInstance()->executeS($sql);
        // Reset the cache before the following return, or else an empty cart will add dozens of queries
        $products_ids = array();
        $pa_ids = array();
        if ($result) {
            foreach ($result as $row) {
                $products_ids[] = $row['id_product'];
                $pa_ids[] = $row['id_product_attribute'];
            }
        }
        // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
        Product::cacheProductsFeatures($products_ids);
        Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang);
        $this->_products = array();
        if (empty($result)) {
            return array();
        }
        $cart_shop_context = Context::getContext()->cloneContext();
        foreach ($result as &$row) {
            if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) {
                $row['ecotax'] = (double) $row['ecotax_attr'];
            }
            $row['stock_quantity'] = (int) $row['quantity'];
            // for compatibility with 1.2 themes
            $row['quantity'] = (int) $row['cart_quantity'];
            if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) {
                $row['weight'] = (double) $row['weight_attribute'];
            }
            if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
                $address_id = (int) $this->id_address_invoice;
            } else {
                $address_id = (int) $row['id_address_delivery'];
            }
            if (!Address::addressExists($address_id)) {
                $address_id = null;
            }
            if ($cart_shop_context->shop->id != $row['id_shop']) {
                $cart_shop_context->shop = new Shop((int) $row['id_shop']);
            }
            $address = Address::initialize($address_id, true);
            $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $row['id_product'], $cart_shop_context);
            $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
            $row['price'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, false, true, $cart_shop_context);
            switch (Configuration::get('PS_ROUND_TYPE')) {
                case Order::ROUND_TOTAL:
                    $row['total'] = $row['price'] * (int) $row['cart_quantity'];
                    $row['total_wt'] = $tax_calculator->addTaxes($row['price']) * (int) $row['cart_quantity'];
                    break;
                case Order::ROUND_LINE:
                    $row['total'] = Tools::ps_round($row['price'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                    $row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']) * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
                    break;
                case Order::ROUND_ITEM:
                default:
                    $row['total'] = Tools::ps_round($row['price'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
                    $row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']), _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
                    break;
            }
            $row['price_wt'] = $tax_calculator->addTaxes($row['price']);
            $row['description_short'] = Tools::nl2br($row['description_short']);
            if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0) {
                $cache_id = 'Cart::getProducts_' . '-pai_id_image-' . (int) $row['id_product'] . '-' . (int) $this->id_lang . '-' . (int) $row['id_shop'];
                if (!Cache::isStored($cache_id)) {
                    $row2 = Db::getInstance()->getRow('
						SELECT image_shop.`id_image` id_image, il.`legend`
						FROM `' . _DB_PREFIX_ . 'image` i
						JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $row['id_shop'] . ')
						LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang . ')
						WHERE i.`id_product` = ' . (int) $row['id_product'] . ' AND image_shop.`cover` = 1');
                    Cache::store($cache_id, $row2);
                }
                $row2 = Cache::retrieve($cache_id);
                if (!$row2) {
                    $row2 = array('id_image' => false, 'legend' => false);
                } else {
                    $row = array_merge($row, $row2);
                }
            } else {
                $row['id_image'] = $row['pai_id_image'];
                $row['legend'] = $row['pai_legend'];
            }
            $row['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
            $row['quantity_discount_applies'] = $specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity'];
            $row['id_image'] = Product::defineProductImage($row, $this->id_lang);
            $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
            $row['features'] = Product::getFeaturesStatic((int) $row['id_product']);
            if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) {
                $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]);
            }
            /* 
             * EU-Legal
             * assign standard delivery times to products
             */
            $row['delivery_now'] = !empty($row['delivery_now']) ? $row['delivery_now'] : Configuration::get('LEGAL_DELIVERY_NOW', $this->id_lang);
            $row['delivery_later'] = !empty($row['delivery_later']) ? $row['delivery_later'] : Configuration::get('LEGAL_DELIVERY_LATER', $this->id_lang);
            $row = Product::getTaxesInformations($row, $cart_shop_context);
            $this->_products[] = $row;
        }
        return $this->_products;
    }
 /**
  * Updates positions submitted via Ajax
  */
 public function ajaxProcessUpdatePositions()
 {
     $id_shop = Shop::getContextShopID();
     // Build an array of order IDs (could be a page!)
     $submittedIds = array();
     $rows = (array) Tools::getValue($this->table);
     foreach ($rows as $row) {
         $ids = explode('_', $row);
         $submittedIds[] = (int) $ids[2];
     }
     // Get all IDs from database
     $sql = new DbQuery();
     $sql->select('id_ct_top_menu_item');
     $sql->from('ct_top_menu_item_shop');
     $sql->where('id_shop = ' . (int) $id_shop);
     $sql->orderBy('position ASC');
     $rows = (array) Db::getInstance()->executeS($sql);
     $allIds = array();
     foreach ($rows as $row) {
         $allIds[] = (int) $row['id_ct_top_menu_item'];
     }
     // Go through all IDs, if the ID exists in the sorted ID list (could be fragment (page) or sorted IDs)
     // then pick an ID from sorted ID list and overwrite the value.
     $i = 0;
     foreach ($allIds as $key1 => $id) {
         $key2 = array_search($id, $submittedIds);
         if ($key2 !== false) {
             $allIds[$key1] = $submittedIds[$i++];
         }
     }
     // Update positions of all values the way the are ordered in the array
     $position = 0;
     $isSuccess = true;
     $shopIDs = Shop::getContextListShopID();
     foreach ($allIds as $id_ct_top_menu_item) {
         $isSuccess &= Db::getInstance()->update($this->table . '_shop', array('position' => $position++), 'id_ct_top_menu_item = ' . (int) $id_ct_top_menu_item . ' AND id_shop IN (' . implode(', ', $shopIDs) . ')');
         if (!$isSuccess) {
             break;
         }
     }
     Hook::exec('actionCTTopMenuCompositionChanged');
     if ($isSuccess) {
         die(true);
     } else {
         header('Content-Type: application/json');
         die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->l('Could not update positions in the database table.'))));
     }
 }
Beispiel #17
0
 /**
  * Get list of modules we can execute per hook
  *
  * @since 1.5.0
  * @param string $hook_name Get list of modules for this hook if given
  * @return array
  */
 public static function getHookModuleExecList($hook_name = null)
 {
     $context = Context::getContext();
     $cache_id = 'hook_module_exec_list' . (isset($context->customer) ? '_' . $context->customer->id : '');
     if (!Cache::isStored($cache_id) || $hook_name == 'displayPayment') {
         $frontend = true;
         $groups = array();
         if (isset($context->employee)) {
             $shop_list = array((int) $context->shop->id);
             $frontend = false;
         } else {
             // Get shops and groups list
             $shop_list = Shop::getContextListShopID();
             if (isset($context->customer) && $context->customer->isLogged()) {
                 $groups = $context->customer->getGroups();
             } elseif (isset($context->customer) && $context->customer->isLogged(true)) {
                 $groups = array((int) Configuration::get('PS_GUEST_GROUP'));
             } else {
                 $groups = array((int) Configuration::get('PS_UNIDENTIFIED_GROUP'));
             }
         }
         // SQL Request
         $sql = new DbQuery();
         $sql->select('h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`');
         $sql->from('module', 'm');
         $sql->innerJoin('hook_module', 'hm', 'hm.`id_module` = m.`id_module`');
         $sql->innerJoin('hook', 'h', 'hm.`id_hook` = h.`id_hook`');
         $sql->where('(SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN (' . implode(', ', $shop_list) . ')) = ' . count($shop_list));
         if ($hook_name != 'displayPayment') {
             $sql->where('h.name != "displayPayment"');
         } elseif ($frontend) {
             if (Validate::isLoadedObject($context->country)) {
                 $sql->where('(h.name = "displayPayment" AND (SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country mc WHERE mc.id_module = m.id_module AND id_country = ' . (int) $context->country->id . ' LIMIT 1) = ' . (int) $context->country->id . ')');
             }
             if (Validate::isLoadedObject($context->currency)) {
                 $sql->where('(h.name = "displayPayment" AND (SELECT id_currency FROM ' . _DB_PREFIX_ . 'module_currency mcr WHERE mcr.id_module = m.id_module AND id_currency IN (' . (int) $context->currency->id . ', -2) LIMIT 1) IN (' . (int) $context->currency->id . ', -2))');
             }
         }
         if (Validate::isLoadedObject($context->shop)) {
             $sql->where('hm.id_shop = ' . (int) $context->shop->id);
         }
         if ($frontend) {
             $sql->leftJoin('module_group', 'mg', 'mg.`id_module` = m.`id_module`');
             $sql->where('mg.`id_group` IN (' . implode(', ', $groups) . ')');
             $sql->groupBy('hm.id_hook, hm.id_module');
         }
         $sql->orderBy('hm.`position`');
         // Store results per hook name
         $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
         $list = array();
         // Get all available payment module
         $payment_modules = array();
         if (isset($context->shop->id)) {
             foreach (Module::getPaymentModules() as $module) {
                 $payment_modules[] = $module['name'];
             }
         }
         if ($results) {
             foreach ($results as $row) {
                 if ($row['hook'] == 'displayPayment' && !in_array($row['module'], $payment_modules)) {
                     continue;
                 }
                 $row['hook'] = strtolower($row['hook']);
                 if (!isset($list[$row['hook']])) {
                     $list[$row['hook']] = array();
                 }
                 $list[$row['hook']][] = array('id_hook' => $row['id_hook'], 'module' => $row['module'], 'id_module' => $row['id_module'], 'live_edit' => $row['live_edit']);
             }
         }
         if ($hook_name != 'displayPayment') {
             Cache::store($cache_id, $list);
             // @todo remove this in 1.6, we keep it in 1.5 for retrocompatibility
             self::$_hook_modules_cache_exec = $list;
         }
     } else {
         $list = Cache::retrieve($cache_id);
     }
     // If hook_name is given, just get list of modules for this hook
     if ($hook_name) {
         $retro_hook_name = Hook::getRetroHookName($hook_name);
         $hook_name = strtolower($hook_name);
         $return = array();
         if (isset($list[$hook_name])) {
             $return = $list[$hook_name];
         }
         if (isset($list[$retro_hook_name])) {
             $return = array_merge($return, $list[$retro_hook_name]);
         }
         if (count($return) > 0) {
             return $return;
         }
         return false;
     } else {
         return $list;
     }
 }
Beispiel #18
0
 /**
  * Get list of modules we can execute per hook
  *
  * @since 1.5.0
  * @param string $hook_name Get list of modules for this hook if given
  * @return array
  */
 public static function getHookModuleExecList($hook_name = null)
 {
     $context = Context::getContext();
     $cache_id = 'hook_module_exec_list_' . (isset($context->shop->id) ? '_' . $context->shop->id : '') . (isset($context->customer) ? '_' . $context->customer->id : '');
     if (!Cache::isStored($cache_id) || $hook_name == 'displayPayment' || $hook_name == 'displayPaymentEU' || $hook_name == 'displayBackOfficeHeader') {
         $frontend = true;
         $groups = array();
         $use_groups = Group::isFeatureActive();
         if (isset($context->employee)) {
             $frontend = false;
         } else {
             // Get groups list
             if ($use_groups) {
                 if (isset($context->customer) && $context->customer->isLogged()) {
                     $groups = $context->customer->getGroups();
                 } elseif (isset($context->customer) && $context->customer->isLogged(true)) {
                     $groups = array((int) Configuration::get('PS_GUEST_GROUP'));
                 } else {
                     $groups = array((int) Configuration::get('PS_UNIDENTIFIED_GROUP'));
                 }
             }
         }
         // SQL Request
         $sql = new DbQuery();
         $sql->select('h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`');
         $sql->from('module', 'm');
         if ($hook_name != 'displayBackOfficeHeader') {
             $sql->join(Shop::addSqlAssociation('module', 'm', true, 'module_shop.enable_device & ' . (int) Context::getContext()->getDevice()));
             $sql->innerJoin('module_shop', 'ms', 'ms.`id_module` = m.`id_module`');
         }
         $sql->innerJoin('hook_module', 'hm', 'hm.`id_module` = m.`id_module`');
         $sql->innerJoin('hook', 'h', 'hm.`id_hook` = h.`id_hook`');
         if ($hook_name != 'displayPayment' && $hook_name != 'displayPaymentEU') {
             $sql->where('h.`name` != "displayPayment" AND h.`name` != "displayPaymentEU"');
         } elseif ($frontend) {
             if (Validate::isLoadedObject($context->country)) {
                 $sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_country` FROM `' . _DB_PREFIX_ . 'module_country` mc WHERE mc.`id_module` = m.`id_module` AND `id_country` = ' . (int) $context->country->id . ' AND `id_shop` = ' . (int) $context->shop->id . ' LIMIT 1) = ' . (int) $context->country->id . ')');
             }
             if (Validate::isLoadedObject($context->currency)) {
                 $sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_currency` FROM `' . _DB_PREFIX_ . 'module_currency` mcr WHERE mcr.`id_module` = m.`id_module` AND `id_currency` IN (' . (int) $context->currency->id . ', -1, -2) LIMIT 1) IN (' . (int) $context->currency->id . ', -1, -2))');
             }
         }
         if (Validate::isLoadedObject($context->shop)) {
             $sql->where('hm.`id_shop` = ' . (int) $context->shop->id);
         }
         if ($frontend) {
             if ($use_groups) {
                 $sql->leftJoin('module_group', 'mg', 'mg.`id_module` = m.`id_module`');
                 if (Validate::isLoadedObject($context->shop)) {
                     $sql->where('mg.`id_shop` = ' . (int) $context->shop->id . (count($groups) ? ' AND  mg.`id_group` IN (' . implode(', ', $groups) . ')' : ''));
                 } elseif (count($groups)) {
                     $sql->where('mg.`id_group` IN (' . implode(', ', $groups) . ')');
                 }
             }
         }
         $sql->groupBy('hm.id_hook, hm.id_module');
         $sql->orderBy('hm.`position`');
         $list = array();
         if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) {
             foreach ($result as $row) {
                 $row['hook'] = strtolower($row['hook']);
                 if (!isset($list[$row['hook']])) {
                     $list[$row['hook']] = array();
                 }
                 $list[$row['hook']][] = array('id_hook' => $row['id_hook'], 'module' => $row['module'], 'id_module' => $row['id_module'], 'live_edit' => $row['live_edit']);
             }
         }
         if ($hook_name != 'displayPayment' && $hook_name != 'displayPaymentEU' && $hook_name != 'displayBackOfficeHeader') {
             Cache::store($cache_id, $list);
             // @todo remove this in 1.6, we keep it in 1.5 for backward compatibility
             self::$_hook_modules_cache_exec = $list;
         }
     } else {
         $list = Cache::retrieve($cache_id);
     }
     // If hook_name is given, just get list of modules for this hook
     if ($hook_name) {
         $retro_hook_name = strtolower(Hook::getRetroHookName($hook_name));
         $hook_name = strtolower($hook_name);
         $return = array();
         $inserted_modules = array();
         if (isset($list[$hook_name])) {
             $return = $list[$hook_name];
         }
         foreach ($return as $module) {
             $inserted_modules[] = $module['id_module'];
         }
         if (isset($list[$retro_hook_name])) {
             foreach ($list[$retro_hook_name] as $retro_module_call) {
                 if (!in_array($retro_module_call['id_module'], $inserted_modules)) {
                     $return[] = $retro_module_call;
                 }
             }
         }
         return count($return) > 0 ? $return : false;
     } else {
         return $list;
     }
 }
 /**
  * Exports CSV
  */
 protected function renderCSV()
 {
     // exports orders
     if (Tools::isSubmit('csv_orders')) {
         $ids = array();
         foreach ($this->_list as $entry) {
             $ids[] = $entry['id_supply_order'];
         }
         if (count($ids) <= 0) {
             return;
         }
         $id_lang = Context::getContext()->language->id;
         $orders = new PrestaShopCollection('SupplyOrder', $id_lang);
         $orders->where('is_template', '=', false);
         $orders->where('id_supply_order', 'in', $ids);
         $id_warehouse = $this->getCurrentWarehouse();
         if ($id_warehouse != -1) {
             $orders->where('id_warehouse', '=', $id_warehouse);
         }
         $orders->getAll();
         $csv = new CSV($orders, $this->l('supply_orders'));
         $csv->export();
     } elseif (Tools::isSubmit('csv_orders_details')) {
         // header
         header('Content-type: text/csv');
         header('Content-Type: application/force-download; charset=UTF-8');
         header('Cache-Control: no-store, no-cache');
         header('Content-disposition: attachment; filename="' . $this->l('supply_orders_details') . '.csv"');
         // echoes details
         $ids = array();
         foreach ($this->_list as $entry) {
             $ids[] = $entry['id_supply_order'];
         }
         if (count($ids) <= 0) {
             return;
         }
         // for each supply order
         $keys = array('id_product', 'id_product_attribute', 'reference', 'supplier_reference', 'ean13', 'upc', 'name', 'unit_price_te', 'quantity_expected', 'quantity_received', 'price_te', 'discount_rate', 'discount_value_te', 'price_with_discount_te', 'tax_rate', 'tax_value', 'price_ti', 'tax_value_with_order_discount', 'price_with_order_discount_te', 'id_supply_order');
         echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $keys)));
         // overrides keys (in order to add FORMAT calls)
         $keys = array('sod.id_product', 'sod.id_product_attribute', 'sod.reference', 'sod.supplier_reference', 'sod.ean13', 'sod.upc', 'sod.name', 'FORMAT(sod.unit_price_te, 2)', 'sod.quantity_expected', 'sod.quantity_received', 'FORMAT(sod.price_te, 2)', 'FORMAT(sod.discount_rate, 2)', 'FORMAT(sod.discount_value_te, 2)', 'FORMAT(sod.price_with_discount_te, 2)', 'FORMAT(sod.tax_rate, 2)', 'FORMAT(sod.tax_value, 2)', 'FORMAT(sod.price_ti, 2)', 'FORMAT(sod.tax_value_with_order_discount, 2)', 'FORMAT(sod.price_with_order_discount_te, 2)', 'sod.id_supply_order');
         foreach ($ids as $id) {
             $query = new DbQuery();
             $query->select(implode(', ', $keys));
             $query->from('supply_order_detail', 'sod');
             $query->leftJoin('supply_order', 'so', 'so.id_supply_order = sod.id_supply_order');
             $id_warehouse = $this->getCurrentWarehouse();
             if ($id_warehouse != -1) {
                 $query->where('so.id_warehouse = ' . (int) $id_warehouse);
             }
             $query->where('sod.id_supply_order = ' . (int) $id);
             $query->orderBy('sod.id_supply_order_detail DESC');
             $resource = Db::getInstance()->query($query);
             // gets details
             while ($row = Db::getInstance()->nextRow($resource)) {
                 echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $row)));
             }
         }
     } elseif (Tools::isSubmit('csv_order_details') && Tools::getValue('id_supply_order')) {
         $supply_order = new SupplyOrder((int) Tools::getValue('id_supply_order'));
         if (Validate::isLoadedObject($supply_order)) {
             $details = $supply_order->getEntriesCollection();
             $details->getAll();
             $csv = new CSV($details, $this->l('supply_order') . '_' . $supply_order->reference . '_details');
             $csv->export();
         }
     }
 }
 /**
  * Returns all menu items for a given shop
  *
  * @param int $id_lang
  * @param int $id_shop
  *
  * @return array
  */
 public static function getMenuItems($id_lang, $id_shop)
 {
     $sql = new DbQuery();
     $sql->select('i.*, il.url, il.title, il.name');
     $sql->from('ct_top_menu_item', 'i');
     $sql->leftJoin('ct_top_menu_item_lang', 'il', 'i.id_ct_top_menu_item = il.id_ct_top_menu_item AND il.id_lang = ' . (int) $id_lang);
     $sql->innerJoin('ct_top_menu_item_shop', 'ishop', 'i.id_ct_top_menu_item = ishop.id_ct_top_menu_item AND ishop.id_shop = ' . (int) $id_shop);
     $sql->orderBy('ishop.position ASC');
     return (array) Db::getInstance()->executeS($sql);
 }
Beispiel #21
0
 /**
  * Get list of parent categories
  *
  * @since 1.5.0
  * @param int $id_lang
  * @return array
  */
 public function getParentCategories($id_lang = null)
 {
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     $interval = Category::getInterval($this->id_category_default);
     $sql = new DbQuery();
     $sql->from('category', 'c');
     $sql->leftJoin('category_lang', 'cl', 'c.id_category = cl.id_category AND id_lang = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl'));
     $sql->where('c.nleft <= ' . (int) $interval['nleft'] . ' AND c.nright >= ' . (int) $interval['nright']);
     $sql->orderBy('c.nleft');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
 }
Beispiel #22
0
    public function searchProducts($query)
    {
        if (version_compare(_PS_VERSION_, '1.5', '<')) {
            $sql = '
				SELECT p.`id_product`, pl.`name`, p.`weight`
				FROM `' . _DB_PREFIX_ . 'category_product` cp
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.`id_product` = cp.`id_product`)
				LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = "' . (int) $this->context->language->id . '")
				WHERE pl.`name` LIKE \'%' . pSQL($query) . '%\'
					OR p.`ean13` LIKE \'%' . pSQL($query) . '%\'
					OR p.`upc` LIKE \'%' . pSQL($query) . '%\'
					OR p.`reference` LIKE \'%' . pSQL($query) . '%\'
					OR p.`supplier_reference` LIKE \'%' . pSQL($query) . '%\'
				GROUP BY `id_product`
				ORDER BY pl.`name` ASC
			';
        } else {
            $sql = new DbQuery();
            $sql->select('p.`id_product`, pl.`name`, p.`weight`');
            $sql->from('category_product', 'cp');
            $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
            $sql->join(Shop::addSqlAssociation('product', 'p'));
            $sql->leftJoin('product_lang', 'pl', '
				p.`id_product` = pl.`id_product`
				AND pl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('pl'));
            $where = 'pl.`name` LIKE \'%' . pSQL($query) . '%\'
			OR p.`ean13` LIKE \'%' . pSQL($query) . '%\'
			OR p.`upc` LIKE \'%' . pSQL($query) . '%\'
			OR p.`reference` LIKE \'%' . pSQL($query) . '%\'
			OR p.`supplier_reference` LIKE \'%' . pSQL($query) . '%\'
			OR  p.`id_product` IN (SELECT id_product FROM ' . _DB_PREFIX_ . 'product_supplier sp WHERE `product_supplier_reference` LIKE \'%' . pSQL($query) . '%\')';
            $sql->groupBy('`id_product`');
            $sql->orderBy('pl.`name` ASC');
            if (Combination::isFeatureActive()) {
                $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product` = p.`id_product`');
                $sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false));
                $where .= ' OR pa.`reference` LIKE \'%' . pSQL($query) . '%\'';
            }
            $sql->where($where);
        }
        $result = Db::getInstance()->executeS($sql);
        if (!$result) {
            return array('found' => false, 'notfound' => $this->l('No product has been found.'));
        }
        foreach ($result as &$product) {
            $product['id_product_attribute'] = Product::getDefaultAttribute($product['id_product']);
            $product['weight_numeric'] = $product['weight'];
            $product['weight'] = sprintf('%.3f', $product['weight']) . ' ' . _DPDPOLAND_DEFAULT_WEIGHT_UNIT_;
        }
        return array('products' => $result, 'found' => true);
    }
Beispiel #23
0
    public function getNewProducts($where, $id_lang, $page_number = 0, $nb_products = 10, $count = false, $order_by = null, $order_way = null, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $front = true;
        if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
            $front = false;
        }
        if ($page_number < 0) {
            $page_number = 0;
        }
        if ($nb_products < 1) {
            $nb_products = 10;
        }
        if (empty($order_by) || $order_by == 'position') {
            $order_by = 'date_add';
        }
        if (empty($order_way)) {
            $order_way = 'DESC';
        }
        if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd') {
            $order_by_prefix = 'p';
        } else {
            if ($order_by == 'name') {
                $order_by_prefix = 'pl';
            }
        }
        if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
            die(Tools::displayError());
        }
        $sql_groups = '';
        if (Group::isFeatureActive()) {
            $groups = FrontController::getCurrentCustomerGroups();
            $sql_groups = 'AND p.`id_product` IN (
					SELECT cp.`id_product`
					FROM `' . _DB_PREFIX_ . 'category_group` cg
					LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
					WHERE cg.`id_group` ' . (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1') . '
				)';
        }
        if (strpos($order_by, '.') > 0) {
            $order_by = explode('.', $order_by);
            $order_by_prefix = $order_by[0];
            $order_by = $order_by[1];
        }
        if ($count) {
            $sql = 'SELECT COUNT(p.`id_product`) AS nb
						FROM `' . _DB_PREFIX_ . 'product` p
						' . Shop::addSqlAssociation('product', 'p') . '
						WHERE product_shop.`active` = 1
						AND product_shop.`date_add` > "' . date('Y-m-d', strtotime('-' . (Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int) Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY')) . '"
						' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
						' . $sql_groups;
            return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
        }
        $sql = new DbQuery();
        $sql->select('p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
				pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
				product_shop.`date_add` > "' . date('Y-m-d', strtotime('-' . (Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int) Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY')) . '" as new');
        $sql->from('product', 'p');
        $sql->join(Shop::addSqlAssociation('product', 'p'));
        $sql->leftJoin('product_lang', 'pl', '
				p.`id_product` = pl.`id_product`
				AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl'));
        $sql->leftJoin('image', 'i', 'i.`id_product` = p.`id_product`');
        $sql->join(Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1'));
        $sql->leftJoin('image_lang', 'il', 'i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang);
        $sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
        $sql->where('product_shop.`active` = 1');
        if ($front) {
            $sql->where('product_shop.`visibility` IN ("both", "catalog")');
        }
        $sql->where('product_shop.`date_add` > "' . date('Y-m-d', strtotime('-' . (Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int) Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY')) . '"');
        if (Group::isFeatureActive()) {
            $sql->where('p.`id_product` IN (
					SELECT cp.`id_product`
					FROM `' . _DB_PREFIX_ . 'category_group` cg
					LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
					WHERE ' . $where . ' cg.`id_group` ' . $sql_groups . '
				)');
        }
        $sql->groupBy('product_shop.id_product');
        $sql->orderBy((isset($order_by_prefix) ? pSQL($order_by_prefix) . '.' : '') . '`' . pSQL($order_by) . '` ' . pSQL($order_way));
        $sql->limit($nb_products, $page_number * $nb_products);
        if (Combination::isFeatureActive()) {
            $sql->select('MAX(product_attribute_shop.id_product_attribute) id_product_attribute');
            $sql->leftOuterJoin('product_attribute', 'pa', 'p.`id_product` = pa.`id_product`');
            $sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1'));
        }
        $sql->join(Product::sqlStock('p', Combination::isFeatureActive() ? 'product_attribute_shop' : 0));
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
        if ($order_by == 'price') {
            Tools::orderbyPrice($result, $order_way);
        }
        if (!$result) {
            return false;
        }
        $products_ids = array();
        foreach ($result as $row) {
            $products_ids[] = $row['id_product'];
        }
        // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
        Product::cacheFrontFeatures($products_ids, $id_lang);
        return Product::getProductsProperties((int) $id_lang, $result);
    }
 /**
  * Get all available taxes
  *
  * @return array Taxes
  */
 public static function getTaxes($id_lang = false, $active_only = true)
 {
     $sql = new DbQuery();
     $sql->select('t.id_tax, t.rate');
     $sql->from('tax', 't');
     $sql->where('t.`deleted` != 1');
     if ($id_lang) {
         $sql->select('tl.name, tl.id_lang');
         $sql->leftJoin('tax_lang', 'tl', 't.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . (int) $id_lang);
         $sql->orderBy('`name` ASC');
     }
     if ($active_only) {
         $sql->where('t.`active` = 1');
     }
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
 }
 public static function getUserEbooks($user_id, $just_id = false)
 {
     if ($user_id == null) {
         return null;
     }
     $user_id = pSQL($user_id);
     $lang_id = pSQL((int) Context::getContext()->language->id);
     $shop_id = pSQL((int) Context::getContext()->shop->id);
     $sql = new DbQuery();
     $sql->select('DISTINCT(PRSTEBK.product_id)');
     if ($just_id == false) {
         $sql->select('PRSTEBK.id_prestaebooks');
         $sql->select('PRSTEBK.ebook_author');
         $sql->select('PRSTEBK.ebook_isbn');
         $sql->select('PRDTLG.link_rewrite');
         $sql->select('PRDTLG.description');
         $sql->select('PRDTLG.name');
         $sql->select('PRDIMG.id_image');
     }
     $sql->from('prestaebooks', 'PRSTEBK');
     $sql->from('product_lang', 'PRDTLG');
     $sql->from('orders', 'ORD');
     $sql->from('order_detail', 'ORDDTL');
     $sql->from('image', 'PRDIMG');
     $sql->where('ORD.valid = 1');
     $sql->where('ORDDTL.product_id = PRSTEBK.product_id');
     $sql->where('ORDDTL.id_order = ORD.id_order');
     $sql->where('PRDTLG.id_product = PRSTEBK.product_id');
     $sql->where('PRDTLG.id_lang = "' . $lang_id . '"');
     $sql->where('PRDTLG.id_shop = "' . $shop_id . '"');
     $sql->where('PRDIMG.id_product = PRSTEBK.product_id');
     $sql->where('PRDIMG.cover = 1');
     $sql->where('ORD.id_customer = "' . $user_id . '"');
     $sql->orderBy('ORD.invoice_date DESC');
     $sql->groupBy('PRSTEBK.product_id');
     return Db::getInstance()->executeS($sql);
 }
Beispiel #26
0
    public function getProducts($refresh = false, $id_product = false, $id_country = null)
    {
        if (!$this->id) {
            return array();
        }
        // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
        if ($this->_products !== null && !$refresh) {
            // Return product row with specified ID if it exists
            if (is_int($id_product)) {
                foreach ($this->_products as $product) {
                    if ($product['id_product'] == $id_product) {
                        return array($product);
                    }
                }
                return array();
            }
            return $this->_products;
        }
        // Build query
        $sql = new DbQuery();
        // Build SELECT
        $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
						pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`,
						p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`,
						product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`, 
						stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`,
						p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
						CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery,
						product_shop.`wholesale_price`, product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference');
        // Build FROM
        $sql->from('cart_product', 'cp');
        // Build JOIN
        $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
        $sql->innerJoin('product_shop', 'product_shop', '(product_shop.`id_shop` = cp.`id_shop` AND product_shop.`id_product` = p.`id_product`)');
        $sql->leftJoin('product_lang', 'pl', '
			p.`id_product` = pl.`id_product`
			AND pl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('pl', 'cp.id_shop'));
        $sql->leftJoin('category_lang', 'cl', '
			product_shop.`id_category_default` = cl.`id_category`
			AND cl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('cl', 'cp.id_shop'));
        $sql->leftJoin('product_supplier', 'ps', 'ps.`id_product` = cp.`id_product` AND ps.`id_product_attribute` = cp.`id_product_attribute` AND ps.`id_supplier` = p.`id_supplier`');
        // @todo test if everything is ok, then refactorise call of this method
        $sql->join(Product::sqlStock('cp', 'cp'));
        // Build WHERE clauses
        $sql->where('cp.`id_cart` = ' . (int) $this->id);
        if ($id_product) {
            $sql->where('cp.`id_product` = ' . (int) $id_product);
        }
        $sql->where('p.`id_product` IS NOT NULL');
        // Build GROUP BY
        $sql->groupBy('unique_id');
        // Build ORDER BY
        $sql->orderBy('p.`id_product`, cp.`id_product_attribute`, cp.`date_add` ASC');
        if (Customization::isFeatureActive()) {
            $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity');
            $sql->leftJoin('customization', 'cu', 'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = ' . (int) $this->id);
        } else {
            $sql->select('NULL AS customization_quantity, NULL AS id_customization');
        }
        if (Combination::isFeatureActive()) {
            $sql->select('
				product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
				IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
				(p.`weight`+ pa.`weight`) weight_attribute,
				IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
				IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
				pai.`id_image` as pai_id_image, il.`legend` as pai_legend,
				IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity
			');
            $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
            $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');
            $sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`');
            $sql->leftJoin('image_lang', 'il', 'il.`id_image` = pai.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang);
        } else {
            $sql->select('p.`reference` AS reference, p.`ean13`,
				p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity');
        }
        $result = Db::getInstance()->executeS($sql);
        // Reset the cache before the following return, or else an empty cart will add dozens of queries
        $products_ids = array();
        $pa_ids = array();
        if ($result) {
            foreach ($result as $row) {
                $products_ids[] = $row['id_product'];
                $pa_ids[] = $row['id_product_attribute'];
            }
        }
        // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
        Product::cacheProductsFeatures($products_ids);
        Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang);
        $this->_products = array();
        if (empty($result)) {
            return array();
        }
        $cart_shop_context = Context::getContext()->cloneContext();
        foreach ($result as &$row) {
            //                        $quantityDiscount = SpecificPrice::getQuantityDiscount((int)$row['id_product'], $row['id_shop'],
            //			(int)$cart->id_currency, (int)$this->vat_address->id_country,
            //			(int)$this->customer->id_default_group, (int)$row['cart_quantity'], false, null, null, $null, true, true, $this->context);
            //
            //                        echo '<pre>';
            //                        print_r($quantityDiscount);
            //                        echo '</pre>';
            if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) {
                $row['ecotax'] = (double) $row['ecotax_attr'];
            }
            $row['stock_quantity'] = (int) $row['quantity'];
            // for compatibility with 1.2 themes
            $row['quantity'] = (int) $row['cart_quantity'];
            if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) {
                $row['weight'] = (double) $row['weight_attribute'];
            }
            if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
                $address_id = (int) $this->id_address_invoice;
            } else {
                $address_id = (int) $row['id_address_delivery'];
            }
            if (!Address::addressExists($address_id)) {
                $address_id = null;
            }
            if ($cart_shop_context->shop->id != $row['id_shop']) {
                $cart_shop_context->shop = new Shop((int) $row['id_shop']);
            }
            if ($this->_taxCalculationMethod == PS_TAX_EXC) {
                $row['price'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 2, null, false, true, (int) $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
                // Here taxes are computed only once the quantity has been applied to the product price
                $row['price_wt'] = Product::getPriceStatic((int) $row['id_product'], true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 2, null, false, true, (int) $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
                $tax_rate = Tax::getProductTaxRate((int) $row['id_product'], (int) $address_id);
                $row['total_wt'] = Tools::ps_round($row['price'] * (double) $row['cart_quantity'] * (1 + (double) $tax_rate / 100), 2);
                $row['total'] = $row['price'] * (int) $row['cart_quantity'];
            } else {
                $row['price'] = Product::getPriceStatic((int) $row['id_product'], false, (int) $row['id_product_attribute'], 2, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
                $row['price_wt'] = Product::getPriceStatic((int) $row['id_product'], true, (int) $row['id_product_attribute'], 2, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
                // In case when you use QuantityDiscount, getPriceStatic() can be return more of 2 decimals
                $row['price_wt'] = Tools::ps_round($row['price_wt'], 2);
                $row['total_wt'] = $row['price_wt'] * (int) $row['cart_quantity'];
                $row['total'] = Tools::ps_round($row['price'] * (int) $row['cart_quantity'], 2);
                $row['description_short'] = Tools::nl2br($row['description_short']);
            }
            if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0) {
                $cache_id = 'Cart::getProducts_' . '-pai_id_image-' . (int) $row['id_product'] . '-' . (int) $this->id_lang . '-' . (int) $row['id_shop'];
                if (!Cache::isStored($cache_id)) {
                    $row2 = Db::getInstance()->getRow('
						SELECT image_shop.`id_image` id_image, il.`legend`
						FROM `' . _DB_PREFIX_ . 'image` i
						JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $row['id_shop'] . ')
						LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang . ')
						WHERE i.`id_product` = ' . (int) $row['id_product'] . ' AND image_shop.`cover` = 1');
                    Cache::store($cache_id, $row2);
                }
                $row2 = Cache::retrieve($cache_id);
                if (!$row2) {
                    $row2 = array('id_image' => false, 'legend' => false);
                } else {
                    $row = array_merge($row, $row2);
                }
            } else {
                $row['id_image'] = $row['pai_id_image'];
                $row['legend'] = $row['pai_legend'];
            }
            $row['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
            $row['quantity_discount_applies'] = $specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity'];
            $row['id_image'] = Product::defineProductImage($row, $this->id_lang);
            $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
            $row['features'] = Product::getFeaturesStatic((int) $row['id_product']);
            if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) {
                $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]);
            }
            if (Context::getContext()->language->id != 1) {
                $row['name'] = Tools::rus2translit($row['name']);
            }
            $row = Product::getTaxesInformations($row, $cart_shop_context);
            $this->_products[] = $row;
        }
        return $this->_products;
    }
Beispiel #27
0
 /**
  * For a given product, returns the warehouses it is stored in
  *
  * @param int $id_product Product Id
  * @param int $id_product_attribute Optional, Product Attribute Id - 0 by default (no attribues)
  * @return array Warehouses Ids and names
  */
 public static function getWarehousesByProductId($id_product, $id_product_attribute = 0)
 {
     if (!$id_product && !$id_product_attribute) {
         return array();
     }
     $query = new DbQuery();
     $query->select('DISTINCT w.id_warehouse, CONCAT(w.reference, " - ", w.name) as name');
     $query->from('warehouse', 'w');
     $query->leftJoin('stock', 's', 's.id_warehouse = w.id_warehouse');
     if ($id_product) {
         $query->where('s.id_product = ' . (int) $id_product);
     }
     if ($id_product_attribute) {
         $query->where('s.id_product_attribute = ' . (int) $id_product_attribute);
     }
     $query->orderBy('w.reference ASC');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
 }
Beispiel #28
0
 /**
  * For a given product, gets the last positive stock mvt
  *
  * @since 1.5.0
  * @param int $id_product
  * @param int $id_product_attribute Use 0 if the product does not have attributes
  * @return bool|array
  */
 public static function getLastPositiveStockMvt($id_product, $id_product_attribute)
 {
     $query = new DbQuery();
     $query->select('sm.*, w.id_currency, (s.usable_quantity = sm.physical_quantity) as is_usable');
     $query->from('stock_mvt', 'sm');
     $query->innerJoin('stock', 's', 's.id_stock = sm.id_stock');
     $query->innerJoin('warehouse', 'w', 'w.id_warehouse = s.id_warehouse');
     $query->where('sm.sign = 1');
     if ($id_product_attribute) {
         $query->where('s.id_product = ' . (int) $id_product . ' AND s.id_product_attribute = ' . (int) $id_product_attribute);
     } else {
         $query->where('s.id_product = ' . (int) $id_product);
     }
     $query->orderBy('date_add DESC');
     $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
     if ($res != false) {
         return $res['0'];
     }
     return false;
 }
Beispiel #29
0
 public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true)
 {
     $sql = new DbQuery();
     $sql->select('*');
     $sql->from('cms', 'c');
     if ($id_lang) {
         $sql->innerJoin('cms_lang', 'l', 'c.id_cms = l.id_cms AND l.id_lang = ' . (int) $id_lang);
     }
     if ($active) {
         $sql->where('c.active = 1');
     }
     if ($id_cms_category) {
         $sql->where('c.id_cms_category = ' . (int) $id_cms_category);
     }
     $sql->orderBy('position');
     return Db::getInstance()->executeS($sql);
 }
    private function getAbandonedCartInfo()
    {
        if ((int) $this->cart_id < 1) {
            return false;
        }
        $query_limit = 0;
        $query_offset = 0;
        $cart_products = array();
        if ($this->page !== null && !empty($this->page) && $this->show !== null && !empty($this->show)) {
            $query_limit = ((int) $this->page - 1) * (int) $this->show;
            $query_offset = (int) $this->show;
        }
        // Get cart information
        $cart_info_obj = new DbQuery();
        $cart_info_obj->select("\r\n\t\t\tc.id_cart,\r\n\t\t\tc.date_add,\r\n\t\t\tc.id_currency,\r\n\t\t\tc.id_customer,\r\n\t\t\tcus.date_add AS account_registered,\r\n\t\t\tcus.email,\r\n\t\t\ta.phone,\r\n\t\t\tCONCAT(cus.firstname, ' ', cus.lastname) AS customer,\r\n\t\t\ts.name AS shop_name,\r\n\t\t\tcar.name AS carrier_name,\r\n\t\t\tSUM((ps.price + pas.price) * cp.quantity) AS cart_total\r\n\t\t");
        $cart_info_obj->from('cart', 'c');
        $cart_info_obj->innerJoin('cart_product', 'cp', 'cp.id_cart = c.id_cart');
        $cart_info_obj->leftJoin('product_shop', 'ps', 'ps.id_product = cp.id_product AND ps.id_shop = cp.id_shop');
        $cart_info_obj->leftJoin('product_attribute_shop', 'pas', 'pas.id_product_attribute = cp.id_product_attribute AND pas.id_shop = cp.id_shop');
        $cart_info_obj->leftJoin('customer', 'cus', 'c.id_customer = cus.id_customer');
        $cart_info_obj->leftJoin('address', 'a', 'a.id_customer = cus.id_customer');
        $cart_info_obj->leftJoin('shop', 's', 's.id_shop = c.id_shop');
        $cart_info_obj->leftJoin('carrier', 'car', 'car.id_carrier = c.id_carrier');
        $cart_info_obj->where('c.id_cart = ' . (int) $this->cart_id);
        $cart_info_obj->groupBy('c.id_cart');
        $cart_info_sql = $cart_info_obj->build();
        $cart_info = Db::getInstance()->executeS($cart_info_sql);
        $cart_info = array_shift($cart_info);
        if (trim($cart_info['customer']) == '') {
            $cart_info['customer'] = self::GUEST;
        }
        // Convert and format price data
        if ($this->currency_code != $cart_info['id_currency']) {
            $cart_info['cart_total'] = $this->convertPrice($cart_info['cart_total'], $this->def_currency, $cart_info['id_currency']);
        }
        $cart_info['cart_total'] = $this->displayPrice($cart_info['cart_total'], $cart_info['id_currency']);
        // Get cart products
        $cart_products_obj = new DbQuery();
        $cart_products_obj->select('
			cp.id_product,
			cp.id_product_attribute,
			cp.quantity AS product_quantity,
			p.reference AS sku,
			(ps.price + pas.price) AS product_price,
			(ps.wholesale_price + pas.wholesale_price) AS wholesale_price,
			c.id_currency,
			pl.name AS product_name,
			pl.link_rewrite
		');
        $cart_products_obj->from('cart_product', 'cp');
        $cart_products_obj->leftJoin('product_shop', 'ps', 'ps.id_product = cp.id_product AND ps.id_shop = cp.id_shop');
        $cart_products_obj->leftJoin('product_attribute_shop', 'pas', 'pas.id_product_attribute = cp.id_product_attribute AND pas.id_shop = cp.id_shop');
        $cart_products_obj->leftJoin('product', 'p', 'p.id_product = cp.id_product');
        $cart_products_obj->leftJoin('cart', 'c', 'c.id_cart = cp.id_cart');
        $cart_products_obj->leftJoin('product_lang', 'pl', 'pl.id_product = cp.id_product AND pl.id_shop = cp.id_shop AND pl.id_lang = ' . (int) $this->def_lang);
        $cart_products_obj->where('cp.id_cart = ' . (int) $this->cart_id);
        $cart_products_obj->limit($query_offset, $query_limit);
        $cart_products_sql = $cart_products_obj->build();
        $cart_products_res = Db::getInstance()->executeS($cart_products_sql);
        // Get attribute values
        foreach ($cart_products_res as $product) {
            $product_attributes_obj = new DbQuery();
            $product_attributes_obj->select('
				al.name AS attribute_value,
				agl.public_name AS attribute_name
			');
            $product_attributes_obj->from('product_attribute_combination', 'pac');
            $product_attributes_obj->leftJoin('attribute_lang', 'al', 'al.id_attribute = pac.id_attribute AND al.id_lang = ' . (int) $this->def_lang);
            $product_attributes_obj->leftJoin('attribute', 'a', 'a.id_attribute = pac.id_attribute');
            $product_attributes_obj->leftJoin('attribute_group_lang', 'agl', 'agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = ' . (int) $this->def_lang);
            $product_attributes_obj->where('pac.id_product_attribute = ' . (int) $product['id_product_attribute']);
            $product_attributes_obj->orderBy('attribute_name');
            $product_attributes_sql = $product_attributes_obj->build();
            $product_attributes = Db::getInstance()->executeS($product_attributes_sql);
            $product_attr = array();
            foreach ($product_attributes as $product_attribute) {
                $product_attr[] = $product_attribute['attribute_name'] . ' : ' . $product_attribute['attribute_value'];
            }
            $product['combination'] = !empty($product_attr) ? implode(', ', $product_attr) : '';
            // Convert and form price data
            if ($this->currency_code != $this->def_currency) {
                $product['product_price'] = $this->convertPrice($product['product_price'], $this->def_currency, $product['id_currency']);
                $product['wholesale_price'] = $this->convertPrice($product['wholesale_price'], $this->def_currency, $product['id_currency']);
            }
            $product['product_price'] = $this->displayPrice($product['product_price'], $product['id_currency']);
            $product['wholesale_price'] = $this->displayPrice($product['wholesale_price'], $product['id_currency']);
            // Get url of product image
            $image_url = $this->getProductImageUrl($product['id_product'], $product['link_rewrite']);
            if ($image_url) {
                $product['product_image'] = $image_url;
            }
            $cart_products[] = $product;
        }
        // Get cart product count
        $cart_product_count_obj = new DbQuery();
        $cart_product_count_obj->select('
			COUNT(cp.id_product) AS product_count
		');
        $cart_product_count_obj->from('cart_product', 'cp');
        $cart_product_count_obj->where('cp.id_cart = ' . (int) $this->cart_id);
        $cart_product_count_sql = $cart_product_count_obj->build();
        $cart_product_count_res = Db::getInstance()->executeS($cart_product_count_sql);
        $cart_product_count_res = array_shift($cart_product_count_res);
        return array('cart_info' => $cart_info, 'cart_products' => $cart_products, 'cart_products_count' => $cart_product_count_res['product_count']);
    }