spider17 Posted October 12, 2013 Share Posted October 12, 2013 (edited) hi, im trying to create a new tpl for blocknewproducts, blocknewproductsHome.tpl that will be attached to the homehook. i use presta 1.5.6. in blocknewproducts.php into mywebsite/module/blocknewproducts.php i modified: public function hookHome($params) { return $this->hookRightColumn($params); } to: public function hookHome($params) { if (!$this->isCached('blocknewproductsHome.tpl', $this->getCacheId())) { if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) return; $newProducts = Product::getNewProducts((int) $params['cookie']->id_lang, 0, (int) Configuration::get('NEW_PRODUCTS_NBR')); if (!$newProducts) return; $this->smarty->assign(array( 'new_products' => $newProducts, 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), )); } return $this->display(__FILE__, 'blocknewproductsHome.tpl', $this->getCacheId()); } the i create i new file named "blocknewproductsHome.tpl" in mywebsite/theme/mytheme/moudels/blocknewproducts * * 2007-2012 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 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/afl-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-2012 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} <style> .title_block_home{ font-size: 15px; font-weight: bold; padding: 17px 7px 18px 37px; text-transform: uppercase; height: 35px; background: #8dc63f; line-height: 35px; width: 200px; } .title_block_home a{ text-decoration: none; } .add_to_cart{ margin-left: 28px; } </style> <!-- MODULE Block new products --> <div id="new-products_block" class="block products_block"> <br><br> <p class="title_block_home"><a href="{$link->getPageLink('new-products')}" title="{l s='New products' mod='blocknewproducts'}">{l s='    Nouveaux Produits' mod='blocknewproducts'}</a></p> <br><br> <div class="block_content"> {if $new_products !== false} <ul class="products clearfix"> {foreach from=$new_products item='product' name='newProducts'} <li {if $smarty.foreach.newProducts.first} class="first"{/if} style="margin: 0 7px 55px 0 !important; width: 180px !important;"> <div class="prod_image"> <a href="{$product.link}" title="{$product.legend|escape:html:'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" alt="{$product.legend|escape:html:'UTF-8'}" /></a> </div> <div class="prod_content"> <h5><a href="{$product.link}" title="{$product.name|escape:html:'UTF-8'}">{$product.name|truncate:20:'...'|escape:html:'UTF-8'}</a></h5> <span class="price">{convertPrice price=$product.price}</span> </div> <div class="add_to_cart"> <a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart.php')}?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='homefeatured'}">{l s='Ajouter au panier' mod='homefeatured'}</a> </div> </li> {/foreach} </ul> {else} <p>» {l s='No new products at this time' mod='blocknewproducts'}</p> {/if} </div> </div> <!-- /MODULE Block new products --> the problem is when i click to add to cart, nothing happen, but when i refresh the page, i found the product in the cart. can someone please help me. Edited October 12, 2013 by spider17 (see edit history) Link to comment Share on other sites More sharing options...
Broceliande Posted October 12, 2013 Share Posted October 12, 2013 Hi, IMO there are a few things to check looking @ what u wanna do and the way you do it. Usage of ajax_add_to_cart_button class and rel to spécify the id both look fine. - Are you sure ajax-cart.js is loaded in your home page though ? - Supposing it's loaded, did you set the debug parameter to true in /config/defines.inc.php ? (in case you did, any notice or warning on any of loaded module will break ajax response) I really wonder why you put some inline style ine your tpl. There is a css file loaded in header wich at least uses CCC. Inline styles aren't really good for "google pagespeed" like tests . You'd be inspired to put those css in blocknewproducts.css reather than in tpl. You'd be inspired too to have a look @ modules's tpl and css overrides cause it would have been far enough to override the module tpl and css rather than modify them inside module's directory. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now