按magento中销售最多的产品筛选产品

按magento中销售最多的产品筛选产品,magento,magento-1.7,Magento,Magento 1.7,我想使用下面的查询按大多数销售产品筛选产品,但不起作用 $category = Mage::getModel('catalog/category')->load($cat_id); $collection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category); $collection->addAttributeToFilter('city',array('fin

我想使用下面的查询按大多数销售产品筛选产品,但不起作用

$category = Mage::getModel('catalog/category')->load($cat_id);

$collection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
$collection->addAttributeToFilter('city',array('finset' => Mage::getResourceModel('catalog/product')->getAttribute('city')->getSource()->getOptionId($city_name)));
$collection->addAttributeToSelect('*');
$collection->setOrder('ordered_qty', 'DESC');
$collection->setOrder('name', 'ASC');
$collection->getSelect();

请在上面的查询中指出我做错了什么?

请尝试以下查询

$collection = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addStoreFilter()
            ->addPriceData()
            ->addTaxPercents()
            ->addUrlRewrite()
            ->setPageSize(6);

        $collection->getSelect()
            ->joinLeft(
                array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
                "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'",
                array('SUM(aggregation.qty_ordered) AS sold_quantity')
            )
            ->group('e.entity_id')
            ->order(array('sold_quantity DESC', 'e.created_at'));

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$category = Mage::getModel('catalog/category')->load($cat_id);

    $collection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
    $collection->addAttributeToFilter('city',array('finset' => Mage::getResourceModel('catalog/product')->getAttribute('city')->getSource()->getOptionId($city_name)));
    $collection->addAttributeToSelect('*');

    $collection->getSelect()
                ->joinLeft(
                    array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
                    "e.entity_id = aggregation.product_id",
                    array('SUM(aggregation.qty_ordered) AS sold_quantity')
                )
                ->group('e.entity_id')
                ->order(array("sold_quantity DESC"));