-3

Looks like this problem comes up alot, and I did some searching and based on that was going to put "isset" before $ _POST or $ _GET functions. Issue is in the code I have I can't figure out where to put it.

    foreach ($product['option'] as $option) {
        if ($option['type'] != 'file') {
            $value = $option['value'];
        } else {
            $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

            if ($upload_info) {
                $value = $upload_info['name'];
            } else {
                $value = '';
            }
        }

the errors I get are the following:

Notice: Undefined index: option in /home/mdfehr/public_html/store/catalog/controller/common/cart.php on line 65Warning: Invalid argument supplied for foreach() in /home/mdfehr/public_html/store/catalog/controller/common/cart.php on line 65

Line 65 would be the first line in the code I posted. I have the same error in two other spots but I am hoping that what I learn from the suggestions here on this one can help me solve those.

Tom
  • 67
  • 10
  • 1
    The error is quite clear. Do check what `$product` contains – Sami Kuhmonen Aug 11 '15 at 10:44
  • 2
    possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – RiggsFolly Aug 11 '15 at 10:44

2 Answers2

0

Simply put the isset piece right before you use a value. In this particular scenario, place it right before the first line of your code snippet. If it occurs in other parts as well, place those prats in an if statement featuring isset.

0

Replace whole code like follows.

if(isset($product['option']) && is_array($product['option']))
{
    foreach ($product['option'] as $option) {
        if ($option['type'] != 'file') {
            $value = $option['value'];
        } else {
        $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

        if ($upload_info) {
            $value = $upload_info['name'];
        } else {
            $value = '';
        }
    }
}
sugunan
  • 4,408
  • 6
  • 41
  • 66