API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

My OrderLine_CreateFromDataArray says soap-encoding:id' attribute is not declared?

0
Hi Forum

I am using PHP.

When i try to make 'My OrderLine_CreateFromDataArray' i get the responce:

soap-encoding:id' attribute is not declared (id=SOME_LONG_NUMBER)

How can i know the id when the orderline is not yet created?

An print_r of my dataarray looks like this:

Array
(
    [0] => Array
        (
            [Number] => 1
            [ProductHandle] => stdClass Object
                (
                    [Number] => 1198
                )

            [OrderHandle] => stdClass Object
                (
                    [Id] => 132
                )

            [Description] => Blå Ecco sko
            [Quantity] => 3
            [UnitNetPrice] => 339
            [DiscountAsPercent] => 0
            [UnitCostPrice] => 100.00
            [TotalMargin] => 0
            [MarginAsPercent] => 0
        )
    [1] => Array
        (

A lot of more orderlinesdata...

)

What makes me exstra confused is that i dont have all this problems when i make each orderline with

'My OrderLine_CreateFromData'

Can anybody give me a hint if my syntax is wrong and hopefully how i make it right?

Regards Christian

 

ADD:

Ok - I solved some of the problem:

When i created my dataarray i used the php command 'array_push' for each orderlinedata i created.

That means that each that the first place in the array had index 0.

By some strange reason the API wants the first index in the array to be one.

Now i dont get the errormessage about missing id.

My orderhandles i get from the orders i have just created.

But even there is no errormessage the the orderlines is not created!

Now my dataarray looks like this:

Array
(
    [1] => Array
        (
            [Number] => 1
            [ProductHandle] => stdClass Object
                (
                    [Number] => 1198
                )
            [OrderHandle] => stdClass Object
                (
                    [Id] => 123
                )
            [Description] => Blå Ecco sko
            [Quantity] => 3
            [UnitNetPrice] => 339
            [DiscountAsPercent] => 0
            [UnitCostPrice] => 100.00
            [TotalMargin] => 0
            [MarginAsPercent] => 0
        )
    [2] => Array
        (
            [Number] => 2
            [ProductHandle] => stdClass Object
                (
                    [Number] => 1199
                )
            [OrderHandle] => stdClass Object
                (
                    [Id] => 123
                )
            [Description] => Røde Ecco sko
            [Quantity] => 7
            [UnitNetPrice] => 270
            [DiscountAsPercent] => 0
            [UnitCostPrice] => 120.00
            [TotalMargin] => 0
            [MarginAsPercent] => 0
        )
    [3] => Array
        (
            [Number] => 3
            [ProductHandle] => stdClass Object
                (
                    [Number] => 1201
                )
            [OrderHandle] => stdClass Object
                (
                    [Id] => 123
                )
            [Description] => Grøn Te
            [Quantity] => 3
            [UnitNetPrice] => 32
            [DiscountAsPercent] => 0
            [UnitCostPrice] => 5.00
            [TotalMargin] => 0
            [MarginAsPercent] => 0
        )
)
created Aug 27, 2013 by cheyn
87% Accept Rate

edited Aug 27, 2013 by cheyn
Q 15 A 6 C 7

1 Answer

0
Ok - After mutch figth i solved the problem.

It seems to be a problem with PHP.

When making arrays inside arrays and then declaring objects in the innerarray each time an object is declared the former declared object will be changed to be an reference to the secund object.

The solution is to declare completely new objects each runthroug of the rutine that buids the dataarray.

     function CreateOrderLinesFromDataArray($client,$orderlinedataarray){

           $orderLinesData = array();
            foreach($orderlinedataarray as $orderlinedata){
                $orderlineHandle = new stdClass();
                $orderlineHandle->Id = $orderlinedata['OrderHandle']->Id;
                $orderlineHandle->Number = $orderlinedata['Number'];
                $orderHandle = new stdClass();
                $orderHandle->Id = $orderlinedata['OrderHandle']->Id;

                $temparr = array(
                    'Handle' => $orderlineHandle,
                    'Id'                => $orderlineHandle->Id,
                    'Number'            => $orderlineHandle->Number,
                    'OrderHandle'        => $orderHandle,
                   ...

                   ...

                 );
                array_push($orderLinesData, $temparr);
            );

             $orderlineHandleArray = $client->OrderLine_CreateFromDataArray(array(
                                            'dataArray' => array(
                                            'OrderLineData' => $orderLinesData
                                            )))->OrderLine_CreateFromDataArrayResult;

Regards Christian
answered Sep 2, 2013 by cheyn
Just to finish completely.
Above is ofcource leading to the problem that whem the producthandle is later declared after the orderline- and orderhandle the problem occurs.
Producthandle dont contain the value 'id' - only 'number'.
When the 2 other objects have become reference to the producthandle Economic will send back the failmessage 'Id is missing' for the orderline- and orderlinehandles.
Visma e-conomic A/S
...