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