【问题标题】:Magento 1.7 sorting by ordered quantity - bestseller products issuesMagento 1.7 按订购数量排序 - 畅销产品问题
【发布时间】:2013-04-09 04:43:06
【问题描述】:

报告了几种情况,该查询的标准解决方案不起作用(关于 SO 的类似问题很多,但没有任何明确的解决方案)。

检索“畅销书”集合的方法是使用此查询构建器:

    $storeId = Mage::app()->getStore()->getId();
    $collection = Mage::getResourceModel('reports/product_collection');

    $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

    $collection = $collection
        ->addFieldToFilter('*')
        ->addOrderedQty()
        ->addStoreFilter()
        ->setStoreId($storeId)
        ->setOrder('ordered_qty', 'desc')
        ->setPageSize(10)
        ->setCurPage(1);

现在,$collection 结果包含一些虚假值,并且完全缺少重要属性(没有名称、价格等)。我什至无法在 1.7 中尝试 this core-code workaround

任何人都可以发布一个经过 Magento 1.7 验证/认证/测试的解决方案吗? (或最新的 Magento 版本)。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    这可能对您有用,也可能不适用,它可能不是最有效的方法,但它对我有用,所以在这里它与您的部分代码合并。

    $storeId = Mage::app()->getStore()->getId();
    $collection = Mage::getResourceModel('reports/product_collection');
    $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
    
    $collection = $collection
        ->addFieldToFilter('*')
        ->addStoreFilter()
        ->setStoreId($storeId)
        ->setPageSize(10)
        ->setCurPage(1);
    
    $collection->getSelect()
        ->joinLeft(
            'sales_flat_order_item AS order_item',
            'e.entity_id = order_item.product_id',
            'SUM(order_item.qty_ordered) AS ordered_qty')
        ->group('e.entity_id')
        ->order('ordered_qty DESC')
    ;
    

    【讨论】:

    • 感谢您的回答,我目前有另一个实现依赖于更程序化的方法。它一点也不优雅,所以我试试你的版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    相关资源
    最近更新 更多