2013-07-30 131 views
0

客戶想要一個頁面,他可以從他的產品中看到自定義選項,我設法複製Sales> Order,然後自定義該頁面以顯示自定義選項。Magento銷售訂單 - 僅從一個SKU返回項目

問題是,只有其中一個項目具有自定義選項,並且在Sales> Orders中可以看到所有訂單,當然,您也可以只輸入SKU(我也可以輸入SKU),但我希望它自動帶來該SKU的所有訂單。在Grid.php這裏我有什麼:

protected function _prepareCollection() 
    { 
     $collection = Mage::getResourceModel($this->_getCollectionClass()) 
     ->join(
     'sales/order_item', 
     '`sales/order_item`.order_id=`main_table`.entity_id', 
     array(
     'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'), 
     )); 

     $collection->getSelect()->group('main_table.entity_id'); 

     $collection->getSelect()->joinLeft(array('sfoi' => 'sales_flat_order_item'), 
     'main_table.entity_id = sfoi.order_id', 
     array('sfoi.product_options')); 

     $collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('coupon_code')); 

     $this->setCollection($collection); 

     return parent::_prepareCollection(); 
    } 

有了這個,我可以得到SKU,產品選項和使用的優惠券代碼。我如何將它設置爲僅返回SKU SD0003?

感謝

回答

1

試試這個:

$collection->getSelect()->where('sfoi.sku = "' . $yourDesireSku . '"'); 

問候。

+0

謝謝!工作完美,我搜索了很多關於它,答案是如此簡單大聲笑。我是新來的stackoverflow,所以我不知道我可以推薦你,介意嗎?我還標記了答案 –

+0

單擊問題左側的「上部」按鈕。很高興爲您提供幫助,來自墨西哥的問候。 –

相關問題