Question

I am trying to get the list of shipments for a given order via the API (I use the SOAP API but I don't think it matters).

I don't have the order ID but the 9-digit number (the increment_id from the sales_flat_order table).

I can see the following code in the API method I am trying to call:

    /**
     * Retrieve shipments by filters
     *
     * @param null|object|array $filters
     * @return array
     */
    public function items($filters = null)
    {
        $shipments = array();

        $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
            ->addAttributeToSelect('increment_id')
            ->addAttributeToSelect('created_at')
            ->addAttributeToSelect('total_qty')
            ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
            ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
            ->joinAttribute('order_increment_id', 'order/increment_id', 'order_id', null, 'left')
            ->joinAttribute('order_created_at', 'order/created_at', 'order_id', null, 'left');

        $apiHelper = Mage::helper('api');
        $filters = $apiHelper->parseFilters($filters, $this->_attributesMap['shipment']);
        foreach ($filters as $field => $value) {
            $shipmentCollection->addFieldToFilter($field, $value);
        }

        ...
        return $shipments;
    }

From: Mage/Sales/Model/Order/Shipment/Api.php (slightly edited for brevity).

I don't fully understand the syntax of this query but it seems like a join is made with the orders table, and then filters are added from the filters API parameter.

I have tried to call this API this way (calling from a C# program):

var shipments = Client.SalesOrderShipmentList(sessionId, new Filters
{
    filter = new AssociativeEntity[]
    {
        new AssociativeEntity
        {
            key = "order_increment_id",
            value = "000000006"
        }
    }
});

I am getting the following error:

'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'order_increment_id' in 'where clause', query was: SELECT main_table.increment_id, main_table.created_at, main_table.total_qty FROM sales_flat_shipment AS main_table WHERE (order_increment_id = '000000006')'

It seems that the join isn't being translated to SQL. I have tried several things like prefixing the column name with the orders table name, to no avail.

Am I doing something wrong?

Thank you

Was it helpful?

Solution

Although I can't help with the actual problem, I suggest to use a workaround:

Use 2 API-requests to first get the order's entity_id, and get shipment info with the second request.

The API-method to use here is salesOrderInfo as, for example, described here:

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top