public function getData() { if (!isset($this->_data)) { $shop = $this->getShop(); $lang = $this->getLang(); if (empty($this->_root_category)) { $root_category = Category::getRootCategory($lang, new Shop((int) Configuration::get('PS_SHOP_DEFAULT')))->id; } $categories = $new_selected_categories = array(); $selected_categories = Category::getAllCategoriesName($root_category, $lang, false, null, false); $categories[$root_category] = Category::getChildren($root_category, $lang, false, (int) Configuration::get('PS_SHOP_DEFAULT')); foreach ($selected_categories as $selected_category) { $category = new Category($selected_category['id_category'], $lang, (int) Configuration::get('PS_SHOP_DEFAULT')); $new_selected_categories[] = $selected_category['id_category']; $parents = $category->getParentsCategories($lang); foreach ($parents as $value) { $new_selected_categories[] = $value['id_category']; } } $new_selected_categories = array_unique($new_selected_categories); foreach ($new_selected_categories as $selected_category) { $current_category = Category::getChildren($selected_category, $lang, false, (int) Configuration::get('PS_SHOP_DEFAULT')); if (!empty($current_category)) { $categories[$selected_category] = $current_category; } } $tree = $this->fillTree($categories, $root_category); if (!empty($children)) { $tree[$root_category]['children'] = $children; } $this->setData($tree); } return $this->_data; }
public function __construct() { global $cookie; $this->table = 'category'; $this->className = 'Category'; $this->lang = true; $this->edit = true; $this->view = true; $this->delete = true; $this->fieldImageSettings = array('name' => 'image', 'dir' => 'c'); $this->fieldsDisplay = array('id_category' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 30), 'name' => array('title' => $this->l('Name'), 'width' => 100, 'callback' => 'hideCategoryPosition'), 'description' => array('title' => $this->l('Description'), 'width' => 480, 'maxlength' => 90, 'orderby' => false), 'physical_products_quantity' => array('title' => $this->l('In stock Products'), 'align' => 'center', 'width' => 50), 'active' => array('title' => $this->l('Displayed'), 'active' => 'status', 'align' => 'center', 'type' => 'bool', 'orderby' => false)); $this->_category = AdminCatalog::getCurrentCategory(); $this->_filter = 'AND `id_parent` = ' . intval($this->_category->id); $children = Category::getChildren($this->_category->id, $cookie->id_lang); foreach ($children as &$child) { $tmp_list = $this->_category->id . ','; $obj = new Category($child['id_category']); $parents = $obj->getParentsCategories(); foreach ($parents as $parent) { $tmp_list .= $parent['id_category'] . ','; } $child['parent_id_list'] = rtrim($tmp_list, ','); } parent::__construct(); }
public function getData() { if (!isset($this->_data)) { $shop = $this->getShop(); $lang = $this->getLang(); $root_category = (int) $this->getRootCategory(); if ($this->_full_tree) { $this->setData(Category::getNestedCategories($root_category, $lang, false, null, $this->useShopRestriction())); $this->setDataSearch(Category::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction())); } elseif ($this->_children_only) { if (empty($root_category)) { $root_category = Category::getRootCategory()->id; } $categories[$root_category] = Category::getChildren($root_category, $lang, false, $shop->id); $children = $this->fillTree($categories, $root_category); $this->setData($children); } else { if (empty($root_category)) { $root_category = Category::getRootCategory()->id; } $new_selected_categories = array(); $selected_categories = $this->getSelectedCategories(); $categories[$root_category] = Category::getChildren($root_category, $lang, false, $shop->id); foreach ($selected_categories as $selected_category) { $category = new Category($selected_category, $lang, $shop->id); $new_selected_categories[] = $selected_category; $parents = $category->getParentsCategories($lang); foreach ($parents as $value) { $new_selected_categories[] = $value['id_category']; } } $new_selected_categories = array_unique($new_selected_categories); foreach ($new_selected_categories as $selected_category) { $current_category = Category::getChildren($selected_category, $lang, false, $shop->id); if (!empty($current_category)) { $categories[$selected_category] = $current_category; } } $tree = Category::getCategoryInformations(array($root_category), $lang); $children = $this->fillTree($categories, $root_category); if (!empty($children)) { $tree[$root_category]['children'] = $children; } $this->setData($tree); $this->setDataSearch(Category::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction())); } } return $this->_data; }
public function getCategoryLink($category, $alias = NULL, $id_lang = NULL, $selected_filters = NULL, $id_shop = NULL) { $dispatcher = Dispatcher::getInstance(); if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = _PS_BASE_URL_ . __PS_BASE_URI__ . $this->getLangLink($id_lang); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } if ($dispatcher->hasKeyword('category_rule', $id_lang, 'parent_categories')) { //RETRIEVING ALL THE PARENT CATEGORIES $cats = array(); foreach ($category->getParentsCategories() as $cat) { if (!in_array($cat['id_category'], array(1, 2, $category->id))) { //remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; } } //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?) $params['parent_categories'] = implode('/', array_reverse($cats)); //ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER } return $url . Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow); }
/** * Create a link to a category * * @param mixed $category Category object (can be an ID category, but deprecated) * @param string $alias * @param int $id_lang * @param string $selected_filters Url parameter to autocheck filters of the module blocklayered * @return string */ public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords')); $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title')); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } $dispatcher = Dispatcher::getInstance(); if ($dispatcher->hasKeyword('category_rule', $id_lang, 'parent_categories')) { // Retrieve all parent categories $p_cats = array(); foreach ($category->getParentsCategories($id_lang) as $p_cat) { // remove root and current category from the URL if (!in_array($p_cat['id_category'], array_merge(self::$category_disable_rewrite, array($category->id)))) { $p_cats[] = $p_cat['link_rewrite']; } } // add the URL slashes among categories, in reverse order $params['parent_categories'] = implode('/', array_reverse($p_cats)); } return $url . $dispatcher->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop); }
/** * Override method getCategoryLink for use "categories" in category rule keyword on route * * @module now_seo_links * * @param mixed $category * @param null $alias * @param null $id_lang * @param null $selected_filters * @param null $id_shop * @return string * @see LinkCore::getCategoryLink() */ public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop) . $this->getLangLink($id_lang, null, $id_shop); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } $dispatcher = Dispatcher::getInstance(); if ($dispatcher->hasKeyword('category_rule', $id_lang, 'categories', $id_shop)) { $cats = array(); foreach ($category->getParentsCategories($id_lang) as $cat) { if (!in_array($cat['id_category'], array_merge(Link::$category_disable_rewrite, array($category->id)))) { //remove root and home category from the URL $cats[] = $cat['link_rewrite']; } } krsort($cats); $params['categories'] = implode('/', $cats); } return $url . $dispatcher->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop); }
public function hookLeftColumn() { if (get_class($this->context->controller) == 'ConvermaxSearchModuleFrontController') { $this->context->smarty->assign(array('pagesize' => abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'))))); return $this->display(__FILE__, 'views/templates/hook/facets.tpl'); } $home_category = Configuration::get('PS_HOME_CATEGORY'); $id_category = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', $home_category)); if ($id_category != $home_category) { $category = new Category($id_category); $categories = $category->getParentsCategories(); $category_full = array(); foreach ($categories as $cat) { if ($cat['id_category'] != $home_category) { $category_full[] = $cat['name']; } } if (!empty($category_full)) { $category_full = implode('>', array_reverse($category_full)); } $facet = array('category_full' => array($category_full)); $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'))); $search = Cmsearch::find($this->context->language->id, ' ', 1, $n, 'position', 'desc', false, true, null, $facet); if ($search) { $facets_params = ''; $is_ranged = 'IsRanged'; $field_name = 'FieldName'; $values = 'Values'; $display_name = 'DisplayName'; foreach ($search['cm_result']->Facets as $facet) { if ($facet->{$is_ranged}) { $rangemin = preg_replace('|TO .*\\]|', '', $facet->{$values}[0]->Term); $rangemax = preg_replace('|\\[.*? |', '', $facet->{$values}[count($facet->{$values}) - 1]->Term); $facets_params .= 'cm_params.sliders.' . $facet->{$field_name} . ' = []' . ";\r\n"; $facets_params .= 'cm_params.sliders.' . $facet->{$field_name} . '[0] = "' . $rangemin . $rangemax . "\";\r\n"; } else { $values_count = count($facet->{$values}); for ($i = 0; $i < $values_count; $i++) { if ($facet->{$values}[$i]->Selected == true) { $facets_params .= 'cm_params.facets.' . $facet->{$field_name} . ' = []' . ";\r\n"; $facets_params .= 'cm_params.facets.' . $facet->{$field_name} . '[' . $i . '] = "' . $facet->{$values}[$i]->Term . "\";\r\n"; $facets_params .= 'cm_params.facets_display.' . $facet->{$field_name} . ' = "' . $facet->{$display_name} . "\";\r\n"; } } } } $this->context->smarty->assign(array('facets' => $search['cm_result']->Facets, 'query' => ' ', 'pagenumber' => 1, 'pagesize' => $n, 'facets_params' => isset($facets_params) ? $facets_params : false)); return $this->display(__FILE__, 'views/templates/hook/facets.tpl'); } } return ''; }
/** * Returns a simple breacrumb from a categoryId, the delimiter can be choosen * @param $categoryId * @param string $delimiter * @return string */ public function getBreadCrumb($categoryId, $delimiter = " > ") { $currentCategory = new \Category($categoryId); $categories = $currentCategory->getParentsCategories(); $categories = array_reverse($categories, true); $breadCrumb = ''; foreach ($categories as $category) { $breadCrumb .= ' > ' . $category['name']; } return substr($breadCrumb, strlen($delimiter)); }
private function getBreadCrumbs($product) { if (!method_exists('Product', 'getProductCategoriesFull')) { return ''; } $result = array(); $lang_id; if (isset($this->context)) { $lang_id = (int) $this->context->language->id; } else { global $cookie; $lang_id = (int) $cookie->id_lang; } $all_product_subs = Product::getProductCategoriesFull((int) $product->id, (int) $lang_id); if (isset($all_product_subs) && count($all_product_subs) > 0) { foreach ($all_product_subs as $subcat) { $sub_category = new Category((int) $subcat['id_category'], (int) $lang_id); $sub_category_path = $sub_category->getParentsCategories(); foreach ($sub_category_path as $key) { $result[] = $key['name']; } } } return implode(';', $result); }
public function hookLeftColumn($params) { $from_category = Configuration::get('PS_HOME_CATEGORY'); $all_categories = Category::getCategories($this->context->language->id, true, true, 'AND `c`.`hide_on_left` = \'0\''); $menu_categories = blockcategories::createMenuCategories($all_categories, $from_category, 1); if (Tools::getIsset('id_category')) { $current_category = new Category(Tools::getValue('id_category')); } else { if (Tools::getIsset('id_product')) { $product = new Product(Tools::getIsset('id_product')); $current_category = new Category($product->id_category_default); } else { $current_category = new Category($from_category); } } $current_tree = array_reverse($current_category->getParentsCategories()); array_shift($current_tree); if (!empty($current_tree)) { $level = 1; $categories =& $menu_categories; $maxLevel = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); do { $category = array_shift($current_tree); $categories[$category['id_category']]['open'] = true; if (empty($current_tree) || $level == $maxLevel) { $categories[$category['id_category']]['current'] = true; $this->context->smarty->assign('title', $categories[$category['id_category']]['name']); } if ($level < $maxLevel - 1) { $categories[$category['id_category']]['childs'] = blockcategories::createMenuCategories($all_categories, $category['id_category'], $level); $categories =& $categories[$category['id_category']]['childs']; } $level++; } while (!empty($current_tree) && $level < $maxLevel); } $this->context->smarty->assign('menu_categories', $menu_categories); $this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl'); return $this->display(__FILE__, 'blockcategories.tpl'); }
private function makeMenu() { $menu = ''; $menu_items = $this->getMenuItems(); $id_lang = (int) $this->context->language->id; $id_shop = (int) Shop::getContextShopID(); $head = $this->_itemHead; $tail = $this->_itemTail; foreach ($menu_items as $item) { if (!$item) { continue; } preg_match($this->pattern, $item, $value); $id = (int) substr($item, strlen($value[1]), strlen($item)); switch (substr($item, 0, strlen($value[1]))) { case 'CAT': $activeCategories = array(); $id_cat = (int) Tools::getValue('id_category', false); if ($id_cat && $this->page_name == 'category') { $categ = new Category($id_cat, $id_lang, $id_shop); $activeCategories = $categ->getParentsCategories($id_lang); } $menu .= $this->generateCategoriesMenu(Category::getNestedCategories($id, $id_lang, true, $this->user_groups), $activeCategories, false); break; case 'PRD': $selected = $this->page_name == 'product' && Tools::getValue('id_product') == $id ? ' active' : ''; $product = new Product((int) $id, true, (int) $id_lang); if (!is_null($product->id)) { $menu .= $head . '<li class="' . $this->_itemClass . $selected . '"><a href="' . Tools::HtmlEntitiesUTF8($product->getLink()) . '" title="' . $product->name . '"><span>' . $product->name . '</span></a></li>' . $tail . PHP_EOL; } break; case 'CMS': $selected = $this->page_name == 'cms' && Tools::getValue('id_cms') == $id ? ' class="active"' : ''; $cms = CMS::getLinks((int) $id_lang, array($id)); if (count($cms)) { $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . Tools::HtmlEntitiesUTF8($cms[0]['link']) . '" title="' . Tools::safeOutput($cms[0]['meta_title']) . '"' . $selected . '><span>' . Tools::safeOutput($cms[0]['meta_title']) . '</span></a></li>' . $tail . PHP_EOL; } break; case 'CMS_CAT': $selected = $this->page_name == 'cms' ? ' class="active"' : ''; $category = new CMSCategory((int) $id, (int) $id_lang); if (count($category)) { $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . Tools::HtmlEntitiesUTF8($category->getLink()) . '" title="' . $category->name . '"' . $selected . '><span>' . $category->name . '</span></a>'; $this->getCMSMenuItems($menu, $category->id); $menu .= '</li>' . $tail . PHP_EOL; } break; // Case to handle the option to show all Manufacturers // Case to handle the option to show all Manufacturers case 'ALLMAN': $selected = $this->page_name == 'manufacturer' ? ' class="active"' : ''; $link = new Link(); $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . $link->getPageLink('manufacturer') . '" title="' . $this->l('All manufacturers') . '"' . $selected . '><span>' . $this->l('All manufacturers') . '</span></a>'; $manufacturers = Manufacturer::getManufacturers(); $sub_menu_active = ''; $sub_menu = ''; foreach ($manufacturers as $key => $manufacturer) { $id_man = (int) $manufacturer['id_manufacturer']; $active = Tools::getValue('id_manufacturer') == $id_man ? ' class="active"' : ''; $sub_menu_active = empty($active) ? $sub_menu_active : ' active'; $sub_menu .= $this->_subItemHead . '<li class="' . $this->_subItemClass . '"><a href="' . $link->getManufacturerLink($id_man, $manufacturer['link_rewrite']) . '" title="' . Tools::safeOutput($manufacturer['name']) . '"' . $active . '><span>' . Tools::safeOutput($manufacturer['name']) . '</span></a></li>' . $this->_subItemTail . PHP_EOL; } $menu .= $this->_subMenuHead . '<ul class="' . $this->_subMenuClass . $sub_menu_active . '">' . $sub_menu . '</ul>' . $this->_subMenuTail; $menu .= '</li>' . $tail; break; case 'MAN': $selected = $this->page_name == 'manufacturer' && Tools::getValue('id_manufacturer') == $id ? ' class="active"' : ''; $manufacturer = new Manufacturer((int) $id, (int) $id_lang); if (!is_null($manufacturer->id)) { if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) { $manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name); } else { $manufacturer->link_rewrite = 0; } $link = new Link(); $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . Tools::HtmlEntitiesUTF8($link->getManufacturerLink((int) $id, $manufacturer->link_rewrite)) . '" title="' . Tools::safeOutput($manufacturer->name) . '"' . $selected . '><span>' . Tools::safeOutput($manufacturer->name) . '</span></a></li>' . $tail . PHP_EOL; } break; // Case to handle the option to show all Suppliers // Case to handle the option to show all Suppliers case 'ALLSUP': $selected = $this->page_name == 'supplier' ? ' class="active"' : ''; $link = new Link(); $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . $link->getPageLink('supplier') . '" title="' . $this->l('All suppliers') . '"' . $selected . '><span>' . $this->l('All suppliers') . '</span></a>'; $suppliers = Supplier::getSuppliers(); $sub_menu_active = ''; $sub_menu = ''; foreach ($suppliers as $key => $supplier) { $id_sup = (int) $supplier['id_supplier']; $active = Tools::getValue('id_supplier') == $id_sup ? ' class="active"' : ''; $sub_menu_active = empty($active) ? $sub_menu_active : ' active'; $sub_menu .= $this->_subItemHead . '<li class="' . $this->_subItemClass . '"><a href="' . $link->getSupplierLink($id_sup, $supplier['link_rewrite']) . '" title="' . Tools::safeOutput($supplier['name']) . '"' . $active . '><span>' . Tools::safeOutput($supplier['name']) . '</span></a></li>' . $this->_subItemTail . PHP_EOL; } $menu .= $this->_subMenuHead . '<ul class="' . $this->_subMenuClass . $sub_menu_active . '">' . $sub_menu . '</ul>' . $this->_subMenuTail; $menu .= '</li>' . $tail; break; case 'SUP': $selected = $this->page_name == 'supplier' && Tools::getValue('id_supplier') == $id ? ' class="active"' : ''; $supplier = new Supplier((int) $id, (int) $id_lang); if (!is_null($supplier->id)) { $link = new Link(); $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . Tools::HtmlEntitiesUTF8($link->getSupplierLink((int) $id, $supplier->link_rewrite)) . '" title="' . $supplier->name . '"' . $selected . '><span>' . $supplier->name . '</span></a></li>' . $tail . PHP_EOL; } break; case 'SHOP': $selected = $this->page_name == 'index' && $this->context->shop->id == $id ? ' class="active"' : ''; $shop = new Shop((int) $id); if (Validate::isLoadedObject($shop)) { $link = new Link(); $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . Tools::HtmlEntitiesUTF8($shop->getBaseURL()) . '" title="' . $shop->name . '"' . $selected . '><span>' . $shop->name . '</span></a></li>' . $tail . PHP_EOL; } break; case 'LNK': $link = MenuTopLinks_mod::get((int) $id, (int) $id_lang, (int) $id_shop); if (count($link)) { if (!isset($link[0]['label']) || $link[0]['label'] == '') { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks_mod::get($link[0]['id_linksmenutop'], $default_language, (int) Shop::getContextShopID()); } $menu .= $head . '<li class="' . $this->_itemClass . '"><a href="' . Tools::HtmlEntitiesUTF8($link[0]['link']) . '"' . ($link[0]['new_window'] ? ' onclick="return !window.open(this.href);"' : '') . ' title="' . Tools::safeOutput($link[0]['label']) . '"><span>' . Tools::safeOutput($link[0]['label']) . '</span></a></li>' . $tail . PHP_EOL; } break; } } return $menu; }
/** * returns the parent categories * * @param int $categoryId * * @return array */ protected function getCategoryPathsFromModel($categoryId) { $categoryModel = new Category($categoryId, $this->getPlugin()->getLanguageId()); return $categoryModel->getParentsCategories($this->getPlugin()->getLanguageId()); }
public function getCurrentCategoriesId($lang_id = NULL) { if (isset($_GET['id_category'])) { $lastCateId = $_GET['id_category']; } else { $lastCateId = 0; } $lastCate = new Category((int) $lastCateId); //echo $lastCate->name[1]; echo '--------'; $parentCate = $lastCate->getParentsCategories($lang_id); $arrayCateCurrent = array(); foreach ($parentCate as $pcate) { $arrayCateCurrent[] = $pcate['id_category']; } return $arrayCateCurrent; }
public static function isParentCategoryProductDiscount($id_category_product, $id_category_discount) { $category = new Category(intval($id_category_product)); $parentCategories = $category->getParentsCategories(); foreach ($parentCategories as $parentCategory) { if ($id_category_discount == $parentCategory['id_category']) { return true; } } return false; }
foreach (Product::getIndexedCategories($product->id) as $row) { $category_ids[] = $row['id_category']; } $category_id = $product->id_category_default; if (isset($cookie->last_visited_category) && in_array(intval($cookie->last_visited_category), $category_ids)) { $category_id = intval($cookie->last_visited_category); } $category = new Category($category_id, intval($cookie->id_lang)); } if (!$category && isset($cookie->last_visited_category)) { $category = new Category($cookie->last_visited_category, intval($cookie->id_lang)); } } /* Theme */ $theme = _THEME_NAME_; if ($category) { $category_path = $category->getParentsCategories(intval($cookie->id_lang), true); foreach ($category_path as $cat) { if ($cat['theme']) { $theme = $cat['theme']; break; } } } define('_THEME_IMG_DIR_', _THEMES_DIR_ . $theme . '/img/'); define('_THEME_CSS_DIR_', _THEMES_DIR_ . $theme . '/css/'); define('_THEME_JS_DIR_', _THEMES_DIR_ . $theme . '/js/'); define('_THEME_DIR_', _THEMES_DIR_ . $theme . '/'); define('_PS_THEME_DIR_', _PS_ROOT_DIR_ . '/themes/' . $theme . '/'); /* Smarty */ include dirname(__FILE__) . '/smarty.config.inc.php';
/** * Convert the entities data into an xml object and return the xml object as a string * * @param array $aEntity Entity data */ public function formatEntityToXML($aEntity) { $sReturn = ''; $dom = new DOMDocument('1.0', 'utf-8'); $bUseRoutes = (bool) Configuration::get('PS_REWRITING_SETTINGS'); $oDispatcher = Dispatcher::getInstance(); // Force the dispatcher to use custom routes because the use of custom routes is disabled in the BO Context foreach ($oDispatcher->default_routes as $route_id => $route_data) { if ($custom_route = Configuration::get('PS_ROUTE_' . $route_id)) { foreach (Language::getLanguages() as $lang) { $oDispatcher->addRoute($route_id, $custom_route, $route_data['controller'], $lang['id_lang'], $route_data['keywords'], isset($route_data['params']) ? $route_data['params'] : array()); } } } $oPrediggoConfig = $this->aPrediggoConfigs[(int) $aEntity['id_shop']]; $link = $oPrediggoConfig->getContext()->link; $oProduct = new Product((int) $aEntity['id_product'], true, null, (int) $aEntity['id_shop'], $oPrediggoConfig->getContext()); if ((int) StockAvailable::getQuantityAvailableByProduct((int) $aEntity['id_product'], 0, (int) $aEntity['id_shop']) < (int) $oPrediggoConfig->export_product_min_quantity) { $this->nbEntitiesTreated--; $this->nbEntities--; return ' '; } $ps_tax = (int) Configuration::get('PS_TAX'); foreach ($this->aLanguages as $aLanguage) { $id_lang = (int) $aLanguage['id_lang']; // Set the root of the XML $root = $dom->createElement($this->sEntity); $dom->appendChild($root); $root->setAttribute('timestamp', (int) strtotime($oProduct->date_add)); $id = $dom->createElement('id', (int) $oProduct->id); $root->appendChild($id); $profile = $dom->createElement('profile', (int) $aEntity['id_shop']); $root->appendChild($profile); $name = $dom->createElement('name'); $name->appendChild($dom->createCDATASection($oProduct->name[$id_lang])); $root->appendChild($name); $oCategory = new Category((int) $oProduct->id_category_default); $aCategories = $oCategory->getParentsCategories($id_lang); if (is_array($aCategories) && count($aCategories) > 0) { foreach ($aCategories as $aCategory) { $oCategoryTmp = new Category((int) $aCategory['id_category'], $id_lang); if (!empty($oCategoryTmp->name)) { $genre = $dom->createElement('genre'); $genre->appendChild($dom->createCDATASection($oCategoryTmp->name)); $root->appendChild($genre); } unset($oCategoryTmp); } } unset($aCategories); unset($oCategory); if (!empty($oProduct->ean13)) { $ean = $dom->createElement('ean'); $ean->appendChild($dom->createCDATASection($oProduct->ean13)); $root->appendChild($ean); } $price = $dom->createElement('price', number_format($oProduct->getPrice($ps_tax), 2, '.', '')); $root->appendChild($price); if (isset($oProduct->tags[$id_lang]) && ($aTags = $oProduct->tags[$id_lang])) { $tag = $dom->createElement('tag'); $tag->appendChild($dom->createCDATASection(join(',', $aTags))); $root->appendChild($tag); } $sDesc = trim(strip_tags($oProduct->description[$id_lang])); if ($oPrediggoConfig->export_product_description && !empty($sDesc)) { $description = $dom->createElement('description'); $description->appendChild($dom->createCDATASection($sDesc)); $root->appendChild($description); } if (!empty($oProduct->id_manufacturer)) { $supplierid = $dom->createElement('supplierid', (int) $oProduct->id_manufacturer); $root->appendChild($supplierid); } $recommendable = $dom->createElement('recommendable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_recommendable)) ? 'false' : 'true'); $root->appendChild($recommendable); $searchable = $dom->createElement('searchable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_searchable)) ? 'false' : 'true'); $root->appendChild($searchable); // Set product URL $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName', 'producturl'); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($link->getProductLink((int) $oProduct->id, $oProduct->link_rewrite[$id_lang], Category::getLinkRewrite((int) $oProduct->id_category_default, $id_lang), NULL, $id_lang, (int) $aEntity['id_shop'], 0, $bUseRoutes))); $attribute->appendChild($attValue); // Set product picture if ($oPrediggoConfig->export_product_image) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName', 'imageurl'); $attribute->appendChild($attName); $aCover = $oProduct->getCover((int) $oProduct->id); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($link->getImageLink($oProduct->link_rewrite[$id_lang], (int) $aCover['id_image'], 'large'))); $attribute->appendChild($attValue); } // Set combinations $aProductCombinations = Product::getAttributesInformationsByProduct((int) $oProduct->id); if (sizeof($aProductCombinations)) { foreach ($aProductCombinations as $aProductCombination) { if (!empty($oPrediggoConfig->attributes_groups_ids) && in_array((int) $aProductCombination['id_attribute_group'], explode(',', $oPrediggoConfig->attributes_groups_ids))) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection($aProductCombination['group'])); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($aProductCombination['attribute'])); $attribute->appendChild($attValue); } } } unset($aProductCombinations); // Set features $aProductFeatures = $oProduct->getFrontFeatures($id_lang); if (sizeof($aProductFeatures)) { foreach ($aProductFeatures as $aProductFeature) { if (!empty($oPrediggoConfig->features_ids) && in_array((int) $aProductFeature['id_feature'], explode(',', $oPrediggoConfig->features_ids))) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection($aProductFeature['name'])); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($aProductFeature['value'])); $attribute->appendChild($attValue); } } } unset($aProductFeatures); $aAccessories = Product::getAccessoriesLight($id_lang, (int) $oProduct->id); if (sizeof($aAccessories)) { foreach ($aAccessories as $aAccessory) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection('accessory')); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection((int) $aAccessory['id_product'])); $attribute->appendChild($attValue); } } unset($aAccessories); $sReturn .= $dom->saveXML($root); } unset($dom); unset($oProduct); return $sReturn; }
public function ajaxCallBackOffice($category_box = array(), $id_layered_filter = null) { global $cookie; if (!empty($id_layered_filter)) { $layered_filter = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) $id_layered_filter); if ($layered_filter && isset($layered_filter['filters']) && !empty($layered_filter['filters'])) { $layered_values = Tools::unSerialize($layered_filter['filters']); } if (isset($layered_values['categories']) && count($layered_values['categories'])) { foreach ($layered_values['categories'] as $id_category) { $category_box[] = (int) $id_category; } } } /* Clean categoryBox before use */ if (isset($category_box) && is_array($category_box)) { foreach ($category_box as &$value) { $value = (int) $value; } } else { $category_box = array(); } $attribute_groups = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT ag.id_attribute_group, ag.is_color_group, agl.name, COUNT(DISTINCT(a.id_attribute)) n FROM ' . _DB_PREFIX_ . 'attribute_group ag LEFT JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl ON (agl.id_attribute_group = ag.id_attribute_group) LEFT JOIN ' . _DB_PREFIX_ . 'attribute a ON (a.id_attribute_group = ag.id_attribute_group) ' . (count($category_box) ? ' LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON (pac.id_attribute = a.id_attribute) LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa ON (pa.id_product_attribute = pac.id_product_attribute)' . Shop::addSqlAssociation('product_attribute', 'pa') . ' LEFT JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = pa.id_product)' : '') . ' WHERE agl.id_lang = ' . (int) $cookie->id_lang . (count($category_box) ? ' AND cp.id_category IN (' . implode(',', $category_box) . ')' : '') . ' GROUP BY ag.id_attribute_group'); $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT fl.id_feature, fl.name, COUNT(DISTINCT(fv.id_feature_value)) n FROM ' . _DB_PREFIX_ . 'feature_lang fl LEFT JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature = fl.id_feature) ' . (count($category_box) ? ' LEFT JOIN ' . _DB_PREFIX_ . 'feature_product fp ON (fp.id_feature = fv.id_feature) LEFT JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = fp.id_product)' : '') . ' WHERE (fv.custom IS NULL OR fv.custom = 0) AND fl.id_lang = ' . (int) $cookie->id_lang . (count($category_box) ? ' AND cp.id_category IN (' . implode(',', $category_box) . ')' : '') . ' GROUP BY fl.id_feature'); $n_elements = count($attribute_groups) + count($features) + 4; if ($n_elements > 20) { $n_elements = 20; } $html = ' <div id="layered_container_right" style="width: 360px; float: left; margin-left: 20px; height: ' . (int) (30 + $n_elements * 38) . 'px; overflow-y: auto;"> <h3>' . $this->l('Available filters') . ' <span id="num_avail_filters">(0)</span></h3> <ul id="all_filters"></ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_subcategories" name="layered_selection_subcategories" /> <span class="position"></span>' . $this->l('Sub-categories filter') . ' <select class="filter_show_limit" name="layered_selection_subcategories_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_subcategories_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_stock" name="layered_selection_stock" /> <span class="position"></span>' . $this->l('Product stock filter') . ' <select class="filter_show_limit" name="layered_selection_stock_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_stock_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_condition" name="layered_selection_condition" /> <span class="position"></span>' . $this->l('Product condition filter') . ' <select class="filter_show_limit" name="layered_selection_condition_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_condition_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_manufacturer" name="layered_selection_manufacturer" /> <span class="position"></span>' . $this->l('Product manufacturer filter') . ' <select class="filter_show_limit" name="layered_selection_manufacturer_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_manufacturer_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_weight_slider" name="layered_selection_weight_slider" /> <span class="position"></span>' . $this->l('Product weight filter (slider)') . ' <select class="filter_show_limit" name="layered_selection_weight_slider_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_weight_slider_filter_type"> <option value="0">' . $this->l('Slider') . '</option> <option value="1">' . $this->l('Inputs area') . '</option> <option value="2">' . $this->l('List of values') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_price_slider" name="layered_selection_price_slider" /> <span class="position"></span>' . $this->l('Product price filter (slider)') . ' <select class="filter_show_limit" name="layered_selection_price_slider_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_price_slider_filter_type"> <option value="0">' . $this->l('Slider') . '</option> <option value="1">' . $this->l('Inputs area') . '</option> <option value="2">' . $this->l('List of values') . '</option> </select> </li> </ul>'; if (count($attribute_groups)) { $html .= '<ul>'; foreach ($attribute_groups as $attribute_group) { $html .= ' <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '" name="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '" /> <span class="position"></span> ' . ($attribute_group['n'] > 1 ? sprintf($this->l('Attribute group: %1$s (%2$d attributes)'), $attribute_group['name'], $attribute_group['n']) : sprintf($this->l('Attribute group: %1$s (%2$d attribute)'), $attribute_group['name'], $attribute_group['n'])) . ')' . ($attribute_group['is_color_group'] ? ' <img src="../img/admin/color_swatch.png" alt="" title="' . $this->l('This group will allow user to select a color') . '" />' : '') . ' <select class="filter_show_limit" name="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li>'; } $html .= '</ul>'; } if (count($features)) { $html .= '<ul>'; foreach ($features as $feature) { $html .= ' <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_feat_' . (int) $feature['id_feature'] . '" name="layered_selection_feat_' . (int) $feature['id_feature'] . '" /> <span class="position"></span> ' . ($feature['n'] > 1 ? sprintf($this->l('Feature: %1$s (%2$d values)'), $feature['name'], $feature['n']) : sprintf($this->l('Feature: %1$s (%2$d value)'), $feature['name'], $feature['n'])) . ') <select class="filter_show_limit" name="layered_selection_feat_' . (int) $feature['id_feature'] . '_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_feat_' . (int) $feature['id_feature'] . '_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li>'; } $html .= '</ul>'; } $html .= ' </div>'; if (isset($layered_values)) { $html .= ' <script type="text/javascript"> $(document).ready(function() { $(\'#selected_filters li\').remove(); '; foreach ($layered_values as $key => $layered_value) { if ($key != 'categories' && $key != 'shop_list') { $html .= ' $(\'#' . $key . '\').click(); $(\'select[name=' . $key . '_filter_type]\').val(' . $layered_value['filter_type'] . '); $(\'select[name=' . $key . '_filter_show_limit]\').val(' . $layered_value['filter_show_limit'] . '); '; } } if (isset($layered_values['categories']) && count($layered_values['categories'])) { $html .= ' function expandCategories(categories, iteration, id_category, init) { if (categories[iteration]) { category = $(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+categories[iteration]+\']\'); if (category.length) { if (category.parent().hasClass(\'expandable\')) { $(\'#\'+categories[iteration]+\' .hitarea\').click(); } if (parseInt(categories[iteration]) == parseInt(id_category)) { $(\'#layered-cat-counter\').html(parseInt($(\'#layered-cat-counter\').html()) + 1); if ($(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+id_category+\']:checked\').length == 0) { $(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+id_category+\']\').click(); clickOnCategoryBox($(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+id_category+\']\')); } collapseAllCategories(); } } else { setTimeout(function() { expandCategories(categories, iteration, id_category, false); }, 20 ); return; } $(\'#categories-treeview\').parent().parent().show(); expandCategories(categories, iteration+1, id_category); if (typeof(lock_treeview_hidding) == \'undefined\' || !lock_treeview_hidding) $(\'#categories-treeview\').parent().parent().hide(); } } $(\'#layered-cat-counter\').html(0); $(\'.nb_sub_cat_selected\').hide(); $(\'#categories-treeview\').find(\'input[name="categoryBox[]"]:checked\').each(function(i, it) { $(it).click(); updateNbSubCategorySelected($(it), false); });'; foreach ($layered_values['categories'] as $id_category) { if ($id_category != 1) { $category = new Category($id_category); $parent_list = array_reverse($category->getParentsCategories()); } else { $parent_list = array(array('id_category' => 1)); } $html .= 'var categories = []; '; foreach ($parent_list as $parent) { $html .= ' categories.push(' . (int) $parent['id_category'] . ');'; } $html .= ' expandCategories(categories, 0, ' . (int) $id_category . ', false);'; } $html .= ' updCatCounter(); $(\'#scope_1\').attr(\'checked\', \'\'); $(\'#scope_2\').attr(\'checked\', \'checked\'); '; } else { $html .= ' $(\'#scope_2\').attr(\'checked\', \'\'); $(\'#scope_1\').attr(\'checked\', \'checked\'); '; } $html .= ' $(\'#layered_tpl_name\').val(\'' . addslashes($layered_filter['name']) . '\'); $(\'#id_layered_filter\').val(\'' . (int) $layered_filter['id_layered_filter'] . '\'); '; $html .= ' }); </script>'; } if (!empty($id_layered_filter)) { if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) { $shops = Shop::getShops(true, null, true); if (count($shops) > 1) { $helper = new HelperForm(); $helper->id = (int) $id_layered_filter; $helper->table = 'layered_filter'; $helper->identifier = 'id_layered_filter'; $helper->base_folder = Tools::getValue('base_folder') . '/themes/default/template/helpers/form/'; $html .= ' <div id="shop_association_ajax">' . $helper->renderAssoShop() . '</div> <script type="text/javascript"> $(document).ready(function() { $(\'#shop_association\').html($(\'#shop_association_ajax\').html()); $(\'#shop_association_ajax\').remove(); // Initialize checkbox $(\'.input_shop\').each(function(k, v) { check_shop_group_status($(v).val()); check_all_shop(); }); }); </script>'; } } } return $html; }
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; }
/** * @param int $id_category_product * @param int $id_category_discount * @return bool * @deprecated */ public static function isParentCategoryProductDiscount($id_category_product, $id_category_discount) { Tools::displayAsDeprecated(); $category = new Category((int) $id_category_product); $parentCategories = $category->getParentsCategories(); foreach ($parentCategories as $parentCategory) { if ($id_category_discount == $parentCategory['id_category']) { return true; } } return false; }
/** * Convert the entities data into an xml object and return the xml object as a string * * @param array $aEntity Entity data */ public function formatEntityToXML($aEntity) { global $link; $sReturn = ''; $dom = new DOMDocument('1.0', 'utf-8'); $oProduct = new Product((int) $aEntity['id_product'], true); if ((int) $oProduct->quantity < (int) $this->productMinQuantity) { $this->nbEntitiesTreated--; $this->nbEntities--; return ' '; } $ps_tax = (int) Configuration::get('PS_TAX'); foreach ($this->aLanguages as $aLanguage) { $id_lang = (int) $aLanguage['id_lang']; // Set the root of the XML $root = $dom->createElement($this->sEntity); $dom->appendChild($root); //$root->setAttribute('timestamp', date('c',strtotime($oProduct->date_add))); $root->setAttribute('timestamp', (int) strtotime($oProduct->date_add)); $id = $dom->createElement('id', (int) $oProduct->id); $root->appendChild($id); $profile = $dom->createElement('profile', $id_lang); $root->appendChild($profile); $name = $dom->createElement('name'); $name->appendChild($dom->createCDATASection($oProduct->name[$id_lang])); $root->appendChild($name); $oCategory = new Category((int) $oProduct->id_category_default); $aCategories = $oCategory->getParentsCategories($id_lang); if (is_array($aCategories) && count($aCategories) > 0) { foreach ($aCategories as $aCategory) { $oCategoryTmp = new Category((int) $aCategory['id_category'], $id_lang); if (!empty($oCategoryTmp->name)) { $genre = $dom->createElement('genre'); $genre->appendChild($dom->createCDATASection($oCategoryTmp->name)); $root->appendChild($genre); } unset($oCategoryTmp); } } unset($aCategories); unset($oCategory); if (!empty($oProduct->ean13)) { $ean = $dom->createElement('ean'); $ean->appendChild($dom->createCDATASection($oProduct->ean13)); $root->appendChild($ean); } $price = $dom->createElement('price', number_format($oProduct->getPrice($ps_tax), 2, '.', '')); $root->appendChild($price); if (isset($oProduct->tags[$id_lang]) && ($aTags = $oProduct->tags[$id_lang])) { $tag = $dom->createElement('tag'); $tag->appendChild($dom->createCDATASection(join(',', $aTags))); $root->appendChild($tag); } $sDesc = trim(strip_tags($oProduct->description[$id_lang])); if ($this->descInExport && !empty($sDesc)) { $description = $dom->createElement('description'); $description->appendChild($dom->createCDATASection($sDesc)); $root->appendChild($description); } if (!empty($oProduct->id_manufacturer)) { $supplierid = $dom->createElement('supplierid', (int) $oProduct->id_manufacturer); $root->appendChild($supplierid); } $recommendable = $dom->createElement('recommendable', in_array((int) $oProduct->id, $this->aProductsNotRecommendable) ? 'false' : 'true'); $root->appendChild($recommendable); $searchable = $dom->createElement('searchable', in_array((int) $oProduct->id, $this->aProductsNotSearchable) ? 'false' : 'true'); $root->appendChild($searchable); // Set product URL $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName', 'producturl'); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($link->getProductLink((int) $oProduct->id, $oProduct->link_rewrite[$id_lang], Category::getLinkRewrite((int) $oProduct->id_category_default, $id_lang), NULL, $id_lang))); $attribute->appendChild($attValue); // Set product picture if ($this->imageInExport) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName', 'imageurl'); $attribute->appendChild($attName); $aCover = $oProduct->getCover((int) $oProduct->id); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($link->getImageLink($oProduct->link_rewrite[$id_lang], (int) $aCover['id_image'], 'large'))); $attribute->appendChild($attValue); } // Set combinations $aProductCombinations = $oProduct->getAttributeCombinaisons($id_lang); if (sizeof($aProductCombinations)) { foreach ($aProductCombinations as $aProductCombination) { if (!is_array($this->aAttributesGroupsIds) || in_array((int) $aProductCombination['id_attribute_group'], $this->aAttributesGroupsIds)) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection($aProductCombination['group_name'])); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($aProductCombination['attribute_name'])); $attribute->appendChild($attValue); } } } unset($aProductCombinations); // Set features $aProductFeatures = $oProduct->getFrontFeatures($id_lang); if (sizeof($aProductFeatures)) { foreach ($aProductFeatures as $aProductFeature) { if (!is_array($this->aFeaturesIds) || in_array((int) $aProductFeature['id_feature'], $this->aFeaturesIds)) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection($aProductFeature['name'])); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($aProductFeature['value'])); $attribute->appendChild($attValue); } } } unset($aProductFeatures); $aAccessories = Product::getAccessoriesLight($id_lang, (int) $oProduct->id); if (sizeof($aAccessories)) { foreach ($aAccessories as $aAccessory) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection('accessory')); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($aAccessory['reference'])); $attribute->appendChild($attValue); } } unset($aAccessories); $sReturn .= $dom->saveXML($root); } unset($dom); unset($oProduct); return $sReturn; }