Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Category image support
givanzb927f17c2b5f
diff --git a/app/component/content/categories.php b/app/component/content/categories.phpindex 8025dd1..cea2551 100755--- a/app/component/content/categories.php+++ b/app/component/content/categories.php@@ -25,20 +25,25 @@ namespace Vvveb\Component\Content;use Vvveb\Sql\CategorySQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;+use Vvveb\System\Images;use function Vvveb\url;class Categories extends ComponentBase {public static $defaultOptions = [- 'start' => 0,- 'limit' => 7,- 'site_id' => NULL,- 'language_id' => NULL,- 'taxonomy_id' => NULL,- 'post_id' => NULL,- 'parent_id' => NULL,- 'search' => NULL,- 'type' => 'categories',- 'post_type' => 'post',+ 'start' => 0,+ 'limit' => 7,+ 'site_id' => NULL,+ 'order' => ['url', 'price asc'],+ 'taxonomy_id' => NULL,+ 'post_id' => NULL,+ 'parent_id' => NULL,+ 'search' => NULL,+ 'type' => 'categories',+ 'post_type' => 'post',+ 'count' => false, //include number of posts+ 'parents_only' => false,+ 'parents_children_only' => false,+ 'parents_without_children' => false,];function results() {@@ -55,8 +60,18 @@ class Categories extends ComponentBase {$category['children'] = 0;}+ if (isset($category['post_type'])) {+ $category['type'] = $category['post_type'];+ }++ //$category['count'] = $category['count'] ?? 0;+$category['url'] = url('content/category/index', $category);+ if (isset($category['image'])) {+ $category['image_url'] = Images::image($category['image'], 'taxonomy_item');+ }+if ($parent_id > 0 && isset($results['categories'][$parent_id])) {$parent = &$results['categories'][$parent_id];@@ -73,4 +88,39 @@ class Categories extends ComponentBase {return $results;}++ //called on each request+ function request(&$results, $index = 0) {+ $module = \Vvveb\getModuleName();+ $categoryId = false;++ switch ($module) {+ case 'product/category':+ $categoryId = $this->request->get['category_id'] ?? '';++ break;+ }++ if (isset($results['categories']) && $categoryId) {+ $categories = &$results['categories'];+ //traverse array in reverse to also set parents as active+ $category = end($categories);++ while ($category !== false) {+ if ($categoryId == $category['taxonomy_item_id']) {+ $key = key($categories);+ $categories[$key]['active'] = true;+ //$category['active'] = true;+ $categoryId = $category['parent_id'];++ if (! $categoryId) {+ break;+ }+ }+ $category = prev($categories);+ }+ }++ return $results;+ }}