Magento - 获得畅销产品,包括售完产品

this is my code but i get only the products that are available in stock. I want to get all products, including the sold-out. Do you have any idea?

 $productCount = 5;
        $storeId    = Mage::app()->getStore()->getId(); 


$productsBestSellerMens = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->addAttributeToSelect('*')  
            ->setStoreId($storeId)
            ->addCategoryFilter($mensID)
            ->setPageSize($productCount);

You may want to try an extension that will show not only best selling products, but also new/sale/best-selling/most-viewed/top-rated/featured/sold-out products.

Source: http://www.magentocommerce.com/magento-connect/product-gallery.html

The comment by OSdave is a good place to start with finding the answer to your question.

At it's heart Magento uses Zend_Db when accessing the database. As a result you can use the 'magic' __toString() method of Zend_Db_Select to output the underlying MySQL query generated by your PHP code. As category filtering is specific to your situation I've adapted your original code slightly:

$productCount   = 5;
$storeId        = Mage::app()->getStore()->getId();

$productsBestSellerMens = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty()
    ->addAttributeToSelect('*')  
    ->setStoreId($storeId)
    ->setPageSize($productCount);

var_dump((string) $productsBestSellerMens->getSelect());
exit;

This is a crude but very simple way of finding that the resulting SQL query is:

SELECT 
SUM(order_items.qty_ordered) AS `ordered_qty`,
`order_items`.`name` AS `order_items_name`,
`order_items`.`product_id` AS `entity_id`,
`e`.`entity_type_id`,
`e`.`attribute_set_id`,
`e`.`type_id`,
`e`.`sku`,
`e`.`has_options`,
`e`.`required_options`,
`e`.`created_at`,
`e`.`updated_at` 
FROM `sales_flat_order_item` AS `order_items` 
INNER JOIN `sales_flat_order` AS `order` ON `order`.entity_id = order_items.order_id AND `order`.state <> 'canceled' 
LEFT JOIN `catalog_product_entity` AS `e` ON (e.type_id NOT IN ('grouped', 'configurable', 'bundle')) AND e.entity_id = order_items.product_id AND e.entity_type_id = 4 
WHERE (parent_item_id IS NULL) 
GROUP BY `order_items`.`product_id` 
HAVING (SUM(order_items.qty_ordered) > 0)

As you can see from reviewing the query there is nothing that filters 'sold out' products.

You can handle the display of 'sold out' products by using the isSaleable() method of the Mage_Catalog_Model_Product class. An example of this in practice is shown within the Magento template file /app/design/frontend/base/default/template/catalog/product/view.phtml.

It's also worth noting that when I tried to use the same method to pull back a list of best-sellers I found that the results didn't match audited sales data. A fuller investigation and a corrected method for retrieving best sellers that macth auditedsales data is available on our blog.