扩展核心功能,添加新列。构建网格,使用数据构建查询,但是在生成行时,它无法添加填充行中的“可见性”单元格。想法?
编辑:为了清楚起见。
zend_debug($row) 的输出
class Mage_Catalog_Model_Product#751 (28) {
protected $_cacheTag => string(15) "catalog_product"
protected $_eventPrefix => string(15) "catalog_product"
protected $_eventObject => string(7) "product"
protected $_canAffectOptions => bool(false)
protected $_typeInstance => NULL
protected $_typeInstanceSingleton => NULL
protected $_linkInstance => NULL
protected $_customOptions => array(0) {
}
protected $_urlModel => NULL
protected $_errors => array(0) {
}
protected $_optionInstance => NULL
protected $_options => array(0) {
}
protected $_reservedAttributes => NULL
protected $_isDuplicable => bool(true)
protected $_defaultValues => array(0) {
}
protected $_lockedAttributes => array(0) {
}
protected $_isDeleteable => bool(true)
protected $_isReadonly => bool(false)
protected $_resourceName => string(15) "catalog/product"
protected $_resource => NULL
protected $_resourceCollectionName => string(26) "catalog/product_collection"
protected $_dataSaveAllowed => bool(true)
protected $_isObjectNew => NULL
protected $_data => array(13) {
'entity_id' => string(4) "2384"
'entity_type_id' => string(1) "4"
'attribute_set_id' => string(1) "4"
'type_id' => string(6) "simple"
'sku' => string(0) ""
'has_options' => string(1) "0"
'required_options' => string(1) "0"
'created_at' => string(19) "2012-06-22 16:19:32"
'updated_at' => string(19) "2012-07-03 14:06:08"
'position' => NULL
'name' => string(25) "Games Site Test Product 4"
'price' => string(8) "100.0000"
'stock_item' => class Varien_Object#792 (5) {
protected $_data => array(1) {
...
}
protected $_hasDataChanges => bool(false)
protected $_origData => NULL
protected $_idFieldName => NULL
protected $_isDeleted => bool(false)
}
}
protected $_hasDataChanges => bool(true)
protected $_origData => array(12) {
'entity_id' => string(4) "2384"
'entity_type_id' => string(1) "4"
'attribute_set_id' => string(1) "4"
'type_id' => string(6) "simple"
'sku' => string(0) ""
'has_options' => string(1) "0"
'required_options' => string(1) "0"
'created_at' => string(19) "2012-06-22 16:19:32"
'updated_at' => string(19) "2012-07-03 14:06:08"
'position' => NULL
'name' => string(25) "Games Site Test Product 4"
'price' => string(8) "100.0000"
}
protected $_idFieldName => string(9) "entity_id"
protected $_isDeleted => bool(false)
}
,
sqdump(我添加了 LIMIT 10)
mysql> SELECT `e`.*, `_table_position`.`position`, `_table_visibility`.`value` AS `visibility` FROM `catalog_product_entity` AS `e` LEFT JOIN `catalog_category_product` AS `_table_position` ON (_table_position.product_id=e.entity_id) AND (category_id=0) INNER JOIN `catalog_product_entity_int` AS `_table_visibility` ON (_table_visibility.entity_id = e.entity_id) AND (_table_visibility.attribute_id='89') AND (_table_visibility.store_id=0) limit 10;
+-----------+----------------+------------------+---------+---------+-------------+------------------+---------------------+---------------------+----------+------------+
| entity_id | entity_type_id | attribute_set_id | type_id | sku | has_options | required_options | created_at | updated_at | position | visibility |
+-----------+----------------+------------------+---------+---------+-------------+------------------+---------------------+---------------------+----------+------------+
| 2 | 4 | 9 | simple | PWOPER | 0 | 0 | 2010-06-09 20:14:44 | 2012-01-09 19:20:06 | NULL | 1 |
| 3 | 4 | 9 | simple | PW20WCB | 0 | 0 | 2010-06-10 14:36:04 | 2012-07-03 16:46:09 | NULL | 4 |
| 20 | 4 | 9 | simple | PW5TBW | 0 | 0 | 2010-06-28 15:44:23 | 2011-04-08 21:35:02 | NULL | 1 |
| 21 | 4 | 9 | simple | PWBJACK | 0 | 0 | 2010-06-28 15:51:35 | 2011-10-27 15:26:21 | NULL | 1 |
| 22 | 4 | 9 | simple | YK32006 | 0 | 0 | 2010-06-28 16:22:25 | 2012-07-03 16:47:46 | NULL | 4 |
| 23 | 4 | 9 | simple | YK32008 | 0 | 0 | 2010-06-28 16:30:51 | 2012-07-03 16:48:55 | NULL | 4 |
| 24 | 4 | 9 | simple | RFBURG | 0 | 0 | 2010-06-28 16:37:12 | 2011-09-16 14:03:04 | NULL | 4 |
| 25 | 4 | 9 | simple | PW10EWJ | 0 | 0 | 2010-06-28 17:34:15 | 2011-08-11 15:43:49 | NULL | 1 |
| 26 | 4 | 9 | simple | PW10WJ | 0 | 0 | 2010-06-28 17:39:26 | 2011-08-11 16:04:37 | NULL | 4 |
| 27 | 4 | 9 | simple | HDNG10 | 0 | 0 | 2010-06-28 17:48:00 | 2012-07-03 17:00:07 | NULL | 4 |
+-----------+----------------+------------------+---------+---------+-------------+------------------+---------------------+---------------------+----------+------------+
10 rows in set (0.00 sec)
mysql>
_prepareCollection()
class My_CategoryFilters_Block_Adminhtml_Catalog_Category_Tab_Product extends Mage_Adminhtml_Block_Catalog_Category_Tab_Product {
...
protected function _prepareCollection()
{
if ($this->getCategory()->getId()) {
$this->setDefaultFilter(array('in_category'=>1));
}
#$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('sku')
->addAttributeToSelect('price')
->addAttributeToSelect('store_id')
#->addAttributeToSelect('visibility')
->addStoreFilter($this->getRequest()->getParam('store'))
->joinField('position',
'catalog/category_product',
'position',
'product_id=entity_id',
'category_id='.(int) $this->getRequest()->getParam('id', 0),
'left')
->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', 'entity_id', 'entity_id='.(int) $this->getRequest()->getParam('id', 0), 'inner')
;
$this->setCollection($collection);
$this->getCollection()->addWebsiteNamesToResult();
if ($this->getCategory()->getProductsReadonly()) {
$productIds = $this->_getSelectedProducts();
if (empty($productIds)) {
$productIds = 0;
}
$this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
}
return parent::_prepareCollection();
}
_prepareColumns()
$this->addColumn('visibility', array(
'header' => Mage::helper('catalog')->__('Visibility'),
'width' => '100',
'sortable' => false,
'index' => 'visibility',
'type' => 'options',
'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
));