Magento 1.9,我无法获得选中产品的网格
Magento 1.9,i can't get grid with checked products
我创建了一个自定义模块,我在我的模块的管理中使用了网格产品。当我检查产品时,我可以成功地将它们保存到我的 table,但我想让这个产品加载选中的行。
我该怎么做?
这是我的代码:
$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;
}
这是带有序列化器的网格的解决方案:
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;
}
我创建了一个自定义模块,我在我的模块的管理中使用了网格产品。当我检查产品时,我可以成功地将它们保存到我的 table,但我想让这个产品加载选中的行。
我该怎么做?
$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;
}
这是带有序列化器的网格的解决方案:
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;
}