Pergunta

então, eu tenho um renderizador para encomendas e aqui está o código:o sku do processador está funcionando bem eu tenho problema de pesquisa e filtragem de skus a

$this->addColumn('sku', array(
                'header'=> Mage::helper('sales')->__('SKU'),
                'index' => 'sku',
                // begin: render the sku content
                'renderer' => new Lenmar_Adminhtml_Block_Sales_Order_RendererSkuFk1(),
                // end: render the sku content
                'type' => 'text',
           'filter_condition_callback' => array($this, '_addressFilter'),
            ));

Eu leia o artigo o que eu deveria usar o retorno de chamada, mas eu não sei como escrever a função para seleccionar o sku porque o $this aqui não tem o sku também usei este, mas isso não é correto e dá-me erro de desconhecido coluna sku:

protected function _addressFilter($collection, $column)
    {
        if (!$value = $column->getFilter()->getValue()) {
            return $this;
        }

        $this->getCollection()->getSelect()->where(
            "sales_flat_order_item.sku like ?"
        , "%$value%");


        return $this;
    }

Error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sales_flat_order_item.sku' in 'where clause'

atualizado preparar coleção:

 protected function _prepareCollection()
    {
        $storeCode='bceu';
        $stores = array_keys(Mage::app()->getStores());
        foreach($stores as $id){
          $store = Mage::app()->getStore($id);
          if($store->getCode()==$storeCode) {
            $storeId=$id;
          }
         }
        //$value=3200000001;        
        $from="2014-05-21"; 
        $collection = Mage::getResourceModel('sales/order_collection')

        ->addFieldToFilter('store_id',$storeId)
        //->addAttributeToFilter('increment_id', array('gt' => $value))

        ->addAttributeToFilter('created_at', array("from" => $from, "datetime" => true))
        ->join(array('a' => 'sales/order_address'), 'main_table.entity_id = a.parent_id AND a.address_type != \'billing\'', array(
                'city'       => 'city',
                'country_id' => 'country_id'
            ))
            ->join(array('c' => 'customer/customer_group'), 'main_table.customer_group_id = c.customer_group_id', array(
                'customer_group_code' => 'customer_group_code'
            ))
            ->addExpressionFieldToSelect(
                'fullname',
                'CONCAT({{customer_firstname}}, \' \', {{customer_lastname}})',
                array('customer_firstname' => 'main_table.customer_firstname', 'customer_lastname' => 'main_table.customer_lastname'))
            ->addExpressionFieldToSelect(
                'products',
                '(SELECT GROUP_CONCAT(\' \', x.name)
                    FROM sales_flat_order_item x
                    WHERE {{entity_id}} = x.order_id
                        AND x.product_type != \'configurable\')',
                array('entity_id' => 'main_table.entity_id')
            )

        ;

         // CUSTOM

        $collection->getSelect()->joinLeft(array('sfop'=>'sales_flat_order_payment'), 
    'main_table.entity_id = sfop.parent_id',array('po_number' => 'sfop.po_number'
    ));
Foi útil?

Solução

Desde sales_flat_order_item não está incluído na versão original do sql você vai ficar Unknown column 'sales_flat_order_item.sku' erro porque a tabela é desconhecido

Tente

$collection = Mage::getResourceModel('sales/order_collection')
....
->join(array('sfoi' => 'sales_flat_order_item'), 'main_table.entity_id = sfoi.order_id, array('sku'))
...
->group('main_table.entity_id')

Se o exemplo acima funcionar, em seguida, desfazer e tentar

protected function _addressFilter($collection, $column)
{
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }

    $this->getCollection()->getSelect()
    ->join(array('sfoi' => 'sales_flat_order_item'), 'main_table.entity_id = sfoi.order_id, array('sku'))
    ->where(
        "sales_flat_order_item.sku like ?"
    , "%$value%");


    return $this;
}

Resposta Final:

protected function _addressFilter($collection, $column)
{
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }
    $this->getCollection()->getSelect()
    ->join(array('sfoi' => 'sales_flat_order_item'), 'main_table.entity_id = sfoi.order_id', array('sku'))
    ->where(
        "sfoi.sku like ?"
    , "%$value%")->group('main_table.entity_id');
 return $this;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top