Unsupported Operand Types While Saving Shipments

I am trying to save shipments remotly in my addon. I check database and save the shipment.


<br />
  $shipment = fn_get_shipments_info(array('order_id' => $order_info['order_id'], 'advanced_info' => true));<br />
<br />
  if(empty($shipment[0])){<br />
  <br />
	$shipment_data = array(<br />
	'shipment_id' => '',<br />
	'timestamp' => time(),<br />
	'shipping_id' => $order_info['shipping'][0]['shipping_id'],<br />
	'carrier' => 'ups',<br />
	'comments' => '',<br />
	'items' => $order_info['products'],<br />
	'order_id' => $order_id,<br />
	'tracking_number' => $XMLTakipNo[1],<br />
	'products' => $order_info['products'],<br />
   );<br />
<br />
<br />
	   	 fn_update_shipment($shipment_data, $shipment_data['shipment_id']);<br />
<br />
}<br />
<br />

```<br />
<br />
But I am gettting this error below:<br />
```php
<br />
[19-Jun-2015 09:06:25 UTC] PHP Fatal error:  Unsupported operand types in C:\wamp\www\app\functions\fn.cart.php on line 6209<br />
[19-Jun-2015 09:06:25 UTC] PHP Stack trace:<br />
[19-Jun-2015 09:06:25 UTC] PHP   1. {main}() C:\wamp\www\admin.php:0<br />
[19-Jun-2015 09:06:25 UTC] PHP   2. fn_dispatch() C:\wamp\www\admin.php:27<br />
[19-Jun-2015 09:06:25 UTC] PHP   3. fn_run_controller() C:\wamp\www\app\functions\fn.control.php:370<br />
[19-Jun-2015 09:06:25 UTC] PHP   4. include() C:\wamp\www\app\functions\fn.control.php:587<br />
[19-Jun-2015 09:06:25 UTC] PHP   5. fn_cce_kargo_entegrasyon_siparis_kontrol() C:\wamp\www\app\addons\cce_kargo_entegrasyon\controllers\backend\cce_kargo_entegrasyon.php:23<br />
[19-Jun-2015 09:06:25 UTC] PHP   6. fn_update_shipment() C:\wamp\www\app\addons\cce_kargo_entegrasyon\func.php:150<br />
[19-Jun-2015 09:06:25 UTC] PHP   7. fn_check_shipped_products() C:\wamp\www\app\functions\fn.cart.php:6297<br />

```<br />
<br />
So I am getting error in fn_check_shipped_products()  function. I checked and see the problem based on  this line in fn_check_shipped_products  function:<br />
```php
<br />
$total_amount += empty($amount) ? 0 : $amount;<br />

```<br />
fn.cart.php on line 6209<br />
<br />
Here is the whole function :<br />
```php
<br />
function fn_check_shipped_products($products)<br />
{<br />
	$allow = true;<br />
	$total_amount = 0;<br />
	if (!empty($products) && is_array($products)) {<br />
		foreach ($products as $key => $amount) {<br />
			$total_amount += empty($amount) ? 0 : $amount;<br />
		}<br />
		if ($total_amount == 0) {<br />
			$allow = false;<br />
		}<br />
	} else {<br />
		$allow = false;<br />
	}<br />
	return $allow;<br />
}<br />

```<br />
<br />
Although products are listed  and  in array I get this "Unsupported operand types" error. <img src="upload://n4syhXZrRhsStKvmS4jT3Mp2S3k.png" class="bbc_emoticon" alt=":(">

Any help would be appreciated. :)

Looking at the foreach line, it is expecting an array of numeric amounts, you may be passing the whole products array which is a list of product data, not amounts.

I would print $amount to see its values. For example you can modify fn_check_shipped_products like this


function fn_check_shipped_products($products)
{
$allow = true;
$total_amount = 0;
if (!empty($products) && is_array($products)) {
echo '

';
foreach ($products as $key => $amount) {
$total_amount += empty($amount) ? 0 : $amount;
print_r($amount);
}
echo '
';
exit;
if ($total_amount == 0) {
$allow = false;
}
} else {
$allow = false;
}
return $allow;
}

better to place

print_r($amount);

before

$total_amount += empty($amount) ? 0 : $amount;

or comment this line not to receive error

//$total_amount += empty($amount) ? 0 : $amount;

Amount should be an integer, not an array so if you have something that is setting the value of each products element to anyhing but an integer (the quantity of product in that line item) then you will get the operand error since total_amount is not an array. Basically the LH and RH operands must both be of the same type to be used in a scalar fashion. You can use += with arrays but that's not what's desired in this case.



Products should look like:

products => [ 1, 3, 5]

for quanties 1, 3 and 5 for each line item. There's probably an index 'key' used too for reference into the $order_info['products'] array.