Question

I have a custom module which does same function of product view page. I am using this module in order to show my bundle products. i have created a fully functional module for this.

I have loaded the product successfully and displayed products name,description, different options in my page. However my add to cart button is not working.

I am loading my product like this

<?php
/*getInternationalPlans() is a custom function which filter out bundle products that 
  satisfy certain conditions. there may be more than one bundle products for this   
  function
 */
$_product=$this->getInternationalPlans($custom_select_business);                                    
foreach ( $_product as $product ){
$plan_array [] = $product->getId ();
}

?>
<?php
 /*it unregisters the product  */
  Mage::unregister ( 'product' );
  Mage::register('international_product',$plan_array[0]);// i need only the first product                       
/*  loading the current product*/  
  $_product=Mage::getSingleton('catalog/product')->load($plan_array[0]);
 /*registering the current product*/
 Mage::register('product', $_product); // add the product object in the registry                    
 $block = Mage::getBlockSingleton('Mage_Catalog_Block_Product_View'); // Instantiate the product view block

?>

but in default product view page prdoucts are loading using getProduct() method. my form is like this... which is exactly same as that of default one

 <form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post"
 id="product_addtocart_form"
  <?php if($_product->getOptions()): ?> enctype="multipart/form-data"
 <?php endif; ?>> 
       /*all options are showing here*/
      /*...................................*/
         $buttonTitle = $this->__('Order Now');
         <button type="button" title="<?php echo $buttonTitle ?>" id="international_btn" class="btn btn-success" onclick="productAddToCartForm.submit(this)">
 </form>

However the action part of form is blank, after I load this code. when I click on the button, it loads the same page again and during consoling it says that 'productId is not defined'. So I have checked 'productAddToCartForm ' definition and found out that it uses 'productId' in its definition. How can I set 'prdouctId' in my page? why form action field is empty?

how can make my order now button work perfectly?

Please help me...

Was it helpful?

Solution

On the standard layout there is a hidden field that sets this in the product view template (/app/design/frontend/base/default/template/catalog/product/view.phtml):

<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />

I would suggest with your code you could simple add this hidden field after the form is opened.

The form gets the action from calling $this->getSubmitUrl($_product). If you look into the class Mage_Catalog_Block_Product_Abstract you will see the default way of getting this. The easiest option would be to make sure that your block extends this class or another block that extends it (e.g. Mage_Catalog_Block_Product_View). Something like the following would be enough.

class Your_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstract

OTHER TIPS

You does not add this Block in Form

 <?php echo $this->getBlockHtml('formkey') ?>

or you can also add this in form

 <input type="hidden" value="<?php Mage::getSingletonModel('core/session')->getFormKey()?>" name="form_key">
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top