Fmarta Posted October 7, 2013 Share Posted October 7, 2013 Hi I need to show featured products in a cms page id=11. It is possible? and how Thanks Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2013 Share Posted October 8, 2013 by default it isn;t possible. You can achieve it only with modification of cms controller. you will need to add code from module (function to get products) there and attach it to smarty array then in cms.tpl you will be able to display it with code from module .tpl file (with some modifications) Link to comment Share on other sites More sharing options...
Fmarta Posted October 8, 2013 Author Share Posted October 8, 2013 Thanks for the answer, it is possible to give me an example of code to insert. Thanks Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2013 Share Posted October 8, 2013 in cmsController in initContent function add this: $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8)); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); then in cms.tpl file you can use foreach: {foreach from=$products item=product name=homeFeaturedProducts} {math equation="(total%perLine)" total=$smarty.foreach.homeFeaturedProducts.total perLine=$nbItemsPerLine assign=totModulo} {if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if} <li class="ajax_block_product {if $smarty.foreach.homeFeaturedProducts.first}first_item{elseif $smarty.foreach.homeFeaturedProducts.last}last_item{else}item{/if} {if $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 0}last_item_of_line{elseif $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 1} {/if} {if $smarty.foreach.homeFeaturedProducts.iteration > ($smarty.foreach.homeFeaturedProducts.total - $totModulo)}last_line{/if}"> <a href="{$product.link|escape:'html'}" title="{$product.name|escape:html:'UTF-8'}" class="product_image"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html'}" height="{$homeSize.height}" width="{$homeSize.width}" alt="{$product.name|escape:html:'UTF-8'}" />{if isset($product.new) && $product.new == 1}<span class="new">{l s='New' mod='homefeatured'}</span>{/if}</a> <h5 class="s_title_block"><a href="{$product.link|escape:'html'}" title="{$product.name|truncate:50:'...'|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a></h5> <div class="product_desc"><a href="{$product.link|escape:'html'}" title="{l s='More' mod='homefeatured'}">{$product.description_short|strip_tags|truncate:65:'...'}</a></div> <div> <a class="lnk_more" href="{$product.link|escape:'html'}" title="{l s='View' mod='homefeatured'}">{l s='View' mod='homefeatured'}</a> {if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}<p class="price_container"><span class="price">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span></p>{else}<div style="height:21px;"></div>{/if} {if ($product.id_product_attribute == 0 OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND $product.available_for_order AND !isset($restricted_country_mode) AND $product.minimal_quantity == 1 AND $product.customizable != 2 AND !$PS_CATALOG_MODE} {if ($product.quantity > 0 OR $product.allow_oosp)} <a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart')|escape:'html'}?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='homefeatured'}">{l s='Add to cart' mod='homefeatured'}</a> {else} <span class="exclusive">{l s='Add to cart' mod='homefeatured'}</span> {/if} {else} <div style="height:23px;"></div> {/if} </div> </li> {/foreach} Link to comment Share on other sites More sharing options...
Fmarta Posted October 8, 2013 Author Share Posted October 8, 2013 Thanks for the example, last question I trie to add that in cmscontroler.php in several places but always the same error Fatal error: Call to a member function assign() on a non-object in /home/mapaclik/public_html/queenbox/controllers/front/CmsController.php on line 126 This is my original cmscontroler.php <?php/** 2007-2013 PrestaShop** NOTICE OF LICENSE** This source file is subject to the Open Software License (OSL 3.0)* that is bundled with this package in the file LICENSE.txt.* It is also available through the world-wide-web at this URL:* http://opensource.org/licenses/osl-3.0.php* If you did not receive a copy of the license and are unable to* obtain it through the world-wide-web, please send an email* to [email protected] so we can send you a copy immediately.** DISCLAIMER** Do not edit or add to this file if you wish to upgrade PrestaShop to newer* versions in the future. If you wish to customize PrestaShop for your* needs please refer to http://www.prestashop.com for more information.** @author PrestaShop SA <[email protected]>* @copyright 2007-2013 PrestaShop SA* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)* International Registered Trademark & Property of PrestaShop SA*/class CmsControllerCore extends FrontController{ public $php_self = 'cms'; public $assignCase; public $cms; public $cms_category; public function canonicalRedirection($canonicalURL = '') { if (Tools::getValue('live_edit')) return ; if (Validate::isLoadedObject($this->cms) && ($canonicalURL = $this->context->link->getCMSLink($this->cms))) parent::canonicalRedirection($canonicalURL); else if (Validate::isLoadedObject($this->cms_category) && ($canonicalURL = $this->context->link->getCMSCategoryLink($this->cms_category))) parent::canonicalRedirection($canonicalURL); } /** * Initialize cms controller * @see FrontController::init() */ public function init() { parent::init(); if ($id_cms = (int)Tools::getValue('id_cms')) $this->cms = new CMS($id_cms, $this->context->language->id); else if ($id_cms_category = (int)Tools::getValue('id_cms_category')) $this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id); $this->canonicalRedirection(); // assignCase (1 = CMS page, 2 = CMS category) if (Validate::isLoadedObject($this->cms)) { $adtoken = Tools::getAdminToken('AdminCmsContent'.(int)Tab::getIdFromClassName('AdminCmsContent').(int)Tools::getValue('id_employee')); if (!$this->cms->isAssociatedToShop() || !$this->cms->active && Tools::getValue('adtoken') != $adtoken) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } else $this->assignCase = 1; } else if (Validate::isLoadedObject($this->cms_category)) $this->assignCase = 2; else { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } } public function setMedia() { parent::setMedia(); if ($this->assignCase == 1) $this->addJS(_THEME_JS_DIR_.'cms.js'); $this->addCSS(_THEME_CSS_DIR_.'cms.css'); } /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $parent_cat = new CMSCategory(1, $this->context->language->id); $this->context->smarty->assign('id_current_lang', $this->context->language->id); $this->context->smarty->assign('home_title', $parent_cat->name); $this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID')); if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category) $path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS'); else if (isset($this->cms_category->meta_title)) $path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS'); if ($this->assignCase == 1) { $this->context->smarty->assign(array( 'cms' => $this->cms, 'content_only' => (int)(Tools::getValue('content_only')), 'path' => $path )); } else if ($this->assignCase == 2) { $this->context->smarty->assign(array( 'category' => $this->cms_category, //for backward compatibility 'cms_category' => $this->cms_category, 'sub_category' => $this->cms_category->getSubCategories($this->context->language->id), 'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ), 'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '', )); } $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); }} Where i need to put the first code you send. Thanks in advance Federico Link to comment Share on other sites More sharing options...
vekia Posted October 10, 2013 Share Posted October 10, 2013 what you mean by: I trie to add that in cmscontroler.php in several places but always the same error can you shed some light on this? i don't understand what you exactly changed (used) and where Link to comment Share on other sites More sharing options...
Denys06 Posted November 28, 2013 Share Posted November 28, 2013 (edited) Up, do you have found the solution please ? I have make modification, but after in CMS page how I can I call products (id=293 for example) ? Edited November 28, 2013 by Denys06 (see edit history) Link to comment Share on other sites More sharing options...
Denys06 Posted December 3, 2013 Share Posted December 3, 2013 Up again please I search a solution Link to comment Share on other sites More sharing options...
vekia Posted December 3, 2013 Share Posted December 3, 2013 Up again please I search a solution i missed your message. change $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8)); to: $products = $category->getProducts(293, 1, ($nb ? $nb : 8)); Link to comment Share on other sites More sharing options...
Denys06 Posted December 3, 2013 Share Posted December 3, 2013 (edited) I'm sorry but this change is not what I want. I would like to see a products to some place of a paragraph same of this picture (photoshop) : With your indications I have change the code of my files : CmsController.php and cms.tpl but I don't see any modification into my CMS page. Also I think I'm missing a code to display a product in the source code of CMS content.Thank you for your help, and sorry for my bad English Edited December 3, 2013 by Denys06 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted December 4, 2013 Share Posted December 4, 2013 so i don't know what you want exactly. you want to insert products inside cms content? or just create product list as author of this thread wanted? Link to comment Share on other sites More sharing options...
Denys06 Posted December 12, 2013 Share Posted December 12, 2013 (edited) Hello vekia, sorry for my last answer but I have not receive the mail about your answer i dont know why...I want insert products inside cms content same of my picture. I thought it was as requested by the author.Do you know what modification I need to do please ? Edited December 12, 2013 by Denys06 (see edit history) Link to comment Share on other sites More sharing options...
rajlaskar Posted February 24, 2014 Share Posted February 24, 2014 is there any custom module available, so that through CMS pages, we can list some specific categories of product? i mean creating landing pages with 3-4 categories blocks with carousel i mean page with category 1 [ 8 products in carousel] category 2 [ 8 products in carousel] category 3 [ 8 products in carousel] category 4 [ 8 products in carousel] through cms module or any new custom module one can able create many such landing pages Link to comment Share on other sites More sharing options...
Recommended Posts