Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8862907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:50:36+00:00 2026-06-14T15:50:36+00:00

I have 3d-party extention that add new tabs while product edit at the backend.

  • 0

I have 3d-party extention that add new tabs while product edit at the backend. Now I want to add one more tab there.

New tab should have “add” button and let user to add new item, In addition It should have the list with added items. First of all, I have looked at extention code. They have added similar tab using

extends Mage_Adminhtml_Block_Widget
implements Varien_Data_Form_Element_Renderer_Interface 

So I try to folow their way and add my one. Code below.

    $this->addTab('cancellpolicy', array(
            'label'     => Mage::helper('catalog')->__('Cancellation Policies'),
            'content'   => $this->_translateHtml($this->getLayout()->createBlock('Apptha_Reservation_Block_Adminhtml_Catalog_Product_Edit_Tab_Cancellationpolicy')->toHtml()),
        )); 

Above I add new tab and then I create new block class below

class Apptha_Reservation_Block_Adminhtml_Catalog_Product_Edit_Tab_Cancellationpolicy 

extends Mage_Adminhtml_Block_Widget
implements Varien_Data_Form_Element_Renderer_Interface 
{

   /**
 * Form element instance
 *
 * @var Varien_Data_Form_Element
 */
protected $_element;

/**
 * Customer Groups cache
 *
 * @var array
 */
protected $_customerGroups;

/**
 * Websites cache
 *
 * @var array
 */
protected $_websites;



public function __construct(){
    $this->setTemplate('reservation/product/edit/tab/cancellationpolicy.phtml');
}

 public function getProduct(){
    return Mage::registry('product');
}
public function render(Varien_Data_Form_Element_Abstract $element){
    $this->setElement($element);
    return $this->toHtml();
}


protected function _prepareLayout()
{
    $this->setChild('add_button',
        $this->getLayout()->createBlock('adminhtml/widget_button')
            ->setData(array(
                'label'     => Mage::helper('catalog')->__('Add Room Type(s)'),
                'onclick'   => 'roomtypesControl.addItem()',
                'class' => 'add'
            )));   

    return parent::_prepareLayout();
}


 /**
 * Set form element instance
 *
 * @param Varien_Data_Form_Element_Abstract $element
 * @return Apptha_Reservation_Block_Adminhtml_Catalog_Product_Edit_Tab_Cancellationpolicy
 */   
public function setElement(Varien_Data_Form_Element_Abstract $element){
    $this->_element = $element;
    return $this;
}



/**
 * Retrieve form element instance
 *
 * @return Apptha_Reservation_Block_Adminhtml_Catalog_Product_Edit_Tab_Cancellationpolicy
 */
public function getElement(){
    return $this->_element;
}    


public function getWebsites()
{

    if (!is_null($this->_websites)) {
        return $this->_websites;
    }
    $websites = array();
    $websites[0] = array(
        'name'      => $this->__('All Websites'),
        'currency'  => Mage::app()->getBaseCurrencyCode()
    );
    if (Mage::app()->isSingleStoreMode() || $this->getElement()->getEntityAttribute()->isScopeGlobal()) {
        return $websites;
    }
    elseif ($storeId = $this->getProduct()->getStoreId()) {
        $website = Mage::app()->getStore($storeId)->getWebsite();
        $websites[$website->getId()] = array(
            'name'      => $website->getName(),
            'currency'  => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
        );
    }
    else {
        $websites[0] = array(
            'name'      => $this->__('All Websites'),
            'currency'  => Mage::app()->getBaseCurrencyCode()
        );
        foreach (Mage::app()->getWebsites() as $website) {
            if (!in_array($website->getId(), $this->getProduct()->getWebsiteIds())) {
                continue;
            }
            $websites[$website->getId()] = array(
                'name'      => $website->getName(),
                'currency'  => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
            );
        }
    }
    $this->_websites = $websites;
    return $this->_websites;
}

public function getValues(){
    return Mage::getModel('reservation/roomtypes')->getCollection()
                ->addEntityIdFilter($this->getProduct()->getId())
                ->addStoreIdFilter($this->getProduct()->getStoreId())
                ->getItems();
}

}

And then add reservation/product/edit/tab/cancellationpolicy.phtml template file. A the beginig of template I get

<?php   Mage::log(get_class($this->getElement())); ?>
<?php $_htmlId      = $this->getElement()->getHtmlId() ?>
<?php $_htmlClass   = $this->getElement()->getClass() ?>
<?php $_storeId     = $this->getProduct()->getStoreId() ?>
<?php $_htmlName    = $this->getElement()->getName() ?>
<?php $_readonly    = $this->getElement()->getReadonly() ?>
<?php $_multiWebsite= 0 && !Mage::app()->isSingleStoreMode() ?>

And here I get error:

Fatal error: Call to a member function getHtmlId() on a non-object in /var/www/vhosts/bluning.com/httpdocs/app/design/adminhtml/default/default/template/reservation/product/edit/tab/cancellationpolicy.phtml on line 10

Mage::log(get_class($this->getElement()));

give me “Mage_Core_Block_Template” but why? As per my code getElement() should return “Apptha_Reservation_Block_Adminhtml_Catalog_Product_Edit_Tab_Cancellationpolicy”

So why Magento return wrong class in the .phtml file?

UPDATE
config.xml has section

      <blocks>
        <reservation>
            <class>Apptha_Reservation_Block</class>
        </reservation>

    </blocks>

UPDATE2
I have placed Mage::log inside getElement function and after calling. It returns different values:

inside: Apptha_Reservation_Block_Adminhtml_Catalog_Product_Edit_Tab_Cancellationpolicy
outside: Mage_Core_Block_Template

Crazy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:50:37+00:00Added an answer on June 14, 2026 at 3:50 pm

    Using debugger I have found issue.

    $this->getElement()
    

    It return NULL because It hasnt been set properly. It should be set in the observer. Code is below:

      public function attachPolicyEditor($observer) {
        $form = $observer->getForm();
        if ($policies = $form->getElement('apptha_hotel_cancellationpolicy')) {
            $policies->setRenderer(
                Mage::getSingleton('core/layout')->createBlock('reservation/adminhtml_catalog_product_edit_tab_cancellationpolicy')
            );
        }
    }
    

    attachPolicyEditor is called by adminhtml_catalog_product_edit_prepare_form observer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have third-party C code that writes data to a file. I want to
I have a third-party library that is sometimes throwing an exception. So I decided
I have third party sites that link to some images on my site. The
I have a 3rd Party tool that generates an xml spreadsheet (*.xls). I have
I have a 3rd party JAR that I have converted to an OSGI bundle
We have a background operation (Window service) that we want to use through a
I have a piece of C# code that add the values of an enum
I have directory that keeps a number of 3rd party libraries. It is under
So I have an air application that I want to save data from into
I have an activity that some times OutOfMemory exception occurs in some parts of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.