1

I have created a new1.phtml file in catalog/product with following content

<?php
        //getting new product collection

        $product=Mage::getModel("catalog/product")->getCollection();
        $filtered_prodduct=$product->addAttributeToSelect("*")
                                    ->setOrder("created_at","desc")
                                    ->addPriceData();
        echo "<ul>
                <li>";
                $i=0;
                $row=3;
        foreach($filtered_prodduct as $prod){ 
            $i++;
            if($i>$row*3){
                break;
            }
            ?>
        <div class="prod_box">
            <div class="center_prod_box">
                <div class="product_title">
                    <a href="<?php echo $prod->getProductUrl()?>">
                        <?php echo $prod->getName() ?>
                    </a>
                </div>
                <div class="product_img">
                    <a href="<?php echo $prod->getproductUrl()?>">
                        <img src="<?php echo $prod->getImageUrl()?>" alt=""          border="0" height="100" width="100"> 

                    </a>
                </div>
                <div class="prod_price">
                    <span class="reduce"><?php echo $prod->getSpecialPrice()?></span>
                    <span class="price"><?php echo $prod->getPrice()?></span><br/>
                </div>
            </div>
            <div class="prod_details_tab">

                <?php if($prod->isSaleable()): ?>
                        <a href="<?php echo $this->getUrl()?>checkout/cart/add? product=<?php echo $prod->getId(); ?>&qty=1" class="prod_buy">
                            <?php echo $this->__('Add') ?>
                        </a>

                    <?php else: ?>
                         <p class="availability out-of-stock"><span>
                 <?php echo   $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                <a href="<?php echo $prod->getProductUrl()?>" class="prod_details">
                    Details
                </a>
            </div>
        </div>
        <?php } 
      ?>

Every thing is ok ,but 'Add' button (means add to cart) is not working .It just opens checkout/cart.

i have added this phtml file in layout xml of home page. what is wrong in the code ?

1
  • No. It is add?product= Commented Jul 4, 2014 at 13:43

3 Answers 3

1

You can do this my using below code ,which generated add to cart url.

Mage::helper('checkout/cart')->getAddUrl(($prod);

If product type is configurable and group or if product type is simple and it have customoption ,then it did not cart directly without selecting any options

Sign up to request clarification or add additional context in comments.

Comments

0

The controller's action validates request therefore you should send formKey

public function addAction() { if (!$this->_validateFormKey()) { $this->_goBack(); return; } ... {

Comments

0
Mage::helper('checkout/cart')->getAddUrl(($prod);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.