Today I want to show you how to create "Add to cart" button into the default prestashop Featured Products (homefeatured) module. This tutorial is based on default template but of course it will also works in non-default templates.
Add to cart button and homefeatured module
Modification of the CSS styles
Open the /modules/homefeatured/homefeatured.css file. You've got there CSS styles related to the homefeatured module. At the end of this file you've got styles definition for Add to cart button:
#featured-products_block_center li .ajax_add_to_cart_button {display:none;} #featured-products_block_center li span.exclusive {display:none;}
As you can see, styles related to the add_to_cart have got display:none; param. It mean, that add to cart button will not appear. Just change it to: display:block; exactly as I show below:
#featured-products_block_center li .ajax_add_to_cart_button {display:block;} #featured-products_block_center li span.exclusive {display:block;}
After that just refresh your store front-end. You will see that "add to cart" buttons will appear. But "add to cart" text inside the each button isn't aligned well (not in the middle):
If you want to center the "add to cart" button, just add text-align:center; into the styles that I changed above. Final code:
#featured-products_block_center li .ajax_add_to_cart_button {display:block; text-align:center;} #featured-products_block_center li span.exclusive {display:block; text-align:center;}
If you want to change the position of the "add to cart" button, you have to edit the .tpl file of the module. What I mean? I mean that you have to open the /modules/homefeatured/homefeatured.tpl file (or if exist: /themes/YOUR_THEME/modules/homefeatured/homefeatured.tpl)
you've got there definition of the button, which looks like:
{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')}?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}
Move it anywhere you want. You can change the postition of this code between the {foreach} {/foreach} tags. For example, you can move it above the price (as I show on the first image here). This is the code of price:
{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}
Just paste the button code before code above. You will achieve the same effect as I:
That's all. if you've got any questions related to this case - feel free to continue discussion below. Happy selling!