Example #1
0
 /**
  * Search a specific string in the products and categories
  *
  * @params string $query String to find in the catalog
  */
 public function searchCatalog($query)
 {
     global $cookie;
     $this->_list['products'] = Product::searchByName((int) $cookie->id_lang, $query);
     if (!empty($this->_list['products'])) {
         for ($i = 0; $i < count($this->_list['products']); $i++) {
             $this->_list['products'][$i]['nameh'] = str_ireplace($query, '<span class="highlight">' . Tools::htmlentitiesUTF8($query) . '</span>', $this->_list['products'][$i]['name']);
         }
     }
     $this->_list['categories'] = Category::searchByName((int) $cookie->id_lang, $query);
 }
Example #2
0
 /**
  * Search a specific string in the products and categories
  *
  * @params string $query String to find in the catalog
  */
 public function searchCatalog($query)
 {
     global $cookie;
     $products = false;
     if (Validate::isCatalogName($query)) {
         $this->_list['products'] = Product::searchByName(intval($cookie->id_lang), $query);
         if (!empty($this->_list['products'])) {
             for ($i = 0; $i < count($this->_list['products']); $i++) {
                 $this->_list['products'][$i]['nameh'] = str_ireplace($query, '<span class="highlight">' . $query . '</span>', $this->_list['products'][$i]['name']);
             }
         }
     }
     if (Validate::isCatalogName($query)) {
         $this->_list['categories'] = Category::searchByName(intval($cookie->id_lang), $query);
     }
 }
 /**
  * Search a specific string in the products and categories
  *
  * @params string $query String to find in the catalog
  */
 public function searchCatalog()
 {
     $this->context = Context::getContext();
     $this->_list['products'] = Product::searchByName($this->context->language->id, $this->query);
     $this->_list['categories'] = Category::searchByName($this->context->language->id, $this->query);
 }
 protected function searchProducts($search)
 {
     if ($products = Product::searchByName((int) $this->context->language->id, $search)) {
         foreach ($products as &$product) {
             $combinations = array();
             $productObj = new Product((int) $product['id_product'], false, (int) $this->context->language->id);
             $attributes = $productObj->getAttributesGroups((int) $this->context->language->id);
             $product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $this->context->currency), $this->context->currency);
             foreach ($attributes as $attribute) {
                 if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) {
                     $combinations[$attribute['id_product_attribute']]['attributes'] = '';
                 }
                 $combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'] . ' - ';
                 $combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
                 $combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
                 if (!isset($combinations[$attribute['id_product_attribute']]['price'])) {
                     $price_tax_incl = Product::getPriceStatic((int) $product['id_product'], true, $attribute['id_product_attribute']);
                     $combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_incl, $this->context->currency), $this->context->currency);
                 }
             }
             foreach ($combinations as &$combination) {
                 $combination['attributes'] = rtrim($combination['attributes'], ' - ');
             }
             $product['combinations'] = $combinations;
         }
         return array('products' => $products, 'found' => true);
     } else {
         return array('found' => false, 'notfound' => Tools::displayError('No product has been found.'));
     }
 }
Example #5
0
 public function ajaxProcessSearchProducts()
 {
     Context::getContext()->customer = new Customer((int) Tools::getValue('id_customer'));
     $currency = new Currency((int) Tools::getValue('id_currency'));
     if ($products = Product::searchByName((int) $this->context->language->id, pSQL(Tools::getValue('product_search')))) {
         foreach ($products as &$product) {
             // Formatted price
             $product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $currency), $currency);
             // Concret price
             $product['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_incl'], $currency), 2);
             $product['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_excl'], $currency), 2);
             $productObj = new Product((int) $product['id_product'], false, (int) $this->context->language->id);
             $combinations = array();
             $attributes = $productObj->getAttributesGroups((int) $this->context->language->id);
             // Tax rate for this customer
             if (Tools::isSubmit('id_address')) {
                 $product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address')));
             }
             $product['warehouse_list'] = array();
             foreach ($attributes as $attribute) {
                 if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) {
                     $combinations[$attribute['id_product_attribute']]['attributes'] = '';
                 }
                 $combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'] . ' - ';
                 $combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
                 $combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
                 if (!isset($combinations[$attribute['id_product_attribute']]['price'])) {
                     $price_tax_incl = Product::getPriceStatic((int) $product['id_product'], true, $attribute['id_product_attribute']);
                     $price_tax_excl = Product::getPriceStatic((int) $product['id_product'], false, $attribute['id_product_attribute']);
                     $combinations[$attribute['id_product_attribute']]['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($price_tax_incl, $currency), 2);
                     $combinations[$attribute['id_product_attribute']]['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), 2);
                     $combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_excl, $currency), $currency);
                 }
                 if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) {
                     $combinations[$attribute['id_product_attribute']]['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], $attribute['id_product_attribute'], (int) $this->context->shop->id);
                 }
                 if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) {
                     $product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']);
                 } else {
                     $product['warehouse_list'][$attribute['id_product_attribute']] = array();
                 }
                 $product['stock'][$attribute['id_product_attribute']] = Product::getRealQuantity($product['id_product'], $attribute['id_product_attribute']);
             }
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1) {
                 $product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']);
             } else {
                 $product['warehouse_list'][0] = array();
             }
             $product['stock'][0] = StockAvailable::getQuantityAvailableByProduct((int) $product['id_product'], 0, (int) $this->context->shop->id);
             foreach ($combinations as &$combination) {
                 $combination['attributes'] = rtrim($combination['attributes'], ' - ');
             }
             $product['combinations'] = $combinations;
             if ($product['customizable']) {
                 $product_instance = new Product((int) $product['id_product']);
                 $product['customization_fields'] = $product_instance->getCustomizationFields($this->context->language->id);
             }
         }
         $to_return = array('products' => $products, 'found' => true);
     } else {
         $to_return = array('found' => false);
     }
     $this->content = Tools::jsonEncode($to_return);
 }
 *
 * @author    PrestaShop SA <*****@*****.**>
 * @copyright 2007-2015 PrestaShop SA
 * @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
*/
include_once realpath(dirname(__FILE__) . '/../../../') . '/config/config.inc.php';
include_once _PS_ROOT_DIR_ . '/init.php';
include_once _PS_MODULE_DIR_ . 'mailjet/mailjet.php';
$return = '';
if (Tools::getValue('token') != Configuration::get('SEGMENT_CUSTOMER_TOKEN')) {
    exit;
}
if (Tools::getValue('action') == 'product') {
    if (Tools::getValue('name') != '') {
        $products = Product::searchByName(Configuration::get('PS_LANG_DEFAULT'), Tools::getValue('name'));
        if ($products) {
            $i = 0;
            $return = '<ul id="plugproduct' . Tools::safeOutput(Tools::getValue('id')) . '">';
            foreach ($products as $product) {
                $name = str_replace("'", '&#146;', $product['name']);
                $name = str_replace('"', '\\"', $name);
                if ($i % 2 == 0) {
                    $return .= '<li id="' . Tools::safeOutput($product['id_product']) . '" class="pair">' . Tools::safeOutput($name) . '</li>';
                } else {
                    $return .= '<li id="' . Tools::safeOutput($product['id_product']) . '" class="impair">' . Tools::safeOutput($name) . '</li>';
                }
                $i++;
            }
            $return .= '</ul>';
        }
 public function searchAction()
 {
     $rows = Product::searchByName($this->getParam('search'));
     $this->view->products = $rows;
     $this->render('index');
 }