title: Magento: $this->getAddToCartUrl($product) not working when I try to display the best selling products on homepage
body: <p>I am new to Magento, so I am stucked in a different situation for me. I found a guide on how to display best selling products on homepage, implemented it and everything is working fine, except the $this->getAddToCartUrl($product). The product are not added to the cart after clicking on "Add to cart".
  Here is my code:</p>
  
  <pre><code>$totalPerPage = ($this-&gt;show_total) ? $this-&gt;show_total : 4;
  $counter = 1;
  $visibility = array(
                        Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                        Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                    );
  
  $storeId = Mage::app()-&gt;getStore()-&gt;getId();
  $productCollection = Mage::getResourceModel('reports/product_collection')
                                -&gt;addAttributeToSelect('*')
                                -&gt;addOrderedQty()
                                -&gt;addAttributeToFilter('visibility', $visibility)
                                -&gt;setOrder('ordered_qty', 'desc');
  
  &lt;div class="main_content"&gt;
      &lt;div class="container"&gt;
          &lt;div class="products_list"&gt;
              &lt;div class="best_deals"&gt;
                  &lt;div class="recommended_products best_deals_products"&gt;
                      &lt;ul&gt;
              &lt;?php foreach($productCollection as $product): ?&gt;
  
              &lt;?php
                      $categories = null;
                      foreach (explode(",", $product-&gt;category_ids) as $catId){
  
                        //Mage_Catalog_Model_Category
                        $cat = Mage::getModel('catalog/category')
                                      -&gt;setStoreId(Mage::app()-&gt;getStore()-&gt;getId())
                                      -&gt;load($catId);
                        $catName = $cat-&gt;getName();
  
                        $catLink = $cat-&gt;getUrlPath();
                        $categories .= '&lt;a href="'.$catLink.'" title="'.$catName.'"&gt;'.$catName.'&lt;/a&gt;&amp;nbsp;&amp;nbsp;';
                      }
  
              ?&gt;
  
              &lt;?php if($counter &lt;= $totalPerPage): ?&gt;
  
              &lt;?php $productUrl =  $product-&gt;getProductUrl() ?&gt; 
                          &lt;li&gt;
              &lt;div class="img_bottle"&gt;
              &lt;a href="&lt;?php echo $productUrl ?&gt;" title="View &lt;?php echo $product-&gt;name ?&gt;"&gt;
              &lt;img src="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($product, 'image')-&gt;resize(107, 339); ?&gt;" alt="Product image"  /&gt;
              &lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="product_desc"&gt;            
              &lt;span&gt;&lt;?php echo $product-&gt;name ?&gt;&lt;/span&gt;            
              &lt;span&gt;Our price: $&lt;?php echo number_format($product-&gt;getPrice(), 2); ?&gt;&lt;/span&gt;
              &lt;?php if($product['country_of_manufacture']): ?&gt;
              &lt;span&gt;Country: &lt;i&gt;&lt;?php echo strtoupper($product-&gt;getAttributeText('country_of_manufacture')); ?&gt;&lt;/i&gt;&lt;/span&gt;
              &lt;?php endif; ?&gt;
              &lt;?php if($product['region']): ?&gt;
              &lt;span&gt;Region: &lt;i&gt;&lt;?php echo strtoupper($product['region']); ?&gt;&lt;/i&gt;&lt;/span&gt;
              &lt;?php endif; ?&gt;                            
                  &lt;?php if($product-&gt;isSaleable()): ?&gt;
                      &lt;button type="button" title="&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;" class="button btn-cart buy_now_button" onclick="setLocation('&lt;?php echo $this-&gt;getAddToCartUrl($product) ?&gt;')"&gt;Add to Cart&lt;/button&gt;
                  &lt;?php else: ?&gt;
                      &lt;p class="availability out-of-stock"&gt;&lt;span&gt;&lt;?php echo $this-&gt;__('Out of stock') ?&gt;&lt;/span&gt;&lt;/p&gt;
                  &lt;?php endif; ?&gt;
              &lt;/div&gt;
                              &lt;/li&gt;
              &lt;?php endif; $counter++; ?&gt;
  
              &lt;?php endforeach; ?&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thank you in advance, I hope that my problem will be solved here.</p>