I have written a small shipping in extension for my opencart it works fine but when i haven't set a region/state for an address i get the below error
Warning: key() expects parameter 1 to be array, null given in /home/51/html/k/catalog/controller/fastshipping/shipping.php on line 289
but once the field is set it works great. Since my form is jquery the shipping form doesn't loads coz of that warning.
below is the code
if (isset($defaultshippingmethod['quote'][key($defaultshippingmethod['quote'])]['code']))
{
$this->data['code'] = $defaultshippingmethod['quote'][key($defaultshippingmethod['quote'])]['code'];
}
else {
$this->data['code'] = '';
}
can someone please tell me how can fix that? (not just disable php warning)
replace the if
to :
if (isset($defaultshippingmethod['quote']) &&
isset($defaultshippingmethod['quote'][key($defaultshippingmethod['quote'])]['code']))
the error is because there no entry in the array
$defaultshippingmethod['quote']