1

I am trying to insert a phtml file using observer through this code

public function insertShippingBlock($observer)
{
    /** @var $_block Mage_Core_Block_Abstract */
    /*Get block instance*/
    $_block              = $observer->getBlock();
    /*get Block type*/
    $_type               = $_block->getType();


    if ($_type == 'checkout/onepage_shipping') {

        $_block->unsetChild('child_branchoptions');
        /*Clone block instance*/
        $_child = clone $_block;
        /*set another type for block*/
        $_child->setType('core/template');

        $_block->setChild('child_options', $_child);
        /*set child for block*/
        $_block->setTemplate('shipping_method/customoptions.phtml');
    }
}

But It's repeating the custom optionsenter image description here

"Custom option 1" is repeating twice. Could you please help in this

customoptions.phtml

<input name="selected" type="radio" name="chooseoption" id="chooseoption" onclick="chooseoption()">Custom Option 1
<?php echo $this->getChildHtml('child_options') ?></li></ul>
1

I think this event called twice this is simple solution Use registry

if ($_type == 'checkout/onepage_shipping') {
       if(!Mage::registry('checking'))
    { 
         Mage::register('checking', 'yes'); 
        $_block->unsetChild('child_branchoptions');
        /*Clone block instance*/
        $_child = clone $_block;
        /*set another type for block*/
        $_child->setType('core/template');

        $_block->setChild('child_options', $_child);
        /*set child for block*/
        $_block->setTemplate('shipping_method/customoptions.phtml');
        }
    }
  • @ Fme Extension -- Still I am facing the same issue. I like to know why the dropdown was not duplicating, only the static content was duplicating. – Arjun Me Dec 7 '16 at 10:03

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.