Exemplo n.º 1
0
 public function cron()
 {
     $context = Context::getContext();
     //need for Product::getPriceStatic() method
     $context->employee = true;
     Cmsearch::indexation();
 }
Exemplo n.º 2
0
 public function createIndexFields()
 {
     $fields = Cmsearch::getFields();
     $s_fields = array();
     foreach ($fields as $key => $val) {
         $s_fields[$this->sanitize($key)] = '';
     }
     $url = $this->url . '/scheme/createfields?catalog=products';
     $url = str_replace('api.', 'admin.', $url);
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, Tools::jsonEncode(array($s_fields)));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_SSLCERT, $this->cert);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
     $data = curl_exec($ch);
     if (curl_errno($ch)) {
         return false;
     }
     unset($data);
     return true;
 }
Exemplo n.º 3
0
 public function displayAjax()
 {
     $query = Tools::getValue('search_query');
     $original_query = $query;
     $query = Tools::replaceAccentedChars(urldecode($query));
     $this->productSort();
     $this->n = abs((int) Tools::getValue('n', isset($this->context->cookie->nb_item_per_page) ? (int) $this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE')));
     $this->p = abs((int) Tools::getValue('p', 1));
     $facets = Tools::getValue('cm_select');
     $search = Cmsearch::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay, false, true, null, $facets);
     if ($search) {
         $position = 1;
         foreach ($search['result'] as &$product) {
             $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'] . '&pid=' . (int) $product['id_product'] . '&position=' . $position . '&page=' . $this->p . '&num=' . $this->n;
             $position++;
         }
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) {
             $this->addColorsToProductList($search['result']);
         }
         if (stripos($search['cm_result']->State, 'nothing')) {
             $cm_message = 'nothing found';
         } elseif (!empty($search['cm_result']->Corrections) && $search['cm_result']->Corrections[0]->Apply) {
             if (!empty($search['cm_result']->Query)) {
                 $cm_message = 'your request has been corrected to ' . $search['cm_result']->Query;
             } else {
                 $cm_message = 'nothing found';
             }
         } else {
             $cm_message = false;
         }
         $this->context->smarty->assign(array('search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => !empty($search['cm_result']->OriginalQuery) ? $search['cm_result']->OriginalQuery : ' ', 'cm_message' => $cm_message, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
         $list = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'convermax/views/templates/front/search.tpl');
         $this->context->smarty->assign(array('facets' => $search['cm_result']->Facets, 'query' => $search['cm_result']->Query, 'pagenumber' => $this->p, 'pagesize' => $this->n, 'col_img_dir' => _PS_COL_IMG_DIR_));
         $facets = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'convermax/views/templates/hook/facet.tpl');
         $vars = array('productList' => utf8_encode($list), 'facets' => $facets, 'redirect_url' => isset($search['cm_result']->Actions[0]->RedirectUrl) ? $search['cm_result']->Actions[0]->RedirectUrl : false);
     } else {
         $this->context->smarty->assign(array('search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => !empty($original_query) ? $original_query : ' ', 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
         $list = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'convermax/views/templates/front/search.tpl');
         $vars = array('productList' => utf8_encode($list), 'facets' => array(), 'redirect_url' => false);
     }
     echo Tools::jsonEncode($vars);
 }
Exemplo n.º 4
0
    public static function getFields()
    {
        $fields = array('id_product' => '', 'id_supplier' => '', 'id_manufacturer' => '', 'id_category_default' => '', 'id_shop_default' => '', 'id_tax_rules_group' => '', 'on_sale' => '', 'online_only' => '', 'ean13' => '', 'upc' => '', 'ecotax' => '', 'quantity' => '', 'minimal_quantity' => '', 'price' => '', 'wholesale_price' => '', 'unity' => '', 'unit_price_ratio' => '', 'additional_shipping_cost' => '', 'reference' => '', 'supplier_reference' => '', 'location' => '', 'width' => '', 'height' => '', 'depth' => '', 'weight' => '', 'out_of_stock' => '', 'quantity_discount' => '', 'customizable' => '', 'uploadable_files' => '', 'text_fields' => '', 'active' => '', 'redirect_type' => '', 'id_product_redirected' => '', 'available_for_order' => '', 'available_date' => '', 'condition' => '', 'show_price' => '', 'indexed' => '', 'visibility' => '', 'cache_is_pack' => '', 'cache_has_attachments' => '', 'is_virtual' => '', 'cache_default_attribute' => '', 'date_add' => '', 'date_upd' => '', 'advanced_stock_management' => '', 'pack_stock_type' => '', 'id_shop' => '', 'id_lang' => '', 'description' => '', 'description_short' => '', 'link_rewrite' => '', 'meta_description' => '', 'meta_keywords' => '', 'meta_title' => '', 'name' => '', 'available_now' => '', 'available_later' => '', 'manufacturer_name' => '', 'supplier_name' => '', 'allow_oosp' => '', 'id_product_attribute' => '', 'category' => '', 'link' => '', 'attribute_price' => '', 'price_tax_exc' => '', 'price_without_reduction' => '', 'reduction' => '', 'specific_prices' => '', 'quantity_all_versions' => '', 'id_image' => '', 'virtual' => '', 'pack' => '', 'nopackprice' => '', 'customization_required' => '', 'rate' => '', 'tax_name' => '', 'img_link' => '', 'category_full' => '');
        $id_lang = Cmsearch::getLangId();
        $sql = 'SELECT name
				FROM `' . _DB_PREFIX_ . 'feature_lang`
				WHERE `id_lang` = ' . (int) $id_lang;
        $features = Db::getInstance()->executeS($sql);
        foreach ($features as $feature) {
            $fields['f_' . $feature['name']] = '';
        }
        return $fields;
    }
Exemplo n.º 5
0
 public static function getColor($id_attribute)
 {
     $sql = 'SELECT name, color
     FROM `' . _DB_PREFIX_ . 'attribute`, `' . _DB_PREFIX_ . 'attribute_lang`
     WHERE `' . _DB_PREFIX_ . 'attribute`.id_attribute = `' . _DB_PREFIX_ . 'attribute_lang`.id_attribute
     AND id_lang = ' . Cmsearch::getLangId() . '
     AND `' . _DB_PREFIX_ . 'attribute`.id_attribute = ' . $id_attribute;
     $row = Db::getInstance()->executeS($sql);
     return $row[0];
 }