Post by Khal » Sun Mar 09, 2014 11:29 pm

I have noticed this error message in my error log:

Code: Select all

PHP Notice:  Undefined index: category_id in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 186
Here is the code:

Code: Select all

   if(!isset($category_info)) {
          $categories = $this->model_catalog_product->getCategoriesByProductId($this->request->get['product_id']);
          if($categories) {
            foreach($categories as $category){
              $path = $this->getPath($category['category_id']);
              $category_info = $this->model_catalog_category->getCategory($category['category_id']);
              if($path){
                $cat_path = $path;
              }else{
                $cat_path = $category_info['category_id'];
Line 186 is the last line.

I'm not sure if it is affecting anything of my site, the categories all seen to be working fine, i think.

Does anyone know what this error message means, and how it can be fixed?

Thank you

OC v1.5.6.1
http://khaleejiabaya.com/
Last edited by Khal on Tue Mar 18, 2014 4:42 pm, edited 1 time in total.

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by melbagnato » Mon Mar 10, 2014 2:38 pm

Hi there,

that error is because you are referencing "category_id" in a function before it has been defined/populated. This can happen if you make a database call and nothing is returned.

I'd suggest you add an "if statement check" to confirm if $category_info was populated by the following line of code:

$category_info = $this->model_catalog_category->getCategory($category['category_id']);

You are assuming that is has been with this call:

$cat_path = $category_info['category_id'];

Hope this helps.

- Mel

http://online.enterpriseconsulting.com.au

Site with OpenCart extensions & code downloads, many new extensions coming soon!
Follow us on twitter for more updates

Image


User avatar
Active Member

Posts

Joined
Wed Jan 13, 2010 1:39 pm
Location - Melbourne

Post by Khal » Mon Mar 10, 2014 6:32 pm

Thank you for that Mel. Yes that seems to have worked.

Your help is much appreciated.

Just wondering if you can help me with another issue I have having: the Leave A Review form isn't working on my OC version: http://forum.opencart.com/viewtopic.php?f=20&t=121273

I have checked the code from product.tpl on both the default theme and my custom theme and it appears to be the same.

Thank you again.

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by Khal » Mon Mar 10, 2014 11:16 pm

Oh no! I've just checked my error log and I am now getting this error message:

Code: Select all

Undefined variable: category in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 185
Here is the code:

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product_id);

		if ($product_info) {
Line 185 is the last line. It looks like something is missing at the end? Did I accidentally delete something when adding the previous code?

Please help!

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by melbagnato » Tue Mar 11, 2014 9:37 am

Hi Khal,

is that code you quoted from your php file, or from the cached vqmod file located in the "\vqmod\vqcache" directory?

The error is similar to your previous one, you just need to check if the "category" variable is defined/populated before you try to use it in your code. It's best to use an "if statement" to check this first.

Hope this helps.

- Mel

http://online.enterpriseconsulting.com.au

Site with OpenCart extensions & code downloads, many new extensions coming soon!
Follow us on twitter for more updates

Image


User avatar
Active Member

Posts

Joined
Wed Jan 13, 2010 1:39 pm
Location - Melbourne

Post by Khal » Wed Mar 12, 2014 12:39 am

Mel, thanks for getting back to me.

The code is from the cached vqmod at vqmod/cache.

Sorry for the dumb question, but the line of code- the "if statement"- where does this go?

I am now getting this error message:

Code: Select all

Undefined variable: category in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 798
Why do I keep getting these different errors when I haven't made any changes? I tried deleting the cached file

Code: Select all

vq2-catalog_controller_product_product.php

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by melbagnato » Wed Mar 12, 2014 9:01 pm

Hi Khal,

I can't answer that question without reviewing your code. Do you want to upload a copy of that php file somewhere and I'll take a look for you.

- Mel

http://online.enterpriseconsulting.com.au

Site with OpenCart extensions & code downloads, many new extensions coming soon!
Follow us on twitter for more updates

Image


User avatar
Active Member

Posts

Joined
Wed Jan 13, 2010 1:39 pm
Location - Melbourne

Post by Khal » Wed Mar 12, 2014 9:45 pm

Thanks Mel.

I have attached the file below. This is the cached file:

Code: Select all

vqmod/vqcache/vq2-catalog_controller_product_product.php
I couldn't attach it as a html so it is a Notepad file and it isn't very readable. It there another way to upload it?

Attachments


https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by melbagnato » Wed Mar 12, 2014 11:04 pm

Hi Khal,

here are the lines of code that are the issue (lines 797-799):

Code: Select all

protected function getPath($parent_id, $current_path = '') {
     $category_info = $this->model_catalog_category->getCategory($category['category_id']);
     $category_info = $this->model_catalog_category->getCategory($parent_id);
As you can see, you have declared $category_info twice in two lines, so I'm guessing one of these (the top one) is a mistake. This is proven as this function only takes two parameters ($parent_id and $current_path), it doesn't get passed the $category[] array, but on the very next line you are trying to reference the $category['category_id'] value.

So, what's the answer ?

This line is a mistake and should be removed:

Code: Select all

     $category_info = $this->model_catalog_category->getCategory($category['category_id']);
Hope this helps.

- Mel

http://online.enterpriseconsulting.com.au

Site with OpenCart extensions & code downloads, many new extensions coming soon!
Follow us on twitter for more updates

Image


User avatar
Active Member

Posts

Joined
Wed Jan 13, 2010 1:39 pm
Location - Melbourne

Post by Khal » Thu Mar 13, 2014 2:16 am

Thanks for that Mel.

But when I remove that line I get this error message instead!:

Code: Select all

Undefined variable: category_info in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 54
These errors are not affecting my site, so should I just ignore them?

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by melbagnato » Thu Mar 13, 2014 11:12 am

Hi Khal,

These lines of code are used for the breadcrumbs and to write the url to the browser.

I think there are lines missing in your code. If you look at lines 79 - 81 they read:

Code: Select all

		}

		$this->load->model('catalog/manufacturer');
I think they should say:

Code: Select all

		} else {
			$category_id = 0;
		}

		$this->load->model('catalog/manufacturer');
I'm not sure if this will fix your issue, but it will at least add a default value which might make that error go away.

Hope this helps.

- Mel

http://online.enterpriseconsulting.com.au

Site with OpenCart extensions & code downloads, many new extensions coming soon!
Follow us on twitter for more updates

Image


User avatar
Active Member

Posts

Joined
Wed Jan 13, 2010 1:39 pm
Location - Melbourne

Post by Khal » Thu Mar 13, 2014 10:36 pm

Hi Mel

Thanks for your perseverance in trying to resolve this for me.

I added the line of code you gave, but now I am getting this error:

Code: Select all

 Undefined variable: category in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 800
Line 800 is this one:

Code: Select all

$category_info = $this->model_catalog_category->getCategory($category_id)
But when I remove that line of code I still get this error:

Code: Select all

Undefined variable: category_info in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 54 
as well as the first error above on line 800.

I tried adding and removing some brackets ({) in case there were too many or not enough, but that is no the problem.

What is going on?!

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by Khal » Fri Mar 14, 2014 8:14 pm

Sorry Mel, I just realised the file I attached above was wrong- it should be the xml file. I have pasted the code for that file below.
Last edited by Khal on Sat Mar 15, 2014 12:35 am, edited 1 time in total.

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by melbagnato » Fri Mar 14, 2014 10:03 pm

Hi Khal,

I'll take another look over the whole file this weekend and let you know what I find.

- Mel

http://online.enterpriseconsulting.com.au

Site with OpenCart extensions & code downloads, many new extensions coming soon!
Follow us on twitter for more updates

Image


User avatar
Active Member

Posts

Joined
Wed Jan 13, 2010 1:39 pm
Location - Melbourne

Post by Khal » Fri Mar 14, 2014 11:14 pm

Thank you Mel. I really appreciate your time and help.

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by billynoah » Fri Mar 14, 2014 11:58 pm

Khal wrote:These errors are not affecting my site, so should I just ignore them?
No, you should not ignore them. You have some buggy code somewhere and something isn't working the way it should because of it.

Also, except for short-term debugging, you shouldn't bother editing the vqcache files. Changes you make there will simply be rewritten by the vqmod at a later point in time.

The code changes need to happen in either the vQmod xml or in the original code. Probably the former since the controller files in question don't need any fixing.

Image


User avatar
Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Khal » Sat Mar 15, 2014 12:28 am

BillyNoah, thanks for clarifying those issues.

I was making the changes to this file:

Code: Select all

catalog/controller/product/product.php
But I did think that it couldn't be a bug in those files- otherwise other people would be getting these errors too.

Looking through the xml files, I have just realized that it must be this file I should be editing:

Code: Select all

vqmod/xml/category_breadcrumb.xml
Here is the code for that file:

Code: Select all

<modification>
	<id>Always display categories in breadcrumb trail</id>
	<author>Casey Faber</author>
	<email>kc@caseyfaber.com</email>
	
	<file name="catalog/model/catalog/product.php">
		<operation>
			<search position="before" index="1"><![CDATA[public function getTotalProducts($data = array()) {]]></search>
			<add><![CDATA[
        public function getCategoriesByProductId($product_id) {
          $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");

          return $query->rows;
        }
      ]]></add>
		</operation>
	</file>
	
	<file name="catalog/controller/product/product.php">
		<operation>
			<search position="before"><![CDATA[public function upload() {]]></search>
			<add><![CDATA[
        protected function getPath($parent_id, $current_path = '') {
					$category_info = $this->model_catalog_category->getCategory($category['category_id']);
					$category_info = $this->model_catalog_category->getCategory($parent_id);
				
					if ($category_info) {
						if (!$current_path) {
							$new_path = $category_info['category_id'];
						} else {
							$new_path = $category_info['category_id'] . '_' . $current_path;
						}	
					
						$path = $this->getPath($category_info['parent_id'], $new_path);
								
						if ($path) {
							return $path;
						} else {
							return $new_path;
						}
					}
				}
      ]]></add>
		</operation>
		<operation>
			<search position="after"><![CDATA[if ($product_info) {]]></search>
			<add><![CDATA[
        if(!isset($category_info)) {
          $categories = $this->model_catalog_product->getCategoriesByProductId($this->request->get['product_id']);
          if($categories) {
            foreach($categories as $category){
              $path = $this->getPath($category['category_id']);
              $category_info = $this->model_catalog_category->getCategory($category['category_id']);
              if($path){
                $cat_path = $path;
              }else{
                $cat_path = $category_info['category_id'];
              }

              if($category_info) {
                $path = '';
                foreach (explode('_', $cat_path) as $path_id) {
                  if (!$path) {
                    $path = $path_id;
                  } else {
                    $path .= '_' . $path_id;
                  }

                  $category_info = $this->model_catalog_category->getCategory($path_id);

                  if ($category_info) {
                    $this->data['breadcrumbs'][] = array(
                      'text'      => $category_info['name'],
                      'href'      => $this->url->link('product/category', '&path=' . $path),
                      'separator' => $this->language->get('text_separator')
                    );
                  }
                }
                break;
              }

            }
          }
        }
      ]]></add>
		</operation>
	</file>
	
</modification>
I would really appreciate it if anyone could take a look and see what needs changing.

Thank you

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by billynoah » Sat Mar 15, 2014 12:42 am

It appears you've moddified that vqmod code. Try downloading it again. Also, you may want to restore your controller files to their original state if you've made any changes.

I've used the same vQmod in the past with no issues.

Do you have any other vQmods affecting the product controller?

Image


User avatar
Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Khal » Sat Mar 15, 2014 12:52 am

Thanks for the quick reply BillyNoah.

Do you mean download vqmod again?

And how can I restore the controller files? Yes I did make changes to that one file

Code: Select all

catalog/controller/product/product
(oops)

Will I need to download it from an OpenCart installation? But can I/how do I just replace one file?

No I think this is the only vqmod affecting the product controller, apart from a mobile theme I have installed.

https:KhaleejiAbaya.Com
OC 2.0.1.1


Active Member

Posts

Joined
Thu May 24, 2012 9:24 pm
Location - Teesside, UK

Post by billynoah » Sat Mar 15, 2014 12:58 am

Did your theme replace the product controller? Could be a theme conflict.

To restore controller files just download your version and replace the controller you modded with the original.. unless you're using a controller which was supplied by your theme, in which case you should use your theme's controller.

Image


User avatar
Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm
Who is online

Users browsing this forum: No registered users and 47 guests