3

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...

| improve this question | | | | |
1

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
| improve this answer | | | | |
  • i have added following code.. but it didnt work. loads the same page again. why action field of form is empty? – Rajeev K Tomy Dec 16 '13 at 16:00
  • Oh sorry I miss read your question. What block are you using to show this form? As you will need the action from the block abstract Mage_Catalog_Block_Product_Abstract – David Manners Dec 16 '13 at 16:02
  • i copied the form element definition from view.phtml file and pasted it in my custom view.phtml page. since i have loaded the prdouct to the variable $_product, i assumed that, it may work like standard form element definition. howewver it didnt worked. please note that, i am not using any of standard blocks in my custom module. – Rajeev K Tomy Dec 16 '13 at 16:06
  • see my edit about the Mage_Catalog_Block_Product_Abstract as this holds the getSubmitUrl code – David Manners Dec 16 '13 at 16:07
  • what should i do in order to get this action from Mage_Catalog_Block_Product_Abstract? – Rajeev K Tomy Dec 16 '13 at 16:13
2

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">
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.