因为:
- Google sees this as a solution
我的解决方案在 Php 方面,在 Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories 类中。
// start Added stuff
protected $_ubProductCategoriesParents;
public function getUbProductCategories()
{
if (is_null($this->_ubProductCategoriesParents)) {
$this->_ubProductCategoriesParents = array();
$this->_ubProductCategoriesParents = array();
foreach ($this->getCategoryIds() as $id) {
$storeId = (int) $this->getRequest()->getParam('store');
$path = Mage::getResourceModel('catalog/category')
->getAttributeRawValue($id, 'path', $storeId); // no model->load ever ever ever
if (empty($path)) {
$path = "";
}
$parentsIds = explode("/", $path);
if (!(is_array($parentsIds) && count($parentsIds) > 0)) {
$parentsIds = array();
}
$this->_ubProductCategoriesParents = array_unique(array_merge($this->_ubProductCategoriesParents, $parentsIds));
}
//Mage::log(print_r($this->_ubProductCategoriesParents, true));
}
return $this->_ubProductCategoriesParents;
}
// end Added stuff
// magento core function from class
protected function _getNodeJson($node, $level = 1)
{
$item = parent::_getNodeJson($node, $level);
if ($this->_isParentSelectedCategory($node)) {
$item['expanded'] = true;
}
// added new if statement
if (!(isset($item['expanded']) && $item['expanded'] == true) && array_search($node->getId(), $this->getUbProductCategories()) !== false) {
$item['expanded'] = true;
}
if (in_array($node->getId(), $this->getCategoryIds())) {
$item['checked'] = true;
}
if ($this->isReadonly()) {
$item['disabled'] = true;
}
return $item;
}
现在将上面的代码放在重写类中。
谢谢