1

Magentoのproductsテーブルにカスタムフィールドを追加しました。そのカスタムフィールドを使用して並べ替えたいのですが、そうではありません。何が問題なのかわかりません。

    $_cproduct = Mage::getmodel('catalog/product');
    $_productCollection = $_cproduct->getCollection();
    $_productCollection->addAttributeToSelect('name')->addAttributeToSelect('expired')->addAttributeToSelect('dealcategory')->addAttributeToSelect('dealcity')->addAttributeToSelect('deal_position')->addAttributeToSelect('special_to_date')->addAttributeToSelect('title')->setStore(Mage::app()->getStore()->getId())->addStoreFilter(Mage::app()->getStore()->getId())->addAttributeToSort('entity_id', 'DESC')->addAttributeToSort('dealcategory', 'DESC');
    $_productCollection->addAttributeToFilter('status', 1)->addAttributeToFilter('expired', 0);


$_productCollection->addAttributeToFilter('dealcategory', array('in' => array(129, 135, 136, 137, 141, 156, 205)));


    $now = Mage::getModel('core/date')->timestamp(time());
    $dateStart = date('Y-m-d' . ' 00:00:00', $now);    

    $_productCollection->addFieldToFilter('special_to_date', array('from' => $dateStart));
    $dealcity = Mage::app()->getRequest()->getParam('dealcity', false);
    $_productCollection->addAttributeToSort('deal_position', 'ASC');


    echo "<pre>";
    print_r($_productCollection->getData());
    echo "</pre>";

しかし、以下のような異常な注文を受けるたびに、「deal_position」に基づいて並べ替えたいと思います。

Array
(
    [0] => Array
        (
            [entity_id] => 2568
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => virtual
            [sku] => comedybar7/2/12
            [created_at] => 2012-07-02 18:36:22
            [updated_at] => 2012-10-16 09:52:41
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side travel deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 135
            [special_to_date] => 2012-10-25 00:00:00
            [deal_position] => 4
        )

    [1] => Array
        (
            [entity_id] => 2566
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => virtual
            [sku] => livingwellfinal
            [created_at] => 2012-06-28 14:48:34
            [updated_at] => 2012-10-16 09:51:58
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side Deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 129
            [special_to_date] => 2012-11-30 00:00:00
            [deal_position] => 1
        )

    [2] => Array
        (
            [entity_id] => 2565
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => simple
            [sku] => laser-toenail-10-toes
            [created_at] => 2012-06-27 21:10:19
            [updated_at] => 2012-10-16 09:52:23
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side Deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 129
            [special_to_date] => 2012-11-30 00:00:00
            [deal_position] => 3
        )

    [3] => Array
        (
            [entity_id] => 2564
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => simple
            [sku] => laser-toenail-5-toes
            [created_at] => 2012-06-27 21:10:19
            [updated_at] => 2012-10-16 09:52:10
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side Deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 129
            [special_to_date] => 2012-12-31 00:00:00
            [deal_position] => 2
        )

)

addOrder()同じ出力を返すものを使用しました。どうした?

4

1 に答える 1

3

自分のコードに迷い込んだようです。3つ追加しました!コードを並べ替えます。

line3: ...->addAttributeToSort('entity_id', 'DESC')->addAttributeToSort('dealcategory', 'DESC');
line10: $_productCollection->addAttributeToSort('deal_position', 'ASC');

必要なものだけを並べ替えることを確認してください。また、addAttributeToSelect複数回使用せず、1回使用しますが、引数として配列を渡します。

$_productCollection->addAttributeToSelect(array('name', 'expired', ...));
于 2012-10-16T11:09:27.593 に答える