Beispiel #1
0
    public static function getRandomSpecial($id_lang, $beginning = false, $ending = false, Context $context = null)
    {
        if (!Module::isInstalled('agilemultipleseller')) {
            return parent::getRandomSpecial($id_lang, $beginning, $ending, $context);
        }
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p", true);
        if (!$context) {
            $context = Context::getContext();
        }
        $front = true;
        if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
            $front = false;
        }
        $current_date = date('Y-m-d H:i:s');
        $product_reductions = Product::_getProductIdByDate(!$beginning ? $current_date : $beginning, !$ending ? $current_date : $ending, $context, true);
        if ($product_reductions) {
            $ids_product = ' AND (';
            foreach ($product_reductions as $product_reduction) {
                $ids_product .= '( product_shop.`id_product` = ' . (int) $product_reduction['id_product'] . ($product_reduction['id_product_attribute'] ? ' AND product_attribute_shop.`id_product_attribute`=' . (int) $product_reduction['id_product_attribute'] : '') . ') OR';
            }
            $ids_product = rtrim($ids_product, 'OR') . ')';
            $groups = FrontController::getCurrentCustomerGroups();
            $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
            $sql = 'SELECT product_shop.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute
					FROM `' . _DB_PREFIX_ . 'product` p
					' . Shop::addSqlAssociation('product', 'p') . '
					LEFT JOIN  `' . _DB_PREFIX_ . 'product_attribute` pa ON (product_shop.id_product = pa.id_product)
					' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1') . '
					' . $agile_sql_parts['joins'] . '
					WHERE product_shop.`active` = 1
						' . ($ids_product ? $ids_product : '') . '
						' . $agile_sql_parts['wheres'] . '
						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` ' . $sql_groups . '
						)
					' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
					GROUP BY product_shop.id_product
					ORDER BY RAND()';
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
            if (!($id_product = $result['id_product'])) {
                return false;
            }
            $sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
						pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
						p.`ean13`, p.`upc`, MAX(image_shop.`id_image`) id_image, il.`legend`,
						DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
						INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . '
							DAY)) > 0 AS new
					FROM `' . _DB_PREFIX_ . 'product` p
					LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
						p.`id_product` = pl.`id_product`
						AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
					)
					' . Shop::addSqlAssociation('product', 'p') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
					' . Product::sqlStock('p', 0) . '
					' . $agile_sql_parts['joins'] . '
					WHERE p.id_product = ' . (int) $id_product . '
						' . $agile_sql_parts['wheres'] . '
					GROUP BY product_shop.id_product';
            $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
            if (!$row) {
                return false;
            }
            if ($result['id_product_attribute']) {
                $row['id_product_attribute'] = $result['id_product_attribute'];
            }
            return Product::getProductProperties($id_lang, $row);
        } else {
            return false;
        }
    }