Jump to content

[SOLVED] Combinations - Product Controller error when out of Stock


Chris G 29

Recommended Posts

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 by Chris G 29 (see edit history)
Link to comment
Share on other sites

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

  • 3 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...