*/require_once dirname(__FILE__).'/MegahomefeaturedCore.php';class MegaHomeFeatured extends MegaHomeFeaturedCore{ private $_html = ''; private $_postErrors = array(); function __construct() { $this->name = 'megahomefeatured'; $this->tab = 'front_office_features'; $this->version = 1.0; $this->author = 'www.alabazweb.com'; parent::__construct(); // The parent construct is required for translations $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Mega Featured Products on the homepage'); $this->description = $this->l('Displays Featured Products in the middle of your homepage or random products'); } function install() { if (!Configuration::updateValue('MEGA_HOME_FEATURED_NBR', 0) OR !Configuration::updateValue('MEGA_HOME_FEATURED_RANDOM', 1) OR !Configuration::updateValue('MEGA_HOME_FEATURED_TIME', 10) OR !Configuration::updateValue('MEGA_HOME_FEATURED_TEMPLATES', 1) OR !parent::install() OR !$this->registerHook('home') OR !$this->registerHook('header')) return false; return true; } public function _displayHomeContent() { $this->getHeaderContent(); $this->displayForm(); } public function getHeaderContent() { $this->_html = ''; if (Tools::isSubmit('submitHomeFeatured')) { $nbr = intval(Tools::getValue('nbr')); $ran = intval(Tools::getValue('random')); $time = intval(Tools::getValue('time')); $categories = Tools::getValue('categoryBox'); $templates = intval(Tools::getValue('templates')); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('Invalid number of product'); elseif (!$time OR $time <= 0 OR !Validate::isInt($time)) $errors[] = $this->l('Invalid time in seconds'); else { Configuration::updateValue('MEGA_HOME_FEATURED_NBR', $nbr); Configuration::updateValue('MEGA_HOME_FEATURED_RANDOM', $ran); Configuration::updateValue('MEGA_HOME_FEATURED_TIME', $time); Configuration::updateValue('MEGA_HOME_FEATURED_TEMPLATES', $templates); if(isset($categories) && $categories!='') Configuration::updateValue('MEGA_HOME_FEATURED_CATEGORIES', implode(",", array_filter($categories))); else Configuration::updateValue('MEGA_HOME_FEATURED_CATEGORIES',''); } } return $this->_html; } public function getContent() { $this->_html .= $this->checkCurrency(true,true,true); return $this->_html; } public static function getAssociateCategories($id_faq) { $ids = explode(",", Configuration::get('MEGA_HOME_FEATURED_CATEGORIES')); if($ids) { $arrayIds = array(); foreach($ids as $id) { if(!in_array($id['id_category'], $arrayIds)) array_push($arrayIds, $id['id_category']); } return $arrayIds; } return false; } public function displayForm() { $root = Category::getRootCategory(); $default_category = array(); $selected_cat = array(); //$cats = self::getAssociateCategories(Tools::getValue('id_loffaq_faq')); $cats = explode(",", Configuration::get('MEGA_HOME_FEATURED_CATEGORIES')); if($cats) { $selected_cat = $cats; } //else $tab_root = array('id_category' => $root->id, 'name' => $root->name); $helper = new Helper(); if(_PS_VERSION_<1.5) { $category_tree = $helper->renderAdminCategorieTree($tab_root, $selected_cat, 'categoryBox'); } else if(_PS_VERSION_<1.6) { $category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, false, array(), false, true); } else { $tree_categories_helper = new HelperTreeCategories('categoryBox', $this->l('Select Categories')); $tree_categories_helper->setRootCategory((Shop::getContext() == Shop::CONTEXT_SHOP ? Category::getRootCategory()->id_category : 0)) ->setUseCheckBox(true)->setSelectedCategories($selected_cat); $category_tree= $tree_categories_helper->render(); // $category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, true, array(), false, true); } $this->_html .= '
'.$this->l('Settings').'

'.$this->l('The number of products displayed on homepage (default: 10)').'

'; /* */ $this->_html .= $category_tree; $this->_html .= '

'.$this->l('The number of seconds with change products (default: 10)').'

'; return $this->_html; } function hookHeader($params) { $context = Context::getContext(); $context->controller->addCSS(($this->_path).'megahomefeatured.css', 'all'); if(_PS_VERSION_<1.6) $context->controller->addCSS(_THEME_DIR_.'css/product_list.css', 'all'); } function getHomeTemplate() { global $smarty,$cookie; $template = Configuration::get('MEGA_HOME_FEATURED_TEMPLATES'); $product_list = ''; if($template==1) { if (file_exists(_PS_THEME_DIR_.'modules/homefeatured/views/templates/hook/homefeatured.tpl')) $product_list = $smarty->fetch(_PS_THEME_DIR_.'modules/homefeatured/views/templates/hook/homefeatured.tpl'); elseif(file_exists(_PS_MODULE_DIR_.'homefeatured/views/templates/hook/homefeatured.tpl')) $product_list = $smarty->fetch(_PS_MODULE_DIR_.'homefeatured/views/templates/hook/homefeatured.tpl'); elseif(file_exists(_PS_THEME_DIR_.'homefeatured/homefeatured.tpl')) $product_list = $smarty->fetch(_PS_THEME_DIR_.'homefeatured/homefeatured.tpl'); elseif(file_exists(_PS_MODULE_DIR_.'homefeatured/homefeatured.tpl')) $product_list = $smarty->fetch(_PS_MODULE_DIR_.'homefeatured/homefeatured.tpl'); } elseif($template==0) { $product_list = $smarty->fetch( _PS_THEME_DIR_.'product-list.tpl'); } else { if (file_exists(_PS_THEME_DIR_.'modules/megahomefeatured/megahomefeaturedtemplate.tpl')) $product_list = $smarty->fetch(_PS_THEME_DIR_.'modules/megahomefeatured/megahomefeaturedtemplate.tpl'); else $product_list = $smarty->fetch(_PS_MODULE_DIR_.'megahomefeatured/megahomefeaturedtemplate.tpl'); } return $product_list; } function hookHome($params) { global $smarty,$cookie; $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = intval(Configuration::get('MEGA_HOME_FEATURED_NBR')); $rand = intval(Configuration::get('MEGA_HOME_FEATURED_RANDOM')); $time = intval(Configuration::get('MEGA_HOME_FEATURED_TIME')); $showproducts = Configuration::get('MEGA_HOME_FEATURED_CATEGORIES'); if($rand==0 || $showproducts=='') $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb); else $products = self::getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10),$showproducts); $smarty->assign(array( 'allow_buy_when_out_of_stock' => Configuration::get('PS_ORDER_OUT_OF_STOCK', false), 'max_quantity_to_allow_display' => Configuration::get('PS_LAST_QTIES'), 'category' => $category, 'products' => $products, 'showli' => 1, 'currency' => new Currency(intval($params['cart']->id_currency)), 'random' => $rand, 'time' => $time, 'homeSize' => Image::getSize('home'), 'lang' => Language::getIsoById(intval($params['cookie']->id_lang)), 'productNumber' => sizeof($products), 'this_path' => $this->_path, 'tpl_module' => _PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax.php', 'tpl_module1' => Tools::getHttpHost(true, true).__PS_BASE_URI__.'modules/megahomefeatured/', )); $product_list = ''; if($this->checkCurrency(true, false,false)) $product_list = $this->getHomeTemplate(); $smarty->assign('product_list',$product_list); return $this->display(__FILE__, 'megahomefeatured.tpl'); } public function hookDisplayAwCustomView() { $this->_displayHomeContent(); return $this->_html; } public static function getProducts($id_lang, $p, $n,$categories) { $context = Context::getContext(); if ($p < 1) $p = 1; $order_by = 'position'; $order_way = 'ASC'; $wherecategories = ''; if($categories!='') $wherecategories .= ' AND cp.`id_category` IN ('.$categories.') '; $sql = 'SELECT DISTINCT p.`id_product`, p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, image_shop.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, (product_shop.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop).' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$context->country->id.' AND tr.`id_state` = 0 AND tr.`zipcode_from` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND p.active = 1 AND (pa.id_product_attribute IS NULL OR product_attribute_shop.id_shop='.(int)$context->shop->id.') AND (i.id_image IS NULL OR image_shop.id_shop='.(int)$context->shop->id.')'.$wherecategories; $sql .= ' ORDER BY RAND()'; $sql .= ' LIMIT 0, '.(int)$n; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) return false; /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); }} Chitel.es

Chitel.es

Reciba un newsletter

Envíos

24 / 48 horas

Devoluciones

14 días

Pago seguro

Tarjeta, pay pal y transferencia

Ir al Inicio