3

instagrampro.xml file code is

<adminhtml_instagrampro_related>
        <block type="core/text_list" name="root" output="toHtml">
            <block type="instagrampro/adminhtml_instagrampro_edit_tab_related" name="adminhtml.pinstagram.related"/>
            <block type="adminhtml/widget_grid_serializer" name="related_grid_serializer">
                <reference name="related_grid_serializer">
                    <action method="initSerializerBlock">
                        <grid_block_name>adminhtml.pinstagram.related</grid_block_name>
                        <data_callback>getSelectedProduct</data_callback>
                        <hidden_input_name>links[related]</hidden_input_name>
                        <reload_param_name>products_related</reload_param_name>
                    </action>
                    <action method="addColumnInputName">
                        <input_name>position</input_name>
                    </action>
                </reference>
            </block>
        </block>
</adminhtml_instagrampro_related>

<adminhtml_instagrampro_relatedgrid>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="instagrampro/adminhtml_instagrampro_edit_tab_related" name="adminhtml.pinstagram.related"/>
    </block>
</adminhtml_instagrampro_relatedgrid>

grid.php file is

<?php

/**
 * Magento Instagrampro extension
 *
 * @category   Magecomp
 * @package    Magecomp_Instagrampro
 * @author     Magecomp
 */

class Magecomp_Instagrampro_Block_Adminhtml_Instagrampro_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
    public function __construct()
     {
          parent::__construct();
          $this->setId('instagrampro_tabs');
          $this->setDestElementId('edit_form');
          $this->setTitle('Image Configuration');
      }
      protected function _beforeToHtml()
      {
          $this->addTab('form_section', array(
                   'label' => 'Image Information',
                   'title' => 'Image Information',
                   'content' => $this->getLayout()
     ->createBlock('instagrampro/adminhtml_instagrampro_edit_tab_form')
     ->toHtml()
         ));

        $this->addTab('related', array(
                'label'     => 'Related Products',
                'url'       => $this->getUrl('*/*/related', array('_current' => true)),
                'class'     => 'ajax',
            ));




         return parent::_beforeToHtml();
    }
}

?>

related.php is

<?php
class Magecomp_Instagrampro_Block_Adminhtml_Instagrampro_Edit_Tab_Related extends Mage_Adminhtml_Block_Widget_Grid
{
    /**
     * Set grid params
     *
     */
    public function __construct()
    {
        parent::__construct();
        $this->setId('related_product_grid');
        $this->setDefaultSort('entity_id');
        $this->setUseAjax(true);
        $this->setDefaultFilter(array('in_products' => 1));
    }

    /**
     * Retirve currently edited product model
     *
     * @return Mage_Catalog_Model_Product
     */
    protected function _getProduct()
    {
        if(!Mage::registry('instagrampro_data')){
            $id = $this->getRequest()->getParam('id');
            $model = Mage::getModel('pinstagram/pinstagram');
             $model->load($id);
            Mage::register('instagrampro_data', $model);
        }

        return Mage::registry('instagrampro_data');

    }

    /**
     * Add filter
     *
     * @param object $column
     * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Related
     */
    protected function _addColumnFilterToCollection($column)
    {
        // Set custom filter for in product flag
        if ($column->getId() == 'in_products') {
            $productIds = $this->_getSelectedProducts();
            if (empty($productIds)) {
                $productIds = 0;
            }

            if ($column->getFilter()->getValue()) {
                $this->getCollection()->addFieldToFilter('entity_id', array('in' => $productIds));
            } else {
                if($productIds) {
                    $this->getCollection()->addFieldToFilter('entity_id', array('nin' => $productIds));
                }
            }
        } else {
            parent::_addColumnFilterToCollection($column);
        }
        return $this;
    }

    /**
     * Prepare collection
     *
     * @return Mage_Adminhtml_Block_Widget_Grid
     */
    protected function _prepareCollection()
    {
        $collection = Mage::getModel('catalog/product_link')->useRelatedLinks()
            ->getProductCollection()
            //->setProduct($this->_getProduct())
            ->addAttributeToSelect('*');

        if ($this->isReadonly()) {
            $productIds = $this->_getSelectedProducts();
            if (empty($productIds)) {
                $productIds = array(0);
            }
            $collection->addFieldToFilter('entity_id', array('in' => $productIds));
        }

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    /**
     * Checks when this block is readonly
     *
     * @return boolean
     */
    public function isReadonly()
    {

        return false;// $this->_getProduct()->getReadonly();
    }

    /**
     * Add columns to grid
     *
     * @return Mage_Adminhtml_Block_Widget_Grid
     */
    protected function _prepareColumns()
    {

        if (!$this->isReadonly()) {
            $this->addColumn('in_products', array(
                'header_css_class'  => 'a-center',
                'type'              => 'checkbox',
                'name'              => 'in_products',
                'values'            => $this->_getSelectedProducts(),
                'align'             => 'center',
                'index'             => 'entity_id'
            ));
        }

        $this->addColumn('entity_id_product', array(
            'header'    => Mage::helper('catalog')->__('ID'),
            'sortable'  => true,
            'width'     => 60,
            'index'     => 'entity_id'
        ));

        $this->addColumn('name_product', array(
            'header'    => Mage::helper('catalog')->__('Name'),
            'index'     => 'name'
        ));

        $this->addColumn('type_product', array(
            'header'    => Mage::helper('catalog')->__('Type'),
            'width'     => 100,
            'index'     => 'type_id',
            'type'      => 'options',
            'options'   => Mage::getSingleton('catalog/product_type')->getOptionArray(),
        ));

        $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
            ->load()
            ->toOptionHash();

        $this->addColumn('set_name_product', array(
            'header'    => Mage::helper('catalog')->__('Attrib. Set Name'),
            'width'     => 130,
            'index'     => 'attribute_set_id',
            'type'      => 'options',
            'options'   => $sets,
        ));

        $this->addColumn('product_status_product', array(
            'header'    => Mage::helper('catalog')->__('Status'),
            'width'     => 90,
            'index'     => 'status',
            'type'      => 'options',
            'options'   => Mage::getSingleton('catalog/product_status')->getOptionArray(),
        ));

        $this->addColumn('visibility_product', array(
            'header'    => Mage::helper('catalog')->__('Visibility'),
            'width'     => 90,
            'index'     => 'visibility',
            'type'      => 'options',
            'options'   => Mage::getSingleton('catalog/product_visibility')->getOptionArray(),
        ));

        $this->addColumn('sku_product', array(
            'header'    => Mage::helper('catalog')->__('SKU'),
            'width'     => 80,
            'index'     => 'sku'
        ));

        $this->addColumn('price_product', array(
            'header'        => Mage::helper('catalog')->__('Price'),
            'type'          => 'currency',
            'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
            'index'         => 'price'
        ));

        $this->addColumn('position', array(
            'header'            => Mage::helper('catalog')->__('Position'),
            'name'              => 'position',
            'type'              => 'number',
            'validate_class'    => 'validate-number',
            'index'             => 'position',
            'width'             => 60,
            'editable'          => true,
            //'edit_only'         => !$this->_getProduct()->getId()
        ));

        return parent::_prepareColumns();
    }

    /**
     * Rerieve grid URL
     *
     * @return string
     */
    public function getGridUrl()
    {
        return $this->getData('grid_url')
            ? $this->getData('grid_url')
            : $this->getUrl('*/*/relatedGrid', array('_current' => true));
    }

    /**
     * Retrieve selected related products
     *
     * @return array
     */
    protected function _getSelectedProducts()
    {
        $products = $this->getProductsRelated();

        if (!is_array($products)) {
            $products = array_keys($this->getSelectedRelatedProducts());
        }
        return $products;
    }

    /**
     * Retrieve related products
     *
     * @return array
     */
    public function getSelectedRelatedProducts()
    {
        $products = array();


        if(!Mage::registry("news_related_data")){

            $colRelated = $this->getRelatedProducts();
            Mage::register("news_related_data", $colRelated);
        }

        $id = $this->getRequest()->getParam('id');
        //if(count(Mage::registry("news_related_data"))> 0)
        foreach (Mage::registry("news_related_data") as $product) {
            $products[$product->getEntityId()] = array('position' => $product->getPosition());
        }

    // var_dump($products);die;
        return $products;
    }

    public function getRelatedProducts(){
    $id = $this->getRequest()->getParam('id');
        $collection = Mage::getModel('instagrampro/instagramproimage')
                    ->getCollection()
                    ->addFieldToFilter('ins_id', $id)
                    ->load()
                    ;           
        return $collection;
    }


}

in controller action

public function relatedAction()
        {
            $this->loadLayout();
         /**
         * 68 line in controller
         *
         */
$this->getLayout()->getBlock('adminhtml.pinstagram.related')
                    ->setProductsRelated($this->getRequest()->getPost('id', null))
                   ;
   
            $this->renderLayout();

        }

        /**
         * Get related products grid
         */
        public function relatedGridAction()
        {
            $this->_initPinstagram();
            $this->loadLayout();
            $this->getLayout()->getBlock('adminhtml.pinstagram.related')
                ->setProductsRelated($this->getRequest()->getPost('id', null));
            $this->renderLayout();
        }

error in edit is

Fatal error: Call to a member function setProductsRelated() on boolean in D:\xampp\htdocs\instagram\app\code\local\Magecomp\Instagrampro\controllers\Adminhtml\ProindexController.php on line 68

8
  • Post your code of file "instagram\app\code\local\Magecomp\Instagrampro\controllers\Adminhtml\ProindexController.php" Dec 12, 2016 at 11:28
  • i add controller code at last you check Dec 12, 2016 at 11:33
  • Put comment in front of line number 68 so the we get where the issue is Dec 12, 2016 at 11:35
  • in controller action you find setProductsRelated Dec 12, 2016 at 11:38
  • you just check i add commentt Dec 12, 2016 at 11:44

1 Answer 1

0

I think you just have to add reference name

<adminhtml_instagrampro_related>
    <reference name="content">
    <block type="core/text_list" name="root" output="toHtml">
        <block type="instagrampro/adminhtml_instagrampro_edit_tab_related" name="adminhtml.pinstagram.related"/>
        <block type="adminhtml/widget_grid_serializer" name="related_grid_serializer">
            <reference name="related_grid_serializer">
                <action method="initSerializerBlock">
                    <grid_block_name>adminhtml.pinstagram.related</grid_block_name>
                    <data_callback>getSelectedProduct</data_callback>
                    <hidden_input_name>links[related]</hidden_input_name>
                    <reload_param_name>products_related</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </block>
    </reference>
</adminhtml_instagrampro_related>

<adminhtml_instagrampro_relatedgrid>
<reference name="content">
    <block type="core/text_list" name="root" output="toHtml">
    <block type="instagrampro/adminhtml_instagrampro_edit_tab_related" name="adminhtml.pinstagram.related"/>
    </block>
</reference>
</adminhtml_instagrampro_relatedgrid>
4
  • no any effact it give me same error Dec 12, 2016 at 12:19
  • @jigs parmar : have you done this as I am also getting same error. May 4, 2017 at 12:11
  • ya i solve this May 4, 2017 at 12:24
  • can you provide me solution for this May 4, 2017 at 12:27

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.