4

I need to add custom dropdowns to the Credit Memo create form. I read that you should be able to add a simple field without having to rewrite core code.

The following line fails in the Observer:

$form->addFieldset();

Fatal error: Call to a member function addFieldset() on a non-object in

I just can't seem to get the block for CreditMemo that contains the form object.

config.xml

<events>
  <adminhtml_block_html_before>
    <observers>
      <company_custom_creditmemo_fields>
        <type>model</type>
        <class>Company_ExtendedCreditMemo_Model_Observer</class>
        <method>addCustomsFieldsToCreditMemo</method>
      </company_custom_creditmemo_fields>
    </observers>
  </adminhtml_block_html_before>
</events>

Observer.php

<?php

class Company_ExtendedCreditMemo_Model_Observer
{
    public function addCustomsFieldsToCreditMemo(Varien_Event_Observer $observer)
    {
        $block = $observer->getBlock();
        if (!isset($block)) {
            return $this;
        }

        if ($block->getType() == 'adminhtml/sales_order_creditmemo_create_form') {
            $form = $block->getForm();
            $fieldset = $form->addFieldset('Reasons', array(
                    'legend' => 'Reason',
                    'class' => 'fieldset-wide',
                )
            );
            $fieldset->addField('select2', 'select', array(
                'label' => Mage::helper('form')->__('Select Type2'),
                'class' => 'required-entry',
                'required' => true,
                'name' => 'title',
                'onclick' => '',
                'onchange' => '',
                'value' => '4',
                'values' => array(
                '-1' => 'Please Select..',
                    '1' => array(
                        'value' => array(
                            array('value' => '2', 'label' => 'Option2'),
                            array('value' => '3', 'label' => 'Option3'), ),
                        'label' => 'Size',
                    ),
                    '2' => array(
                        'value' => array(
                            array('value' => '4', 'label' => 'Option4'),
                            array('value' => '5', 'label' => 'Option5'), ),
                        'label' => 'Color',
                    ),
                ),
                'disabled' => false,
                'readonly' => false,
                'after_element_html' => '<small>Reason</small>',
                'tabindex' => 1,
            ));
        }
    }
}
  • Has nobody any insight? Is there a better way to approach this problem? I'm new to Magento development. – proulxs May 4 '17 at 19:05
  • when and where this event company_custom_creditmemo_fields is dispatched ? – Attila Naghi May 3 at 9:03

Your Answer

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

Browse other questions tagged or ask your own question.