我希望在magento中显示特定父类别的畅销/畅销。我有一些家长类别,如鲜花,蛋糕等。当我去花时,我只想展示来自蛋糕等蛋糕中的花朵的畅销产品。
答案 0 :(得分:2)
Use following code:- public function getBestSellersCollection($numDays = 60, $categoryId) { $todayDate = Mage::getModel('core/date')->date('Y-m-d'); $fromDate = date('Y-m-d', strtotime('now -'.$numDays.' days')); $_bestSellersCollection = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() ->setStoreId($storeId) ->addAttributeToSelect('name') ->addAttributeToSelect('entity_id') ->addAttributeToSelect('url_path') ->addCategoryFilter($categoryId) ->addAttributeToFilter('created_at', array('date' => true, 'from' => $fromDate, 'to' => $todayDate)) ->setOrder('ordered_qty', 'desc'); $bestsoldids = Array(); foreach($_bestSellersCollection as $col){ $bestsoldids[] = $col->getData('entity_id'); } return $bestsoldids; }