扩展核心功能,添加新列。网格构建,查询构建与数据,但生成行时,它无法添加填充行中的“可见性”单元格。想法?
编辑:为清楚起见。
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)
}
,
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>
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();
}
$this->addColumn('visibility', array(
'header' => Mage::helper('catalog')->__('Visibility'),
'width' => '100',
'sortable' => false,
'index' => 'visibility',
'type' => 'options',
'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
));
答案 0 :(得分:1)
查看产品系列catalog/model/resource/product/collection.php
我看到的一些事情可能是罪魁祸首:
/**
* Apply limitation filters to collection
* Method allows using one time category product index table (or product website table)
* for different combinations of store_id/category_id/visibility filter states
* Method supports multiple changes in one collection object for this parameters
*
* @return Mage_Catalog_Model_Resource_Product_Collection
*/
protected function _applyProductLimitations()
{
$this->_prepareProductLimitationFilters();
看来Magento阻止和/或路由集合中的visibility
字段。
进一步研究_prepareProductLimitationFilters()
方法本身揭示:
/**
* Apply front-end price limitation filters to the collection
*
* @return Mage_Catalog_Model_Resource_Product_Collection
*/
public function applyFrontendPriceLimitations()
{
$this->_productLimitationFilters['use_price_index'] = true;
if (!isset($this->_productLimitationFilters['customer_group_id'])) {
$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$this->_productLimitationFilters['customer_group_id'] = $customerGroupId;
}
if (!isset($this->_productLimitationFilters['website_id'])) {
$websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId();
$this->_productLimitationFilters['website_id'] = $websiteId;
}
$this->_applyProductLimitations();
return $this;
}
如何解决这个问题而不会对“推理”造成严重破坏,为什么我不确定。
答案 1 :(得分:0)
想出来。
我的实现扩展了Mage_Adminhtml_Block_Catalog_Category_Tab_Product。因为它扩展了Mage_Adminhtml_Block_Catalog_Category_Tab_Product,所以我对扩展方法的功能非常有限。新列的数据未显示的原因是因为父方法无法访问数据( - > addAttribute('visibility'))。
为了处理新数据,我需要扩展Mage_Adminhtml_Block_Widget_Grid。小部件提供了更通用的方法来处理数据。