public static function indexation($id_product = false, $update = false) { $id_lang = Cmsearch::getLangId(); $convermax = new ConvermaxAPI(); if (!$id_product) { if (!$convermax->batchStart()) { return false; } } $start = 0; while ($products = Cmsearch::getProductsToIndex($id_lang, $start, 200, $id_product)) { $start = $start + 200; if (count($products) == 0) { break; } $products_array = array(); $products_count = count($products); for ($i = 0; $i < $products_count; $i++) { if ($products[$i]['features']) { foreach ($products[$i]['features'] as $feature) { $f_name = 'f_' . $convermax->sanitize($feature['name']); $products[$i][$f_name][] = $feature['value']; } unset($products[$i]['features']); } foreach ($products[$i] as $key => $val) { if (is_array($val)) { foreach ($val as $k => $v) { if (is_array($v)) { unset($products[$i][$key]); } } } } $img_id = Product::getCover($products[$i]['id_product']); $link = new Link(); $img_link = $link->getImageLink($products[$i]['link_rewrite'], $img_id['id_image'], ImageType::getFormatedName('small')); $products[$i]['img_link'] = str_replace(Tools::getHttpHost(), '', $img_link); $products[$i]['link'] = str_replace(Tools::getHttpHost(true), '', $products[$i]['link']); $cat_full = Product::getProductCategoriesFull($products[$i]['id_product']); $category_full = array(); $home_category = Configuration::get('PS_HOME_CATEGORY'); foreach ($cat_full as $cat) { $category = new Category($cat['id_category']); $categories = $category->getParentsCategories(); $c_full = array(); foreach ($categories as $cats) { if ($cats['id_category'] != $home_category) { $c_full[] = $cats['name']; } } if (!empty($c_full)) { $category_full[] = implode('>', array_reverse($c_full)); } } $products[$i]['category_full'] = $category_full; $attributes = Product::getAttributesInformationsByProduct($products[$i]['id_product']); if (!empty($attributes)) { foreach ($attributes as $attribute) { $a_name = 'a_' . $convermax->sanitize($attribute['group']); $products[$i][$a_name][] = $attribute['attribute']; } } if (!in_array($products[$i]['id_product'], $products_array)) { $products_array[] = (int) $products[$i]['id_product']; } } if ($update) { if (!$convermax->update($products)) { return false; } } elseif ($id_product) { if (!$convermax->add($products)) { return false; } } elseif (!$convermax->batchAdd($products)) { return false; } if ($id_product) { break; } } if (!$id_product) { if (!$convermax->batchEnd()) { return false; } } return true; }