I add the "Add to cart" button on the product list page successfully, then I see many people want to use this button..
I'm using open cart v 1.4.5.
First:
modify OPENCART_ROOT/catalog/controller/product/category.php
Add
Code: Select all
$this->data['action'] = HTTP_SERVER . 'index.php?route=checkout/cart';
Code: Select all
$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
Code: Select all
this->data['products'][] = array(
Code: Select all
'id' => $result['product_id'],
Code: Select all
$this->data['products'][] = array(
Code: Select all
'name' => $result['name'],
Second:
OPENCART_ROOT\catalog\view\theme\default\template\module\cart.tpl
add
Code: Select all
$('.add_to_cart').each(function(){
var _pa = $(this);
var _pid = _pa.attr('rel');
_pa.click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#product_'+_pid+' :input'),
success: function (html) {
$('#module_cart .middle').html(html);
},
complete: function () {
var image = $('#image_'+_pid).offset();
var cart = $('#module_cart').offset();
$('#image_'+_pid).before('<img src="' + $('#image_'+_pid).attr('src') + '" id="temp_'+_pid+'" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
heigth : $('#module_cart').height()
};
$('#temp_'+_pid).animate(params, 'slow', false, function () {
$('#temp_'+_pid).remove();
});
}
});
});
});
Code: Select all
$(document).ready(function () {
third:
OPENCART_ROOT\catalog\view\theme\default\template\product\category.tpl
after
Code: Select all
<?php if ($products[$j]['rating']) { ?>
<img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
<?php } ?>
Code: Select all
<form action="<?php echo $action; ?>" method="post" id="product_<?php echo $j;?>">
<input type="hidden" name="quantity" size="3" value="1" />
<a onclick="" id="add_to_cart_<?php echo $j;?>" rel="<?php echo $j;?>" class="button add_to_cart"><span>Add to Cart</span></a>
<input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />
</form>
Have fun.
Ady