/**
  * Assign template vars related to category
  */
 protected function assignCategory()
 {
     // Assign category to the template
     if ($this->category !== false && Validate::isLoadedObject($this->category)) {
         $this->context->smarty->assign(array('path' => Tools::getPath($this->category->id, $this->product->name, true), 'category' => $this->category, 'subCategories' => $this->category->getSubCategories($this->context->language->id, true), 'id_category_current' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->name)));
     } else {
         $this->context->smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name));
     }
     $this->context->smarty->assign('categories', Category::getHomeCategories($this->context->language->id));
     $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
 }
Example #2
0
 public function renderContent($args, $setting)
 {
     $t = array('category_id' => '');
     $setting = array_merge($t, $setting);
     $category = new Category($setting['category_id'], $this->langID);
     $subCategories = $category->getSubCategories($this->langID);
     $setting['title'] = $category->name;
     $setting['subcategories'] = $subCategories;
     $output = array('type' => 'sub_categories', 'data' => $setting);
     return $output;
 }
Example #3
0
 /**
  * Assign template vars related to category.
  */
 protected function assignCategory()
 {
     // Assign category to the template
     if (($this->category === false || !Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop()) && Category::inShopStatic($this->product->id_category_default, $this->context->shop)) {
         $this->category = new Category((int) $this->product->id_category_default, (int) $this->context->language->id);
     }
     $sub_categories = array();
     if (Validate::isLoadedObject($this->category)) {
         $sub_categories = $this->category->getSubCategories($this->context->language->id, true);
         // various assignements before Hook::exec
         $this->context->smarty->assign(array('category' => $this->category, 'subCategories' => $sub_categories, 'id_category_current' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->getFieldByLang('name')), 'categories' => Category::getHomeCategories($this->context->language->id, true, (int) $this->context->shop->id)));
     }
 }
 /**
  * Assign template vars related to category
  */
 protected function assignCategory()
 {
     // Assign category to the template
     if ($this->category !== false && Validate::isLoadedObject($this->category) && $this->category->inShop() && $this->category->isAssociatedToShop()) {
         $path = Tools::getPath($this->category->id, $this->product->name, true);
     } elseif (Category::inShopStatic($this->product->id_category_default, $this->context->shop)) {
         $this->category = new Category((int) $this->product->id_category_default);
         if (Validate::isLoadedObject($this->category) && $this->category->active && $this->category->isAssociatedToShop()) {
             $path = Tools::getPath((int) $this->product->id_category_default, $this->product->name);
         }
     }
     if (!isset($path) || !$path) {
         $path = Tools::getPath((int) $this->context->shop->id_category, $this->product->name);
     }
     // various assignements before Hook::exec
     $this->context->smarty->assign(array('path' => $path, 'category' => $this->category, 'subCategories' => $this->category->getSubCategories($this->context->language->id, true), 'id_category_current' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->name), 'categories' => Category::getHomeCategories($this->context->language->id, true, (int) $this->context->shop->id)));
     $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
 }
 public function hookDisplayHome($params)
 {
     if (!$this->isCached('blockhomecategories.tpl', $this->getCacheId('blockhomecategories'))) {
         $categoryRoot = new Category((int) Configuration::get('BLK_FEATURED_CAT_ID'), $this->context->language->id, $this->context->shop->id);
         $categoriesHome = $categoryRoot->getSubCategories($this->context->language->id, true, true);
         array_splice($categoriesHome, (int) Configuration::get('BLK_FEATURED_CATEGORIES_NBR'));
         foreach ($categoriesHome as $key => $item) {
             if ($item['level_depth'] > 1) {
                 $categoryRoot = new Category($item['id_category'], $this->context->language->id, $this->context->shop->id);
                 $categoriesHome[$key]['childcategory'] = $categoryRoot->getSubCategories($this->context->language->id, true, true);
                 $categoriesHome[$key]['count_cild'] = count($categoriesHome[$key]['childcategory']);
                 array_splice($categoriesHome[$key]['childcategory'], (int) Configuration::get('BLK_FEATURED_CHILD_CATEGORIES_NBR'));
             }
         }
         $this->smarty->assign(array('categories' => $categoriesHome, 'max_child_cats' => (int) Configuration::get('BLK_FEATURED_CHILD_CATEGORIES_NBR'), 'homeSize' => Image::getSize('medium_default')));
     }
     return $this->display(__FILE__, 'blockhomecategories.tpl', $this->getCacheId('blockhomecategories'));
 }
Example #6
0
    public function hookLeftColumn($params)
    {
        $this->setLastVisitedCategory();
        $phpself = $this->context->controller->php_self;
        $current_allowed_controllers = array('category');
        if ($phpself != null && in_array($phpself, $current_allowed_controllers) && Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) {
            $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id);
            if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 2 && !$category->is_root_category && $category->id_parent) {
                $category = new Category($category->id_parent, $this->context->language->id);
            } elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 3 && !$category->is_root_category && !$category->getSubCategories($category->id, true)) {
                $category = new Category($category->id_parent, $this->context->language->id);
            }
        } else {
            $category = new Category((int) Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
        }
        $cacheId = $this->getCacheId($category ? $category->id : null);
        if (!$this->isCached('blockcategories.tpl', $cacheId)) {
            $range = '';
            $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
            if (Validate::isLoadedObject($category)) {
                if ($maxdepth > 0) {
                    $maxdepth += $category->level_depth;
                }
                $range = 'AND nleft >= ' . (int) $category->nleft . ' AND nright <= ' . (int) $category->nright;
            }
            $resultIds = array();
            $resultParents = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
			FROM `' . _DB_PREFIX_ . 'category` c
			INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ')
			INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ')
			WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ')
			AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . '
			' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . '
			' . $range . '
			AND c.id_category IN (
				SELECT id_category
				FROM `' . _DB_PREFIX_ . 'category_group`
				WHERE `id_group` IN (' . pSQL(implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id))) . ')
			)
			ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'));
            foreach ($result as &$row) {
                $resultParents[$row['id_parent']][] =& $row;
                $resultIds[$row['id_category']] =& $row;
            }
            $blockCategTree = $this->getTree($resultParents, $resultIds, $maxdepth, $category ? $category->id : null);
            $this->smarty->assign('blockCategTree', $blockCategTree);
            if ((Tools::getValue('id_product') || Tools::getValue('id_category')) && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) {
                $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id);
                if (Validate::isLoadedObject($category)) {
                    $this->smarty->assign(array('currentCategory' => $category, 'currentCategoryId' => $category->id));
                }
            }
            $this->smarty->assign('isDhtml', Configuration::get('BLOCK_CATEG_DHTML'));
            if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories.tpl')) {
                $this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl');
            } else {
                $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl');
            }
        }
        return $this->display(__FILE__, 'blockcategories.tpl', $cacheId);
    }
Example #7
0
    public static function getRandomSpecialCategory($categoryid, $id_lang, $beginning = false, $ending = false)
    {
        $category = new Category($categoryid, Configuration::get('PS_LANG_DEFAULT'));
        $subcategories = $category->getSubCategories($id_lang);
        $subcategoryidArr = array();
        foreach ($subcategories as $subcategory) {
            $subcategoryidArr[] = $subcategory['id_category'];
        }
        $subcategoryidArr[] = $categoryid;
        $cateid = implode(', ', $subcategoryidArr);
        $currentDate = date('Y-m-d H:i:s');
        $ids_product = self::_getProductIdByDate(!$beginning ? $currentDate : $beginning, !$ending ? $currentDate : $ending);
        $groups = FrontController::getCurrentCustomerGroups();
        $sqlGroups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
        $sql = 'SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,  p.`upc`,
			i.`id_image`, il.`legend`, t.`rate`
		FROM `' . _DB_PREFIX_ . 'product` p
		LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`													AND tr.`id_country` = ' . (int) Country::getDefaultCountryId() . '
													AND tr.`id_state` = 0)
		LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
		WHERE p.id_product IN (' . implode(', ', $ids_product) . ') and p.id_category_default in (' . implode(', ', $subcategoryidArr) . ')';
        $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
        $results = array();
        foreach ($rows as $row) {
            $results[] = Product::getProductProperties($id_lang, $row);
        }
        return $results;
    }
 function getSubCategories()
 {
     $session = Session::singletone();
     $db = Database::singletone()->db();
     $cid = Utils::pg("cid", 0);
     $full = Utils::pg("full-tree", 0);
     $this->_query->appendChild($this->_dom->createElement("category-id", $cid));
     if ($cid < 0) {
         $this->error("bad-arguments");
         return;
     }
     $subs = Category::getSubCategories($cid);
     foreach ($subs as $sub) {
         $el = $this->_dom->createElement("category");
         $el->appendChild($this->_dom->createElement("category-id", $sub['category_id']));
         $el->appendChild($this->_dom->createElement("subcategories-count", $sub['subcategories_count']));
         $el->appendChild($this->_dom->createElement("category-name", $sub['category_name']));
         $el->appendChild($this->_dom->createElement("category-description", $sub['category_description']));
         $el->appendChild($this->_dom->createElement("category-order", $sub['category_order']));
         $el->appendChild($this->_dom->createElement('category-created', Utils::formatTime($sub['category_created'], Config::getUser($session->uid(), 'datetime-format'))));
         $el->appendChild($this->_dom->createElement('creator-id', $sub['category_creator']));
         $el->appendChild($this->_dom->createElement('creator-login', $sub['creator_login']));
         $el->appendChild($this->_dom->createElement('creator-name', $sub['creator_name']));
         $el->appendChild($this->_dom->createElement('creator-title', $sub['creator_title']));
         $el->appendChild($this->_dom->createElement('photos-count', Category::getPhotosCount($sub['category_id'], false)));
         $el->appendChild($this->_dom->createElement('total-photos-count', Category::getPhotosCount($sub['category_id'], true)));
         $this->_response->appendChild($el);
     }
     $this->success();
 }
Example #9
0
 public function renderWidgetSub_categoriesContent($args, $setting)
 {
     # validate module
     unset($args);
     $t = array('category_id' => '', 'limit' => '12');
     $setting = array_merge($t, $setting);
     //			$nb = (int)$setting['limit'];
     $category = new Category($setting['category_id'], $this->langID);
     $subCategories = $category->getSubCategories($this->langID);
     $setting['title'] = $category->name;
     $setting['subcategories'] = $subCategories;
     $output = array('type' => 'sub_categories', 'data' => $setting);
     return $output;
 }
Example #10
0
    function hookAjaxCall()
    {
        $action = Tools::getValue('action');
        $errors = null;
        $id_shop = null;
        if (Tools::getValue('id_shop') != '' && Tools::getValue('id_shop') != 0) {
            Shop::setContext(Shop::CONTEXT_SHOP, Tools::getValue('id_shop'));
            $id_shop = (int) Shop::getContextShopID();
        } else {
            $id_shop = Configuration::get('PS_SHOP_DEFAULT');
        }
        if ($action == "delete") {
            $link = new MegaMenuClass((int) Tools::getValue('id'));
            Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'megamenu` SET `position` = (`position` - 0.01) WHERE `position` > ' . $link->position . ' AND `parent` = ' . $link->parent);
            $link->delete();
            echo Tools::jsonEncode('Link deleted successfully');
        } elseif ($action == "enable") {
            if (Tools::getValue('custom') == 'true') {
                $link = new MegaMenuClass((int) Tools::getValue('id'));
                $link->active = $link->active ? 0 : 1;
                $link->update();
                $response = array('msg' => 'Item status has changed.', 'active' => $link->active);
                // if categories element
            } else {
                $active = null;
                $CATS = Configuration::get('MEGAMENU_CATS');
                $UN_CATS = array();
                $UN_CATS = unserialize($CATS);
                // get serialzie date
                if (empty($UN_CATS)) {
                    is_array($UN_CATS) == false ? $UN_CATS = array() : '';
                    // add first time if empty
                    array_push($UN_CATS, (int) Tools::getValue('id'));
                    $SE_CATS = serialize($UN_CATS);
                    Configuration::updateValue('MEGAMENU_CATS', $SE_CATS);
                    $active = 0;
                } else {
                    if (in_array(Tools::getValue('id'), $UN_CATS)) {
                        foreach ($UN_CATS as $key => $value) {
                            if ($value == Tools::getValue('id')) {
                                unset($UN_CATS[$key]);
                                $active = 1;
                            }
                        }
                    } else {
                        $active = 0;
                        array_push($UN_CATS, (int) Tools::getValue('id'));
                    }
                    //corect keys
                    $UN_CATS = array_values($UN_CATS);
                    //serialize and save configuration
                    $SE_CATS = serialize($UN_CATS);
                    Configuration::updateValue('MEGAMENU_CATS', $SE_CATS);
                }
                $response = array('msg' => 'Item status has changed.', 'active' => $active);
            }
            echo Tools::jsonEncode($response);
        } elseif ($action == "edit") {
            $link = new MegaMenuClass((int) Tools::getValue('id'), Context::getContext()->cookie->id_lang);
            echo Tools::jsonEncode($link);
        } elseif ($action == "add") {
            $link = new MegaMenuClass();
            $link->active = 1;
            $link->parent = (int) Tools::getValue('parent');
            $link->parent_custom = Tools::getValue('custom') == 'true' ? 1 : 0;
            $link->copyFromPost();
            $link->add();
            $response = array('id' => $link->id, 'parent' => $link->parent, 'name' => $link->name[Context::getContext()->cookie->id_lang], 'msg' => 'Menu item added.');
            echo Tools::jsonEncode($response);
        } elseif ($action == "saveedit") {
            $link = new MegaMenuClass((int) Tools::getValue('id_megamenu'));
            $link->copyFromPost();
            $link->update();
            $item = new MegaMenuClass((int) Tools::getValue('id_megamenu'), Context::getContext()->cookie->id_lang);
            $response = array('msg' => 'Item modified.', 'item' => $item);
            echo Tools::jsonEncode($response);
        } elseif ($action == "copycms") {
            $id_cms = array((int) Tools::getValue('id_cms'));
            $cmslink[] = null;
            $languages = Language::getLanguages(false);
            foreach ($languages as $language) {
                $cms = CMS::getLinks($language['id_lang'], $id_cms);
                $cmslink += array('name_' . $language['id_lang'] => $cms[0]['meta_title'], 'title_' . $language['id_lang'] => $cms[0]['meta_title'], 'url_' . $language['id_lang'] => $cms[0]['link']);
            }
            if (!$errors) {
                $link = new MegaMenuClass();
                $link->active = 1;
                $link->parent = (int) Tools::getValue('parentid');
                $link->parent_custom = Tools::getValue('custom') == 'true' ? 1 : 0;
                $link->copyFromPost($cmslink);
                $link->add();
                $response = array('id' => $link->id, 'parent' => $link->parent, 'name' => $link->name[Context::getContext()->cookie->id_lang], 'msg' => 'Cms item added.');
                echo Tools::jsonEncode($response);
            } else {
                $error = array('error' => $errors);
                echo Tools::jsonEncode($error);
            }
        } elseif ($action == "position") {
            $csvAll = explode(",", Tools::getValue('csv'));
            $total = count($csvAll) - 1;
            for ($i = 0; $i < $total; $i++) {
                $csv = explode("/", $csvAll[$i]);
                Db::getInstance()->Execute('update `' . _DB_PREFIX_ . 'megamenu` set position = ' . (double) $csv[2] . ', parent = ' . $csv[1] . ', parent_custom = ' . ($csv[3] == 'true' ? 1 : 0) . ' where id_megamenu = ' . $csv[0]);
            }
            echo Tools::jsonEncode('Position update.');
        } elseif ($action == "removeimage") {
            $id = Tools::getValue('id');
            if (file_exists(dirname(__FILE__) . "/images/" . $id . '.jpg')) {
                unlink(dirname(__FILE__) . "/images/" . $id . '.jpg');
            }
        } elseif ($action == "gettree") {
            $response = null;
            $subs = null;
            if (Tools::getValue('custom') == 'false') {
                $cat = new Category((int) Tools::getValue('id'));
                if (version_compare(_PS_VERSION_, '1.5.0.0') == +1) {
                    $subs = $this->getSubCategories($cat->id, Context::getContext()->cookie->id_lang, true);
                } else {
                    $subs = $cat->getSubCategories($cookie->id_lang, true);
                }
                //get disable categories
                $CATS = Configuration::get('MEGAMENU_CATS');
                $UN_CATS = array();
                $UN_CATS = unserialize($CATS);
            }
            $customLinks = MegaMenuClass::getCustomLinks(Tools::getValue('id'), Tools::getValue('custom'), Configuration::get('PS_LANG_DEFAULT'), $id_shop);
            if (count($subs) > 0) {
                $allLinks = array_merge($subs, $customLinks);
                $this->aasort($allLinks, "position");
            } else {
                $allLinks = $customLinks;
            }
            //echo( print_r($allLinks) );
            if ($allLinks) {
                foreach ($allLinks as $link) {
                    if (isset($link['id_category'])) {
                        $children = MegaMenuClass::getNBchildren(false, $link['id_category']);
                        $response .= '<li class="' . ($children > 0 ? 'parent collapsed' : '') . '" data-id="' . $link['id_category'] . '" pos="' . $link['position'] . '">
	                            	<a class="caption ui-droppable ' . (is_array($UN_CATS) && in_array($link['id_category'], $UN_CATS) == true ? 'disable' : 'enable') . '" rel="' . $link['id_category'] . '">' . $link['name'] . '</a>
	                             </li>';
                    } else {
                        $children = MegaMenuClass::getNBchildren(true, $link['id_megamenu']);
                        $response .= '<li class="custom ' . ($children > 0 ? 'parent collapsed' : '') . '" data-id="' . $link['id_megamenu'] . '" pos="' . $link['position'] . '">
	                        		<span class="custom-img"></span>
	                        		<a class="caption ui-droppable  ' . ($link['active'] ? 'enable' : 'disable') . '" rel="' . $link['id_megamenu'] . '">' . $link['name'] . '</a>
	                      	  </li>';
                    }
                }
            }
            echo $response;
        }
    }
Example #11
0
 /**
  *
  * Returns an array of News article IDs belonging to the search categories
  */
 protected function subsetNewsCategories()
 {
     global $_zp_CMS;
     if (!is_array($this->category_list)) {
         return false;
     }
     $cat = '';
     $list = $_zp_CMS->getAllCategories();
     if (!empty($list)) {
         foreach ($list as $category) {
             if (in_array($category['title'], $this->category_list)) {
                 $catobj = new Category($category['titlelink']);
                 $cat .= ' `cat_id`=' . $catobj->getID() . ' OR';
                 $subcats = $catobj->getSubCategories();
                 if ($subcats) {
                     foreach ($subcats as $subcat) {
                         $catobj = new Category($subcat);
                         $cat .= ' `cat_id`=' . $catobj->getID() . ' OR';
                     }
                 }
             }
         }
         if ($cat) {
             $cat = ' WHERE ' . substr($cat, 0, -3);
         }
     }
     $sql = 'SELECT DISTINCT `news_id` FROM ' . prefix('news2cat') . $cat;
     $result = query($sql);
     $list = array();
     if ($result) {
         while ($row = db_fetch_assoc($result)) {
             $list[] = $row['news_id'];
         }
         db_free_result($result);
     }
     return $list;
 }
 public function getWidgetVariables($hookName = null, array $configuration = [])
 {
     $category = new Category((int) Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
     if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) {
         $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id);
         if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 2 && !$category->is_root_category && $category->id_parent) {
             $category = new Category($category->id_parent, $this->context->language->id);
         } elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 3 && !$category->is_root_category && !$category->getSubCategories($category->id, true)) {
             $category = new Category($category->id_parent, $this->context->language->id);
         }
     }
     return ['categories' => $this->getCategories($category), 'currentCategory' => $category->id];
 }