Instead of using a custom controller it's easier (and perhaps cleaner) to do this from a controller. So, we'll need to build a little module for that
config.xml
<?xml version="1.0"?>
<config>
[...]
<global>
<fieldsets>
<sales_convert_quote_item>
<custom_attribute_column>
<to_order_item>*</to_order_item>
</custom_attribute_column>
</sales_convert_quote_item>
</fieldsets>
<resources>
<[namespace]_[module]_setup>
<setup>
<module>[Namespace]_[Module]</module>
<class>Mage_Sales_Model_Mysql4_Setup</class>
</setup>
</[namespace]_[module]_setup>
</resources>
<models>
<[namespace]_[module]>
<class>[namespace]_[module]_Model</class>
</[namespace]_[module]>
</models>
<events>
<checkout_cart_product_add_after>
<observers>
<[namespace]_[module]_checkout_cart_product_add_after>
<type>model</type>
<class>[Namespace]_[Module]_Model_Observer</class>
<method>checkoutCartProductAddAfter</method>
</[namespace]_[module]_checkout_cart_product_add_after>
</observers>
</checkout_cart_product_add_after>
</events>
</global>
[...]
</config>
your setup script
$installer = $this;
$installer->getConnection()->addColumn($this->getTable('sales_flat_quote_item'), 'custom_attribute_column', 'varchar(255) NOT NULL');
$installer->getConnection()->addColumn($this->getTable('sales_flat_order_item'), 'custom_attribute_column', 'varchar(255) NOT NULL');
$installer->endSetup();
And the observer [Namespace]/[Module]/Model/Observer.php
class [Namespace]_[Module]_Model_Observer
{
public function checkoutCartProductAddAfter($observer)
{
$item = $observer->getEvent()->getQuoteItem();
$item->setData('custom_attribute_column', 'the value');
$item->save();
return $this;
}
}
I have Create An Module For This Purpose.
It May be help full for you.
app\etc\modules\Designo_Productname.xml
<?xml version="1.0"?>
<config>
<modules>
<Designo_Productname>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Designo_Productname>
</modules>
</config>
app\code\local\Designo\Productname\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Designo_Productname>
<version>0.1.0</version>
</Designo_Productname>
</modules>
<global>
<helpers>
<productname>
<class>Designo_Productname_Helper</class>
</productname>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Designo_Productname before="Mage_Adminhtml">Designo_Productname_Adminhtml</Designo_Productname>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
app\code\local\Designo\Productname\Helper\Data.php
<?php
class Designo_Productname_Helper_Data extends Mage_Core_Helper_Abstract
{
}
app\code\local\Designo\Productname\controllers\Adminhtml\Catalog\ProductController.php
<?php
require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';
class Designo_Productname_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
public function editAction()
{
$productId = (int) $this->getRequest()->getParam('id');
$product = $this->_initProduct();
$productName = $product->getData('name');
Mage::register('previous_name',$productName);
$productColor = $product->getAttributeText('color');
$productBrand = $product->getAttributeText('computer_manufacturers');
$ProductCompleteName = $productName.' '.$productBrand.' '.$productColor;
$product->setData('name',$ProductCompleteName);
if ($productId && !$product->getId()) {
$this->_getSession()->addError(Mage::helper('catalog')->__('This product no longer exists.'));
$this->_redirect('*/*/');
return;
}
$this->_title($product->getName());
Mage::dispatchEvent('catalog_product_edit_action', array('product' => $product));
$_additionalLayoutPart = '';
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
&& !($product->getTypeInstance()->getUsedProductAttributeIds()))
{
$_additionalLayoutPart = '_new';
}
$this->loadLayout(array(
'default',
strtolower($this->getFullActionName()),
'adminhtml_catalog_product_'.$product->getTypeId() . $_additionalLayoutPart
));
$this->_setActiveMenu('catalog/products');
if (!Mage::app()->isSingleStoreMode() && ($switchBlock = $this->getLayout()->getBlock('store_switcher'))) {
$switchBlock->setDefaultStoreName($this->__('Default Values'))
->setWebsiteIds($product->getWebsiteIds())
->setSwitchUrl(
$this->getUrl('*/*/*', array('_current'=>true, 'active_tab'=>null, 'tab' => null, 'store'=>null))
);
}
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
$block = $this->getLayout()->getBlock('catalog.wysiwyg.js');
if ($block) {
$block->setStoreId($product->getStoreId());
}
$this->renderLayout();
}
/**
* Save product action
*/
public function saveAction()
{
$storeId = $this->getRequest()->getParam('store');
$redirectBack = $this->getRequest()->getParam('back', false);
$productId = $this->getRequest()->getParam('id');
$isEdit = (int)($this->getRequest()->getParam('id') != null);
$data = $this->getRequest()->getPost();
$data['name'] = Mage::registry('previous_name');
if ($data) {
$this->_filterStockData($data['product']['stock_data']);
$product = $this->_initProductSave();
try {
$product->save();
$productId = $product->getId();
/**
* Do copying data to stores
*/
if (isset($data['copy_to_stores'])) {
foreach ($data['copy_to_stores'] as $storeTo=>$storeFrom) {
$newProduct = Mage::getModel('catalog/product')
->setStoreId($storeFrom)
->load($productId)
->setStoreId($storeTo)
->save();
}
}
$this->_getSession()->addSuccess($this->__('The product has been saved.'));
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage())
->setProductData($data);
$redirectBack = true;
} catch (Exception $e) {
Mage::logException($e);
$this->_getSession()->addError($e->getMessage());
$redirectBack = true;
}
}
if ($redirectBack) {
$this->_redirect('*/*/edit', array(
'id' => $productId,
'_current'=>true
));
} elseif($this->getRequest()->getParam('popup')) {
$this->_redirect('*/*/created', array(
'_current' => true,
'id' => $productId,
'edit' => $isEdit
));
} else {
$this->_redirect('*/*/', array('store'=>$storeId));
}
}
}
Before Install this Module Create Backup of your site and Database. After Install this Module Flush All Cache.
It May be helpfull for you.
Best Answer
You would need to edit the template file directly. Depending on where exactly on the order page you want it displayed, but it would be in this folder:
The most common one is in
info.phtml
. You will see at the top, it instantiates the$_order
object, so anywhere in the file you can just call$_order->getData('my_custom_attribute')