1

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

Below you can see an overview of my goal.

I'm using Magento CE 1.7.0.2

I'm working with Grid in my custom module

I did like this

http://inchoo.net/ecommerce/magento/how-to-create-a-custom-grid-from-scratch/

I have columns like this ID,NAME,Price,STATUS,STOCK.... etc in admin i'm in

http://naresh.com/index.php/mycustom/products/index/key/731306280e32d62f8b8ff481e82bd73b/

when i click on the column it is redirecting to

http://naresh.com/index.php/mycustom/index/index/key/70ddf137f1b055b13b3de0b6fd42b572/

& showing 404 exception

you can see my code here

<?php

class my_mycustom_Block_Products_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct(){
        parent::__construct();
        $this->setId('customersProducts');
        $this->setUseAjax(true);
        //$this->setDefaultSort('mageproductid');
        $this->setDefaultDir('DESC');
        $this->_emptyText = Mage::helper('mycustom')->__('No Products Found.');
    }

     protected function _prepareCollection(){
       $mysqlprefix = Mage::getConfig()->getTablePrefix();//code for mysql prefix
        $mytablepartnerstatus=$mysqlprefix.'mycustom_entity_userdata';
        $mytabledata=$mysqlprefix.'mycustom_entity_data';
        $customerModel = Mage::getModel('customer/customer')->getCollection();
            $collection = Mage::getResourceModel('mycustom/userdata_collection');
        if($this->getRequest()->getParam('unapp')==1){
           $collection->addFieldToFilter('status', array('neq' => '1'));
        }
            $this->setCollection($collection);
            parent::_prepareCollection();
            $customerModel = Mage::getModel('customer/customer');

        //Modify loaded collection
        foreach ($this->getCollection() as $item) {
        $customer = $customerModel->load($item->getuserid());
            $item->customer_name = sprintf('<a href="%s" title="View Customer\'s Profile">%s</a>',
                                            $this->getUrl('adminhtml/customer/edit/id/' . $item->getuserid()),
                                            $customer->getName()
                                          );

        $item->prev = sprintf('<span data="%s" product-id="%s" customer-id="%s" title="Click to Review" class="prev btn">prev</span>',$this->getUrl('mycustom/prev/index/id/' .$item->getMageproductid()),$item->getProductId(),$item->getCustomerId());
           $item->entity_id = (int)$item->getmageproductid();
             if(!(is_null($item->getmageproductid())) && $item->getmageproductid() != 0){

                $product = Mage::getModel('catalog/product')->load($item->getmageproductid());
                $stock_inventory = Mage::getModel('cataloginventory/stock_item')->loadByProduct($item->getmageproductid());
                $item->name = $product->getName();
                $item->weight = $product->getWeight();
                $item->price = $product->getPrice();
                $item->stock = $stock_inventory->getQty();


            $qtySold = Mage::getModel('mycustom/userdata')->quantitySold($item->getmageproductid());
            $item->qty_sold = (int)$qtySold;
            $amountEarned = Mage::getModel('mycustom/userdata')->amountEarned($item->getmageproductid());
            $item->amount_earned = $amountEarned;
            $cleared_act = Mage::getModel('mycustom/userdata')->clearedAt($item->getmageproductid());
            foreach($cleared_act as $clear){
            if ( isset($clear) && $clear != '0000-00-00 00:00:00' ) {$item->cleared_at = $clear;}
            }
            $created_at = Mage::getModel('mycustom/userdata')->createdAt($item->getmageproductid());
            foreach($created_at as $clear1){
            if ( isset($clear1) && $clear1 != '0000-00-00 00:00:00' ) {$item->created_at = $clear1;}
            }
            }
        }
        $this->setCollection($collection);
        return parent::_prepareCollection();

     }


      protected function _prepareColumns(){
        $this->addColumn('entity_id', array(
            'header'    => Mage::helper('mycustom')->__('ID'),
            'width'     => '50px',
            'index'     => 'entity_id',
            'type'  => 'number',
        ));

        $this->addColumn('customer_name', array(
            'header'    => Mage::helper('mycustom')->__('Customer Name'),
            'index'     => 'customer_name',
            'type'  => 'text',
        ));

       $this->addColumn('name', array(
            'header'    => Mage::helper('mycustom')->__('Name'),
            'index'     => 'name',
            'type'  => 'string',
        ));
         $this->addColumn('price', array(
            'header'    => Mage::helper('mycustom')->__('Price'),
            'index'     => 'price',
            'type'  => 'price',
        ));
        $this->addColumn('stock', array(
            'header'    => Mage::helper('mycustom')->__('Stock'),
            'index'     => 'stock',
            'type'  => 'number',
        ));
        $this->addColumn('weight', array(
            'header'    => Mage::helper('mycustom')->__('Weight'),
            'index'     => 'weight',
            'type'  => 'number',
        ));
        $this->addColumn('prev', array(
            'header'    => Mage::helper('mycustom')->__('Preview'),
            'index'     => 'prev',
            'type'  => 'text',
        ));
        $this->addColumn('qty_sold', array(
            'header'    => Mage::helper('mycustom')->__('Qty. Sold'),
            'index'     => 'qty_sold',
            'type'  => 'number',
        ));
        $this->addColumn('amount_earned', array(
            'header'    => Mage::helper('mycustom')->__('Earned'),
            'index'     => 'amount_earned',
            'type'  => 'price',
        ));

        $this->addColumn('created_at', array(
            'header'    => Mage::helper('mycustom')->__('Created'),
            'index'     => 'created_at',
            'type'  => 'datetime',
        ));
        return parent::_prepareColumns();
        }
}

Any Ideas ?

Naresh
  • 681
  • 2
  • 12
  • 39
  • hello you will create custom module using this creator change as your requirement http://www.silksoftware.com/magento-module-creator/ – Vishal Dec 18 '13 at 05:48
  • @MagikVishal Thanks for the advice i'm using my module not only for this... its bunch of other tasks too... every where its working fine here also except this thing – Naresh Dec 18 '13 at 05:53

2 Answers2

0

Add this code at the end of class :

  public function getRowUrl($row)
  {
      return $this->getUrl('*/*/edit', array('id' => $row->getId()));
  }

This will redirect to your edit action. Knowing your skills i prefer to study the working procedure of modules.Visit the links.First Or this study how modules works.

Community
  • 1
  • 1
Mahmood Rehman
  • 4,303
  • 7
  • 39
  • 76
  • thanks dude thanks for the reply i tried like that too,Still i have same problem... – Naresh Dec 18 '13 at 05:50
  • yeah..sorry i don't have it – Naresh Dec 18 '13 at 05:55
  • and what if you try `$this->getUrl('mycustom/products/edit', array('id' => $row->getId()));` in above answer. atleast you should be redirected to url like http://naresh.com/index.php/mycustom/products/edit/id/1/key/731306280e32d62f8b8ff481e82bd73b/ – Deependra Singh Dec 18 '13 at 06:01
  • @DeependraSingh agree with you but he doesn't have edit Action in controller or edit block for handling edit request. – Mahmood Rehman Dec 18 '13 at 06:04
  • @DeependraSingh thanks for the reply with my code also its working fine for 'Status' only but not for all. – Naresh Dec 18 '13 at 06:06
  • @MahmoodRehman Boss i don't have editAction() controller.... & even i don't have any idea about that (why or for what....) – Naresh Dec 18 '13 at 06:10
  • @MahmoodRehman Sorry Boss i'm using this one just a couple of months. i'm not that much of experienced (sorry don't misunderstand me).... – Naresh Dec 18 '13 at 06:15
  • @Naresh i prefer for you to study how modules works in magento.I added some links for your study on my answer.You can study alot more on google. – Mahmood Rehman Dec 18 '13 at 06:20
  • @MahmoodRehman yeah... sure Boss but not yet. this is very important one.. & i tried my best – Naresh Dec 18 '13 at 06:22
  • than create controller with your module name.add edit action there and in edit action load you form block.like this `$this->_addContent($this->getLayout()->createBlock('module/adminhtml_module_edit')) ->_addLeft($this->getLayout()->createBlock('module/adminhtml_module_edit_tabs')); $this->renderLayout();` – Mahmood Rehman Dec 18 '13 at 06:27
0

try to add below line in grid.php at the end, hope this will be helpful :)

public function getRowUrl($row)

{

if (Mage::getSingleton(‘admin/session’)->isAllowed(‘sales/order/actions/view’))

{
return $this->getUrl(‘*/sales_order/view’, array(‘order_id’ => $row->getId()));
}

return false;

}
Shalu
  • 1