@@ -13,50 +13,50 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Category extends \Model { |
| 15 | 15 | |
| 16 | - public static $objectName = 'Категория магазина'; |
|
| 17 | - public static $treeCategory = 'Ecommerce\Item'; |
|
| 18 | - public static $cols = [ |
|
| 19 | - //Основные параметры |
|
| 20 | - 'parent_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'parent'], |
|
| 21 | - 'name' => ['type' => 'text'], |
|
| 22 | - 'alias' => ['type' => 'text'], |
|
| 23 | - 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsCategoryList', 'module' => 'Ecommerce'], |
|
| 24 | - 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesCategoryList', 'module' => 'Ecommerce'], |
|
| 25 | - 'description' => ['type' => 'html'], |
|
| 26 | - 'image_file_id' => ['type' => 'image'], |
|
| 27 | - 'options_inherit' => ['type' => 'bool'], |
|
| 28 | - //Системные |
|
| 29 | - 'imported' => ['type' => 'bool'], |
|
| 30 | - 'weight' => ['type' => 'number'], |
|
| 31 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 32 | - 'tree_path' => ['type' => 'text'], |
|
| 33 | - 'date_create' => ['type' => 'dateTime'], |
|
| 34 | - //Менеджеры |
|
| 35 | - 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
| 36 | - ]; |
|
| 37 | - public static $labels = [ |
|
| 38 | - 'name' => 'Название', |
|
| 39 | - 'alias' => 'Алиас', |
|
| 40 | - 'parent_id' => 'Родительская категория', |
|
| 41 | - 'image_file_id' => 'Изображение', |
|
| 42 | - 'description' => 'Описание', |
|
| 43 | - 'options_inherit' => 'Наследовать набор свойств', |
|
| 44 | - 'options' => 'Свойства товаров', |
|
| 45 | - ]; |
|
| 46 | - public static $forms = [ |
|
| 47 | - 'manager' => [ |
|
| 48 | - 'map' => [ |
|
| 49 | - ['name', 'alias'], |
|
| 50 | - ['parent_id', 'image_file_id'], |
|
| 51 | - ['viewer', 'template'], |
|
| 52 | - ['options_inherit'], |
|
| 53 | - ['options'], |
|
| 54 | - ['description'] |
|
| 55 | - ] |
|
| 56 | - ] |
|
| 57 | - ]; |
|
| 16 | + public static $objectName = 'Категория магазина'; |
|
| 17 | + public static $treeCategory = 'Ecommerce\Item'; |
|
| 18 | + public static $cols = [ |
|
| 19 | + //Основные параметры |
|
| 20 | + 'parent_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'parent'], |
|
| 21 | + 'name' => ['type' => 'text'], |
|
| 22 | + 'alias' => ['type' => 'text'], |
|
| 23 | + 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsCategoryList', 'module' => 'Ecommerce'], |
|
| 24 | + 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesCategoryList', 'module' => 'Ecommerce'], |
|
| 25 | + 'description' => ['type' => 'html'], |
|
| 26 | + 'image_file_id' => ['type' => 'image'], |
|
| 27 | + 'options_inherit' => ['type' => 'bool'], |
|
| 28 | + //Системные |
|
| 29 | + 'imported' => ['type' => 'bool'], |
|
| 30 | + 'weight' => ['type' => 'number'], |
|
| 31 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 32 | + 'tree_path' => ['type' => 'text'], |
|
| 33 | + 'date_create' => ['type' => 'dateTime'], |
|
| 34 | + //Менеджеры |
|
| 35 | + 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
| 36 | + ]; |
|
| 37 | + public static $labels = [ |
|
| 38 | + 'name' => 'Название', |
|
| 39 | + 'alias' => 'Алиас', |
|
| 40 | + 'parent_id' => 'Родительская категория', |
|
| 41 | + 'image_file_id' => 'Изображение', |
|
| 42 | + 'description' => 'Описание', |
|
| 43 | + 'options_inherit' => 'Наследовать набор свойств', |
|
| 44 | + 'options' => 'Свойства товаров', |
|
| 45 | + ]; |
|
| 46 | + public static $forms = [ |
|
| 47 | + 'manager' => [ |
|
| 48 | + 'map' => [ |
|
| 49 | + ['name', 'alias'], |
|
| 50 | + ['parent_id', 'image_file_id'], |
|
| 51 | + ['viewer', 'template'], |
|
| 52 | + ['options_inherit'], |
|
| 53 | + ['options'], |
|
| 54 | + ['description'] |
|
| 55 | + ] |
|
| 56 | + ] |
|
| 57 | + ]; |
|
| 58 | 58 | |
| 59 | - public static function indexes() { |
|
| 59 | + public static function indexes() { |
|
| 60 | 60 | return [ |
| 61 | 61 | 'ecommerce_category_category_parent_id' => [ |
| 62 | 62 | 'type' => 'INDEX', |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | ] |
| 72 | 72 | ], |
| 73 | 73 | ]; |
| 74 | - } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - public static function relations() { |
|
| 76 | + public static function relations() { |
|
| 77 | 77 | return [ |
| 78 | 78 | 'items' => [ |
| 79 | 79 | 'type' => 'many', |
@@ -103,50 +103,50 @@ discard block |
||
| 103 | 103 | 'col' => 'parent_id', |
| 104 | 104 | ] |
| 105 | 105 | ]; |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - public static $dataManagers = [ |
|
| 109 | - 'manager' => [ |
|
| 110 | - 'name' => 'Категории товаров', |
|
| 111 | - 'cols' => [ |
|
| 112 | - 'name', |
|
| 113 | - 'parent_id', |
|
| 114 | - ], |
|
| 115 | - 'sortMode' => true |
|
| 116 | - ] |
|
| 117 | - ]; |
|
| 108 | + public static $dataManagers = [ |
|
| 109 | + 'manager' => [ |
|
| 110 | + 'name' => 'Категории товаров', |
|
| 111 | + 'cols' => [ |
|
| 112 | + 'name', |
|
| 113 | + 'parent_id', |
|
| 114 | + ], |
|
| 115 | + 'sortMode' => true |
|
| 116 | + ] |
|
| 117 | + ]; |
|
| 118 | 118 | |
| 119 | - public function beforeSave() { |
|
| 119 | + public function beforeSave() { |
|
| 120 | 120 | if ($this->id && $this->id == $this->parent_id) { |
| 121 | - $this->parent_id = 0; |
|
| 122 | - \Msg::add('Категория не может быть сама себе родителем'); |
|
| 121 | + $this->parent_id = 0; |
|
| 122 | + \Msg::add('Категория не может быть сама себе родителем'); |
|
| 123 | + } |
|
| 123 | 124 | } |
| 124 | - } |
|
| 125 | 125 | |
| 126 | - public function beforeDelete() { |
|
| 126 | + public function beforeDelete() { |
|
| 127 | 127 | foreach ($this->catalogs as $category) { |
| 128 | - $category->delete(); |
|
| 128 | + $category->delete(); |
|
| 129 | + } |
|
| 129 | 130 | } |
| 130 | - } |
|
| 131 | 131 | |
| 132 | - public function resolveTemplate() { |
|
| 132 | + public function resolveTemplate() { |
|
| 133 | 133 | if ($this->template !== 'inherit') { |
| 134 | - return $this->template; |
|
| 134 | + return $this->template; |
|
| 135 | 135 | } elseif ($this->template == 'inherit' && $this->category) { |
| 136 | - return $this->category->resolveTemplate(true); |
|
| 136 | + return $this->category->resolveTemplate(true); |
|
| 137 | 137 | } else { |
| 138 | - return 'current'; |
|
| 138 | + return 'current'; |
|
| 139 | + } |
|
| 139 | 140 | } |
| 140 | - } |
|
| 141 | 141 | |
| 142 | - public function resolveViewer() { |
|
| 142 | + public function resolveViewer() { |
|
| 143 | 143 | if ($this->viewer !== 'inherit') { |
| 144 | - return $this->viewer; |
|
| 144 | + return $this->viewer; |
|
| 145 | 145 | } elseif ($this->viewer == 'inherit' && $this->category) { |
| 146 | - return $this->category->resolveViewer(true); |
|
| 146 | + return $this->category->resolveViewer(true); |
|
| 147 | 147 | } else { |
| 148 | - return (!empty(\App::$cur->ecommerce->config['defaultCategoryView']) ? \App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList'); |
|
| 148 | + return (!empty(\App::$cur->ecommerce->config['defaultCategoryView']) ? \App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList'); |
|
| 149 | + } |
|
| 149 | 150 | } |
| 150 | - } |
|
| 151 | 151 | |
| 152 | 152 | } |