Warning: Invalid Argument Supplied For Foreach() In App\controllers\backend\index.php On Line 255

I’ve just done a test store import on my local machine going from 2.2.4 to 4.0.3 - all seems fine apart from an error on the admin screen:



Warning: Invalid argument supplied for foreach() in app\controllers\backend\index.php on line 255



The code in questions is:


<br />
		if (!empty($taxes)) {<br />
			foreach ($taxes as $tax) {<br />
				$tax = unserialize($tax);<br />
                   foreach ($tax as $id => $tax_data) {<br />
					$subtotal += !empty($tax_data['tax_subtotal']) ? $tax_data['tax_subtotal'] : 0;<br />
				}<br />
			}<br />
		}<br />
	}
```<br />
<br />
Specifically this line:<br />
<br />
foreach ($tax as $id => $tax_data) {<br />
<br />
Any ideas as to what may have gone wrong here?

Has anyone at all experienced this? still looking for a resolution.

Bumping this up - surely I'm not the only one having this issue?

Bumping again with an update.



This error does not show when the debugging console is enabled. Does anyone know why this might be? does the debugging console set any extra variables?

@notflic,



We have never faced such issue. May be some data was not transferred correctly. Please try to replace this part of code:



$tax = unserialize($tax);
foreach ($tax as $id => $tax_data) {
$subtotal += !empty($tax_data['tax_subtotal']) ? $tax_data['tax_subtotal'] : 0;
}




with this one:



$tax = unserialize($tax);
if (is_array(tax)) {
foreach ($tax as $id => $tax_data) {
$subtotal += !empty($tax_data['tax_subtotal']) ? $tax_data['tax_subtotal'] : 0;
}
}




Thanks.

Thanks for your reply. That's what I've done and it does fix the error. What's the likely cause of this? a bad tax value in an order somewhere?

@notflic,



Does your store have any custom modifications? I have chcked the “app\controllers\backend\index.php” file of the 4.0.3 version and it contains completely different code on line 255

No, no modifications. I've managed to track it down to some orders which have not imported well and have strange tax values, editing these orders and then saving them solves the error. Bit of a manual process but it's good to have some idea of what it is.

@notfilc,



It looks like an issue in the Store Import module. Please try to forward this request to CS-Cart support team at My account -

They aren't particularly helpful on the bug tracker - it's a site being developed locally so it's hard to give them access but I will endeavour to. This product seems to get more bugs with every release.

@notfilc,



We are sorry to hear that you are not satisfied with CS-Cart. But I must say that we made a lot of upgrades and have never faced such an issue.



As far as I know, support team must answer you within 24 hours at helpdesk (if they are not overloaded). So inform they about your issue.

I have just downloaded copies of my store and installed it into xampp on my local PC and I am also getting this error…just on the admin dashboard screen

I’ve also gotten this issue while upgrading my 2.2.4 store to 4.3.2. Definitely due to unserialized() function failing. I don’t want to ignore it as it is obviously corrupting the data.



I think that I have narrowed it down to a Windows vs Linux issue but still digging. The code below generates an error in my Windows dev environment however works on my Linux prod environment. Any suggestions on what might be causing this ?


<br />
<?php<br />
$data = 'a:1:{i:7;a:8:{s:9:"rate_type";s:1:"P";s:10:"rate_value";s:6:"10.000";s:18:"price_includes_tax";s:1:"Y";s:9:"regnumber";s:0:"";s:8:"priority";i:1;s:12:"tax_subtotal";d:4.79;s:11:"description";s:3:"GST";s:7:"applies";a:3:{s:1:"P";d:4.2000000000000002;s:1:"S";d:0.58999999999999997;s:5:"items";a:2:{s:1:"S";a:1:{i:12;b:1;}s:1:"P";a:13:{i:2795236705;b:1;i:3965362348;b:1;i:669423038;b:1;i:3738170828;b:1;i:2692647281;b:1;i:2930049347;b:1;i:331338368;b:1;i:2327216954;b:1;i:4256281516;b:1;i:3915326440;b:1;i:1674913295;b:1;i:4249166376;b:1;i:4208752565;b:1;}}}}}';<br />
$tmp = unserialize($data);<br />
print_r(array_values($tmp));<br />
?><br />

```<br />
<br />
Have also raised a ticket with the support crew at CS Cart. Hoping a PHP guru can laugh and tell me what I have done wrong. <img src="upload://rA9Qa8gnUPZzRZRdI8kt3dpjkrs.png" class="bbc_emoticon" alt=":)">

Your data decodes properly here: test unserialize online - general PHP functions - functions-online

So the issue is not with the data itself.



Suggest you upgrade your store to 2.2.5 before doing the store_import. I've seen issues with the 2.2.4 import in the past.

I've also seen issues in the taxes with 4.2.4 (don't know about 4.0.3 but assume it's worse the 4.2.4). Suggest you try importing to 4.2.4, then upgrading through 4.3.2.

Thanks tbirnseth.



Good news is that I tracked down the issue. PHP on windows does not support 64bit Integer values and the last array in the example has integers greater than 2,147,483,647.



Looks like I'm moving my dev environment to Linux

I'm sure there's a 64bit windows PHP available. Why are these being stored as integers rather than strings? I don't know of anything in cs-cart that expects the site to be 64bit. Almost all keys are strings unless they are related to product_id or other already defined integer values. Of course, if you originally stored them on a 64bit system and are trying to read them on a 32bit system then all bets would be off.

I was a bit dumb struck and disbelieving too. I changed my mind only after decreasing the numbers in my test script and it unserialized with no errors straight away. Thanks to VirtualBox I am now a proud owner of a Ubuntu LAMP stack and the site is running without those errors.



The following comes from the php manual.