Chris G 29 Posted March 17, 2013 Share Posted March 17, 2013 (edited) PS version 1.4.9.0 Hi For a product with combimations, when all the combinations are out of stock I get the following Warning: Warning: Invalid argument supplied for foreach() in /home/my domain/public_html/controllers/ProductController.php on line 324 This is the code at line 324: foreach ($combinations as $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] as $id_attribute) $attributeList .= '\''.(int)$id_attribute.'\','; $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } self::$smarty->assign(array( 'groups' => $groups, 'combinaisons' => $combinations, /* Kept for compatibility purpose only */ 'combinations' => $combinations, 'colors' => (count($colors) && $this->product->id_color_default) ? $colors : false, 'combinationImages' => $combinationImages)); When all combinations for the product are out of stock $combinations is Null, hence the warning. A solution might be to wrap the code above in an: ' if ($combinations) ' statement. Th only thing is that non of the code above would be executed. When $combination is Null the data is set as: groups = array(0) {} combinations = NULL colors = array(0) {} So should I just apply the ' if ($combinations) ' statement to the 'foreach block' or both the 'foreach block' and the $smarty->assign block ? Thanks Chris G Edited April 4, 2013 by Chris G 29 (see edit history) Link to comment Share on other sites More sharing options...
Radu Posted March 17, 2013 Share Posted March 17, 2013 My opinion as I look to the code is that only to foreach Groups, colors, combinationImages are variables that are created before and assigned to smarty. Otherwise this variables won't be available in the tpl files if(isset($combinations) && is_array($combinations)) { foreach ($combinations as $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] as $id_attribute) $attributeList .= '\''.(int)$id_attribute.'\','; $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } } Link to comment Share on other sites More sharing options...
Chris G 29 Posted March 18, 2013 Author Share Posted March 18, 2013 Radu, Thanks for the reply, that was my feeling, but I was not sure what the effect would be. In the test; if(isset($combinations) && is_array($combinations)) What does the: && is_array($combinations)condition do ? Link to comment Share on other sites More sharing options...
Radu Posted March 18, 2013 Share Posted March 18, 2013 It's just checking if the combination is an array so we can loop using foreach. Link to comment Share on other sites More sharing options...
Chris G 29 Posted March 18, 2013 Author Share Posted March 18, 2013 Radu, Ok many thanks. Regards Chris G Link to comment Share on other sites More sharing options...
Chris G 29 Posted April 4, 2013 Author Share Posted April 4, 2013 (edited) Sorry for the delay in closing this, made the change and everything seems OK. May be worth checking if this is an issue in 1.5 Chris G Edited April 4, 2013 by Chris G 29 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now