4

I must to update a code created by another programmer. It uses php - SOAP to connect Magento. I was digging to understand what he did and I found a query using Complex Filter against sales_order_invoice.list. This is the Complex Filter:

$complexFilter = array(            
      'complex_filter' => array(
        array(
               'key' => 'CREATED_AT',
               'value' => array(
                   'key' => 'from',
                   'value' => '2015-10-16 01:24:37'
               )
        ),
        array(
               'key' => 'state',
               'value' => array(
                   'key' => '=',
                   'value' => '2'
               )
        ),
        array(
               'key' => 'store_id',
               'value' => array(
                   'key' => 'in',
                   'value' => '5,6'
               )
        )
      )
);

This is the code to connect:

$cli = new SoapClient("http://MYstaging.com/api/v2_soap/?wsdl");
$username = 'myuser';
$password = 'myPass';
$session_id = $cli->login($username, $password);
#$cli->__setCookie('XDEBUG_SESSION', 'netbeans-xdebug');      
$result = $cli->salesOrderInvoiceList($session_id, $complexFilter);

As we can see, the query should retrieve some information from salesOrderInvoiceList, and it does. This is the result:

array (size=1)
  0 => 
    object(stdClass)[2]
      public 'increment_id' => string '500000001' (length=9)
      public 'created_at' => string '2015-10-16 20:07:18' (length=19)
      public 'order_currency_code' => string 'YYY' (length=3)
      public 'order_id' => string '9' (length=1)
      public 'state' => string '2' (length=1)
      public 'grand_total' => string '00.0000' (length=7)
      public 'invoice_id' => string '3' (length=1)

I do not understand this. If we check the Magendo doc to sales_order_invoice.list, there is no store_id content or field. So it should not be possible to use it as a filter. But it does exists in the sales_order_invoice.info.

Well, if I change store_id field for something that do not exist at all, lets say "BLAH_BLAH" certainly I would have nothing as result. And it is what is happening. And it makes sense. Behind the scenes maybe we have a sql 1054 (Unknow column) error.

$complexFilter = array(            
      'complex_filter' => array(
        array(
               'key' => 'CREATED_AT',
               'value' => array(
                   'key' => 'from',
                   'value' => '2015-10-16 01:24:37'
               )
        ),
        array(
               'key' => 'state',
               'value' => array(
                   'key' => '=',
                   'value' => '2'
               )
        ),
        array(
               'key' => 'BLAH_BLAH',
               'value' => array(
                   'key' => 'in',
                   'value' => '5,6'
               )
        )
      )
);

Can someone explain why salesOrderInvoiceList is accepting store_id as filter?

  • 1
    Perhaps its just a gap in the documentation. It seems to me that the ability to use store_id as a filter would be incredibly important. – Robbie Averill Dec 16 '15 at 22:00
  • Hi Robbie, this is a good possibility. I was not think about it. I agree with you, store_id is very important. So the possible conclusion is the field exist in the table but not i documentation. Otherwise we should have the same error as field BLAH_BLAH – zwitterion Dec 17 '15 at 15:13
4

Formally, you can pass to complex filter any field from sales/order_invoice model and this field will take part in the filtering. Magento passes your complex filter to \Mage_Sales_Model_Order_Invoice_Api::items. This method inits an invoices collection:

$invoiceCollection = Mage::getResourceModel('sales/order_invoice_collection');

and then iterates over all passed filters by adding them to the set of collection filters

foreach ($filters as $field => $value) {
    $invoiceCollection->addFieldToFilter($field, $value);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.