News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Category Image

Started by sscheidegger, October 28, 2011, 09:46:40 AM

Previous topic - Next topic

sscheidegger

Hi everybody

I'm using an output override to change the look of the category view. My goal is to display on top the category image and description and then below list the products of that category. Everything works fine apart from the category image. I tried many things, but I didn't manage to fetch the category image! (The one which is shown as a thumbnail in the parent category or the categories view!)

I display the category description using echo $this->category->category_description;
I thought it would be straight forward to use echo $this->category->images[0]->displayMediaThumb(''); for the image. However, this doesn't work. I found out that there are no images in $this->category...

Does anybody know how to do this? I imagine sth. like going to the parent of the category and then to the correct child and fetch the image. Or even starting from the root and parsing all categories until I find the correct one and fetch it's image?

Greets Stefan

PRO

<?php echo $category->images[0]->displayMediaThumb("",false); ?>

HAVE you looked around in the view files?

sscheidegger

$category is used to list the subcategories:
foreach ( $this->category->children as $category ) {...}

So, I'm trying to achieve what is very easy for the subcategories (or the products of the category), just for the current category. Either it's very simple and I just don't see it for some reason, or the structure doesn't allow to easily access the images of the current category??? I checked the various views (categories, category, productdetails), but the straight forward solution doesn't work...

PRO

try this

<?php echo $this->category->file_url_thumb ?>


That might not be right,
BUT you will be able to use file_url_thumb    easier.



sscheidegger

Thanks for the hint. Unfortunately, there is also no $this->category->file_url_thumb as well as there is no $this->category->image[0]... I'm starting to think if this thread should go to bug reports!

For analysing what information is available, I inserted the following line somewhere on top of category/default.php: <?php print_r($this->category); ?> To explain the problem, I'm adding it's output for two different pages:

In VM FE I go to the category view of the "Power Tools" (example data). This category has two child categories: "Outdoor Tools" and "Indoor Tools". In the output of print_r I see all the information for the images of these two child categories. However I don't find the information for the image of "Power Tools"!

TableCategories Object ( [virtuemart_category_id] => 2 [virtuemart_vendor_id] => 1 [category_name] => Power Tools [slug] => Power_Tools [category_description] => Power Tools [category_template] => [category_layout] => [category_product_layout] => [products_per_row] => 4 [ordering] => 2 [shared] => 0 [limit_list_start] => [limit_list_step] => [limit_list_max] => [limit_list_initial] => [metadesc] => [metakey] => [metarobot] => [metaauthor] => [published] => 1 [_pkey:protected] => [_pkeyForm:protected] => [_obkeys:protected] => Array ( [category_name] => Category in record is missing ! Can't save the record with no Category. [slug] => The given Sef Alias already exists. ) [_unique:protected] => 1 [_unique_name:protected] => Array ( [slug] => The given Sef Alias already exists. ) [_orderingKey:protected] => ordering [_slugAutoName:protected] => category_name [_slugName:protected] => slug [_loggable:protected] => 1 [_tablePreFix] => c. [_tbl:protected] => #__virtuemart_categories [_tbl_key:protected] => virtuemart_category_id [_db:protected] => JDatabaseMySQLi Object ( [name] => mysqli [nameQuote:protected] => ` [nullDate:protected] => 0000-00-00 00:00:00 [connection:protected] => mysqli Object ( [affected_rows] => 1 [client_info] => 5.1.49 [client_version] => 50149 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [field_count] => 2 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => 5.1.49-3 [server_version] => 50149 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 4954 [warning_count] => 0 ) [count:protected] => 0 [cursor:protected] => mysqli_result Object
Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Property access is not allowed yet in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Property access is not allowed yet in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71
( [current_field] => [field_count] => [lengths] => [num_rows] => [type] => ) [debug:protected] => [limit:protected] => 0 [log:protected] => Array ( ) [offset:protected] => 0 [sql:protected] => SELECT DISTINCT `#__virtuemart_manufacturers`.`mf_name`,`#__virtuemart_manufacturers`.`virtuemart_manufacturer_id` FROM `#__virtuemart_manufacturers` LEFT JOIN `#__virtuemart_product_manufacturers` ON `#__virtuemart_manufacturers`.`virtuemart_manufacturer_id` = `#__virtuemart_product_manufacturers`.`virtuemart_manufacturer_id` WHERE `#__virtuemart_product_manufacturers`.`virtuemart_product_id` in (8,10) ORDER BY `#__virtuemart_manufacturers`.`mf_name` [tablePrefix:protected] => jad4h_ [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [hasQuoted:protected] => [quoted:protected] => Array ( ) ) [_trackAssets:protected] => [_rules:protected] => [_locked:protected] => [_errors:protected] => Array ( ) [hits] => 0 [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 0000-00-00 00:00:00 [modified_by] => 0 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [virtuemart_media_id] => Array ( [0] => 2 ) [haschildren] => 1 [children] => Array ( [0] => stdClass Object ( [virtuemart_category_id] => 4 [virtuemart_vendor_id] => 1 [category_name] => Outdoor Tools [slug] => Outdoor_Tools [category_description] => Outdoor Tools [category_template] => [category_layout] => [category_product_layout] => [products_per_row] => 1 [limit_list_start] => [limit_list_step] => [limit_list_max] => [limit_list_initial] => [hits] => 0 [metadesc] => [metakey] => [metarobot] => [metaauthor] => [ordering] => 4 [shared] => 0 [published] => 1 [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 0000-00-00 00:00:00 [modified_by] => 0 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [virtuemart_media_id] => Array ( [0] => 4 ) [images] => Array ( [0] => VmImage Object ( [media_attributes] => file_is_product_image [setRole] => [_foldersToTest:VmMediaHandler:private] => Array ( [0] => /var/www/CH/images/stories/virtuemart/category/ [1] => /var/www/CH/images/stories/virtuemart/category/resized/ ) [_actions:VmMediaHandler:private] => Array ( ) [_attributes:VmMediaHandler:private] => Array ( ) [_hidden:VmMediaHandler:private] => Array ( ) [virtuemart_media_id] => 4 [theme_url] => http://mypage.dyndns.org/CH/components/com_virtuemart/ [virtuemart_vendor_id] => 1 [file_title] => wooden shovel [file_description] => [file_meta] => [file_mimetype] => image/jpeg [file_type] => category [file_url] => images/stories/virtuemart/category/1b0c96d67abdbea648cd0ea96fd6abcb.jpg [file_url_thumb] => images/stories/virtuemart/category/resized/1b0c96d67abdbea648cd0ea96fd6abcb_90x90.jpg [published] => 1 [file_is_downloadable] => 0 [file_is_forSale] => 0 [file_is_product_image] => 1 [shared] => 0 [file_params] => [_tablePreFix] => [ordering] => [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 0000-00-00 00:00:00 [modified_by] => 0 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [file_url_folder] => images/stories/virtuemart/category/ [file_path_folder] => images/stories/virtuemart/category/ [file_url_folder_thumb] => images/stories/virtuemart/category/resized/ [file_name] => 1b0c96d67abdbea648cd0ea96fd6abcb [file_extension] => jpg ) ) ) [1] => stdClass Object ( [virtuemart_category_id] => 5 [virtuemart_vendor_id] => 1 [category_name] => Indoor Tools [slug] => Indoor_Tools [category_description] => Indoor Tools [category_template] => [category_layout] => [category_product_layout] => [products_per_row] => 1 [limit_list_start] => [limit_list_step] => [limit_list_max] => [limit_list_initial] => [hits] => 0 [metadesc] => [metakey] => [metarobot] => [metaauthor] => [ordering] => 5 [shared] => 0 [published] => 1 [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 0000-00-00 00:00:00 [modified_by] => 0 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [virtuemart_media_id] => Array ( [0] => 5 ) [images] => Array ( [0] => VmImage Object ( [media_attributes] => file_is_product_image [setRole] => [_foldersToTest:VmMediaHandler:private] => Array ( [0] => /var/www/CH/images/stories/virtuemart/product/ [1] => /var/www/CH/images/stories/virtuemart/product/resized/ ) [_actions:VmMediaHandler:private] => Array ( ) [_attributes:VmMediaHandler:private] => Array ( ) [_hidden:VmMediaHandler:private] => Array ( ) [virtuemart_media_id] => 5 [theme_url] => http://mypage.dyndns.org/CH/components/com_virtuemart/ [virtuemart_vendor_id] => 1 [file_title] => black shovel [file_description] => the [file_meta] => [file_mimetype] => image/jpeg [file_type] => product [file_url] => images/stories/virtuemart/product/520efefd6d7977f91b16fac1149c7438.jpg [file_url_thumb] => images/stories/virtuemart/product/resized/520efefd6d7977f91b16fac1149c7438_90x90.jpg [published] => 1 [file_is_downloadable] => 0 [file_is_forSale] => 0 [file_is_product_image] => 1 [shared] => 0 [file_params] => [_tablePreFix] => [ordering] => [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 0000-00-00 00:00:00 [modified_by] => 0 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [file_url_folder] => images/stories/virtuemart/product/ [file_path_folder] => images/stories/virtuemart/product/ [file_url_folder_thumb] => images/stories/virtuemart/product/resized/ [file_name] => 520efefd6d7977f91b16fac1149c7438 [file_extension] => jpg ) ) ) ) [productcount] => 2 [parents] => Array ( [0] => stdClass Object ( [category_name] => Power Tools [virtuemart_category_id] => 2 ) ) )



Further I go to the category view of "Indoor Tools". It doesn't have any subcategories, but one product ("Drill"). Here the output of print_r($this->category) doesn't contain any image information! (The product images are in $this->products.)
TableCategories Object ( [virtuemart_category_id] => 5 [virtuemart_vendor_id] => 1 [category_name] => Indoor Tools [slug] => Indoor_Tools [category_description] => Indoor Tools [category_template] => [category_layout] => [category_product_layout] => [products_per_row] => 1 [ordering] => 5 [shared] => 0 [limit_list_start] => [limit_list_step] => [limit_list_max] => [limit_list_initial] => [metadesc] => [metakey] => [metarobot] => [metaauthor] => [published] => 1 [_pkey:protected] => [_pkeyForm:protected] => [_obkeys:protected] => Array ( [category_name] => Category in record is missing ! Can't save the record with no Category. [slug] => The given Sef Alias already exists. ) [_unique:protected] => 1 [_unique_name:protected] => Array ( [slug] => The given Sef Alias already exists. ) [_orderingKey:protected] => ordering [_slugAutoName:protected] => category_name [_slugName:protected] => slug [_loggable:protected] => 1 [_tablePreFix] => c. [_tbl:protected] => #__virtuemart_categories [_tbl_key:protected] => virtuemart_category_id [_db:protected] => JDatabaseMySQLi Object ( [name] => mysqli [nameQuote:protected] => ` [nullDate:protected] => 0000-00-00 00:00:00 [connection:protected] => mysqli Object ( [affected_rows] => 4 [client_info] => 5.1.49 [client_version] => 50149 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [field_count] => 3 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => 5.1.49-3 [server_version] => 50149 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 5019 [warning_count] => 0 ) [count:protected] => 0 [cursor:protected] => mysqli_result Object
Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Property access is not allowed yet in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71

Warning: print_r() [function.print-r]: Property access is not allowed yet in /var/www/CH/templates/mytemplate/html/com_virtuemart/category/default.php on line 71
( [current_field] => [field_count] => [lengths] => [num_rows] => [type] => ) [debug:protected] => [limit:protected] => 0 [log:protected] => Array ( ) [offset:protected] => 0 [sql:protected] => SELECT `virtuemart_permgroup_id`,`group_name`,`group_level` FROM `#__virtuemart_permgroups` ORDER BY `group_level` [tablePrefix:protected] => jad4h_ [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [hasQuoted:protected] => [quoted:protected] => Array ( ) ) [_trackAssets:protected] => [_rules:protected] => [_locked:protected] => [_errors:protected] => Array ( ) [hits] => 0 [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 0000-00-00 00:00:00 [modified_by] => 0 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [virtuemart_media_id] => Array ( [0] => 5 ) [haschildren] => [children] => Array ( ) [productcount] => 1 [parents] => Array ( [0] => stdClass Object ( [category_name] => Power Tools [virtuemart_category_id] => 2 ) [1] => stdClass Object ( [category_name] => Indoor Tools [virtuemart_category_id] => 5 ) ) )


In the end I analysed the output of print_r($this) and didn't find the category image information. So I conclude that

  • either the information is not stored int $this but somewhere else and I don't know where
  • or the information is not available (bug? not intended?)
  • or there is something in $this which I missed!

Anybody an idea, what might be the correct conclusion?

PRO

try this


<?php echo $this->category->images[0]->file_url_thumb; ?>


sscheidegger

$this->category->images[...] is not defined, as you can see in the above output of print_r(). Therefore echo $this->category->images[0]->file_url_thumb; returns and empty string.

Movs

In category or categories  view  (/components/com_virtuemart/views/category>view.html.php) you should add after line   $category = $categoryModel->getCategory($categoryId);
this string:
$categoryModel->addImages($category);

Then you can access a category image in your template^ $this->category->images[0]->file_url_thumb

The bast way is to use like this
if ($this->category->virtuemart_media_id) echo $this->category->images[0]->displayMediaFull("", false);


scotous

#8
I can confirm that the solution provided by @Movs did work but only for the 1st VM2.

I cant get it working in VM2 2.0.1h
havent tried at 2.0.1n yet...

any clues?


It does work in VM2 2.0.1h i had a problem with my core files... works in all vm2

sscheidegger

Has been fixed in VM 2.0.6.