Monthly Archives: March 2011

Add extra field(s) in registration page

Dear Tow…, this post is basically for new guys. Few guys asked me how to add extra field(s) in registration process. So, here I will try to give few technical tricks.

1. Add new fields in config xml (app\code\core\Mage\Customer\etc\config.xml). If you create new module then you can add this xml block in module config xml file. Create new module is the best practice and recommended :)

<?xml version="1.0"?>
<fieldsets>
   <customer_account>
     <prefix><create>1</create><update>1</update><name>1</name></prefix>
     <firstname><create>1</create><update>1</update><name>1</name></firstname>
     <middlename><create>1</create><update>1</update><name>1</name></middlename>
     <lastname><create>1</create><update>1</update><name>1</name></lastname>
     <suffix><create>1</create><update>1</update><name>1</name></suffix>
     <email><create>1</create><update>1</update></email>
     <password><create>1</create></password>
     <confirmation><create>1</create></confirmation>
     <dob><create>1</create><update>1</update></dob>
     <taxvat><create>1</create><update>1</update></taxvat>
     <gender><create>1</create><update>1</update></gender>

     /* newly added field(s)*/
     <accounttype><create>1</create><update>1</update><name>1</name></accounttype>
     <companyname><create>1</create><update>1</update><name>1</name></companyname>
  </customer_account>
</fieldsets>

2. Add these extra field(s) in your respective theme registration.phtml (app\design\frontend\…\…\template\customer\form\registration.phtml). Keep the field name same as you mentioned in config.xml

3. To save extra data in database with customer registration process you have to add these extra field(s) as entity attribute in eav_attribute table. Here is sql script.

insert into `magento`.`eav_attribute` (`entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`)
values(1, 'accounttype', '', '', 'varchar', '', '', 'select', 'Account Type', '', '', 0, 0, '', 0,''),
        (1, 'companyname', '', '', 'varchar', '', '', 'text', 'Company Name', '', '', 0, 0, '', 0,'');

That’s all. Try and let me know if you face any complexity.

Like this you can add extra field(s) in any magento pages as well.

Add option(s) to quote item object at order processing step

Hi guys, how are you? Hope all of you are doing well. I have been backed after long time and have decided to share few of my recent experiences.

For a recent project I had to create a custom order processing module in magento. I got help from a post of magento forum ( http://www.magentocommerce.com/boards/viewthread/28426/). That was nice and very helpful for me. And it saved my time as well. So my heartiest thanks to all of the guys who have been contributed in that forum post.

But I faced problem to add option(s) with order item. I found a solution to add option(s) to quote object. But using this you can order only single item at a time. Below is the code snap.

$option = array('options'=>array(
              "option_id1" => 'option_value1',
              "option_id2" => 'option_value2'
             ));

$request = new Varien_Object();
 $request->setData($option);
$quoteObj->addProduct($productObj,$request);

To order multiple items at a time you have to add option(s) with quote item object. Here is the code snap for your help.

$quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerObj);
$productModel=Mage::getModel('catalog/product');

foreach($products as $product) {
	$productObj = $productModel->load($productId);
	$quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);

	$quoteItem->addOption(new Varien_Object(
                   	array(
                      		'product' => $quoteItem->getProduct(),
                       		'code' => 'option_ids',
                       		'value' => $option_id  // 45,46,55
               	         )
               	));

	$quoteItem->addOption(new Varien_Object(
                    	array(
                       		'product' => $quoteItem->getProduct(),
                       		'code' => 'option_'.$option_id,   //45
                       		'value' => $option_value          // ‘White’
             	         )
   		));

        $quoteItem->addOption(new Varien_Object(
                    	array(
                       		'product' => $quoteItem->getProduct(),
                       		'code' => 'option_'.$option_id,   //46
                       		'value' => $option_value         // ‘Large’
               	        )
   		));

	$quoteItem->setQuote($quoteObj);
	$quoteItem->setQty($Quantity);
	$quoteObj->addItem($quoteItem);
}
$quoteObj->collectTotals();
$quoteObj->save();

This code snap has been worked so far. For more details and any kind of helps contact with me.