How should I go about capturing a custom form in Magento that is stored with the order?

I am working on a module to add a new step called Rental into the Onepage Checkout module in magento. The problem is not adding a step it is the data capture.

I want to be able to take the custom form I have created and store it with the rest of the order information so when I click view order in the backend, it shows the information in the form as a seperate box.

Preferably I want to seperate the concerns by creating a standalone module.

How would you go about doing this? What would be your personal strategy for implementing this?

Answers


Firstly, it should all depend on what data 'Rental' would be. Could it fit/be appropriately placed inside a product's custom option? Or do you need to create a custom sales attribute to store the data in?

If you want the latter, you should use Magento Module Creator by SilkSoftware to create a module to implement sales attributes.

Also: a good thread / scenario in using sales attributes: Magento: Setting a custom attribute on the sales/order_shipment model

Secondly, is capturing the form data -- this is assuming you already have a block/form created and showing on the checkout page. I highly encourage you name the fields in the following semantic:

<input type="text" name="rental[text_data]" />
<input type="text" name="rental[text_data2]" />

Where text_data and text_data2 are your desired variable names.

An order is submitted / saved finally via a Controller action called saveOrderAction in Mage_Checkout_OnepageController or whatever Controller class you are using currently for your checkout page. Don't edit the corresponding PHP Class file for this found at app/code/core/Mage/Checkout/controllers/OnepageController.php ! Since you want to separate this into another module, you should try and rewrite this controller then so that your custom Controller class inside your module that extends the aforementioned base class (Mage_Checkout_OnepageController) should be used by Magento in its stead.

A good tutorial on rewriting controllers can be found here.

You can then do either of the two options from here:

1.) you could copy the entire saveOrderAction function and create routines to save Rental data there. if you followed the naming semantic I suggested, you should be able to retrieve the form data doing so:

<?php
// app/code/local/Namespace/Module/controllers/Checkout.php
class Namespace_Module_Checkout extends Mage_Checkout_OnepageController {

    public function saveOrderAction() {


        .....

        $this->getOnepage()->getQuote()->save();

        $rental = $this->getRequest->getParam('rental');
        $text_data = $rental['text_data'];
        $text_data = $rental['text_data2'];
        someSaveRoutine($text_data, $text_data2);
        //..or someSaveRoutine($rental);

        .....
   }
}

2.) secondly, you could replace the above code with a custom event dispatch

 $rental = $this->getRequest->getParam('rental');
 Mage::dispatchEvent('checkout_onepage_controller_saveorder', array('rental'=> $rental));

then make an appropriate observer to save your custom data somewhere.

I know this isn't much, but it's a start. I will look into editing this to elaborate more in the near future.


Need Your Help

How do I get lftp to use SSL/TLS security mechanism from the command line?

ubuntu ftp ftps lftp

I'm trying to log into an ftps site. I've tried giving the login creds at the command line (and putting set parameters in ~/.lftprc, then opening an lftp session and typing those parameters with lf...

Devise session after nginx proxy pass to different domain

ruby-on-rails session nginx devise proxy

The goal is to map mask_domain.com to masp.original_domain.com/something. In order to achieve this goal i've set up my nginx for mask_domain.com as follows (this is a rails app):