public function renderContent($setting) { $t = array('list_type' => '', 'limit' => 12, 'image_width' => '200', 'image_height' => '200'); $products = array(); $setting = array_merge($t, $setting); switch ($setting['list_type']) { case 'newest': $products = Product::getNewProducts($this->lang_id, 0, (int) $setting['limit']); break; case 'featured': $category = new Category(Context::getContext()->shop->getCategory(), $this->lang_id); $nb = (int) $setting['limit']; $products = $category->getProducts((int) $this->lang_id, 1, $nb ? $nb : 8); break; case 'bestseller': $products = ProductSale::getBestSalesLight((int) $this->lang_id, 0, (int) $setting['limit']); break; case 'special': $products = Product::getPricesDrop($this->lang_id, 0, (int) $setting['limit']); break; } $setting['products'] = $products; $output = array('type' => 'productlist', 'data' => $setting); return $output; }
public function renderContent($setting) { $t = array('limit' => '6', 'columns' => 4, 'list_mode' => 'grid', 'display_mode' => 'carousel', 'nbr_desktops' => 4, 'nbr_tablets' => 2, 'nbr_mobile' => 1); $setting = array_merge($t, $setting); $nb = (int) $setting['limit']; $porder = 'date add'; $porder = preg_split('#\\s+#', $porder); $special = Product::getPricesDrop((int) $this->lang_id, 0, $nb, false); if ($special) { foreach ($special as &$row) { $time = ''; if ($row['specific_prices']['to'] == '0000-00-00 00:00:00') { $row['js'] = 'unlimited'; $row['finish'] = $this->l('Unlimited'); $row['check_status'] = 1; $row['psdate'] = $this->l('Unlimited'); } else { $time = strtotime($row['specific_prices']['to']); $row['finish'] = $this->l('Expired'); $row['check_status'] = 1; $row['psdate'] = $row['specific_prices']['to']; } if ($time) { $row['js'] = array('month' => date('m', $time), 'day' => date('d', $time), 'year' => date('Y', $time), 'hour' => date('H', $time), 'minute' => date('i', $time), 'seconds' => date('s', $time)); } } } $setting['list_mode_tpl'] = $this->getProductListStyleFile($setting['list_mode'], $setting['product_style']); $setting['products'] = $special; $output = array('type' => 'productdeal', 'data' => $setting); return $output; }
public function process() { parent::process(); $this->productSort(); $nbProducts = Product::getPricesDrop((int) self::$cookie->id_lang, NULL, NULL, true); $this->pagination($nbProducts); self::$smarty->assign(array('products' => Product::getPricesDrop((int) self::$cookie->id_lang, (int) $this->p - 1, (int) $this->n, false, $this->orderBy, $this->orderWay), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home'))); }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $this->productSort(); $nbProducts = Product::getPricesDrop($this->context->language->id, null, null, true); $this->pagination($nbProducts); $this->context->smarty->assign(array('products' => Product::getPricesDrop($this->context->language->id, (int) $this->p - 1, (int) $this->n, false, $this->orderBy, $this->orderWay), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $this->setTemplate(_PS_THEME_DIR_ . 'prices-drop.tpl'); }
public function renderContent($setting) { $t = array('end_date' => '', 'limit' => '12', 'image_width' => '200', 'image_height' => '200', 'columns' => 4, 'list_mode' => 'grid', 'display_mode' => 'carousel', 'nbr_desktops' => 4, 'nbr_tablets' => 2, 'nbr_mobile' => 1); $setting = array_merge($t, $setting); $time = strtotime($setting['end_date']); $setting['dates'] = array('month' => date('m', $time), 'day' => date('d', $time), 'year' => date('Y', $time), 'hour' => date('H', $time), 'minute' => date('i', $time), 'seconds' => date('s', $time)); $nb = (int) $setting['limit']; $special = Product::getPricesDrop((int) $this->lang_id, 0, $nb, false, null, null, false, $setting['end_date']); $setting['list_mode_tpl'] = $this->getProductListStyleFile($setting['list_mode'], $setting['product_style']); $setting['products'] = $special; $output = array('type' => 'flashsale', 'data' => $setting); return $output; }
public function hookHome($params) { if (Configuration::get('PS_CATALOG_MODE')) { return; } global $smarty; $tmp = Product::getPricesDrop(intval($params['cookie']->id_lang)); asort($tmp); if (!($special = Product::getRandomSpecial((int) $params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) { return; } $this->smarty->assign(array('special' => $special, 'specials' => $tmp, 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'mediumSize' => Image::getSize('medium_default'))); return $this->display(__FILE__, 'tmspecials.tpl'); }
public function renderContent($args, $setting) { # validate module unset($args); $t = array('name' => '', 'html' => ''); $setting = array_merge($t, $setting); $nb = $setting['itemstab'] ? (int) $setting['itemstab'] : 8; $orderby = $setting['orderby'] ? $setting['orderby'] : 'date_add'; $orderway = $setting['orderway'] ? $setting['orderway'] : 'date_add'; $items_page = $columns_page = 3; if (isset($setting['itemspage']) && $setting['itemspage']) { $items_page = $setting['itemspage']; } if (isset($setting['columns']) && $setting['columns']) { $columns_page = $setting['columns']; } $interval = isset($setting['interval']) ? (int) $setting['interval'] : 8000; switch ($setting['specialtype']) { case 'newest': $products = Product::getNewProducts($this->langID, 0, $nb, false, $orderby, $orderway); break; case 'featured': $category = new Category(Context::getContext()->shop->getCategory(), $this->langID); $products = $category->getProducts((int) $this->langID, 1, $nb, $orderby, $orderway); break; case 'bestseller': $products = ProductSale::getBestSalesLight((int) $this->langID, 0, $nb); break; case 'special': $products = Product::getPricesDrop($this->langID, 0, $nb, false, $orderby, $orderway); break; case 'random': $random = true; $products = $this->getProducts('WHERE p.id_product > 0', (int) Context::getContext()->language->id, 1, $nb, $orderby, $orderway, false, true, $random, $nb); Configuration::updateValue('LEO_CURRENT_RANDOM_CACHE', '1'); break; } $setting['specialtype'] = $setting['specialtype']; Context::getContext()->controller->addColorsToProductList($products); $setting['products'] = $products; $setting['itemsperpage'] = $items_page; $setting['columnspage'] = $columns_page; $setting['scolumn'] = 12 / $columns_page; $setting['interval'] = $interval; $setting['tab'] = 'leospecialproduct' . rand(20, rand()); $output = array('type' => 'specialproduct', 'data' => $setting); return $output; }
public function renderContent($args, $setting) { # validate module unset($args); $t = array('name' => '', 'html' => ''); $setting = array_merge($t, $setting); $setting['special'] = array(); $setting['bestseller'] = array(); $setting['featured'] = array(); $setting['newproducts'] = array(); $category = new Category(Context::getContext()->shop->getCategory(), (int) Context::getContext()->language->id); $nb = $setting['itemstab'] ? (int) $setting['itemstab'] : 6; $orderby = $setting['orderby'] ? $setting['orderby'] : 'position'; $orderway = $setting['orderway'] ? $setting['orderway'] : 'ASC'; $items_page = $setting['itemspage'] ? (int) $setting['itemspage'] : 3; $columns_page = $setting['columns'] ? (int) $setting['columns'] : 3; $interval = isset($setting['interval']) ? (int) $setting['interval'] : 8000; if ($setting['featured_display'] && $setting['featured_display'] == 1) { $pro_featured = $category->getProducts((int) Context::getContext()->language->id, 1, $nb, $orderby, $orderway); Context::getContext()->controller->addColorsToProductList($pro_featured); $setting['featured'] = $pro_featured; } if ($setting['newarrivals_display'] && $setting['newarrivals_display'] == 1) { $pro_newproducts = Product::getNewProducts((int) Context::getContext()->language->id, 0, $nb, false, $orderby, $orderway); Context::getContext()->controller->addColorsToProductList($pro_newproducts); $setting['newproducts'] = $pro_newproducts; } if ($setting['special_display'] && $setting['special_display'] == 1) { $pro_special = Product::getPricesDrop((int) Context::getContext()->language->id, 0, $nb, false, $orderby, $orderway); Context::getContext()->controller->addColorsToProductList($pro_special); $setting['special'] = $pro_special; } if ($setting['bestseller_display'] && $setting['bestseller_display'] == 1) { $pro_bestseller = ProductSale::getBestSales((int) Context::getContext()->language->id, 0, $nb, $orderby, $orderway); Context::getContext()->controller->addColorsToProductList($pro_bestseller); $setting['bestseller'] = $pro_bestseller; } $setting['itemsperpage'] = $items_page; $setting['columnspage'] = $columns_page; $setting['interval'] = $interval; $setting['scolumn'] = 12 / $columns_page; $setting['homeSize'] = Image::getSize(ImageType::getFormatedName('home')); $setting['myTab'] = 'leoproducttab' . rand(20, rand()); $output = array('type' => 'producttabs', 'data' => $setting); return $output; }
/** * Récupération de la liste des produits * @param string $type * @param int $nb_products */ protected function _getProducts($type, $nb_products) { switch ($type) { case 'price_drop': return Product::getPricesDrop((int) $this->context->language->id, 0, $nb_products); break; case 'category': $this->_datas['id_category'] ? $id_category = $this->_datas['id_category'] : ($id_category = (int) Configuration::get('HOME_FEATURED_CAT')); $category = new Category($id_category, (int) $this->context->language->id); return $category->getProducts((int) $this->context->language->id, 1, $nb_products, 'position'); break; case 'new': default: return Product::getNewProducts((int) $this->context->language->id, 0, $nb_products); break; } }
public function initContent() { parent::initContent(); $this->productSort(); $nbProducts = Product::getPricesDrop($this->context->language->id, null, null, true); $this->pagination($nbProducts); $products = Product::getPricesDrop($this->context->language->id, (int) $this->p - 1, (int) $this->n, false, $this->orderBy, $this->orderWay); $this->addColorsToProductList($products); if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < $nbProducts; $i++) { if (isset($products[$i]['id_product'])) { $image_array[$products[$i]['id_product']] = Product::getProductsImgs($products[$i]['id_product']); } } $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL); } $this->context->smarty->assign(array('products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $this->setTemplate(_PS_THEME_DIR_ . 'prices-drop.tpl'); }
public function initContent() { parent::initContent(); $this->productSort(); $nbProducts = Product::getPricesDrop($this->context->language->id, null, null, true); $this->pagination($nbProducts); $products = Product::getPricesDrop($this->context->language->id, (int) $this->p - 1, (int) $this->n, false, $this->orderBy, $this->orderWay); $this->addColorsToProductList($products); $this->context->smarty->assign(array('HOOK_LEFT_COLUMN' => Hook::exec('displayLeftColumn'), 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); if ($this->ajax) { $product_list = $this->context->smarty->fetch(_PS_THEME_DIR_ . 'product-list.tpl'); $pagination = $this->context->smarty->fetch(_PS_THEME_DIR_ . 'pagination.tpl'); $pagination_bottom = $this->context->smarty->fetch(_PS_THEME_DIR_ . 'pagination_bottom.tpl'); $nbLeftProducts = $nbProducts - ($this->n * ($this->p - 1) + count($products)); $nbLeftProductsPercentage = ($nbProducts - $nbLeftProducts) / $nbProducts * 100; echo Tools::jsonEncode(array('productList' => utf8_encode($product_list), 'pagination' => $pagination, 'pagination_bottom' => $pagination_bottom, 'nbRenderedProducts' => $nbProducts, 'nbLeftProducts' => $nbLeftProducts, 'nbLeftProductsPercentage' => $nbLeftProductsPercentage)); die; } else { $this->setTemplate(_PS_THEME_DIR_ . 'prices-drop.tpl'); } }
/** * get list of Sliders Data following parameter */ public function getData($params) { global $link, $cookie; $nb = (int) $params->get("limit", 10); switch ($params->get('psmode', 'featured')) { case 'newest': $products = Product::getNewProducts((int) $cookie->id_lang, 0, $nb); break; case 'special': $products = Product::getPricesDrop($this->context->language->id, null, $nb, true); break; case 'featured': default: $category = new Category(Context::getContext()->shop->getCategory(), (int) Context::getContext()->language->id); $products = $category->getProducts((int) Context::getContext()->language->id, 1, $nb); break; } $iwidth = $params->get('imgwidth', 960); $iheight = $params->get('imgheight', 360); $twidth = $params->get('thumbwidth', 160); $theight = $params->get('thumbheight', 90); $output = array(); foreach ($products as $i => $product) { $output[] = array('id_slide' => $product['id_product'], 'image' => $link->getImageLink($product["link_rewrite"], $product["id_image"]), 'title' => $product['name'], 'url' => $product['link'], 'oimage' => '', 'thumb' => '', 'legend' => '', 'description' => $product['description_short'], 'category' => $product['category'], 'price' => $product['price'], 'price_tax_exc' => $product['price_tax_exc'], 'attribute_price' => $product['attribute_price'], 'price_without_reduction' => $product['price_without_reduction'], 'manufacturer' => $product['manufacturer_nam']); $output[$i]['thumbnail'] = $output[$i]['image']; $output[$i]['mainimage'] = $output[$i]['image']; if ($params->get('cropthumb', 1) && $output[$i]['image']) { $output[$i]['mainimage'] = $this->renderThumb($output[$i]['image'], $iwidth, $iheight); $output[$i]['thumbnail'] = $this->renderThumb($output[$i]['image'], $twidth, $theight); } // echo '<pre>'.print_r( $output, 1 ); die; } unset($products); // echo '<pre>'.print_r( $output, 1 ); die; return $output; }
public function hookdisplayHome($params) { $finish = Configuration::get('DEALS'); $deals_day = new DateTime($finish); if (!$this->isCached('discountproducts_home.tpl', $this->getCacheId())) { if (new DateTime(date("Y-m-d H:i:s")) < new DateTime($finish)) { $id_lang = $this->context->language->id; $nbProducts = Product::getPricesDrop($this->context->language->id, null, null, true); $products = Product::getPricesDrop($this->context->language->id, 0, $nbProducts, false, 'date_upd', 'asc'); $results = array(); foreach ($products as $product) { if (isset($product['specific_prices']['to']) && $product['specific_prices']['to'] != '0000-00-00 00:00:00') { $end_day = new DateTime($product['specific_prices']['to']); if ($end_day == $deals_day) { $results[] = $product; } } } $this->context->smarty->assign('products', $results); } else { $this->context->smarty->assign(array('expired_warning' => $this->l('Sorry! it\'s expired!'), 'products' => array())); } $end_day = array(); $str_date = explode(' ', $finish); $str_day = explode('-', $str_date[0]); $str_time = explode(':', $str_date[1]); $end_day['y'] = $str_day[0]; $end_day['m'] = $str_day[1]; $end_day['d'] = $str_day[2]; $end_day['h'] = $str_time[0]; $end_day['i'] = $str_time[1]; $end_day['s'] = $str_time[2]; $this->context->smarty->assign(array('deals_day' => $end_day, 'expiryText' => 'End in ' . $finish)); } return $this->display(__FILE__, 'discountproducts_home.tpl', $this->getCacheId()); }
public function buildSubmenuTree(array $dataset, $frontend = false, $cssgenerator = false) { $id_lang = (int) Context::getContext()->language->id; $id_shop = (int) Context::getContext()->shop->id; $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $tree = array(); foreach ($dataset as $id => &$node) { if ($cssgenerator) { //set style if (isset($node['content_s']['br_top_st'])) { $node['content_s']['br_top_st'] = $this->convertBorderType($node['content_s']['br_top_st']); } if (isset($node['content_s']['br_right_st'])) { $node['content_s']['br_right_st'] = $this->convertBorderType($node['content_s']['br_right_st']); } if (isset($node['content_s']['br_bottom_st'])) { $node['content_s']['br_bottom_st'] = $this->convertBorderType($node['content_s']['br_bottom_st']); } if (isset($node['content_s']['br_left_st'])) { $node['content_s']['br_left_st'] = $this->convertBorderType($node['content_s']['br_left_st']); } } if ($frontend) { if (isset($node['content_s']['title'][$id_lang]) && $node['content_s']['title'][$id_lang] != '') { $node['content_s']['title'] = $node['content_s']['title'][$id_lang]; } elseif (isset($node['content_s']['title'][$id_lang_default]) && $node['content_s']['title'][$id_lang_default] != '') { $node['content_s']['title'] = $node['content_s']['title'][$id_lang_default]; } else { unset($node['content_s']['title']); } if (isset($node['content_s']['href'][$id_lang]) && $node['content_s']['href'][$id_lang] != '') { $node['content_s']['href'] = $node['content_s']['href'][$id_lang]; } elseif (isset($node['content_s']['href'][$id_lang_default]) && $node['content_s']['href'][$id_lang_default] != '') { $node['content_s']['href'] = $node['content_s']['href'][$id_lang_default]; } else { unset($node['content_s']['href']); } if (isset($node['content_s']['legend'][$id_lang]) && $node['content_s']['legend'][$id_lang] != '') { $node['content_s']['legend'] = $node['content_s']['legend'][$id_lang]; } elseif (isset($node['content_s']['legend'][$id_lang_default]) && $node['content_s']['legend'][$id_lang_default] != '') { $node['content_s']['legend'] = $node['content_s']['legend'][$id_lang_default]; } else { unset($node['content_s']['legend']); } if (isset($node['tabtitle'][$id_lang]) && $node['tabtitle'][$id_lang] != '') { $node['tabtitle'] = $node['tabtitle'][$id_lang]; } elseif (isset($node['tabtitle'][$id_lang_default]) && $node['tabtitle'][$id_lang_default] != '') { $node['tabtitle'] = $node['tabtitle'][$id_lang_default]; } else { unset($node['tabtitle']); } //set variouse links if (isset($node['contentType'])) { switch ($node['contentType']) { case 1: if (isset($node['content']['ids'])) { $customhtml = new IqitCreatorHtml((int) $node['content']['ids'], $id_lang); if (Validate::isLoadedObject($customhtml)) { $node['content']['ids'] = $customhtml->html; } } break; case 4: if (isset($node['content']['ids']) && !empty($node['content']['ids'])) { $node['content']['products'] = Product::getProductsProperties($id_lang, $this->getProducts($node['content']['ids'])); $products = $node['content']['products']; $this->addColorsToProductList($node['content']['products']); if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < count($products); $i++) { if (isset($products[$i]['id_product'])) { $image_array[$products[$i]['id_product']] = Product::getProductsImgs($products[$i]['id_product']); } } $node['content']['productsimg'] = (isset($image_array) and $image_array) ? $image_array : NULL; } if ($node['content']['view'] == 1 || $node['content']['view'] == 3) { $node['content']['line_lg'] = $this->convertGridSizeValue($node['content']['line_lg']); $node['content']['line_md'] = $this->convertGridSizeValue($node['content']['line_md']); $node['content']['line_sm'] = $this->convertGridSizeValue($node['content']['line_sm']); $node['content']['line_ms'] = $this->convertGridSizeValue($node['content']['line_ms']); $node['content']['line_xs'] = $this->convertGridSizeValue($node['content']['line_xs']); } } break; case 2: if (isset($node['content']['ids'])) { if ($node['content']['ids'] == 'n') { if ($node['content']['o'] == 1) { $products = Product::getNewProducts($id_lang, 0, (int) $node['content']['limit']); } else { $products = Product::getNewProducts($id_lang, 0, (int) $node['content']['limit'], false, $node['content']['o'], $node['content']['ob']); } } elseif ($node['content']['ids'] == 's') { if ($node['content']['o'] == 1) { $products = Product::getPricesDrop($id_lang, 0, (int) $node['content']['limit']); } else { $products = Product::getPricesDrop($id_lang, 0, (int) $node['content']['limit'], false, $node['content']['o'], $node['content']['ob']); } } elseif ($node['content']['ids'] == 'b') { $products = ProductSale::getBestSales($id_lang, 0, (int) $node['content']['limit'], 'sales'); } else { $category = new Category((int) $node['content']['ids'], $id_lang); if ($node['content']['o'] == 1) { $products = $category->getProducts($id_lang, 1, (int) $node['content']['limit'], null, null, false, true, true, (int) $node['content']['limit']); } else { $products = $category->getProducts($id_lang, 1, (int) $node['content']['limit'], $node['content']['o'], $node['content']['ob']); } } $node['content']['products'] = $products; $this->addColorsToProductList($node['content']['products']); if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < count($products); $i++) { if (isset($products[$i]['id_product'])) { $image_array[$products[$i]['id_product']] = Product::getProductsImgs($products[$i]['id_product']); } } $node['content']['productsimg'] = (isset($image_array) and $image_array) ? $image_array : NULL; } if ($node['content']['view'] == 1 || $node['content']['view'] == 3) { $node['content']['line_lg'] = $this->convertGridSizeValue($node['content']['line_lg']); $node['content']['line_md'] = $this->convertGridSizeValue($node['content']['line_md']); $node['content']['line_sm'] = $this->convertGridSizeValue($node['content']['line_sm']); $node['content']['line_ms'] = $this->convertGridSizeValue($node['content']['line_ms']); $node['content']['line_xs'] = $this->convertGridSizeValue($node['content']['line_xs']); } } break; case 6: if (isset($node['content']['source'][$id_lang]) && $node['content']['source'][$id_lang] != '') { $node['content']['source'] = $node['content']['source'][$id_lang]; } elseif (isset($node['content']['source'][$id_lang_default]) && $node['content']['source'][$id_lang_default] != '') { $node['content']['source'] = $node['content']['source'][$id_lang_default]; } else { unset($node['content']['source']); } if (isset($node['content']['href'][$id_lang]) && $node['content']['href'][$id_lang] != '') { $node['content']['href'] = $node['content']['href'][$id_lang]; } elseif (isset($node['content']['href'][$id_lang_default]) && $node['content']['href'][$id_lang_default] != '') { $node['content']['href'] = $node['content']['href'][$id_lang_default]; } else { unset($node['content']['href']); } break; case 7: if ($node['content']['view']) { $node['content']['line_lg'] = $this->convertGridSizeValue($node['content']['line_lg']); $node['content']['line_md'] = $this->convertGridSizeValue($node['content']['line_md']); $node['content']['line_sm'] = $this->convertGridSizeValue($node['content']['line_sm']); $node['content']['line_ms'] = $this->convertGridSizeValue($node['content']['line_ms']); $node['content']['line_xs'] = $this->convertGridSizeValue($node['content']['line_xs']); } break; case 9: $node['content']['module'] = $this->execModuleHook($node['content']['hook'], array(), $node['content']['id_module'], $id_shop); break; } } } if (!$frontend) { if (isset($node['contentType']) && $node['contentType'] == 4) { if (isset($node['content']['ids']) && !empty($node['content']['ids'])) { $node['content']['ids'] = $this->getProducts($node['content']['ids']); } } } if ($node['parentId'] === 0) { $tree[$id] =& $node; } else { if (!isset($dataset[$node['parentId']]['children'])) { $dataset[$node['parentId']]['children'] = array(); } $dataset[$node['parentId']]['children'][$id] =& $node; } } $tree = $this->sortArrayTree($tree); return $tree; }
public function renderContent($args, $setting) { # validate module unset($args); $t = array('name' => '', 'html' => ''); $setting = array_merge($t, $setting); $nb = $setting['itemstab'] ? (int) $setting['itemstab'] : 6; $orderby = $setting['orderby'] ? $setting['orderby'] : 'date_add'; $orderway = $setting['orderway'] ? $setting['orderway'] : 'ASC'; $items_page = $setting['itemspage'] ? (int) $setting['itemspage'] : 3; $columns_page = $setting['columns'] ? (int) $setting['columns'] : 3; $interval = isset($setting['interval']) ? (int) $setting['interval'] : 8000; switch ($setting['source']) { case 'ptype': switch ($setting['ptype']) { case 'newest': $products = Product::getNewProducts($this->langID, 0, $nb, false, $orderby, $orderway); break; case 'featured': $category = new Category(Context::getContext()->shop->getCategory(), $this->langID); $products = $category->getProducts((int) $this->langID, 1, $nb, $orderby, $orderway); break; case 'bestseller': $products = ProductSale::getBestSalesLight((int) $this->langID, 0, $nb); break; case 'special': $products = Product::getPricesDrop($this->langID, 0, $nb, false, $orderby, $orderway); break; case 'random': $random = true; $products = $this->getProducts('WHERE p.id_product > 0', (int) Context::getContext()->language->id, 1, $nb, $orderby, $orderway, false, true, $random, $nb); Configuration::updateValue('LEO_CURRENT_RANDOM_CACHE', '1'); break; } break; case 'pproductids': $where = ''; if (empty($setting['pproductids'])) { return false; } if ($pproductids = $setting['pproductids']) { $where = 'WHERE p.id_product IN (' . pSQL($pproductids) . ')'; } $products = $this->getProducts($where, (int) Context::getContext()->language->id, 1, $nb, $orderby, $orderway); break; case 'pcategories': $where = ''; $catids = isset($setting['categories']) && $setting['categories'] ? $setting['categories'] : array(); $products = array(); if ($catids) { $categorys = implode(',', $catids); $where = 'WHERE cp.id_category IN (' . pSQL($categorys) . ')'; $products = $this->getProducts($where, (int) Context::getContext()->language->id, 1, $nb, $orderby, $orderway); } break; case 'pmanufacturers': $where = ''; $manufacturers = $setting['pmanufacturer'] ? $setting['pmanufacturer'] : array(); if ($manufacturers) { $manufacturers = implode(',', $manufacturers); $where = 'WHERE p.id_manufacturer IN (' . pSQL($manufacturers) . ')'; } $products = $this->getProducts($where, (int) Context::getContext()->language->id, 1, $nb, $orderby, $orderway); break; } Context::getContext()->controller->addColorsToProductList($products); $setting['products'] = $products; $setting['itemsperpage'] = $items_page; $setting['columnspage'] = $columns_page; $setting['scolumn'] = 12 / $columns_page; $setting['interval'] = $interval; $setting['homeSize'] = Image::getSize(ImageType::getFormatedName('home')); $setting['tab'] = 'leoproductcarousel' . rand(20, rand()); $output = array('type' => 'carousel', 'data' => $setting); return $output; }
public function renderContent($args, $setting) { $t = array('ptype' => '', 'limit' => 12, 'image_width' => '200', 'image_height' => '200'); $products = array(); $setting = array_merge($t, $setting); $orderby = $setting['orderby'] ? $setting['orderby'] : 'position'; $orderway = $setting['orderway'] ? $setting['orderway'] : 'ASC'; $plimit = $setting['limit'] ? (int) $setting['limit'] : 6; switch ($setting['source']) { case 'ptype': switch ($setting['ptype']) { case 'newest': $products = Product::getNewProducts($this->langID, 0, $plimit); break; case 'featured': $category = new Category(Context::getContext()->shop->getCategory(), $this->langID); $nb = (int) $setting['limit']; $products = $category->getProducts((int) $this->langID, 1, $plimit); break; case 'bestseller': $products = ProductSale::getBestSalesLight((int) $this->langID, 0, $plimit); break; case 'special': $products = Product::getPricesDrop($this->langID, 0, $plimit); break; } break; case 'pproductids': $where = ''; if (empty($setting['pproductids'])) { return false; } if ($pproductids = $setting['pproductids']) { $where = 'WHERE p.id_product IN (' . pSQL($pproductids) . ')'; } $products = $this->getProducts($where, (int) Context::getContext()->language->id, 1, $plimit, $orderby, $orderway); break; case 'pcategories': $where = ''; $catids = isset($setting['categories']) && $setting['categories'] ? $setting['categories'] : array(); if ($catids) { $categorys = implode(",", $catids); $where = 'WHERE cp.id_category IN (' . pSQL($categorys) . ')'; } $products = $this->getProducts($where, (int) Context::getContext()->language->id, 1, $plimit, $orderby, $orderway); break; case 'pmanufacturers': $where = ''; $manufacturers = $setting['pmanufacturer'] ? $setting['pmanufacturer'] : array(); if ($manufacturers) { $manufacturers = implode(",", $manufacturers); $where = 'WHERE p.id_manufacturer IN (' . pSQL($manufacturers) . ')'; } $products = $this->getProducts($where, (int) Context::getContext()->language->id, 1, $plimit, $orderby, $orderway); break; } Context::getContext()->controller->addColorsToProductList($products); $setting['products'] = $products; $output = array('type' => 'products', 'data' => $setting); return $output; }
public function parseTemplateCategory($output, $smarty) { $output = self::prepareOutput($output); if (Configuration::get('PS_FORCE_SMARTY_2') === "0") { //Smarty v3 template engine //$currentTemplate = substr(basename($smarty->_current_file), 0, -4); $currentTemplate = substr(basename($smarty->template_resource), 0, -4); if ($currentTemplate == 'breadcrumb') { $currentTemplate = 'product'; } elseif ($currentTemplate == 'pagination') { $currentTemplate = 'category'; } $getTemplateVars = 'getTemplateVars'; } else { //Smarty v2 template engine $currentTemplate = $smarty->currentTemplate; $getTemplateVars = 'get_template_vars'; } switch ($currentTemplate) { case 'manufacturer': $currentTemplate = 'manufacturer'; break; case 'best-sales': $currentTemplate = 'bestsellerspage'; break; case 'new-products': $currentTemplate = 'newproductpage'; break; case 'prices-drop': $currentTemplate = 'specialspage'; break; } $tool = $this->loadTool(); if (!$tool->params->profileExists($currentTemplate) || $tool->params->checkValue('enable-effect', 'No', $currentTemplate)) { return self::prepareOutput($output); } $tool->params->setProfile($currentTemplate); global $link; $cookie =& $GLOBALS['magictoolbox']['magiczoomplus']['cookie']; if (method_exists($link, 'getImageLink')) { $_link =& $link; } else { //for Prestashop ver 1.1 $_link =& $this; } switch ($currentTemplate) { case 'homefeatured': $category = new Category(1); $nb = intval(Configuration::get('HOME_FEATURED_NBR')); //Number of product displayed $products = $category->getProducts(intval($cookie->id_lang), 1, $nb ? $nb : 10); $pCount = count($products); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true; $productImagesData = array(); $useLink = !$tool->params->checkValue('link-to-product-page', 'No'); foreach ($products as $p_key => $product) { $productImagesData[$p_key]['link'] = $useLink ? $link->getProductLink($product['id_product'], $product['link_rewrite']) : ''; $productImagesData[$p_key]['title'] = $product['name']; $productImagesData[$p_key]['thumb'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], 'small'); if ($tool->type == 'circle') { $productImagesData[$p_key]['medium'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('large-image')); } else { $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); } } $magiczoomplus = $tool->getMainTemplate($productImagesData, array("id" => "homefeaturedMagicZoomPlus")); $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magiczoomplus, $output); break; case 'category': case 'manufacturer': case 'newproductpage': case 'bestsellerspage': case 'specialspage': break; $products = $smarty->{$getTemplateVars}('products'); $pCount = count($products); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true; if ($pCount < $tool->params->getValue('items')) { $tool->params->setValue('items', $pCount); } $magiczoomplus = array(); foreach ($products as $product) { $lrw = $product['link_rewrite']; $img = $_link->getImageLink($lrw, $product['id_image'], 'home'); $pattern = '/<li class="ajax_block_product[^"]*">[^<]*<div class="center_block">((?:[^<]*<span[^>]*>[^<]*<\\/span>)?[^<]*<a[^>]*>[^<]*<img[^>]*?src="' . preg_quote($img, '/') . '"[^>]*>[^<]*<\\/a>.*?)<\\/div>[^<]*<div class="right_block">(.*?)<\\/div>(?:[^<]*<br[^>]*>)?[^<]*<\\/li>/is'; $matches = array(); if (preg_match($pattern, $output, $matches)) { $magiczoomplus[] = '<div>' . $matches[1] . '<div class="bottom_block">' . $matches[2] . '</div></div>'; } } if (!empty($magiczoomplus)) { $tool->params->setValue('item-tag', 'div'); $options = $tool->getPersonalOptions('categoryMagicZoomPlus'); $additionalClass = ''; if ($tool->params->checkValue('scroll-style', 'with-borders')) { $additionalClass = ' msborder'; } $magiczoomplus = $options . '<div id="categoryMagicZoomPlus" class="MagicZoomPlus' . $additionalClass . '">' . implode('', $magiczoomplus) . '</div>'; $output = preg_replace('/<ul[^>]*?id="product_list"[^>]*>.*?<\\/ul>/is', $magiczoomplus, $output); $tool->params->setValue('item-tag', 'a'); } break; case 'product': if (!isset($GLOBALS['magictoolbox']['magiczoomplus']['product'])) { //for skip loyalty module product.tpl return self::prepareOutput($output); } $pCount = count($smarty->{$getTemplateVars}('images')); if (!$pCount) { break; } //$product = $smarty->tpl_vars['product']; //get some data from $GLOBALS for compatible with Prestashop modules which reset the $product smarty variable $product = $GLOBALS['magictoolbox']['magiczoomplus']['product']; $productImagesData = array(); $ids = array(); foreach ($smarty->{$getTemplateVars}('images') as $image) { $id_image = intval($image['id_image']); $ids[] = $id_image; if ($image['cover']) { $coverID = $id_image; } $productImagesData[$id_image]['title'] = $product['name']; $productImagesData[$id_image]['thumb'] = $_link->getImageLink($product['link_rewrite'], intval($product['id']) . '-' . $id_image, $tool->params->getValue('selector-image')); if ($tool->type == 'circle') { $productImagesData[$id_image]['medium'] = $_link->getImageLink($product['link_rewrite'], intval($product['id']) . '-' . $id_image, $tool->params->getValue('thumb-image')); $productImagesData[$id_image]['img'] = $_link->getImageLink($product['link_rewrite'], intval($product['id']) . '-' . $id_image, $tool->params->getValue('large-image')); } else { $productImagesData[$id_image]['img'] = $_link->getImageLink($product['link_rewrite'], intval($product['id']) . '-' . $id_image, $tool->params->getValue('thumb-image')); } } if (!isset($coverID)) { // ensure that we have the image break; } $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true; $magiczoomplus = $tool->getMainTemplate($productImagesData, array("id" => "productMagicZoomPlus")); //need img#bigpic for blockcart module $magiczoomplus = '<div style="width:0px;height:0px;overflow:hidden;visibility:hidden;"><img id="bigpic" src="' . $productImagesData[$ids[0]]['img'] . '" /></div>' . $magiczoomplus; $replaced = 0; $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($product['link_rewrite'], intval($product['id']) . '-' . $coverID, 'large'), '/') . '".*?>'; $output = preg_replace('/' . $pattern . '/is', $magiczoomplus, $output, -1, $replaced); if (!$replaced) { $iTypes = $this->getImagesTypes(); foreach ($iTypes as $iType) { if ($iType != 'large') { $pattern = '<img src="[^"]*?' . preg_quote($_link->getImageLink($product['link_rewrite'], intval($product['id']) . '-' . $coverID, $iType), '/') . '".*?>'; $output = preg_replace('/' . $pattern . '/is', $magiczoomplus, $output, -1, $replaced); if ($replaced) { break; } } } } //remove selectors $output = preg_replace('/<div id="thumbs_list">.*?<\\/div>/is', '', $output); $output = preg_replace('/<\\!-- thumbnails -->\\s*<div id="views_block"\\s*>.*?<\\/div>/is', '<!-- thumbnails -->', $output); $output = preg_replace('/<\\!-- thumbnails -->\\s*<p[^>]*><a[^>]+reset[^>]+>.*?<\\/a><\\/p>/is', '<!-- thumbnails -->', $output); //remove "View full size" link $output = preg_replace('/<li>[^<]*?<span[^>]*?id="view_full_size"[^>]*?>[^<]*?<\\/span>[^<]*?<\\/li>/is', '', $output); //remove "Display all pictures" link $output = preg_replace('/<p[^>]*>\\s*<span[^>]*?id="wrapResetImages"[^>]*>.*?<\\/span>\\s*<\\/p>/is', '', $output); break; case 'blockspecials': if (version_compare(_PS_VERSION_, '1.4', '<')) { $products = $this->getAllSpecial(intval($cookie->id_lang)); } else { $products = Product::getPricesDrop((int) $cookie->id_lang, 0, 10, false, 'position', 'asc'); } $pCount = count($products); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true; $productImagesData = array(); $useLink = !$tool->params->checkValue('link-to-product-page', 'No'); foreach ($products as $p_key => $product) { if ($useLink && (!isset($_GET['id_product']) || $_GET['id_product'] != $product['id_product'])) { $productImagesData[$p_key]['link'] = $link->getProductLink($product['id_product'], $product['link_rewrite']); } else { $productImagesData[$p_key]['link'] = ''; } $productImagesData[$p_key]['title'] = $product['name']; $productImagesData[$p_key]['thumb'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], 'small'); if ($tool->type == 'circle') { $productImagesData[$p_key]['medium'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('large-image')); } else { $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); } } $magiczoomplus = $tool->getMainTemplate($productImagesData, array("id" => "blockspecialsMagicZoomPlus")); $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magiczoomplus, $output); break; case 'blockviewed': $productsViewed = $GLOBALS['magictoolbox']['magiczoomplus']['productsViewed']; $pCount = count($productsViewed); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true; $productImagesData = array(); $useLink = !$tool->params->checkValue('link-to-product-page', 'No'); foreach ($productsViewed as $id_product) { $productViewedObj = new Product(intval($id_product), false, intval($cookie->id_lang)); if (!Validate::isLoadedObject($productViewedObj) or !$productViewedObj->active) { continue; } else { $images = $productViewedObj->getImages(intval($cookie->id_lang)); foreach ($images as $image) { if ($image['cover']) { $productViewedObj->cover = $productViewedObj->id . '-' . $image['id_image']; $productViewedObj->legend = $image['legend']; break; } } if (!isset($productViewedObj->cover)) { $productViewedObj->cover = Language::getIsoById($cookie->id_lang) . '-default'; $productViewedObj->legend = ''; } $lrw = $productViewedObj->link_rewrite; if ($useLink && (!isset($_GET['id_product']) || $_GET['id_product'] != $id_product)) { $productImagesData[$id_product]['link'] = $link->getProductLink($id_product, $lrw); } else { $productImagesData[$id_product]['link'] = ''; } $productImagesData[$id_product]['title'] = $productViewedObj->name; $productImagesData[$id_product]['thumb'] = $_link->getImageLink($lrw, $productViewedObj->cover, 'small'); if ($tool->type == 'circle') { $productImagesData[$id_product]['medium'] = $_link->getImageLink($lrw, $productViewedObj->cover, $tool->params->getValue('thumb-image')); $productImagesData[$id_product]['img'] = $_link->getImageLink($lrw, $productViewedObj->cover, $tool->params->getValue('large-image')); } else { $productImagesData[$id_product]['img'] = $_link->getImageLink($lrw, $productViewedObj->cover, $tool->params->getValue('thumb-image')); } } } $magiczoomplus = $tool->getMainTemplate($productImagesData, array("id" => "blockviewedMagicZoomPlus")); $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magiczoomplus, $output); break; case 'blockbestsellers': $blockbestsellers = true; case 'blocknewproducts': if (isset($blockbestsellers)) { //$products = $smarty->$getTemplateVars('best_sellers'); //to get with description etc. $products = ProductSale::getBestSales(intval($cookie->id_lang), 0, 4); } else { $products = $smarty->{$getTemplateVars}('new_products'); } $pCount = count($products); if (!$pCount || !$products) { break; } $GLOBALS['magictoolbox']['magiczoomplus']['headers'] = true; $productImagesData = array(); $useLink = !$tool->params->checkValue('link-to-product-page', 'No'); foreach ($products as $p_key => $product) { if ($useLink && (!isset($_GET['id_product']) || $_GET['id_product'] != $product['id_product'])) { $productImagesData[$p_key]['link'] = $link->getProductLink($product['id_product'], $product['link_rewrite']); } else { $productImagesData[$p_key]['link'] = ''; } $productImagesData[$p_key]['title'] = $product['name']; $productImagesData[$p_key]['thumb'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], 'small'); if ($tool->type == 'circle') { $productImagesData[$p_key]['medium'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('large-image')); } else { $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); } } $magiczoomplus = $tool->getMainTemplate($productImagesData, array("id" => $currentTemplate . "MagicZoomPlus")); $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magiczoomplus, $output); break; } return self::prepareOutput($output); }
<?php include dirname(__FILE__) . '/config/config.inc.php'; include dirname(__FILE__) . '/header.php'; include dirname(__FILE__) . '/product-sort.php'; $nbProducts = Product::getPricesDrop(intval($cookie->id_lang), NULL, NULL, true); include dirname(__FILE__) . '/pagination.php'; $smarty->assign(array('products' => Product::getPricesDrop(intval($cookie->id_lang), intval($p) - 1, intval($n), false, $orderBy, $orderWay), 'nbProducts' => $nbProducts)); $smarty->display(_PS_THEME_DIR_ . 'prices-drop.tpl'); include dirname(__FILE__) . '/footer.php';
public function hookDisplayFooter($params) { if (Configuration::get('PS_CATALOG_MODE')) { return; } $products = Product::getPricesDrop((int) $params['cookie']->id_lang, NULL, 3); $this->smarty->assign(array('products' => $products, 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')))); return $this->display(__FILE__, 'tdblockspecials-footer.tpl'); }
public function getSlideshowHtml() { if (!$this->isCached('posspecialproduct.tpl', $this->getCacheId('posspecialproduct'))) { $slideOptions = array('auto_slide' => Configuration::get($this->name . '_auto_slide'), 'speed_slide' => Configuration::get($this->name . '_speed_slide'), 'a_speed' => Configuration::get($this->name . '_a_speed'), 'show_price' => Configuration::get($this->name . '_show_price'), 'show_des' => Configuration::get($this->name . '_show_des'), 'qty_products' => Configuration::get($this->name . '_qty_products'), 'qty_items' => Configuration::get($this->name . '_qty_items'), 'width_item' => Configuration::get($this->name . '_width_item'), 'show_nexback' => Configuration::get($this->name . '_show_nextback'), 'show_control' => Configuration::get($this->name . '_show_control'), 'min_item' => Configuration::get($this->name . '_min_item'), 'max_item' => Configuration::get($this->name . '_max_item'), 'show_addtocart' => Configuration::get($this->name . '_show_addtocart')); //echo "<pre>"; print_r($slideOptions); $category = new Category(Context::getContext()->shop->getCategory(), (int) Context::getContext()->language->id); $nbProducts = (int) Configuration::get($this->name . '_qty_products'); $products = Product::getPricesDrop((int) Context::getContext()->language->id, 0, $nbProducts ? $nbProducts : 5); $this->context->smarty->assign(array('products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'), 'slideOptions' => $slideOptions)); } return $this->display(__FILE__, 'posspecialproduct.tpl', $this->getCacheId('posspecialproduct')); }
public function hookDisplayHomeTab($params) { if (Configuration::get('PS_CATALOG_MODE')) { return; } if (!$this->isCached('tab.tpl', $this->getCacheId('blockspecials-tab'))) { BlockSpecials::$cache_specials = Product::getPricesDrop((int) $params['cookie']->id_lang, 0, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR')); } if (BlockSpecials::$cache_specials === false) { return false; } return $this->display(__FILE__, 'tab.tpl', $this->getCacheId('blockspecials-tab')); }
public function parseTemplateCategory($output, $smarty) { if ($this->isSmarty3) { //Smarty v3 template engine //$currentTemplate = substr(basename($smarty->_current_file), 0, -4); $currentTemplate = substr(basename($smarty->template_resource), 0, -4); if ($currentTemplate == 'breadcrumb') { $currentTemplate = 'product'; } elseif ($currentTemplate == 'pagination') { $currentTemplate = 'category'; } } else { //Smarty v2 template engine $currentTemplate = $smarty->currentTemplate; } if ($this->isPrestaShop15x && $currentTemplate == 'layout') { $matches = array(); $lang = intval($GLOBALS['magictoolbox']['magicscroll']['cookie']->id_lang); if (preg_match_all('/\\[magicscroll(?:\\sid=(\\d+(?:,\\d+)*))?\\]/', $output, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $output = str_replace($match[0], $this->getCustomSlideshow(empty($match[1]) ? '' : $match[1], $lang, false), $output); } $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; } if (version_compare(_PS_VERSION_, '1.5.5.0', '>=')) { //NOTE: because we do not know whether the effect is applied to the blocks in the cache $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; } //NOTE: full contents in prestashop 1.5.x if ($GLOBALS['magictoolbox']['magicscroll']['headers'] == false) { $output = preg_replace('/<\\!-- MAGICSCROLL HEADERS START -->.*?<\\!-- MAGICSCROLL HEADERS END -->/is', '', $output); } else { $output = preg_replace('/<\\!-- MAGICSCROLL HEADERS (START|END) -->/is', '', $output); } return $output; } switch ($currentTemplate) { case 'search': case 'manufacturer': //$currentTemplate = 'manufacturer'; break; case 'best-sales': $currentTemplate = 'bestsellerspage'; break; case 'new-products': $currentTemplate = 'newproductpage'; break; case 'prices-drop': $currentTemplate = 'specialspage'; break; case 'blockbestsellers-home': $currentTemplate = 'blockbestsellers_home'; break; case 'product-list': //for 'Layered navigation block' if (strpos($_SERVER['REQUEST_URI'], 'blocklayered-ajax.php') !== false) { $currentTemplate = 'category'; } break; } $tool = $this->loadTool(); if (!$tool->params->profileExists($currentTemplate) || $tool->params->checkValue('enable-effect', 'No', $currentTemplate)) { return $output; } $tool->params->setProfile($currentTemplate); global $link; $cookie =& $GLOBALS['magictoolbox']['magicscroll']['cookie']; if (method_exists($link, 'getImageLink')) { $_link =& $link; } else { //for Prestashop ver 1.1 $_link =& $this; } $output = self::prepareOutput($output); switch ($currentTemplate) { case 'homefeatured': $categoryID = $this->isPrestaShop15x ? Context::getContext()->shop->getCategory() : 1; $category = new Category($categoryID); $nb = intval(Configuration::get('HOME_FEATURED_NBR')); //Number of product displayed $products = $category->getProducts(intval($cookie->id_lang), 1, $nb ? $nb : 10); if (!is_array($products)) { break; } $pCount = count($products); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; if ($pCount < $tool->params->getValue('items')) { $tool->params->setValue('items', $pCount); } $productImagesData = array(); $useLink = $tool->params->checkValue('link-to-product-page', 'Yes'); foreach ($products as $p_key => $product) { $productImagesData[$p_key]['link'] = $useLink ? $link->getProductLink($product['id_product'], $product['link_rewrite'], isset($product['category']) ? $product['category'] : null) : ''; $productImagesData[$p_key]['title'] = $product['name']; $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); } $magicscroll = $tool->getMainTemplate($productImagesData, array("id" => "homefeaturedMagicScroll")); if ($this->isPrestaShop16x) { $magicscroll = '<div id="homefeatured" class="MagicToolboxContainer homefeatured tab-pane">' . $magicscroll . '</div>'; } $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magicscroll, $output); break; case 'category': case 'manufacturer': case 'newproductpage': case 'bestsellerspage': case 'specialspage': case 'search': $products = $smarty->{$this->getTemplateVars}('products'); if (!is_array($products)) { break; } $pCount = count($products); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; if ($pCount < $tool->params->getValue('items')) { $tool->params->setValue('items', $pCount); } $magicscroll = array(); $left_block_pattern = '(?:<div[^>]*?class="left_block"[^>]*>[^<]*' . '((?:<p[^>]*?class="compare"[^>]*>[^<]*' . '<input[^>]*>[^<]*' . '<label[^>]*>[^<]*<\\/label>[^<]*' . '<\\/p>[^<]*)?)' . '<\\/div>[^<]*)?'; foreach ($products as $product) { $lrw = $product['link_rewrite']; $pattern = preg_quote($_link->getImageLink($lrw, $product['id_image'], 'home' . $this->imageTypeSuffix), '/'); $pattern = str_replace('\\-home' . $this->imageTypeSuffix, '\\-[^"]*?', $pattern); $pattern = '/<li[^>]*?class="[^"]*?ajax_block_product[^"]*"[^>]*>[^<]*' . $left_block_pattern . '<div[^>]*?class="center_block"[^>]*>((?:[^<]*<span[^>]*>[^<]*<\\/span>)?[^<]*' . '<a[^>]*>[^<]*<img[^>]*?src="' . $pattern . '"[^>]*>[^<]*(?:<span[^>]*?class="new"[^>]*>.*?<\\/span>[^<]*)?<\\/a>.*?)' . '<\\/div>[^<]*' . '<div[^>]*?class="right_block"[^>]*>(.*?)<\\/div>(?:[^<]*<br[^>]*>)?[^<]*' . '<\\/li>/is'; $matches = array(); if (preg_match($pattern, $output, $matches)) { $left_block = !empty($matches[1]) ? '<div class="left_block">' . $matches[1] . '</div>' : ''; $magicscroll[] = '<div>' . $left_block . $matches[2] . '<div class="bottom_block">' . $matches[3] . '</div></div>'; } } if (!empty($magicscroll)) { $tool->params->setValue('item-tag', 'div'); $options = $tool->getOptionsTemplate('categoryMagicScroll'); $additionalClass = ''; if ($tool->params->checkValue('scroll-style', 'with-borders')) { $additionalClass = ' msborder'; } if ($this->isPrestaShop15x) { $additionalClass .= ' prestashop15x'; } else { $additionalClass .= ' prestashop14x'; } $magicscroll = $options . '<div id="categoryMagicScroll" class="MagicScroll' . $additionalClass . '">' . implode('', $magicscroll) . '</div>'; $magicscroll = strtr($magicscroll, array('\\' => '\\\\', '$' => '\\$')); $output = preg_replace('/<ul[^>]*?id="product_list"[^>]*>.*?<\\/ul>/is', $magicscroll, $output); $tool->params->setValue('item-tag', 'a'); } break; case 'product': if (!isset($GLOBALS['magictoolbox']['magicscroll']['product'])) { //for skip loyalty module product.tpl break; } $images = $smarty->{$this->getTemplateVars}('images'); $pCount = count($images); if (!$pCount) { break; } if ($pCount < $tool->params->getValue('items')) { $tool->params->setValue('items', $pCount); } //$product = $smarty->tpl_vars['product']; //get some data from $GLOBALS for compatible with Prestashop modules which reset the $product smarty variable $product =& $GLOBALS['magictoolbox']['magicscroll']['product']; $cover = $smarty->{$this->getTemplateVars}('cover'); if (!isset($cover['id_image'])) { break; } $coverImageIds = is_numeric($cover['id_image']) ? $product['id'] . '-' . $cover['id_image'] : $cover['id_image']; $productImagesData = array(); $ids = array(); foreach ($images as $image) { $id_image = intval($image['id_image']); $ids[] = $id_image; //if($image['cover']) $coverID = $id_image; $productImagesData[$id_image]['title'] = $image['legend']; $productImagesData[$id_image]['img'] = $_link->getImageLink($product['link_rewrite'], intval($product['id']) . '-' . $id_image, $tool->params->getValue('thumb-image')); } $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; $magicscroll = $tool->getMainTemplate($productImagesData, array("id" => "productMagicScroll")); $magicscroll .= '<script type="text/javascript">magictoolboxImagesOrder = [' . implode(',', $ids) . '];</script>'; //need img#bigpic for blockcart module $magicscroll = '<div style="width:0px;height:0px;overflow:hidden;visibility:hidden;"><img id="bigpic" src="' . $productImagesData[$ids[0]]['img'] . '" /></div>' . $magicscroll; /* $imagePatternTemplate = '<img [^>]*?src="[^"]*?__SRC__"[^>]*>'; $patternTemplate = '<a [^>]*>[^<]*'.$imagePatternTemplate.'[^<]*<\/a>|'.$imagePatternTemplate; $patternTemplate = '<span [^>]*?id="view_full_size"[^>]*>[^<]*'. '(?:<span [^>]*?class="[^"]*"[^>]*>[^<]*<\/span>[^<]*)*'. '(?:'.$patternTemplate.')[^<]*'. '(?:<span [^>]*?class="[^"]*?span_link[^"]*"[^>]*>.*?<\/span>[^<]*)*'. '<\/span>|'.$patternTemplate; //NOTE: added support custom theme #53897 $patternTemplate = $patternTemplate.'|'. '<div [^>]*?id="wrap"[^>]*>[^<]*'. '<a [^>]*>[^<]*'. '<span [^>]*?id="view_full_size"[^>]*>[^<]*'. $imagePatternTemplate.'[^<]*'. '<\/span>[^<]*'. '<\/a>[^<]*'. '<\/div>[^<]*'. '<div [^>]*?class="[^"]*?zoom-b[^"]*"[^>]*>[^<]*'. '<a [^>]*>[^<]*<\/a>[^<]*'. '<\/div>'; //NOTE: added support custom theme #54204 $patternTemplate = $patternTemplate.'|'. '<span [^>]*?id="view_full_size"[^>]*>[^<]*'. '<a [^>]*>[^<]*'. '<img [^>]*>[^<]*'. $imagePatternTemplate.'[^<]*'. '<span [^>]*?class="[^"]*?mask[^"]*"[^>]*>.*?<\/span>[^<]*'. '<\/a>[^<]*'. '<\/span>[^<]*'; $patternTemplate = '(?:'.$patternTemplate.')'; //$patternTemplate = '(<div[^>]*?id="image-block"[^>]*>[^<]*)'.$patternTemplate;//NOTE: we need this to determine the main image //NOTE: added support custom theme #53897 $patternTemplate = '(<div [^>]*?(?:id="image-block"|class="[^"]*?image[^"]*")[^>]*>[^<]*)'.$patternTemplate; $srcPattern = preg_quote($_link->getImageLink($product['link_rewrite'], $coverImageIds, 'large'.$this->imageTypeSuffix), '/'); $pattern = str_replace('__SRC__', $srcPattern, $patternTemplate); $replaced = 0; $output = preg_replace('/'.$pattern.'/is', '$1'.$magicscroll, $output, -1, $replaced); if(!$replaced) { $iTypes = $this->getImagesTypes(); foreach($iTypes as $iType) { if($iType != 'large'.$this->imageTypeSuffix) { $srcPattern = preg_quote($_link->getImageLink($product['link_rewrite'], $coverImageIds, $iType), '/'); $noImageSrcPattern = preg_quote($img_prod_dir.$lang_iso.'-default-'.$iType.'.jpg', '/'); $pattern = str_replace('__SRC__', $srcPattern, $patternTemplate); $output = preg_replace('/'.$pattern.'/is', '$1'.$magicscroll, $output, -1, $replaced); if($replaced) break; } } } */ //NOTE: common pattern to match div#image-block tag $pattern = '(<div\\b[^>]*?(?:\\bid\\s*+=\\s*+"image-block"|\\bclass\\s*+=\\s*+"[^"]*?\\bimage\\b[^"]*+")[^>]*+>)' . '(' . '(?:' . '[^<]++' . '|' . '<(?!/?div\\b|!--)' . '|' . '<!--.*?-->' . '|' . '<div\\b[^>]*+>' . '(?2)' . '</div\\s*+>' . ')*+' . ')' . '</div\\s*+>'; //$replaced = 0; //preg_match_all('%'.$pattern.'%is', $output, $__matches, PREG_SET_ORDER); //NOTE: limit = 1 because pattern can be matched with other products, located below the main product $output = preg_replace('%' . $pattern . '%is', '$1' . $magicscroll . '</div>', $output, 1); //remove selectors //$output = preg_replace('/<div [^>]*?id="thumbs_list"[^>]*>.*?<\/div>/is', '', $output); //NOTE: added support custom theme #53897 $output = preg_replace('/<div [^>]*?(?:id="thumbs_list"|class="[^"]*?image-additional[^"]*")[^>]*>.*?<\\/div>/is', '', $output); //NOTE: div#views_block is parent for div#thumbs_list $output = preg_replace('/<div [^>]*?id="views_block"[^>]*>.*?<\\/div>/is', '', $output); //#resetImages link $output = preg_replace('/<\\!-- thumbnails -->[^<]*<p[^>]*><a[^>]+reset[^>]+>.*?<\\/a><\\/p>/is', '<!-- thumbnails -->', $output); //remove "View full size" link $output = preg_replace('/<li>[^<]*<span[^>]*?id="view_full_size"[^>]*?>[^<]*<\\/span>[^<]*<\\/li>/is', '', $output); //remove "Display all pictures" link $output = preg_replace('/<p[^>]*>[^<]*<span[^>]*?id="wrapResetImages"[^>]*>.*?<\\/span>[^<]*<\\/p>/is', '', $output); break; case 'blockspecials': if (version_compare(_PS_VERSION_, '1.4', '<')) { $products = $this->getAllSpecial(intval($cookie->id_lang)); } else { $products = Product::getPricesDrop((int) $cookie->id_lang, 0, 10, false, 'position', 'asc'); } if (!is_array($products)) { break; } $pCount = count($products); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; if ($pCount < $tool->params->getValue('items')) { $tool->params->setValue('items', $pCount); } $productImagesData = array(); $useLink = $tool->params->checkValue('link-to-product-page', 'Yes'); foreach ($products as $p_key => $product) { if ($useLink && (!Tools::getValue('id_product', false) || Tools::getValue('id_product', false) != $product['id_product'])) { $productImagesData[$p_key]['link'] = $link->getProductLink($product['id_product'], $product['link_rewrite'], isset($product['category']) ? $product['category'] : null); } else { $productImagesData[$p_key]['link'] = ''; } $productImagesData[$p_key]['title'] = $product['name']; $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); } $magicscroll = $tool->getMainTemplate($productImagesData, array("id" => "blockspecialsMagicScroll")); $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magicscroll, $output); break; case 'blockviewed': $productsViewed = $GLOBALS['magictoolbox']['magicscroll']['productsViewed']; $pCount = count($productsViewed); if (!$pCount) { break; } $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; if ($pCount < $tool->params->getValue('items')) { $tool->params->setValue('items', $pCount); } $productImagesData = array(); $useLink = $tool->params->checkValue('link-to-product-page', 'Yes'); foreach ($productsViewed as $id_product) { $productViewedObj = new Product(intval($id_product), false, intval($cookie->id_lang)); if (!Validate::isLoadedObject($productViewedObj) or !$productViewedObj->active) { continue; } else { $images = $productViewedObj->getImages(intval($cookie->id_lang)); foreach ($images as $image) { if ($image['cover']) { $productViewedObj->cover = $productViewedObj->id . '-' . $image['id_image']; $productViewedObj->legend = $image['legend']; break; } } if (!isset($productViewedObj->cover)) { $productViewedObj->cover = Language::getIsoById($cookie->id_lang) . '-default'; $productViewedObj->legend = ''; } $lrw = $productViewedObj->link_rewrite; if ($useLink && (!Tools::getValue('id_product', false) || Tools::getValue('id_product', false) != $id_product)) { $productImagesData[$id_product]['link'] = $link->getProductLink($id_product, $lrw, $productViewedObj->category); } else { $productImagesData[$id_product]['link'] = ''; } $productImagesData[$id_product]['title'] = $productViewedObj->name; $productImagesData[$id_product]['img'] = $_link->getImageLink($lrw, $productViewedObj->cover, $tool->params->getValue('thumb-image')); } } $magicscroll = $tool->getMainTemplate($productImagesData, array("id" => "blockviewedMagicScroll")); $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magicscroll, $output); break; case 'blockbestsellers': case 'blockbestsellers_home': case 'blocknewproducts': case 'blocknewproducts_home': if (in_array($currentTemplate, array('blockbestsellers', 'blockbestsellers_home'))) { $nb_products = $tool->params->getValue('max-number-of-products', $currentTemplate); //$products = $smarty->{$this->getTemplateVars}('best_sellers'); //to get with description etc. $products = ProductSale::getBestSales(intval($cookie->id_lang), 0, $nb_products); } else { $products = $smarty->{$this->getTemplateVars}('new_products'); } if (!is_array($products)) { break; } $pCount = count($products); if (!$pCount || !$products) { break; } $GLOBALS['magictoolbox']['magicscroll']['headers'] = true; if ($pCount < $tool->params->getValue('items')) { $tool->params->setValue('items', $pCount); } $productImagesData = array(); $useLink = $tool->params->checkValue('link-to-product-page', 'Yes'); foreach ($products as $p_key => $product) { if ($useLink && (!Tools::getValue('id_product', false) || Tools::getValue('id_product', false) != $product['id_product'])) { $productImagesData[$p_key]['link'] = $link->getProductLink($product['id_product'], $product['link_rewrite'], isset($product['category']) ? $product['category'] : null); } else { $productImagesData[$p_key]['link'] = ''; } $productImagesData[$p_key]['title'] = $product['name']; $productImagesData[$p_key]['img'] = $_link->getImageLink($product['link_rewrite'], $product['id_image'], $tool->params->getValue('thumb-image')); } $magicscroll = $tool->getMainTemplate($productImagesData, array("id" => $currentTemplate . "MagicScroll")); if ($this->isPrestaShop16x) { if ($currentTemplate == 'blockbestsellers_home') { $magicscroll = '<div id="blockbestsellers" class="MagicToolboxContainer blockbestsellers tab-pane">' . $magicscroll . '</div>'; } else { if ($currentTemplate == 'blocknewproducts_home') { $magicscroll = '<div id="blocknewproducts" class="MagicToolboxContainer blocknewproducts tab-pane active">' . $magicscroll . '</div>'; } } } $pattern = '<ul[^>]*?>.*?<\\/ul>'; $output = preg_replace('/' . $pattern . '/is', $magicscroll, $output); break; } return self::prepareOutput($output); }