<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.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/osl-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@buy-addons.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    Buy-Addons <contact@buy-addons.com>
*  @copyright 2007-2020 PrestaShop SA
*  @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
* @since 1.6
*/

class AskforaquotemodulbasearchproductModuleFrontController extends ModuleFrontController
{
    public function run()
    {
        $quote_module_token = Tools::getValue('quote_token');
        if ($quote_module_token != md5(sha1(_COOKIE_KEY_.'askforaquotemodul'))) {
            die;
        } else {
            $store_product = array();
            $id_lang = $this->context->language->id;
            $key_search = Tools::getValue('search_product');
            $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
            $data_include_pro = 'Select id_product from ' . _DB_PREFIX_ . 'include_product_dbboo';
            $data_include_product = $db->executeS($data_include_pro, true, false);
            $data_include_pro_save = 'Select id_product from ' . _DB_PREFIX_ . 'include_product_dbboo_save';
            $data_include_product_save = $db->executeS($data_include_pro_save, true, false);
            $store_product = array_merge($data_include_product, $data_include_product_save);
            $sql_search = 'SELECT name,id_product FROM ' . _DB_PREFIX_ . 'product_lang WHERE name LIKE  "%';
            $sql_search .= pSQL($key_search) . '%" and id_product NOT IN (';
            foreach ($store_product as $key => $value) {
                $value;
                $sql_search .= '"'.(int)$store_product[$key]['id_product'] .'",';
            }
            $sql_search .= '"") and id_lang like "'.(int)$id_lang.'"';
            $include_product = $db->executeS($sql_search, true, false);
            $count_sp = Count($include_product);
            $include_product['number_pr'] = $count_sp;
            echo Tools::jsonEncode($include_product);
        }
    }
}
