2010-11-29 16 views
0

注文出荷のコレクションを照会する必要があります(Mage_Sales_Model_Mysql4_Order_Shipment_Collection)。私は、特定のテキストと一致するコメントが書き込まれた注文発送を見たいだけです。非EAVのSQLでMagento:特定のテキストを含むコメントを含む出荷のみを含む貨物収集を取得する

が、それは次のようになります。

$shipments = Mage::getResourceModel('sales/order_shipment_collection') 
    ->addAttributeToSelect('*') 
    // ?? 
    // ?? 
    ->load(); 

これが可能である:もちろん、私はそれを達成するためにMagentoののネイティブモデルのメソッドを使用したい

SELECT shipments.id 
FROM shipments 
JOIN comments ON (
    shipments.id = comments.shipment_id 
    AND comments.content IN('Possible comment', 'Another possible comment') 
    ) 
GROUP BY shipments.id 

答えて

2

私は、次のものを自分自身のリソース・モデル内に入れて、Mage_Sales_Model_Mysql4_Order_Shipment_Collectionを拡張します。

public function addCommentsToFilter($comments = array()) 
{ 
    return $this->join('sales/shipment_comment', 'main_table.entity_id=parent_id', 'comment') 
     ->addFieldToFilter('comment', array('in'=>$comments)); 
} 

その後でそれを呼び出す:

$shipments = Mage::getResourceModel('mymodule/my_custom_collection') 
    ->addAttributeToSelect('*') 
    ->addCommentsToFilter(array('Possible comment', 'Another possible comment')); 
関連する問題