Magento - My "Add to Cart" button will not work and product list formatting is off.

Magento - My "Add to Cart" button will not work and product list formatting is off.

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - My "Add to Cart" button will not work and product list formatting is off.

Title: Resolving Magento “Add to Cart” Button Issues and Fixing Product List Formatting

Are you facing issues with your Magento “Add to Cart” button not working properly? Or perhaps the formatting of your product list is off, leaving too much spacing around each item? These are common challenges that many Magento users encounter, especially those who are new to HTML, CSS, and Magento customization.

The Broken “Add to Cart” Button

If you’ve modified the list.phtml file (found at app/design/frontend/base/default/template/catalog/product/list.phtml) and your “Add to Cart” button stops working, it’s likely due to an error in the PHP syntax. Let me correct that for you:

<p style="display:inline">
    <button type="button"
            title="<?php echo $this->__('Add to Cart') ?>"
            class="button btn-cart"
            onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
        <span><span><?php echo $this->__('Add to Cart') ?></span></span>
    </button>
</p>

The key issue was missing closing PHP tags at the end of the class attribute and inside the onclick attribute. Remember, in Magento, PHP code is enclosed within <?php ?> tags.

Reducing Product List Spacing

If you want to reduce the space around each product in list view, you’ll need to modify your CSS file accordingly. The relevant section of your styles.css file (typically found at skin/frontend/default/f002/css/styles.css) is as follows:

/* View Type: List */
.products-list li.item { border-bottom:1px solid #d9ddd3; padding:1px 1px; }
.products-list li.item.last { border-bottom:1px; padding:25px 1px; }
.products-list .product-image { float:left; width:40px; height:40px; margin:0 0 1px; }
.products-list .product-image img { width:40px; height:40px; }
.products-list .product-shop { margin-left:55px; }

To reduce the spacing, you can decrease the padding values and the margin-left value. Here’s an updated version:

/* View Type: List */
.products-list li.item { border-bottom:1px solid #d9ddd3; padding:0.5px 0.5px; }
.products-list li.item.last { border-bottom:1px; padding:5px 1px; }
.products-list .product-image { float:left; width:40px; height:40px; margin:0; padding:1px; }
.products-list .product-image img { width:40px; height:40px; }
.products-list .product-shop { margin-left:25px; }

In this example, I’ve reduced the padding values to minimize the inner space and decreased the margin-left value of .product-shop to reduce the left spacing.

Remember, CSS changes should be made in your custom theme’s CSS file, not directly in Magento’s core files. Always make a backup before editing these files, as improper modifications can break your site.

Conclusion

Resolving “Add to Cart” button issues and improving product list formatting in Magento requires a basic understanding of PHP syntax for the template files and CSS styling for the presentation layer. By carefully modifying your list.phtml and styles.css files according to the examples provided, you can successfully fix these common problems.

If you’re looking for more advanced customization options or need professional help with your Magento store, don’t hesitate to contact our team at Laravel Company. We specialize in Magento development and support, ensuring your e-commerce platform remains secure, performant, and user-friendly.

Happy coding!

Checkout Catalog Themes Pricing

Our network