Certified Partner and
PrestaShop Developer for:

Add a Javascript alert when the default attributes are selected

Default Attribute Alert

This page was written in English, please see the English version for the most accurate code.


Users may not notice there are attributes to select for a product and just click "Add to cart" without realizing they chose the default attributes.

The code changes below create a Javascript alert when the default attributes were not changed, asking the user to confirm their selection.

Change your code to match the one below, the highlighted text needs to be added.

The line numbers may change a bit depending on your version of prestashop, but the actual code is the same.



/module/blockcart/ajax-cart.js (around line 11)


     //for product page 'add' button...
        $('body#product p#add_to_cart input').unbind('click').click(function(){
            if (attribute_alert == true)
                if (!confirm(attribute_alert_text))
                    return false;

            ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null);
            return false;


/themes/prestashop/product.tpl (line 3)


<script type="text/javascript">
var attribute_alert = {if $groups|@count > 0}true{else}false{/if};
var attribute_alert_text = "{l s='You have not changed the default product options, click OK to add the product, or Cancel to make changes'}.";


/themes/prestashop/product.tpl (around line 166)


         {foreach from=$colors key='id_attribute' item='color'}
                <li><a id="color_{$id_attribute|intval}" style="background: {$color.value};" onclick="updateColorSelect({$id_attribute|intval});attribute_alert=false;">{if file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}<img src="{$img_col_dir}{$id_attribute}.jpg" alt="" title="{$}" />{/if}</a></li>



/themes/prestashop/product.tpl (around line 178)


         <form id="buy_block" action="{$base_dir}cart.php" onsubmit="if (attribute_alert == true) {ldelim}if (!confirm(attribute_alert_text)) {ldelim}return false; {rdelim}{rdelim}" method="post">



/themes/prestashop/product.tpl (around line 243)


             <select name="{$groupName}" id="group_{$id_attribute_group|intval}" onchange="javascript:findCombination();attribute_alert=false;">