Post by Khal » Sat Mar 15, 2014 10:25 pm

BillyNoah, No I don't think my theme replaced the product controller. I've checked the files I downloaded for the theme and they were just tpl and css.

I only added one extra line to the controller file code, so I just removed this line instead of having to download that file again.
So the product.php file is back to how it was originally, but I am still 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
Where line 800 is this line:

Code: Select all

$category_info = $this->model_catalog_category->getCategory($category_id)

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 10:51 pm

thanks Khal,

I think that must be an old error. There is no variable called $category used on that line.

Delete all vqcache files and all error logs. Now see if the error comes back. If it does, please paste or attach the entire cached controller file in question along with the new error log. There is no way to analyze an error like this based on a single line of code.
Last edited by billynoah on Sat Mar 15, 2014 11:23 pm, edited 1 time in total.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by billynoah » Sat Mar 15, 2014 10:55 pm

Also, you apparently did not re-download that Category Breadcrumb vQmod as I suggested because that line of code does not match with the syntax of the current version.

As I said before, let's please work with the original files before you attempted to edit them in order to resolve this. Download again the original vQmod, install it, and trash the one you have.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Khal » Sat Mar 15, 2014 11:17 pm

Thanks BillyNoah,

I've done all of that now- deleted the cache files and error logs.

Yes I forgot that Category Breadcrumb vqmod was an extension which I downloaded. Ive replaced it with a fresh download.

Sorry for not following your instructions properly.

The error seems to have gone away for now... but that line of code that was giving the error is also in this file on line 52.

Thank you for that- fingers crossed the error does not come back

OC 2.0.1.1


Active Member

Posts

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

Post by Khal » Sun Mar 16, 2014 11:07 pm

Oh no :( Now the original error is back:

Code: Select all

Undefined index: category_id in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 188
Here is the code for the cached file:

Code: Select all

vqcache/vq2-catalog_controller_product_product.php
The file was too big to add to the message, so I have only added up to line 215. If you need the whole code, I will attach it as a notepad file.

Line 188 is:

Code: Select all

}else{
                $cat_path = $category_info['category_id'];

Code: Select all

<?php  
class ControllerProductProduct extends Controller {
	private $error = array(); 

	public function index() { 
		$this->language->load('product/product');

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),			
			'separator' => false
		);

		$this->load->model('catalog/category');	

		if(isset($this->session->data['errors'])) {
			$this->data['errors'] = $this->session->data['errors'];
		}
		if($this->isVisitorMobile()) {
			$this->language->load('omf/common');
		}
			

		if (isset($this->request->get['path'])) {
			$path = '';

			$parts = explode('_', (string)$this->request->get['path']);

			$category_id = (int)array_pop($parts);

			foreach ($parts 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')
					);
				}
			}

			// Set the last category breadcrumb
			 $category_info = $this->model_catalog_category->getCategory($category_id);

			if ($category_info) {			
				$url = '';

				if (isset($this->request->get['sort'])) {
					$url .= '&sort=' . $this->request->get['sort'];
				}	

				if (isset($this->request->get['order'])) {
					$url .= '&order=' . $this->request->get['order'];
				}	

				if (isset($this->request->get['page'])) {
					$url .= '&page=' . $this->request->get['page'];
				}

				if (isset($this->request->get['limit'])) {
					$url .= '&limit=' . $this->request->get['limit'];
				}

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

		$this->load->model('catalog/manufacturer');	

		if (isset($this->request->get['manufacturer_id'])) {
			$this->data['breadcrumbs'][] = array( 
				'text'      => $this->language->get('text_brand'),
				'href'      => $this->url->link('product/manufacturer'),
				'separator' => $this->language->get('text_separator')
			);	

			$url = '';

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}	

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}	

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			if (isset($this->request->get['limit'])) {
				$url .= '&limit=' . $this->request->get['limit'];
			}

			$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);

			if ($manufacturer_info) {	
				$this->data['breadcrumbs'][] = array(
					'text'	    => $manufacturer_info['name'],
					'href'	    => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url),					
					'separator' => $this->language->get('text_separator')
				);
			}
		}

		if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
			$url = '';

			if (isset($this->request->get['search'])) {
				$url .= '&search=' . $this->request->get['search'];
			}

			if (isset($this->request->get['tag'])) {
				$url .= '&tag=' . $this->request->get['tag'];
			}

			if (isset($this->request->get['description'])) {
				$url .= '&description=' . $this->request->get['description'];
			}

			if (isset($this->request->get['category_id'])) {
				$url .= '&category_id=' . $this->request->get['category_id'];
			}	

			if (isset($this->request->get['sub_category'])) {
				$url .= '&sub_category=' . $this->request->get['sub_category'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}	

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			if (isset($this->request->get['limit'])) {
				$url .= '&limit=' . $this->request->get['limit'];
			}

			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_search'),
				'href'      => $this->url->link('product/search', $url),
				'separator' => $this->language->get('text_separator')
			); 	
		}

		if (isset($this->request->get['product_id'])) {
			$product_id = (int)$this->request->get['product_id'];
		} else {
			$product_id = 0;
		}

		$this->load->model('catalog/product');

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

		if ($product_info) {

        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;
              }

            }
          }
        }
These are all original files and this is the same error I have been getting for a while. Please help!

OC 2.0.1.1


Active Member

Posts

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

Post by billynoah » Mon Mar 17, 2014 1:25 am

Khal wrote:These are all original files
First of all the controller you pasted differs slightly from the standard 1.5.6.1 controller. Are you sure you don't have other vQmods installed?

For instance, what is this?

Code: Select all

 if($this->isVisitorMobile()) {
             $this->language->load('omf/common');
          }
It's definitely not part of the standard installation. Although that code isn't the reason for your error, I'm just trying to illustrate that the code you pasted is not a standard controller and if it differs here, it likely differs in other places. You've either got other vQmods affecting is or the original file is modified. Either one could be causing issues.

Secondly, and this is my best guess about the source of your problem, the only way I was able to reproduce that error locally was by deliberately messing up the "product_to_category" table in my database by adding a row for a product with category id which doesn't exist in the category table. I would suggest checking that table in your db and see if you have any category id's which don't actually exist in the category table.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Khal » Mon Mar 17, 2014 1:47 am

Yes I have a mobile theme installed, which is where that code must be from.

Sorry for the dumb question, but where is the database and the category table?

Many thanks again for your help and your quick replies.

OC 2.0.1.1


Active Member

Posts

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

Post by billynoah » Mon Mar 17, 2014 1:59 am

you can access the database with a client like sequel pro or phpymadmin. but you'd better know what you are doing before messing around with your database. the potential to wreak havoc here is high.

if you have the budget, you might want to consider hiring someone to debug this for you. The error itself if relatively benign, but it's possibly indicative of deeper problems like errors in your database or theme conflicts. You can choose to ignore it and I could even tell you how to mod that code to make it stop showing up, but the thing is, if all is well you shouldn't be getting errors to begin with. The error is your friend and it's helping alert you to a problem. better to understand whats causing this and solve the problem at it's root than to sweep it under the rug.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Khal » Mon Mar 17, 2014 2:07 am

Thank you for your patience with me and explaining things so clearly.

I have taken a look at the database through phpMyAdmin and yes I really do not want to be changing anything there because I do not know what I am doing.

I think it must be a conflict with my mobile theme. This was a paid theme so I am hoping they can provide support and try to resolve this error.

I agree, I should not be getting any errors and I would like them resolve them as and when they appear.

If the mobile developers can't resolve it then I will look into getting paid help to debug.

Many, many thanks again for your time, patience, and excellent advice. :) :) :)

OC 2.0.1.1


Active Member

Posts

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

Post by melbagnato » Mon Mar 17, 2014 11:36 am

Hi Khal,

I've just caught up on reading this since I last posted.

You do have modifications to your file, if you read my response on Thu Mar 13, 2014 1:04 am you will see that I found two lines that declare a value for "$category_info". Whether that was manually changed or via a vqmod I am not sure (you should be able to find this out by sending me a list of the files in your "vqmod\xml" directory.

The fix I proposed on Thu Mar 13, 2014 1:12 pm will overcome any issues with you having a category_id missing, as the default value of "0" is in the default database.

I still believe you have a vqmod file that is messing around with your code. If you want to send me some admin credentials via a PM I can take a look and work it out 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 » Mon Mar 17, 2014 10:00 pm

Thank you Mel, I have sent you a PM.

The modifications must be from a vqmod I have for a mobile theme.

The code you gave did overcome the issue of the missing category_id, but then I starting getting an error about a missing category.

I have sent you a list of my vqmod/xml files in a PM.

Many thanks

OC 2.0.1.1


Active Member

Posts

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

Post by billynoah » Tue Mar 18, 2014 12:33 am

@melbagnato - Did you read over this thread since you last visited? It's great that you are offering to look at this for free but just want to make sure that you understand this is almost certainly a database issue and not a code issue. I've used the vQmod which is throwing those errors and even went over the scenario in which they appear in a post above.

Patching his code with conditional statements as you mentioned previously will stop the errors from showing up but won't address the root cause of this, which is probably erroneous category id's in the product_to_category table. i don't think you'd want to go changing code which is not broken because of a database issue.

good luck

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Khal » Tue Mar 18, 2014 1:36 am

Thanks guys, for trying to resolve this issue for me correctly.

I am really confused now. The mobile theme developer says that the error is a coding issue in the vqmod

Code: Select all

category_breadcrumb.xml
, on line 89, which adds that line of code giving the error.

But BillyNoah- you also have that extension and you are not getting this error, right?

I really don't want to be messing around with things as it might cause more problems ???

OC 2.0.1.1


Active Member

Posts

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

Post by billynoah » Tue Mar 18, 2014 1:52 am

Funny they should say so since the vQmod has exactly 88 lines of code. Of course it must be line 89! Lol.

Khal, as far as I can tell there is nothing wrong with the code in that extension, nor with your controller. The error happens because the vQmod queries a category id which doesn't exist and then returns an empty array. My bet is this is a database issue and I've shed as much light on this as I possibly can without looking at your site first hand.

You can add conditional statements to work around it but then you are not solving the source of your problem only suppressing an error which will continue to exist, and probably creating more errors or breaking other bits of code as you experienced before when you tried another suggestion.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by melbagnato » Tue Mar 18, 2014 9:17 am

Hi billynoah,

you may be right about the database issue, and I'll confirm that when I take a look. But either way there are coding issues (if you look at my post on Wed Jan 13, 2010 3:39).

I'm not recommending that the code gets modified just to hide the errors, I was explaining some issues with the code, which hasn't been written to check for values before using them, nor having a default value if none is found.

Khal, I'll post my findings once I've had a chance to review this code & database later today.

- 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 billynoah » Tue Mar 18, 2014 9:27 am

I understand and thanks for explaining. Happy debugging :-)

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by melbagnato » Tue Mar 18, 2014 2:24 pm

Hi Khal,

I have found and solved your problem.

You had a product (product 122 called Blue-Tie-Maxi-Dress that was assigned to 3 categories. Unfortunately, one of these was disabled (category 67 called "Maxi Dresses"). So when the following line of code executed

Code: Select all

$category_info = $this->model_catalog_category->getCategory($parent_id);
a null value is returned for that category (because the query filters to only show active categories) and this null value was stored in the $category_id variable.

This is used later and causes the exception. The error message below is caused as the "category_breadcrumb.xml" file uses the $category_info variable, but does not check if this variable is populated:

Code: Select all

PHP Notice:  Undefined index: category_id in /home/khaleeji/public_html/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 188
Since you are not using that category for any other product, and since it is disabled, I have removed that category from your "Blue-Tie-Maxi-Dress" product. This will stop the error from occurring, but you must make sure you don't assign any more products to disabled categories until the bug has been fixed by the vqmod author.

Whomever coded your category_breadcrumb.xml vqmod file needs to add some additional checks for disabled categories or null $category_id values.

Also, I have installed a vQModerator in your administrator's console here. It will help you manage your vqmods better.

If this fixes your issue, please add [solved] to the subject line of your post.

- 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 billynoah » Tue Mar 18, 2014 2:58 pm

Awesome work Melbagnato!

You are 100% on point and I'm going to contribute to the cause by offering an updated function to the category_breadcrumb vQmod which won't return disabled categories:

Code: Select all

public function getCategoriesByProductId($product_id) {
          $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category ptc LEFT JOIN " . DB_PREFIX . "category c ON (ptc.category_id = c.category_id) WHERE ptc.product_id = '" . (int)$product_id . "' AND c.status = '1'");

          return $query->rows;
        }
Replace that query in the first part of the xml and it should only return active categories.

Cheers

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Khal » Tue Mar 18, 2014 4:58 pm

Mel:

That is absolutely fantastic! Thank you so much for spending your time locating and fixing this error, and for explaining it so well. I am so grateful to you.

I will remove all disabled categories and be very careful when assigning products to categories. I will also add the fix by BillyNoah- thank you for adding that BillyNoah.

The VqModerator is such a cool extension- thank you for adding that. Now the files can be checked from the admin panel.

Again, thank you so much for your patience, perseverance and time in resolving this for me. I am so grateful that OC has such knowledgeable developers who are willing to give their time to help people like me. :) :) :)

OC 2.0.1.1


Active Member

Posts

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

Post by stokeyblokey » Sun Nov 13, 2016 7:39 pm

Brilliant work Melbagnato and billynoah, I just tripped over this issue with the category_breadcrumb.xml code after having to disable several categories on my store which had active products.

Mel's investigation confirmed it was the same issue, and Billy's code snippet did the trick - this post may be old, but it is worth a bump to give props to you guys :yahoo:

Stokey


User avatar
Active Member

Posts

Joined
Sat Aug 31, 2013 10:19 pm
Who is online

Users browsing this forum: No registered users and 341 guests