@@ -13,82 +13,82 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Item extends \Model { |
| 15 | 15 | |
| 16 | - public static $categoryModel = 'Ecommerce\Category'; |
|
| 17 | - public static $objectName = 'Товар'; |
|
| 18 | - public static $labels = [ |
|
| 19 | - 'name' => 'Название', |
|
| 20 | - 'alias' => 'Алиас', |
|
| 21 | - 'category_id' => 'Раздел', |
|
| 22 | - 'description' => 'Описание', |
|
| 23 | - 'item_type_id' => 'Тип товара', |
|
| 24 | - 'image_file_id' => 'Изображение', |
|
| 25 | - 'best' => 'Лучшее предложение', |
|
| 26 | - 'options' => 'Параметры', |
|
| 27 | - 'offers' => 'Торговые предложения', |
|
| 28 | - 'widget' => 'Виджет для отображения в каталоге', |
|
| 29 | - 'view' => 'Шаблон для отображения полной информации', |
|
| 30 | - 'deleted' => 'Удален', |
|
| 31 | - 'imgs' => 'Фото' |
|
| 32 | - ]; |
|
| 33 | - public static $cols = [ |
|
| 34 | - //Основные параметры |
|
| 35 | - 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
| 36 | - 'image_file_id' => ['type' => 'image'], |
|
| 37 | - 'name' => ['type' => 'text'], |
|
| 38 | - 'alias' => ['type' => 'text'], |
|
| 39 | - 'description' => ['type' => 'html'], |
|
| 40 | - 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
| 41 | - 'best' => ['type' => 'bool'], |
|
| 42 | - 'deleted' => ['type' => 'bool'], |
|
| 43 | - //Системные |
|
| 44 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 45 | - 'weight' => ['type' => 'number'], |
|
| 46 | - 'sales' => ['type' => 'number'], |
|
| 47 | - 'imported' => ['type' => 'text'], |
|
| 48 | - 'tree_path' => ['type' => 'text'], |
|
| 49 | - 'search_index' => ['type' => 'text'], |
|
| 50 | - 'date_create' => ['type' => 'dateTime'], |
|
| 51 | - 'widget' => ['type' => 'text'], |
|
| 52 | - 'view' => ['type' => 'text'], |
|
| 53 | - //Менеджеры |
|
| 54 | - 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
| 55 | - 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
| 56 | - 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
| 57 | - ]; |
|
| 58 | - public static $dataManagers = [ |
|
| 59 | - 'manager' => [ |
|
| 60 | - 'name' => 'Товары', |
|
| 61 | - 'cols' => [ |
|
| 62 | - 'name', |
|
| 63 | - 'imgs', |
|
| 64 | - 'category_id', |
|
| 65 | - 'item_type_id', |
|
| 66 | - 'best', |
|
| 67 | - 'deleted', |
|
| 68 | - 'options', |
|
| 69 | - 'offers', |
|
| 70 | - ], |
|
| 71 | - 'categorys' => [ |
|
| 72 | - 'model' => 'Ecommerce\Category', |
|
| 73 | - ], |
|
| 74 | - 'sortMode' => true |
|
| 75 | - ] |
|
| 76 | - ]; |
|
| 77 | - public static $forms = [ |
|
| 78 | - 'manager' => [ |
|
| 79 | - 'map' => [ |
|
| 80 | - ['name', 'alias'], |
|
| 81 | - ['category_id', 'item_type_id', 'deleted'], |
|
| 82 | - ['widget', 'view'], |
|
| 83 | - ['best', 'image_file_id'], |
|
| 84 | - ['description'], |
|
| 85 | - ['imgs'], |
|
| 86 | - ['options'], |
|
| 87 | - ['offers'], |
|
| 88 | - ] |
|
| 89 | - ]]; |
|
| 16 | + public static $categoryModel = 'Ecommerce\Category'; |
|
| 17 | + public static $objectName = 'Товар'; |
|
| 18 | + public static $labels = [ |
|
| 19 | + 'name' => 'Название', |
|
| 20 | + 'alias' => 'Алиас', |
|
| 21 | + 'category_id' => 'Раздел', |
|
| 22 | + 'description' => 'Описание', |
|
| 23 | + 'item_type_id' => 'Тип товара', |
|
| 24 | + 'image_file_id' => 'Изображение', |
|
| 25 | + 'best' => 'Лучшее предложение', |
|
| 26 | + 'options' => 'Параметры', |
|
| 27 | + 'offers' => 'Торговые предложения', |
|
| 28 | + 'widget' => 'Виджет для отображения в каталоге', |
|
| 29 | + 'view' => 'Шаблон для отображения полной информации', |
|
| 30 | + 'deleted' => 'Удален', |
|
| 31 | + 'imgs' => 'Фото' |
|
| 32 | + ]; |
|
| 33 | + public static $cols = [ |
|
| 34 | + //Основные параметры |
|
| 35 | + 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
| 36 | + 'image_file_id' => ['type' => 'image'], |
|
| 37 | + 'name' => ['type' => 'text'], |
|
| 38 | + 'alias' => ['type' => 'text'], |
|
| 39 | + 'description' => ['type' => 'html'], |
|
| 40 | + 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
| 41 | + 'best' => ['type' => 'bool'], |
|
| 42 | + 'deleted' => ['type' => 'bool'], |
|
| 43 | + //Системные |
|
| 44 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 45 | + 'weight' => ['type' => 'number'], |
|
| 46 | + 'sales' => ['type' => 'number'], |
|
| 47 | + 'imported' => ['type' => 'text'], |
|
| 48 | + 'tree_path' => ['type' => 'text'], |
|
| 49 | + 'search_index' => ['type' => 'text'], |
|
| 50 | + 'date_create' => ['type' => 'dateTime'], |
|
| 51 | + 'widget' => ['type' => 'text'], |
|
| 52 | + 'view' => ['type' => 'text'], |
|
| 53 | + //Менеджеры |
|
| 54 | + 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
| 55 | + 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
| 56 | + 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
| 57 | + ]; |
|
| 58 | + public static $dataManagers = [ |
|
| 59 | + 'manager' => [ |
|
| 60 | + 'name' => 'Товары', |
|
| 61 | + 'cols' => [ |
|
| 62 | + 'name', |
|
| 63 | + 'imgs', |
|
| 64 | + 'category_id', |
|
| 65 | + 'item_type_id', |
|
| 66 | + 'best', |
|
| 67 | + 'deleted', |
|
| 68 | + 'options', |
|
| 69 | + 'offers', |
|
| 70 | + ], |
|
| 71 | + 'categorys' => [ |
|
| 72 | + 'model' => 'Ecommerce\Category', |
|
| 73 | + ], |
|
| 74 | + 'sortMode' => true |
|
| 75 | + ] |
|
| 76 | + ]; |
|
| 77 | + public static $forms = [ |
|
| 78 | + 'manager' => [ |
|
| 79 | + 'map' => [ |
|
| 80 | + ['name', 'alias'], |
|
| 81 | + ['category_id', 'item_type_id', 'deleted'], |
|
| 82 | + ['widget', 'view'], |
|
| 83 | + ['best', 'image_file_id'], |
|
| 84 | + ['description'], |
|
| 85 | + ['imgs'], |
|
| 86 | + ['options'], |
|
| 87 | + ['offers'], |
|
| 88 | + ] |
|
| 89 | + ]]; |
|
| 90 | 90 | |
| 91 | - public static function indexes() { |
|
| 91 | + public static function indexes() { |
|
| 92 | 92 | return [ |
| 93 | 93 | 'ecommerce_item_item_category_id' => [ |
| 94 | 94 | 'type' => 'INDEX', |
@@ -109,45 +109,45 @@ discard block |
||
| 109 | 109 | ] |
| 110 | 110 | ], |
| 111 | 111 | ]; |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - public function beforeSave() { |
|
| 114 | + public function beforeSave() { |
|
| 115 | 115 | |
| 116 | 116 | if ($this->id) { |
| 117 | - $this->search_index = $this->name . ' '; |
|
| 118 | - if ($this->category) { |
|
| 117 | + $this->search_index = $this->name . ' '; |
|
| 118 | + if ($this->category) { |
|
| 119 | 119 | $this->search_index .= $this->category->name . ' '; |
| 120 | - } |
|
| 121 | - if ($this->options) { |
|
| 120 | + } |
|
| 121 | + if ($this->options) { |
|
| 122 | 122 | foreach ($this->options as $option) { |
| 123 | - if ($option->item_option_searchable && $option->value) { |
|
| 123 | + if ($option->item_option_searchable && $option->value) { |
|
| 124 | 124 | if ($option->item_option_type != 'select') { |
| 125 | - $this->search_index .= $option->value . ' '; |
|
| 125 | + $this->search_index .= $option->value . ' '; |
|
| 126 | 126 | } elseif (!empty($option->option->items[$option->value])) { |
| 127 | - $option->option->items[$option->value]->value . ' '; |
|
| 127 | + $option->option->items[$option->value]->value . ' '; |
|
| 128 | + } |
|
| 128 | 129 | } |
| 129 | - } |
|
| 130 | 130 | } |
| 131 | - } |
|
| 132 | - if ($this->offers) { |
|
| 131 | + } |
|
| 132 | + if ($this->offers) { |
|
| 133 | 133 | foreach ($this->offers as $offer) { |
| 134 | - if ($offer->options) { |
|
| 134 | + if ($offer->options) { |
|
| 135 | 135 | foreach ($offer->options as $option) { |
| 136 | - if ($option->item_offer_option_searchable && $option->value) { |
|
| 136 | + if ($option->item_offer_option_searchable && $option->value) { |
|
| 137 | 137 | if ($option->item_offer_option_type != 'select') { |
| 138 | - $this->search_index .= $option->value . ' '; |
|
| 138 | + $this->search_index .= $option->value . ' '; |
|
| 139 | 139 | } elseif (!empty($option->option->items[$option->value])) { |
| 140 | - $option->option->items[$option->value]->value . ' '; |
|
| 140 | + $option->option->items[$option->value]->value . ' '; |
|
| 141 | + } |
|
| 141 | 142 | } |
| 142 | - } |
|
| 143 | 143 | } |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | } |
| 146 | - } |
|
| 146 | + } |
|
| 147 | + } |
|
| 147 | 148 | } |
| 148 | - } |
|
| 149 | 149 | |
| 150 | - public static function relations() { |
|
| 150 | + public static function relations() { |
|
| 151 | 151 | |
| 152 | 152 | return [ |
| 153 | 153 | 'category' => [ |
@@ -185,55 +185,55 @@ discard block |
||
| 185 | 185 | 'col' => 'user_id' |
| 186 | 186 | ] |
| 187 | 187 | ]; |
| 188 | - } |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - public function getPrice() { |
|
| 190 | + public function getPrice() { |
|
| 191 | 191 | $offers = $this->offers(['key' => false]); |
| 192 | 192 | $curPrice = null; |
| 193 | 193 | |
| 194 | 194 | foreach ($offers[0]->prices as $price) { |
| 195 | - if (!$price->type) { |
|
| 195 | + if (!$price->type) { |
|
| 196 | 196 | $curPrice = $price; |
| 197 | - } elseif ( |
|
| 198 | - (!$price->type->roles && !$curPrice) || |
|
| 197 | + } elseif ( |
|
| 198 | + (!$price->type->roles && !$curPrice) || |
|
| 199 | 199 | ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false) |
| 200 | - ) { |
|
| 200 | + ) { |
|
| 201 | 201 | $curPrice = $price; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | } |
| 204 | 204 | return $curPrice; |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - public function name() { |
|
| 207 | + public function name() { |
|
| 208 | 208 | if (!empty(\App::$primary->ecommerce->config['item_option_as_name'])) { |
| 209 | - $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
| 210 | - if ($param && $param->value) { |
|
| 209 | + $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
| 210 | + if ($param && $param->value) { |
|
| 211 | 211 | return $param->value; |
| 212 | - } |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | return $this->name; |
| 215 | - } |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - public function beforeDelete() { |
|
| 217 | + public function beforeDelete() { |
|
| 218 | 218 | if ($this->id) { |
| 219 | - if ($this->options) { |
|
| 219 | + if ($this->options) { |
|
| 220 | 220 | foreach ($this->options as $option) { |
| 221 | - $option->delete(); |
|
| 221 | + $option->delete(); |
|
| 222 | + } |
|
| 222 | 223 | } |
| 223 | - } |
|
| 224 | - if ($this->offers) { |
|
| 224 | + if ($this->offers) { |
|
| 225 | 225 | foreach ($this->offers as $offer) { |
| 226 | - $offer->delete(); |
|
| 226 | + $offer->delete(); |
|
| 227 | + } |
|
| 227 | 228 | } |
| 228 | - } |
|
| 229 | - if ($this->image) { |
|
| 229 | + if ($this->image) { |
|
| 230 | 230 | $this->image->delete(); |
| 231 | - } |
|
| 231 | + } |
|
| 232 | + } |
|
| 232 | 233 | } |
| 233 | - } |
|
| 234 | 234 | |
| 235 | - public function getHref() { |
|
| 235 | + public function getHref() { |
|
| 236 | 236 | return "/ecommerce/view/{$this->pk()}"; |
| 237 | - } |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | } |
@@ -114,17 +114,17 @@ discard block |
||
| 114 | 114 | public function beforeSave() { |
| 115 | 115 | |
| 116 | 116 | if ($this->id) { |
| 117 | - $this->search_index = $this->name . ' '; |
|
| 117 | + $this->search_index = $this->name.' '; |
|
| 118 | 118 | if ($this->category) { |
| 119 | - $this->search_index .= $this->category->name . ' '; |
|
| 119 | + $this->search_index .= $this->category->name.' '; |
|
| 120 | 120 | } |
| 121 | 121 | if ($this->options) { |
| 122 | 122 | foreach ($this->options as $option) { |
| 123 | 123 | if ($option->item_option_searchable && $option->value) { |
| 124 | 124 | if ($option->item_option_type != 'select') { |
| 125 | - $this->search_index .= $option->value . ' '; |
|
| 125 | + $this->search_index .= $option->value.' '; |
|
| 126 | 126 | } elseif (!empty($option->option->items[$option->value])) { |
| 127 | - $option->option->items[$option->value]->value . ' '; |
|
| 127 | + $option->option->items[$option->value]->value.' '; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | foreach ($offer->options as $option) { |
| 136 | 136 | if ($option->item_offer_option_searchable && $option->value) { |
| 137 | 137 | if ($option->item_offer_option_type != 'select') { |
| 138 | - $this->search_index .= $option->value . ' '; |
|
| 138 | + $this->search_index .= $option->value.' '; |
|
| 139 | 139 | } elseif (!empty($option->option->items[$option->value])) { |
| 140 | - $option->option->items[$option->value]->value . ' '; |
|
| 140 | + $option->option->items[$option->value]->value.' '; |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | 'col' => 'item_id', |
| 161 | 161 | //'resultKey' => 'code', |
| 162 | 162 | 'resultKey' => 'item_option_id', |
| 163 | - 'join' => [Item\Option::table(), Item\Option::index() . ' = ' . Item\Param::colPrefix() . Item\Option::index()] |
|
| 163 | + 'join' => [Item\Option::table(), Item\Option::index().' = '.Item\Param::colPrefix().Item\Option::index()] |
|
| 164 | 164 | ], |
| 165 | 165 | 'offers' => [ |
| 166 | 166 | 'type' => 'many', |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $curPrice = $price; |
| 197 | 197 | } elseif ( |
| 198 | 198 | (!$price->type->roles && !$curPrice) || |
| 199 | - ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false) |
|
| 199 | + ($price->type->roles && !$curPrice && strpos($price->type->roles, "|".\Users\User::$cur->role_id."|") !== false) |
|
| 200 | 200 | ) { |
| 201 | 201 | $curPrice = $price; |
| 202 | 202 | } |