Magento 将产品分组并列出
我想将目录产品列表中的产品分组 我有4个可配置的产品,我想将它们分组为1个产品,显示在目录中 为此,我创建了一个属性文本(assoccode)来关联每个可配置产品Magento 将产品分组并列出,magento,Magento,我想将目录产品列表中的产品分组 我有4个可配置的产品,我想将它们分组为1个产品,显示在目录中 为此,我创建了一个属性文本(assoccode)来关联每个可配置产品 Config 1: code001 - assoccode: code001 Config 2: code002 - assoccode: code001 Config 3: code003 - assoccode: code001 Config 4: code004 - assoccode: code001 我的问题是,当我有一个
Config 1: code001 - assoccode: code001
Config 2: code002 - assoccode: code001
Config 3: code003 - assoccode: code001
Config 4: code004 - assoccode: code001
我的问题是,当我有一个没有其他选项的单一可配置产品时,它不会显示在目录列表中,或者如果它是一个简单的产品,或者如果我将锚点类别激活为“是”,我会出现以下错误:SQLSTATE[42S22]:未找到列:1054未知列“group statement”中的“assoccode”
是否有其他选项可以根据目录产品列表中的属性对产品进行分组
我将产品系列扩展如下:
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();
}
}
非常感谢您的帮助。1.-您需要在管理、目录->属性->管理属性中创建属性产品 之后,创建一个“设置属性”,一旦创建,就与可配置产品关联 2.-创建自定义模块块视图和列表,使用属性渲染组产品作为视图进行选择 3.-进入详细产品视图使用自定义集合显示组产品和选项
4.-创建自定义模块添加到购物车块,以添加多个产品组它看起来是错误的生成查询。尝试记录查询(例如:Mage::log($this->getSelectSql(true)),然后在SQL管理员中执行它。它会告诉您出了什么问题。如果使用FLAT,请确保“assoccode”列确实存在,如果不存在,请确保在“Manage attributes”中启用了“Used in Product list”然后重建索引。您好,我已经通过了这些步骤,在日志sql中,我看到组由assoccode组成,在表平面中是assocode to。请编辑您的问题,将完整查询添加到日志中。您需要什么日志?给出错误的mysql查询,
SELECT…
,您之前说过2条注释