doudi4621 2014-07-08 07:29 采纳率: 0%
浏览 18
已采纳

Magento - Feed按日期属性排序

I've a created a custom observer within Magento for changing the order of my feed. In the config.xml I enabled this part.

<ewfeed_feed_products>
    <observers>
        <example_ewfeed_products>
            <type>singleton</type>
            <class>ewfeed/observer_example</class>
            <method>feedProducts</method>
        </example_ewfeed_products>
    </observers>
</ewfeed_feed_products>

I've changed the Example.php to this.

static function feedProducts(Varien_Object $observer)
{
    $feed = $observer->getFeed();
    $productCollection = $observer->getProductCollection();
    $transport = $observer->getTransport();

    //lets try sorting
    $productCollection->addAttributeToSort('news_to_date', 'DESC'); 

    $originalIds = $productCollection->getAllIds();

    // any ids set here are products that will be used in the feed. they will be listed in the order of the ids in the array
    // so if you change the order it will change the order of the outputted products. you can also filter products here
    $transport->setProductIds($originalIds); // set to null to use default
}

The 'new_to_date' is a attribute with a date value. Now what I need is that the feed will be sorted by this date descending. But nothing happens when I add the addAttributeToSort. Can someone help me out here?

  • 写回答

1条回答 默认 最新

  • dongpochi9741 2014-07-08 19:14
    关注
    1. Is that attribute news_to_date set as required for search and sort.

    2. Is your search using Solr or full text search.

    3. if solr use solr tunnel and query solr for fields that had been populated for products.

    4. We have found that this specific attribute when stores in Solr creates issues as is extracts wrong values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?