Search code examples
sqlmagentoecommerce-sales

Magento Sales Order - Return items from only one SKU


a client wants a page where he can sees custom options from his product, I managed to duplicate Sales > Order, and then custom that page to display the custom options.

Problem is, only one of these items have custom options, and on Sales > Orders you see all orders, of course you can just type in the SKU (I put the column SKU too), but I wanted it to automatically bring all orders from that SKU. On Grid.php here what I have:

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();
    }

With this I can get SKU, product options, and the coupon codes used. How can I set it to return only the SKU SD0003?

Thanks


Solution

  • Try this:

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

    Greetings.