Reputation: 239
When trying to using the code below to add a product to the $products SimpleXML object I get an error Warning: Illegal offset type in file and can't figure out what is wrong.
$fields = array(
$o->order_id => 'order_id',
$o->order_address_id => 'order_address_id',
$o->price_ex_tax => 'price_ex_tax' ,
'DISCS' => 'sku',
'1' => 'quantity'
);
$products->addChild('product');
array_walk_recursive($fields, array ($products, 'addChild'));
HERE IS MY SIMPLEXML OBJECT using print_r for $products:
SimpleXMLElement Object
(
[product] => Array
(
[0] => SimpleXMLElement Object
(
[id] => 23
[order_id] => 110
[product_id] => 63477
[order_address_id] => 11
[name] => Dead Sea Treasures Foot Cream
[sku] => 703
[type] => physical
[base_price] => 20.0000
[price_ex_tax] => 20.0000
[price_inc_tax] => 20.0000
[price_tax] => 0.0000
[base_total] => 40.0000
[total_ex_tax] => 40.0000
[total_inc_tax] => 40.0000
[total_tax] => 0.0000
[weight] => 0.5
[quantity] => 2
[base_cost_price] => 0.0000
[cost_price_inc_tax] => 0.0000
[cost_price_ex_tax] => 0.0000
[cost_price_tax] => 0.0000
[is_refunded] => false
[refund_amount] => 0.0000
[return_id] => 0
[wrapping_name] => SimpleXMLElement Object
(
)
[base_wrapping_cost] => 0.0000
[wrapping_cost_ex_tax] => 0.0000
[wrapping_cost_inc_tax] => 0.0000
[wrapping_cost_tax] => 0.0000
[wrapping_message] => SimpleXMLElement Object
(
)
[quantity_shipped] => 0
[event_name] => NULL
[event_date] => SimpleXMLElement Object
(
)
[fixed_shipping_cost] => 0.0000
[ebay_item_id] => SimpleXMLElement Object
(
)
[ebay_transaction_id] => SimpleXMLElement Object
(
)
[option_set_id] => NULL
[parent_order_product_id] => NULL
[is_bundled_product] => false
[bin_picking_number] => SimpleXMLElement Object
(
)
[applied_discounts] => SimpleXMLElement Object
(
[discount] => SimpleXMLElement Object
(
[id] => 1
[amount] => 4
)
)
[product_options] => SimpleXMLElement Object
(
)
[configurable_fields] => SimpleXMLElement Object
(
)
)
[1] => SimpleXMLElement Object
(
[id] => 24
[order_id] => 110
[product_id] => 63398
[order_address_id] => 11
[name] => Naot Matai
[sku] => 11410-37-577
[type] => physical
[base_price] => 166.0000
[price_ex_tax] => 166.0000
[price_inc_tax] => 166.0000
[price_tax] => 0.0000
[base_total] => 166.0000
[total_ex_tax] => 166.0000
[total_inc_tax] => 166.0000
[total_tax] => 0.0000
[weight] => 2
[quantity] => 1
[base_cost_price] => 0.0000
[cost_price_inc_tax] => 0.0000
[cost_price_ex_tax] => 0.0000
[cost_price_tax] => 0.0000
[is_refunded] => false
[refund_amount] => 0.0000
[return_id] => 0
[wrapping_name] => SimpleXMLElement Object
(
)
[base_wrapping_cost] => 0.0000
[wrapping_cost_ex_tax] => 0.0000
[wrapping_cost_inc_tax] => 0.0000
[wrapping_cost_tax] => 0.0000
[wrapping_message] => SimpleXMLElement Object
(
)
[quantity_shipped] => 0
[event_name] => NULL
[event_date] => SimpleXMLElement Object
(
)
[fixed_shipping_cost] => 0.0000
[ebay_item_id] => SimpleXMLElement Object
(
)
[ebay_transaction_id] => SimpleXMLElement Object
(
)
[option_set_id] => 32446
[parent_order_product_id] => NULL
[is_bundled_product] => false
[bin_picking_number] => SimpleXMLElement Object
(
)
[applied_discounts] => SimpleXMLElement Object
(
)
[product_options] => SimpleXMLElement Object
(
[option] => Array
(
[0] => SimpleXMLElement Object
(
[id] => 57
[option_id] => 49564
[product_option_id] => 36782
[display_name] => Womens Shoe Size
[display_value] => 37 (US6)
[value] => 277224
[type] => SimpleXMLElement Object
(
)
[name] => SimpleXMLElement Object
(
)
[display_style] => SimpleXMLElement Object
(
)
)
[1] => SimpleXMLElement Object
(
[id] => 58
[option_id] => 49565
[product_option_id] => 36783
[display_name] => Shoe Color
[display_value] => Copper/Wine Suede
[value] => 277232
[type] => SimpleXMLElement Object
(
)
[name] => SimpleXMLElement Object
(
)
[display_style] => SimpleXMLElement Object
(
)
)
)
)
[configurable_fields] => SimpleXMLElement Object
(
)
)
)
Upvotes: 0
Views: 309
Reputation: 83
You are passing an array as the second argument to array_walk_recursive.
From the PHP documentation:
bool array_walk_recursive ( array &$input , callable $funcname [, mixed $userdata = NULL ] )
The second argument must be a callable function name which takes two parameters, value and key of the array with a third optional parameter which is passed if you include it as a third parameter to array_walk_recursive.
In other words you would have to call something like:
array_walk_recursive($fields, 'funcname', 'addChild');
You can read about it here: http://php.net/manual/en/function.array-walk-recursive.php
Upvotes: 1