2

I'm trying to create a custom extension with this tutorial:

I copied all the code from the tutorial as per it describe. When create the config file and i can get the custom input type in the admin, but after that i created a config file

<global>
…
<catalog>
            <product>
                <options>
                    <custom>
                        <groups>
                            <instagramimage translate="label" module="webtoprint">
                                <label>Instagram image</label>
                                <render>webtoprint/adminhtml_catalog_product_edit_tab_options_type_instagramimage</render> 
            <types>
                                    <instagramimage_type translate="label" module="webtoprint">
                                        <label>Image</label>
                                    </instagramimage_type>
                                </types>
                            </instagramimage>
                        </groups>
                    </custom>
                </options>
            </product>
        </catalog>
…
</global>

After created the config file i created the class

class Ikantam_Webtoprint_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Instagramimage extends
    Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Abstract
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('webtoprint/catalog/product/edit/options/type/instagramimage.phtml');
    }
}

and also created the template page as

<script type="text/javascript">
    //<![CDATA[
    OptionTemplateInstagramimage = '<table class="border" cellpadding="0" cellspacing="0">'+
            '<tr class="headings">'+
    <?php if ($this->getCanReadPrice() !== false) : ?>
            '<th class="type-price"><?php echo Mage::helper('catalog')->__('Price') ?></th>' +
            '<th class="type-type"><?php echo Mage::helper('catalog')->__('Price Type') ?></th>' +
        <?php endif; ?>
            '<th class="type-sku"><?php echo Mage::helper('catalog')->__('SKU') ?></th>'+
            '</tr>'+
            '<tr>'+
    <?php if ($this->getCanReadPrice() !== false) : ?>
            '<td><input type="text" class="input-text validate-number product-option-price" id="product_option_{{option_id}}_price" name="product[options][{{option_id}}][price]" value="{{price}}"<?php if ($this->getCanEditPrice() === false) : ?> disabled="disabled"<?php endif; ?>></td>' +
            '<td><?php echo $this->getPriceTypeSelectHtml() ?>{{checkboxScopePrice}}</td>' +
        <?php else : ?>
            '<input type="hidden" name="product[options][{{option_id}}][price]">' +
            '<input type="hidden" name="product[options][{{option_id}}][price_type]" id="product_option_{{option_id}}_price_type">' +
        <?php endif; ?>
            '<td class="type-last last"><input type="text" class="input-text" name="product[options][{{option_id}}][sku]" value="{{sku}}"></td>'+
            '</tr>'+
            '</table>';
    if ($('option_panel_type_instagramimage')) {
        $('option_panel_type_instagramimage').remove();
    }
    //]]>
</script>

After create the template part i rewrite the edit tab option as in the tutorial

<blocks>
            <adminhtml>
                <rewrite>
                    <catalog_product_edit_tab_options_option>Ikantam_Webtoprint_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option</catalog_product_edit_tab_options_option>
                </rewrite>
            </adminhtml>
        </blocks>

But after that when i created a custom block inheriting it to the rewritten one as

class Ikantam_Webtoprint_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option
        extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option
{
    /**
     * Class constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('webtoprint/catalog/product/edit/options/option.phtml');
    }
    /**
     * Retrieve html templates for different types of product custom options
     *
     * @return string
     */
    public function getTemplatesHtml()
    {
        $canEditPrice = $this->getCanEditPrice();
        $canReadPrice = $this->getCanReadPrice();

        $this->getChild('instagramimage_option_type')
            ->setCanReadPrice($canReadPrice)
            ->setCanEditPrice($canEditPrice);
        $templates = parent::getTemplatesHtml() . "\n" .
            $this->getChildHtml('instagramimage_option_type');
        return $templates;    } }

Here i got an error

Fatal error: Call to a member function setCanReadPrice() on a non-object in /var/www/TantraProjects/MagentoPOS/Repo/WebApp/app/code/local/Ikantam/Webtoprint/Block/Adminhtml/Catalog/Product/Edit/Tab/Options/Option.php on line 23

What is wrong, please help me.

My whole config.xml file

<?xml version="1.0"?>
<config>
  <modules>  
    <Ikantam_Webtoprint>  
     <version>0.0.1</version>  
    </Ikantam_Webtoprint>  
  </modules>
  <global>
    <catalog>
      <product>
        <options>
          <custom>
            <groups>
              <instagramimage translate="label" module="webtoprint">
                <label>Instagram image</label>
                <render>webtoprint/adminhtml_catalog_product_edit_tab_options_type_instagramimage</render> 
                <types>
                  <instagramimage_type translate="label" module="webtoprint">
                    <label>Image</label>
                  </instagramimage_type>
                </types>
              </instagramimage>
            </groups>
          </custom>
        </options>
      </product>
    </catalog>
<!--    <blocks>
      <adminhtml>
        <rewrite>
          <catalog_product_edit_tab_options_option>Ikantam_Webtoprint_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option</catalog_product_edit_tab_options_option>
        </rewrite>
      </adminhtml>
    </blocks>
    <models>
      <catalog>
        <rewrite>
          <product_option>Ikantam_Webtoprint_Model_Catalog_Product_Option</product_option>
        </rewrite>
      </catalog>
    </models>
    <model>
      <catalog>
        <rewrite>
          <product_option_type_Instagramimagetype>Ikantam_Webtoprint_Model_Catalog_Product_Option_Type_Instagramimagetype</product_option_type_Instagramimagetype>
        </rewrite>
      </catalog>
    </model>
-->  </global>
</config>
1
  • Can you please update full code with exact folder structure, I had a confusion in folder structure
    – Magento 2
    Commented Oct 30, 2015 at 12:09

1 Answer 1

4

Sorry I spotted this when you posted the question earlier on but the issue is that the renderer of that option_type group is set to webtoprint/adminhtml_catalog_product_edit_tab_options_type_instagramimage Which points to a file with the class Ikantam_Webtoprint_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option. But since you placed your extension in the namespace Nettantradevelopment the class should be Nettantradevelopment_Webtoprint_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option.

Make sure all the namespaces and module names are correctly converted when you follow a tutorial. Or better yet, don't change anything at all and use their namespace and module name until you are sure everything works and then start renaming/ moving the extension around.

Also make sure you not only overwrite the block class but also add your block class as well in the config.xml

<blocks>
    <webtoprint>
        <class>Ikantam_Webtoprint_Block</class>
    </webtoprint>
    <adminhtml>
        <rewrite>
            <catalog_product_edit_tab_options_option>Ikantam_Webtoprint_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option</catalog_product_edit_tab_options_option>
        </rewrite>
    </adminhtml>
</blocks>
7
  • Sorry for that and now i edited my question. You cant find any where "Nettantradevelopment" now. Its giving the error, which i have edited. Commented Oct 23, 2013 at 10:15
  • Did you rename the folder as well to Ikantam? Also please post your whole config.xml Commented Oct 23, 2013 at 10:35
  • yes I rename it to Ikantam and the whole config.xml file edited on above post. Commented Oct 23, 2013 at 11:06
  • I've updated my answer, also you shouldn't comment out the config.xml part you've commented Commented Oct 23, 2013 at 11:13
  • I have problem with the frontend view.I cant find the reason. I updated my question for the front end view. Commented Oct 24, 2013 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.