Back to Opencart

File admin\controller\catalog\attribute_group.php

docs/api/source-admin.controller.catalog.attribute_group.html

4.1.0.319.9 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Catalog; | | 3: | /** | | 4: | * Class Attribute Group | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Catalog | | 7: | */ | | 8: | class AttributeGroup extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('catalog/attribute_group'); | | 16: | | | 17: | $this->document->setTitle($this->language->get('heading_title')); | | 18: | | | 19: | $url = ''; | | 20: | | | 21: | if (isset($this->request->get['sort'])) { | | 22: | $url .= '&sort=' . $this->request->get['sort']; | | 23: | } | | 24: | if (isset($this->request->get['order'])) { | | 25: | $url .= '&order=' . $this->request->get['order']; | | 26: | } | | 27: | | | 28: | if (isset($this->request->get['page'])) { | | 29: | $url .= '&page=' . $this->request->get['page']; | | 30: | } | | 31: | | | 32: | $data['breadcrumbs'] = []; | | 33: | | | 34: | $data['breadcrumbs'][] = [ | | 35: | 'text' => $this->language->get('text_home'), | | 36: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 37: | ]; | | 38: | | | 39: | $data['breadcrumbs'][] = [ | | 40: | 'text' => $this->language->get('heading_title'), | | 41: | 'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url) | | 42: | ]; | | 43: | | | 44: | $data['add'] = $this->url->link('catalog/attribute_group.form', 'user_token=' . $this->session->data['user_token'] . $url); | | 45: | $data['delete'] = $this->url->link('catalog/attribute_group.delete', 'user_token=' . $this->session->data['user_token']); | | 46: | | | 47: | $data['list'] = $this->controller_catalog_attribute_group->getList(); | | 48: | | | 49: | $data['user_token'] = $this->session->data['user_token']; | | 50: | | | 51: | $data['header'] = $this->load->controller('common/header'); | | 52: | $data['column_left'] = $this->load->controller('common/column_left'); | | 53: | $data['footer'] = $this->load->controller('common/footer'); | | 54: | | | 55: | $this->response->setOutput($this->load->view('catalog/attribute_group', $data)); | | 56: | } | | 57: | | | 58: | /** | | 59: | * List | | 60: | * | | 61: | * @return void | | 62: | */ | | 63: | public function list(): void { | | 64: | $this->load->language('catalog/attribute_group'); | | 65: | | | 66: | $this->response->setOutput($this->controller_catalog_attribute_group->getList()); | | 67: | } | | 68: | | | 69: | /** | | 70: | * Get List | | 71: | * | | 72: | * @return string | | 73: | */ | | 74: | protected function getList(): string { | | 75: | if (isset($this->request->get['sort'])) { | | 76: | $sort = (string)$this->request->get['sort']; | | 77: | } else { | | 78: | $sort = 'agd.name'; | | 79: | } | | 80: | | | 81: | if (isset($this->request->get['order'])) { | | 82: | $order = (string)$this->request->get['order']; | | 83: | } else { | | 84: | $order = 'ASC'; | | 85: | } | | 86: | | | 87: | if (isset($this->request->get['page'])) { | | 88: | $page = (int)$this->request->get['page']; | | 89: | } else { | | 90: | $page = 1; | | 91: | } | | 92: | | | 93: | $url = ''; | | 94: | | | 95: | if (isset($this->request->get['sort'])) { | | 96: | $url .= '&sort=' . $this->request->get['sort']; | | 97: | } | | 98: | | | 99: | if (isset($this->request->get['order'])) { | | 100: | $url .= '&order=' . $this->request->get['order']; | | 101: | } | | 102: | | | 103: | if (isset($this->request->get['page'])) { | | 104: | $url .= '&page=' . $this->request->get['page']; | | 105: | } | | 106: | | | 107: | $data['action'] = $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . $url); | | 108: | | | 109: | $data['attribute_groups'] = []; | | 110: | | | 111: | $filter_data = [ | | 112: | 'sort' => $sort, | | 113: | 'order' => $order, | | 114: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'), | | 115: | 'limit' => $this->config->get('config_pagination_admin') | | 116: | ]; | | 117: | | | 118: | $this->load->model('catalog/attribute_group'); | | 119: | | | 120: | $results = $this->model_catalog_attribute_group->getAttributeGroups($filter_data); | | 121: | | | 122: | foreach ($results as $result) { | | 123: | $data['attribute_groups'][] = [ | | 124: | 'attribute_group_id' => $result['attribute_group_id'], | | 125: | 'name' => $result['name'], | | 126: | 'sort_order' => $result['sort_order'], | | 127: | 'edit' => $this->url->link('catalog/attribute_group.form', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $result['attribute_group_id'] . $url) | | 128: | ]; | | 129: | } | | 130: | | | 131: | $url = ''; | | 132: | | | 133: | if ($order == 'ASC') { | | 134: | $url .= '&order=DESC'; | | 135: | } else { | | 136: | $url .= '&order=ASC'; | | 137: | } | | 138: | | | 139: | $data['sort_name'] = $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . '&sort=agd.name' . $url); | | 140: | $data['sort_sort_order'] = $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . '&sort=ag.sort_order' . $url); | | 141: | | | 142: | $url = ''; | | 143: | | | 144: | if (isset($this->request->get['sort'])) { | | 145: | $url .= '&sort=' . $this->request->get['sort']; | | 146: | } | | 147: | | | 148: | if (isset($this->request->get['order'])) { | | 149: | $url .= '&order=' . $this->request->get['order']; | | 150: | } | | 151: | | | 152: | $attribute_group_total = $this->model_catalog_attribute_group->getTotalAttributeGroups(); | | 153: | | | 154: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 155: | 'total' => $attribute_group_total, | | 156: | 'page' => $page, | | 157: | 'limit' => $this->config->get('config_pagination_admin'), | | 158: | 'url' => $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}') | | 159: | ]); | | 160: | | | 161: | $data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_group_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($attribute_group_total - $this->config->get('config_pagination_admin'))) ? $attribute_group_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $attribute_group_total, ceil($attribute_group_total / $this->config->get('config_pagination_admin'))); | | 162: | | | 163: | $data['sort'] = $sort; | | 164: | $data['order'] = $order; | | 165: | | | 166: | return $this->load->view('catalog/attribute_group_list', $data); | | 167: | } | | 168: | | | 169: | /** | | 170: | * Form | | 171: | * | | 172: | * @return void | | 173: | */ | | 174: | public function form(): void { | | 175: | $this->load->language('catalog/attribute_group'); | | 176: | | | 177: | $this->document->setTitle($this->language->get('heading_title')); | | 178: | | | 179: | $data['text_form'] = !isset($this->request->get['attribute_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); | | 180: | | | 181: | $url = ''; | | 182: | | | 183: | if (isset($this->request->get['sort'])) { | | 184: | $url .= '&sort=' . $this->request->get['sort']; | | 185: | } | | 186: | | | 187: | if (isset($this->request->get['order'])) { | | 188: | $url .= '&order=' . $this->request->get['order']; | | 189: | } | | 190: | | | 191: | if (isset($this->request->get['page'])) { | | 192: | $url .= '&page=' . $this->request->get['page']; | | 193: | } | | 194: | | | 195: | $data['breadcrumbs'] = []; | | 196: | | | 197: | $data['breadcrumbs'][] = [ | | 198: | 'text' => $this->language->get('text_home'), | | 199: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 200: | ]; | | 201: | | | 202: | $data['breadcrumbs'][] = [ | | 203: | 'text' => $this->language->get('heading_title'), | | 204: | 'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url) | | 205: | ]; | | 206: | | | 207: | $data['save'] = $this->url->link('catalog/attribute_group.save', 'user_token=' . $this->session->data['user_token']); | | 208: | $data['back'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url); | | 209: | | | 210: | if (isset($this->request->get['attribute_group_id'])) { | | 211: | $this->load->model('catalog/attribute_group'); | | 212: | | | 213: | $attribute_group_info = $this->model_catalog_attribute_group->getAttributeGroup($this->request->get['attribute_group_id']); | | 214: | } | | 215: | | | 216: | if (isset($this->request->get['attribute_group_id'])) { | | 217: | $data['attribute_group_id'] = (int)$this->request->get['attribute_group_id']; | | 218: | } else { | | 219: | $data['attribute_group_id'] = 0; | | 220: | } | | 221: | | | 222: | $this->load->model('localisation/language'); | | 223: | | | 224: | $data['languages'] = $this->model_localisation_language->getLanguages(); | | 225: | | | 226: | if (isset($this->request->get['attribute_group_id'])) { | | 227: | $data['attribute_group_description'] = $this->model_catalog_attribute_group->getDescriptions($this->request->get['attribute_group_id']); | | 228: | } else { | | 229: | $data['attribute_group_description'] = []; | | 230: | } | | 231: | | | 232: | if (!empty($attribute_group_info)) { | | 233: | $data['sort_order'] = $attribute_group_info['sort_order']; | | 234: | } else { | | 235: | $data['sort_order'] = ''; | | 236: | } | | 237: | | | 238: | $data['user_token'] = $this->session->data['user_token']; | | 239: | | | 240: | $data['header'] = $this->load->controller('common/header'); | | 241: | $data['column_left'] = $this->load->controller('common/column_left'); | | 242: | $data['footer'] = $this->load->controller('common/footer'); | | 243: | | | 244: | $this->response->setOutput($this->load->view('catalog/attribute_group_form', $data)); | | 245: | } | | 246: | | | 247: | /** | | 248: | * Save | | 249: | * | | 250: | * @return void | | 251: | */ | | 252: | public function save(): void { | | 253: | $this->load->language('catalog/attribute_group'); | | 254: | | | 255: | $json = []; | | 256: | | | 257: | if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) { | | 258: | $json['error']['warning'] = $this->language->get('error_permission'); | | 259: | } | | 260: | | | 261: | foreach ($this->request->post['attribute_group_description'] as $language_id => $value) { | | 262: | if (!oc_validate_length($value['name'], 1, 64)) { | | 263: | $json['error']['name_' . $language_id] = $this->language->get('error_name'); | | 264: | } | | 265: | } | | 266: | | | 267: | if (isset($json['error']) && !isset($json['error']['warning'])) { | | 268: | $json['error']['warning'] = $this->language->get('error_warning'); | | 269: | } | | 270: | | | 271: | if (!$json) { | | 272: | $this->load->model('catalog/attribute_group'); | | 273: | | | 274: | if (!$this->request->post['attribute_group_id']) { | | 275: | $json['attribute_group_id'] = $this->model_catalog_attribute_group->addAttributeGroup($this->request->post); | | 276: | } else { | | 277: | $this->model_catalog_attribute_group->editAttributeGroup($this->request->post['attribute_group_id'], $this->request->post); | | 278: | } | | 279: | | | 280: | $json['success'] = $this->language->get('text_success'); | | 281: | } | | 282: | | | 283: | $this->response->addHeader('Content-Type: application/json'); | | 284: | $this->response->setOutput(json_encode($json)); | | 285: | } | | 286: | | | 287: | /** | | 288: | * Delete | | 289: | * | | 290: | * @return void | | 291: | */ | | 292: | public function delete(): void { | | 293: | $this->load->language('catalog/attribute_group'); | | 294: | | | 295: | $json = []; | | 296: | | | 297: | if (isset($this->request->post['selected'])) { | | 298: | $selected = $this->request->post['selected']; | | 299: | } else { | | 300: | $selected = []; | | 301: | } | | 302: | | | 303: | if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) { | | 304: | $json['error'] = $this->language->get('error_permission'); | | 305: | } | | 306: | | | 307: | $this->load->model('catalog/attribute'); | | 308: | | | 309: | foreach ($selected as $attribute_group_id) { | | 310: | $attribute_total = $this->model_catalog_attribute->getTotalAttributesByAttributeGroupId($attribute_group_id); | | 311: | | | 312: | if ($attribute_total) { | | 313: | $json['error'] = sprintf($this->language->get('error_attribute'), $attribute_total); | | 314: | } | | 315: | } | | 316: | | | 317: | if (!$json) { | | 318: | $this->load->model('catalog/attribute_group'); | | 319: | | | 320: | foreach ($selected as $attribute_group_id) { | | 321: | $this->model_catalog_attribute_group->deleteAttributeGroup($attribute_group_id); | | 322: | } | | 323: | | | 324: | $json['success'] = $this->language->get('text_success'); | | 325: | } | | 326: | | | 327: | $this->response->addHeader('Content-Type: application/json'); | | 328: | $this->response->setOutput(json_encode($json)); | | 329: | } | | 330: | } | | 331: | |

OpenCart API API documentation generated by ApiGen dev-master