Example #1
0
    public function get($limit = 10, $noloadid = 0)
    {
        global $cookie;
        $_content = array();
        if (isset($cookie->viewed) && strlen($cookie->viewed) > 0) {
            $_content = explode(",", $cookie->viewed);
        }
        $product_ids = array();
        $content_num = count($_content);
        if ($content_num > 0) {
            $j = 0;
            for ($i = $content_num - 1; $i >= 0; $i--) {
                if ($_content[$i] != $noloadid) {
                    $product_ids[] = $_content[$i];
                    $j++;
                }
                if ($j >= $limit) {
                    break;
                }
            }
        } else {
            return false;
        }
        if (count($product_ids) == 0) {
            return false;
        }
        $result = Db::getInstance()->ExecuteS('SELECT p.*,b.name AS brand FROM `' . _DB_PREFIX_ . 'product` p
		LEFT JOIN `' . _DB_PREFIX_ . 'brand` b ON b.id_brand=p.id_brand
		WHERE id_product IN(' . implode(',', array_map('intval', $product_ids)) . ')');
        if (!$result) {
            return false;
        }
        return Product::reLoad($result);
    }
Example #2
0
    public function getThisTags($p = 1, $limit = 50)
    {
        $result = Db::getInstance()->getAll('SELECT p.* FROM `' . DB_PREFIX . 'product` p
				LEFT JOIN `' . DB_PREFIX . 'product_to_tag` ptt ON (ptt.`id_product` = p.`id_product`)
				LEFT JOIN `' . DB_PREFIX . 'tag` t ON (t.`id_tag` = ptt.`id_tag`)
				WHERE t.`id_tag`=' . (int) $this->id . ' AND p.active=1
				ORDER BY p.`id_product` DESC
				LIMIT ' . ($p - 1) * $limit . ',' . (int) $limit);
        $rows = array('total' => count($result), 'entity' => Product::reLoad($result));
        return $rows;
    }
Example #3
0
    public function hookDisplay()
    {
        global $smarty, $cookie;
        $result = Db::getInstance()->getAll('SELECT a.*
				FROM `' . DB_PREFIX . 'product` a
				WHERE a.active=1 AND a.is_top=1
				LIMIT 0,4');
        $products = Product::reLoad($result);
        $smarty->assign('products', $products);
        $display = $this->display(__FILE__, 'homeproduct.tpl');
        return $display;
    }
Example #4
0
    public static function getWishProductWithUser($id_user)
    {
        $products = array();
        $result = Db::getInstance()->getAll('
				  SELECT p.* FROM ' . DB_PREFIX . 'wish w
				  LEFT JOIN ' . DB_PREFIX . 'product p ON (w.`id_product` = p.`id_product`)
				  WHERE w.id_user=' . (int) $id_user);
        if (!$result) {
            return 0;
        }
        $products = Product::reLoad($result);
        return $products;
    }
Example #5
0
    public function getBrandProducts($p = 1, $limit = 50, $orderBy = NULL, $orderWay = NULL, $filter = array())
    {
        $cid = isset($filter['id_style']) ? intval($filter['id_style']) : 0;
        $where = '';
        if (!empty($filter['id_color']) && is_array($filter['id_color'])) {
            $where .= ' AND a.`id_color` IN(' . implode(',', array_map("intval", $filter['id_color'])) . ')';
        }
        if (!empty($filter['id_brand']) && is_array($filter['id_brand'])) {
            $where .= ' AND a.`id_brand` IN(' . implode(',', array_map("intval", $filter['id_brand'])) . ')';
        }
        if ($cid > 0) {
            $where .= ' AND ptc.`id_category`=' . intval($cid);
        }
        $cache_key = 'hot-sale-' . md5($cid . ':' . $p . ':' . $limit . ':' . $orderBy . ':' . $orderWay . ':' . $where);
        if (!($rows = Cache::getInstance()->get($cache_key))) {
            if (!is_null($orderBy) and !is_null($orderWay)) {
                $postion = 'ORDER BY a.' . pSQL($orderBy) . ' ' . pSQL($orderWay);
            } else {
                $postion = 'ORDER BY a.`id_product` DESC';
            }
            $total = Db::getInstance()->getRow('SELECT count(*) AS total FROM `' . DB_PREFIX . 'product` a
					' . ($cid > 0 ? 'LEFT JOIN `' . DB_PREFIX . 'product_to_category` ptc ON a.id_product = ptc.id_product' : '') . '
					WHERE a.active=1 ' . $where);
            if ($total == 0) {
                return false;
            }
            $result = Db::getInstance()->getAll('SELECT a.*
					FROM `' . DB_PREFIX . 'product` a
					' . ($cid > 0 ? 'LEFT JOIN `' . DB_PREFIX . 'product_to_category` ptc ON a.id_product = ptc.id_product' : '') . '
					WHERE a.active=1 ' . $where . '
					' . $postion . '
					LIMIT ' . ($p - 1) * $limit . ',' . (int) $limit);
            $rows = array('total' => $total['total'], 'entitys' => Product::reLoad($result));
            Cache::getInstance()->set($cache_key, $rows);
        }
        /*else{
        			foreach($rows as &$row)
        			{
        				$row['orders']= self::ordersWithProduct($row['id_product']);
        				$row['rating']= self::feedbacStateWithProduct($row['id_product']);
        			}
        		}*/
        return $rows;
    }
Example #6
0
    public function getProducts($p = 1, $limit = 50, $orderBy = NULL, $orderWay = NULL)
    {
        $cache_key = 'color-' . md5($this->id . ':' . $p . ':' . $limit . ':' . $orderBy . ':' . $orderWay);
        if (!($rows = Cache::getInstance()->get($cache_key))) {
            if (!is_null($orderBy) and !is_null($orderWay)) {
                $postion = 'ORDER BY a.' . pSQL($orderBy) . ' ' . pSQL($orderWay);
            } else {
                $postion = 'ORDER BY a.`id_product` DESC';
            }
            $total = Db::getInstance()->getRow('SELECT count(*) AS total FROM `' . DB_PREFIX . 'product` a
					WHERE a.active=1 AND a.id_color=' . (int) $this->id);
            if ($total == 0) {
                return false;
            }
            $result = Db::getInstance()->getAll('SELECT a.*
					FROM `' . DB_PREFIX . 'product` a
					WHERE a.active=1 AND a.id_color=' . (int) $this->id . '
					' . $postion . '
					LIMIT ' . ($p - 1) * $limit . ',' . (int) $limit);
            $rows = array('total' => $total['total'], 'entitys' => Product::reLoad($result));
            Cache::getInstance()->set($cache_key, $rows);
        }
        return $rows;
    }