예제 #1
0
    public static function getProductsIdFromProductField($id_search, $field_value, $field)
    {
        if ($field == 'stock') {
            $field = 'quantity';
            $where_clause = (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'sa.' : 'p.') . '`' . $field . '` >= ' . (int) $field_value;
        } else {
            if ($field == 'weight' || $field == 'width' || $field == 'height' || $field == 'depth') {
                $where_clause = 'ROUND(p.`' . $field . '`,5) = ROUND(' . pSQL($field_value) . ',5)';
            } else {
                if ($field == 'pack') {
                    $where_clause = 'p.id_product IN (SELECT id_pack FROM `' . _DB_PREFIX_ . 'pm_advancedpack`)';
                } else {
                    $where_clause = 'p.`' . $field . '` = "' . pSQL($field_value) . '"';
                }
            }
        }
        return Db::getInstance()->ExecuteS('
				SELECT acp.`id_cache_product`
				FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_' . (int) $id_search . '` acp
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.`id_product` = acp.`id_product`)
				' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? AdvancedSearchCoreClass::addSqlAssociation('product', 'p', 'id_product') : '') . '
				' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa ON (p.`id_product` = sa.`id_product` ' . self::_addSqlShopRestrictionStockAvailable('sa') . ') ' : '') . '
				WHERE ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive() ? 'p_shop' : 'p') . '.`active` = 1 AND ' . $where_clause);
    }