Работа с сеткой в ​​Magento

У меня есть проблема, которую я не могу решить. Отчасти потому, что я не могу объяснить это правильными терминами. Я новичок в этом, так что извините за этот неуклюжий вопрос.

Ниже вы можете увидеть обзор моей цели.

Я использую Magento CE 1.7.0.2.

Я работаю с Grid в своем пользовательском модуле.

мне понравилось

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

У меня есть такие столбцы, как этот ID, NAME, Price, STATUS, STOCK .... и т. д. в admin я в

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

когда я нажимаю на столбец, он перенаправляется на

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

& показывает исключение 404

вы можете увидеть мой код здесь

<?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();
        }
}

Любые идеи ?


person Naresh    schedule 18.12.2013    source источник
comment
привет, вы создадите собственный модуль, используя это изменение создателя в соответствии с вашими требованиями silksoftware.com/magento-module- создатель   -  person MagikVishal    schedule 18.12.2013
comment
@MagikVishal Спасибо за совет, я использую свой модуль не только для этого ... он также выполняет кучу других задач ... везде, где он работает нормально, кроме этого.   -  person Naresh    schedule 18.12.2013


Ответы (2)


Добавьте этот код в конце класса:

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

Это перенаправит вас к вашему действию редактирования. Зная ваши навыки, я предпочитаю изучать порядок работы модулей. Посетите ссылки. in-magento">Сначала Или в этом изучите, как работают модули .

person Mahmood Rehman    schedule 18.12.2013
comment
спасибо, чувак, спасибо за ответ, я тоже так пробовал, но у меня такая же проблема ... - person Naresh; 18.12.2013
comment
да.. жаль у меня его нет - person Naresh; 18.12.2013
comment
и что, если вы попробуете $this->getUrl('mycustom/products/edit', array('id' => $row->getId())); в ответе выше. по крайней мере, вы должны быть перенаправлены на URL-адрес вида naresh.com /index.php/mycustom/products/edit/id/1/key/ - person Deependra Singh; 18.12.2013
comment
@DeependraSingh согласен с вами, но у него нет действия редактирования в контроллере или блока редактирования для обработки запроса на редактирование. - person Mahmood Rehman; 18.12.2013
comment
@DeependraSingh спасибо за ответ с моим кодом, он отлично работает только для «Статус», но не для всех. - person Naresh; 18.12.2013
comment
@MahmoodRehman Босс, у меня нет контроллера editAction() .... и даже я понятия не имею об этом (почему и для чего ....) - person Naresh; 18.12.2013
comment
@MahmoodRehman Извините, босс, я использую его всего пару месяцев. я не такой уж опытный (извините, не поймите меня неправильно).... - person Naresh; 18.12.2013
comment
@Naresh, я предпочитаю, чтобы вы изучали, как модули работают в magento. Я добавил несколько ссылок для вашего изучения в свой ответ. Вы можете изучить намного больше в Google. - person Mahmood Rehman; 18.12.2013
comment
@MahmoodRehman, да... конечно, Босс, но еще нет. это очень важно .. и я старался изо всех сил - person Naresh; 18.12.2013
comment
чем создать контроллер с именем вашего модуля. Добавьте туда действие редактирования, а в действии редактирования загрузите блок формы. Вот так $this->_addContent($this->getLayout()->createBlock('module/adminhtml_module_edit')) ->_addLeft($this->getLayout()->createBlock('module/adminhtml_module_edit_tabs')); $this->renderLayout(); - person Mahmood Rehman; 18.12.2013

попробуйте добавить строку ниже в grid.php в конце, надеюсь, это будет полезно :)

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;

}
person Shalu    schedule 18.12.2013