Note that there are some explanatory texts on larger screens.

plurals
  1. POlatest product with add-to-cart in magento
    text
    copied!<p>I'm new for <strong>Magento</strong>. I need to display latest added product in home page. I'm using following code in <code>2columns-left.phtml</code></p> <pre><code>&lt;div class="main"&gt; &lt;?php echo $this-&gt;getChildHtml('breadcrumbs') ?&gt; &lt;div class="col-main"&gt; &lt;?php echo $this-&gt;getChildHtml('global_messages') ?&gt; &lt;?php echo $this-&gt;getChildHtml('content') ?&gt; &lt;?php $productsCollection = Mage::getModel("catalog/product")-&gt;getCollection() -&gt;addAttributeToSort("entity_id","DESC") -&gt;setVisibility(Mage::getSingleton('catalog/product_visibility')-&gt;getVisibleInSiteIds()) -&gt;setPageSize(6) -&gt;setCurPage(1); foreach ($productsCollection as $product) { $model = Mage::getModel('catalog/product')-&gt;load($product-&gt;getId()); echo $model-&gt;getName().'&lt;br&gt;'; echo $model-&gt;getPrice().'&lt;br&gt;'; echo $model-&gt;getImageUrl().'&lt;br&gt;'; echo "&lt;br&gt;&lt;br&gt;"; } ?&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>It's working fine. But I can't correct code for <strong>add-to-cart</strong> option.</p> <p>I found fllowing code from <code>addtocart.phtml</code> with script,</p> <pre><code>&lt;?php $_product = $this-&gt;getProduct(); ?&gt; &lt;form action="&lt;?php echo $this-&gt;getSubmitUrl($_product) ?&gt;" method="post" id="product_addtocart_form"&gt; &lt;?php $buttonTitle = $this-&gt;__('Add to Cart'); ?&gt; &lt;?php if($_product-&gt;isSaleable()): ?&gt; &lt;div class="add-to-cart"&gt; &lt;?php if(!$_product-&gt;isGrouped()): ?&gt; &lt;label for="qty"&gt;&lt;?php echo $this-&gt;__('Qty:') ?&gt;&lt;/label&gt; &lt;input type="text" name="qty" id="qty" maxlength="12" value="&lt;?php echo $this-&gt;getProductDefaultQty() * 1 ?&gt;" title="&lt;?php echo $this-&gt;__('Qty') ?&gt;" class="input-text qty" /&gt; &lt;?php endif; ?&gt; &lt;button type="button" title="&lt;?php echo $buttonTitle ?&gt;" class="button btn-cart" onclick="productAddToCartForm.submit(this)"&gt;&lt;span&gt;&lt;span&gt;&lt;?php echo $buttonTitle ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/button&gt; &lt;?php echo $this-&gt;getChildHtml('', true, true) ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;/form&gt; </code></pre> <p>But, if I click add-to-cart, going to home page.</p> <p>Help me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload