2

このクエリの標準的な解決策が機能しないケースがいくつか報告されています (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で試すことさえできません。

Magento 1.7で検証/認定/テストされたソリューションを投稿していただけますか? (または最新の Magento リリース)。

4

1 に答える 1

2

これはうまくいくかもしれませんし、うまくいかないかもしれません。最も効率的な方法ではないかもしれません。

$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')
;
于 2013-06-28T09:22:49.933 に答える