3
我想获取产品目录产品列表中的产品分组。群组和列表产品分组Magento
我有4个可配置的产品,我想将他们分组到1个产品目录中显示。
为此,我创建了一个属性文本(关联代码)来关联每个可配置产品。
Config 1: code001 - assoccode: code001
Config 2: code002 - assoccode: code001
Config 3: code003 - assoccode: code001
Config 4: code004 - assoccode: code001
我的问题是,当我有没有另一种选择是不在目录列表,或者如果呈现出单一配置产品是一个简单的产品,或者如果我激活锚类别来是我出现此错误:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'assoccode' in 'group statement'
是否有另一个选项可以通过目录产品列表中的属性对产品进行分组?
和我下面延伸产品集合:
class Module_GroupingConfig_Model_Productcollection extends Mage_Catalog_Model_Resource_Product_Collection
{
protected $_disabled = false;
protected $_flatEnabled = array();
public function getFlatHelper()
{
return Mage::helper('catalog/product_flat');
}
protected function isEnabled()
{
return !Mage::app()->getStore()->isAdmin() && !$this->_disabled;
}
public function setDisableGroupBy()
{
$this->_disabled = true;
}
public function isEnabledFlat()
{
// Flat Data can be used only on frontend
if (Mage::app()->getStore()->isAdmin()) {
return false;
}
$storeId = $this->getStoreId();
if (!isset($this->_flatEnabled[$storeId])) {
$flatHelper = $this->getFlatHelper();
$this->_flatEnabled[$storeId] = $flatHelper->isAvailable() && $flatHelper->isBuilt($storeId);
}
return $this->_flatEnabled[$storeId];
}
protected function _beforeLoad()
{
if ($this->isEnabled()) {
if ($this->isEnabledFlat()) {
$this->getSelect()->group('assoccode');
$this->getSelect()->columns(array('assoccode_color_ids' => new Zend_Db_Expr("GROUP_CONCAT(DISTINCT color ORDER BY color_value DESC SEPARATOR ',')")));
} else {
$this->joinAttribute('assoccode', 'catalog_product/assoccode', 'entity_id');
$this->joinAttribute('color', 'catalog_product/color', 'entity_id');
$this->getSelect()->group('assoccode');
$this->getSelect()->columns(array('assoccode_color_ids' => new Zend_Db_Expr("GROUP_CONCAT(DISTINCT at_color.value ORDER BY at_color.value DESC SEPARATOR ',')")));
}
$this->getSelect()->columns(array('assoccode_count' => new Zend_Db_Expr('COUNT(*)')));
}
return parent::_beforeLoad();
}
public function getSelectCountSql()
{
if ($this->isEnabled()) {
$this->_renderFilters();
if ($this->isEnabledFlat()) {
$countSelect = $this->_getClearSelect()
->columns('COUNT(DISTINCT assoccode) AS cnt')
->resetJoinLeft();
} else {
$countSelect = $this->_getClearSelect()
->columns('COUNT(DISTINCT at_assoccode.value) AS cnt')
->resetJoinLeft();
}
$countSelect->reset(Zend_Db_Select::GROUP);
return $countSelect;
}
return parent::getSelectCountSql();
}
}
任何帮助是非常赞赏。
它看起来不合格的查询。尝试记录查询(例如:Mage :: log($ this-> getSelectSql(true)),然后在你的SQL管理中执行它,它会告诉你什么是错误的,如果你使用FLAT,那么确保“assoccode “列确实存在,如果不存在,请确保在”管理属性“中启用了”在产品列表中使用“,然后重建索引。 –
嗨,我已经通过了这一步,在日志sql上我看到了group_by assoccode和 – Dario
请修改您的问题以添加完整查询作为登录日志 – OSdave