Magento 1.9,我无法通过托运产品获得网格

时间:2018-01-06 18:33:21

标签: php mysql magento-1.9

我已经创建了一个自定义模块,其中我在我的模块中使用admin中的网格产品。当我检查产品时,我可以成功地将它们保存到我的表中,但我希望将此产品加载到已检查的行中。

我该怎么做?

enter image description here 这是我的代码:

$this->addColumn('is_selected', array(
        'type'      => 'checkbox',
        'name'      => 'is_selected',
        'field_name' => 'selectedproducts[]',
        'values' => $this->_getSelectedProducts(),//here i go to method
        'index'     => 'entity_id',
    ));

然后吼叫

protected function _getSelectedProducts()
    {
        $products = Mage::getModel('custom_module/mytable')->getData();//Here i need some help 
        return $products;
    }

1 个答案:

答案 0 :(得分:0)

以下是使用序列化程序的网格解决方案:

        protected function _getSelectedProducts(){
            $products = $this->getActionProducts();
            if (!is_array($products)) {
                $products = array_keys($this->getSelectedProducts());
            }
            return $products;
        }
        //callback method for serializer
        public function getSelectedProducts() {
            $products = array();
            $selected = $this->getRequest()->getPost('products');
            if (!is_array($selected)){
                $selected = array();
            }
            foreach ($selected as $product) {
                $products[$product->getId()] = array('position' => 
                $product->getPosition());
            }
            return $products;
        }