【问题标题】:Group and List products grouped Magento分组和列出产品分组 Magento
【发布时间】:2014-02-08 01:25:01
【问题描述】:

我想对目录产品列表中的产品进行分组。

我有 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 并且在 table flat 中是 assocode。
  • 请编辑您的问题以添加日志中记录的完整查询
  • 你到底需要什么日志?
  • 给出错误的 mysql 查询,SELECT ...,你之前说过 2 cmets 你有它

标签: magento


【解决方案1】:

1 .-您需要在管理员、目录-> 属性-> 管理属性中创建属性产品 之后,创建一个“设置属性”,一旦完成,关联到可配置产品,

2.-创建自定义模块块视图和列表,使用属性渲染组产品作为视图来选择

3.-进入详细产品视图使用自定义集合来显示组产品,以及选项

4.-创建自定义模块添加到购物车块,添加多个产品组

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    相关资源
    最近更新 更多