2013-12-18 134 views
1

我有這個問題,我無法解決。部分原因是我無法用正確的術語解釋它。我對此很陌生,所以對於這個笨拙的問題感到抱歉。在Magento中使用網格

您可以在下面看到我的目標概覽。

我使用Magento的CE 1.7.0.2

我與電網的工作在我的自定義模塊

我不喜歡這個

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

我列這樣的ID ,名稱,價格,狀態,股票....等 在管理我在

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

什麼想法?

+0

你好,你會使用這個創作者的變化根據您的要求的HTTP創建自定義模塊://www.silksoftware .com/magento-module-creator/ – MagikVishal

+0

@MagikVishal感謝您的建議,我使用我的模塊不僅僅是爲了...它的一堆其他任務...每個工作都很好的地方除了這個東西 – Naresh

回答

0

在類的末尾添加以下代碼:

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

這將重定向到您的編輯操作。 知道你的技能,我更喜歡研究模塊的工作過程。訪問鏈接。 Firstthis 瞭解模塊如何工作。

+0

謝謝老兄感謝您的答覆,我也嘗試過,仍然我有同樣的問題... – Naresh

+0

你有編輯控制器和窗體編輯行動? –

+0

yeah..sorry我沒有它 – Naresh

0

嘗試添加以下行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; 

}