1
votes

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 ?

2
hello you will create custom module using this creator change as your requirement silksoftware.com/magento-module-creatorMagikVishal
@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 thingNaresh

2 Answers

0
votes

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.

0
votes

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;

}