1

Hi I am developing a magento extension in which I need to show a product custom attribute in the magento order detail. I want to add it through xml without editing/ overwriting any core file .. For now i have edit the following file to show custom attribute value app/design/adminhtml/default/default/template/sales/items/column/name.phtml

but I know this is not the correct way. So please suggest me how can I insert it by blocks through xml. Below is the screen-shot link http://awesomescreenshot.com/0e42y3ac8d

1

Problem solved but with the help of java-script function.

To add your fields on order view page we need to do :

  1. Add layout in your config file:
<adminhtml>
  <layout>
      <updates>
          <customattribute>
              <file>customattribute.xml</file>
          </customattribute>
      </updates>
  </layout>
</adminhtml>
  1. Add design layout for adminhtml "app/design/adminhtml/default/default/layout/customattribute.xml"
<layout version="0.1.0">
  <adminhtml_sales_order_view>
      <reference name="order_items">
            <block type="customattribute/prototal"  name="order_item_extra_info" template="customattribute/productdesign.phtml"/>
      </reference>
  </adminhtml_sales_order_view>
</layout>
  1. Add template File "app/design/adminhtml/default/default/template/customattribute/productdesign.phtml". Please do the format of file placing some sample code.
<?php 
$_item = $this->getItem();
$sku = $_item->getSku();
echo '<div style="display:none;"  id="id_order_item_'.$_item->getID().'"> <strong>'.$this->helper('sales')->__('Artwork ID').':</strong>'.$_item->getArtworkID().'</div>'; ?>
<script>
function codeAddress<?php echo $_item->getID(); ?>() {
          var html = document.getElementById('id_order_item_<?php echo $_item->getID(); ?>').innerHTML;
            var elem = document.getElementById('order_item_<?php echo $_item->getID(); ?>').children[0].innerHTML;
            document.getElementById('order_item_<?php echo $_item->getID(); ?>').children[0].innerHTML  = elem+html;
        }
codeAddress<?php echo $_item->getID(); ?>();
</script>
  1. For getting Item in your template file you need define a block "CustomAttribute/Block/Adminhtml/Prototal.php"

class NameSpace_ModuleName_Block_Prototal extends Mage_Core_Block_Template { public function setItem(Varien_Object $item) { $this->setData('item', $item); return $this; }

  public function getItem() {
      return $this->_getData('item');
  }

}

Please comment someone found any issue or problem.

1

Doing changes in views/blocks is pretty much the same in frontend and adminhtml. You can create a theme/module and make your changes there instead of in the core files. Here is an official guide to do that.

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.