Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Category featured module added with theme
- Loading branch information
1 parent
3a71840
commit 5e359d8
Showing
6 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,179 @@ | |||
<?php | |||
class ControllerExtensionModuleFeaturedCategory extends Controller { | |||
private $error = array(); | |||
|
|||
public function index() { | |||
$this->load->language('extension/module/featuredcategory'); | |||
|
|||
$this->document->setTitle($this->language->get('heading_title')); | |||
|
|||
$this->load->model('setting/module'); | |||
|
|||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { | |||
if (!isset($this->request->get['module_id'])) { | |||
$this->model_setting_module->addModule('featuredcategory', $this->request->post); | |||
} else { | |||
$this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); | |||
} | |||
|
|||
$this->session->data['success'] = $this->language->get('text_success'); | |||
|
|||
$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module')); | |||
} | |||
|
|||
if (isset($this->error['warning'])) { | |||
$data['error_warning'] = $this->error['warning']; | |||
} else { | |||
$data['error_warning'] = ''; | |||
} | |||
|
|||
if (isset($this->error['name'])) { | |||
$data['error_name'] = $this->error['name']; | |||
} else { | |||
$data['error_name'] = ''; | |||
} | |||
|
|||
if (isset($this->error['width'])) { | |||
$data['error_width'] = $this->error['width']; | |||
} else { | |||
$data['error_width'] = ''; | |||
} | |||
|
|||
if (isset($this->error['height'])) { | |||
$data['error_height'] = $this->error['height']; | |||
} else { | |||
$data['error_height'] = ''; | |||
} | |||
|
|||
$data['breadcrumbs'] = array(); | |||
|
|||
$data['breadcrumbs'][] = array( | |||
'text' => $this->language->get('text_home'), | |||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | |||
); | |||
|
|||
$data['breadcrumbs'][] = array( | |||
'text' => $this->language->get('text_extension'), | |||
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module') | |||
); | |||
|
|||
if (!isset($this->request->get['module_id'])) { | |||
$data['breadcrumbs'][] = array( | |||
'text' => $this->language->get('heading_title'), | |||
'href' => $this->url->link('extension/module/featuredcategory', 'user_token=' . $this->session->data['user_token']) | |||
); | |||
} else { | |||
$data['breadcrumbs'][] = array( | |||
'text' => $this->language->get('heading_title'), | |||
'href' => $this->url->link('extension/module/featuredcategory', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']) | |||
); | |||
} | |||
|
|||
if (!isset($this->request->get['module_id'])) { | |||
$data['action'] = $this->url->link('extension/module/featuredcategory', 'user_token=' . $this->session->data['user_token']); | |||
} else { | |||
$data['action'] = $this->url->link('extension/module/featuredcategory', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']); | |||
} | |||
|
|||
$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module'); | |||
|
|||
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { | |||
$module_info = $this->model_setting_module->getModule($this->request->get['module_id']); | |||
} | |||
|
|||
$data['user_token'] = $this->session->data['user_token']; | |||
|
|||
if (isset($this->request->post['name'])) { | |||
$data['name'] = $this->request->post['name']; | |||
} elseif (!empty($module_info)) { | |||
$data['name'] = $module_info['name']; | |||
} else { | |||
$data['name'] = ''; | |||
} | |||
|
|||
$this->load->model('catalog/category'); | |||
|
|||
$data['categories'] = array(); | |||
|
|||
|
|||
|
|||
|
|||
if (!empty($this->request->post['categoriesadded'])) { | |||
$categories = $this->request->post['categoriesadded']; | |||
} elseif (!empty($module_info['categoriesadded'])) { | |||
$categories = $module_info['categoriesadded']; | |||
} else { | |||
$categories = array(); | |||
} | |||
|
|||
|
|||
foreach ($categories as $category_id) { | |||
$category_info = $this->model_catalog_category->getCategory($category_id); | |||
|
|||
if ($category_info) { | |||
$data['categories'][] = array( | |||
'category_id' => $category_info['category_id'], | |||
'name' => $category_info['name'] | |||
); | |||
} | |||
} | |||
|
|||
if (isset($this->request->post['limit'])) { | |||
$data['limit'] = $this->request->post['limit']; | |||
} elseif (!empty($module_info)) { | |||
$data['limit'] = $module_info['limit']; | |||
} else { | |||
$data['limit'] = 5; | |||
} | |||
|
|||
if (isset($this->request->post['width'])) { | |||
$data['width'] = $this->request->post['width']; | |||
} elseif (!empty($module_info)) { | |||
$data['width'] = $module_info['width']; | |||
} else { | |||
$data['width'] = 200; | |||
} | |||
|
|||
if (isset($this->request->post['height'])) { | |||
$data['height'] = $this->request->post['height']; | |||
} elseif (!empty($module_info)) { | |||
$data['height'] = $module_info['height']; | |||
} else { | |||
$data['height'] = 200; | |||
} | |||
|
|||
if (isset($this->request->post['status'])) { | |||
$data['status'] = $this->request->post['status']; | |||
} elseif (!empty($module_info)) { | |||
$data['status'] = $module_info['status']; | |||
} else { | |||
$data['status'] = ''; | |||
} | |||
|
|||
$data['header'] = $this->load->controller('common/header'); | |||
$data['column_left'] = $this->load->controller('common/column_left'); | |||
$data['footer'] = $this->load->controller('common/footer'); | |||
|
|||
$this->response->setOutput($this->load->view('extension/module/featuredcategory', $data)); | |||
} | |||
|
|||
protected function validate() { | |||
if (!$this->user->hasPermission('modify', 'extension/module/featuredcategory')) { | |||
$this->error['warning'] = $this->language->get('error_permission'); | |||
} | |||
|
|||
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { | |||
$this->error['name'] = $this->language->get('error_name'); | |||
} | |||
|
|||
if (!$this->request->post['width']) { | |||
$this->error['width'] = $this->language->get('error_width'); | |||
} | |||
|
|||
if (!$this->request->post['height']) { | |||
$this->error['height'] = $this->language->get('error_height'); | |||
} | |||
|
|||
return !$this->error; | |||
} | |||
} |
25 changes: 25 additions & 0 deletions
25
admin/language/en-gb/extension/module/featuredcategory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
<?php | |||
// Heading | |||
$_['heading_title'] = 'Featured Category'; | |||
|
|||
// Text | |||
$_['text_extension'] = 'Extensions'; | |||
$_['text_success'] = 'Success: You have modified Featured Category module!'; | |||
$_['text_edit'] = 'Edit Featured Category Module'; | |||
|
|||
// Entry | |||
$_['entry_name'] = 'Module Name'; | |||
$_['entry_category'] = 'Category'; | |||
$_['entry_limit'] = 'Limit'; | |||
$_['entry_width'] = 'Width'; | |||
$_['entry_height'] = 'Height'; | |||
$_['entry_status'] = 'Status'; | |||
|
|||
// Help | |||
$_['help_product'] = '(Autocomplete)'; | |||
|
|||
// Error | |||
$_['error_permission'] = 'Warning: You do not have permission to modify Featured Category module!'; | |||
$_['error_name'] = 'Module Name must be between 3 and 64 characters!'; | |||
$_['error_width'] = 'Width required!'; | |||
$_['error_height'] = 'Height required!'; |
122 changes: 122 additions & 0 deletions
122
admin/view/template/extension/module/featuredcategory.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,122 @@ | |||
{{ header }}{{ column_left }} | |||
<div id="content"> | |||
<div class="page-header"> | |||
<div class="container-fluid"> | |||
<div class="pull-right"> | |||
<button type="submit" form="form-module" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button> | |||
<a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div> | |||
<h1>{{ heading_title }}</h1> | |||
<ul class="breadcrumb"> | |||
{% for breadcrumb in breadcrumbs %} | |||
<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li> | |||
{% endfor %} | |||
</ul> | |||
</div> | |||
</div> | |||
<div class="container-fluid"> | |||
{% if error_warning %} | |||
<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }} | |||
<button type="button" class="close" data-dismiss="alert">×</button> | |||
</div> | |||
{% endif %} | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"><i class="fa fa-pencil"></i> {{ text_edit }}</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-module" class="form-horizontal"> | |||
<div class="form-group"> | |||
<label class="col-sm-2 control-label" for="input-name">{{ entry_name }}</label> | |||
<div class="col-sm-10"> | |||
<input type="text" name="name" value="{{ name }}" placeholder="{{ entry_name }}" id="input-name" class="form-control"/> | |||
{% if error_name %} | |||
<div class="text-danger">{{ error_name }}</div> | |||
{% endif %} | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="col-sm-2 control-label" for="input-product"><span data-toggle="tooltip" title="{{ help_product }}">{{ entry_category }}</span></label> | |||
<div class="col-sm-10"> | |||
<input type="text" name="category_name" value="" placeholder="{{ entry_category }}" id="input-product" class="form-control"/> | |||
<div id="featured-product" class="well well-sm" style="height: 150px; overflow: auto;"> | |||
{% for category in categories %} | |||
<div id="featured-product{{ category.category_id }}"><i class="fa fa-minus-circle"></i> {{ category.name }} | |||
<input type="hidden" name="categoriesadded[]" value="{{ category.category_id }}"/> | |||
</div> | |||
{% endfor %} | |||
</div> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="col-sm-2 control-label" for="input-limit">{{ entry_limit }}</label> | |||
<div class="col-sm-10"> | |||
<input type="text" name="limit" value="{{ limit }}" placeholder="{{ entry_limit }}" id="input-limit" class="form-control"/> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="col-sm-2 control-label" for="input-width">{{ entry_width }}</label> | |||
<div class="col-sm-10"> | |||
<input type="text" name="width" value="{{ width }}" placeholder="{{ entry_width }}" id="input-width" class="form-control"/> | |||
{% if error_width %} | |||
<div class="text-danger">{{ error_width }}</div> | |||
{% endif %} | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="col-sm-2 control-label" for="input-height">{{ entry_height }}</label> | |||
<div class="col-sm-10"> | |||
<input type="text" name="height" value="{{ height }}" placeholder="{{ entry_height }}" id="input-height" class="form-control"/> | |||
{% if error_height %} | |||
<div class="text-danger">{{ error_height }}</div> | |||
{% endif %} | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label> | |||
<div class="col-sm-10"> | |||
<select name="status" id="input-status" class="form-control"> | |||
{% if status %} | |||
<option value="1" selected="selected">{{ text_enabled }}</option> | |||
<option value="0">{{ text_disabled }}</option> | |||
{% else %} | |||
<option value="1">{{ text_enabled }}</option> | |||
<option value="0" selected="selected">{{ text_disabled }}</option> | |||
{% endif %} | |||
</select> | |||
</div> | |||
</div> | |||
</form> | |||
</div> | |||
</div> | |||
</div> | |||
<script type="text/javascript"><!-- | |||
$('input[name=\'category_name\']').autocomplete({ | |||
source: function(request, response) { | |||
$.ajax({ | |||
url: 'index.php?route=catalog/category/autocomplete&user_token={{ user_token }}&filter_name=' + encodeURIComponent(request), | |||
dataType: 'json', | |||
success: function(json) { | |||
response($.map(json, function(item) { | |||
return { | |||
label: item['name'], | |||
value: item['category_id'] | |||
} | |||
})); | |||
} | |||
}); | |||
}, | |||
select: function(item) { | |||
$('input[name=\'category_name\']').val(''); | |||
$('#featured-product' + item['value']).remove(); | |||
$('#featured-product').append('<div id="featured-product' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="categoriesadded[]" value="' + item['value'] + '" /></div>'); | |||
} | |||
}); | |||
$('#featured-product').delegate('.fa-minus-circle', 'click', function() { | |||
$(this).parent().remove(); | |||
}); | |||
//--></script> | |||
</div> | |||
{{ footer }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
<?php | |||
class ControllerExtensionModuleFeaturedCategory extends Controller { | |||
public function index($setting) { | |||
$this->load->language('extension/module/featuredcategory'); | |||
|
|||
$this->load->model('catalog/category'); | |||
|
|||
$this->load->model('tool/image'); | |||
|
|||
$data['categories'] = array(); | |||
|
|||
if (!$setting['limit']) { | |||
$setting['limit'] = 4; | |||
} | |||
|
|||
if (!empty($setting['categoriesadded'])) { | |||
|
|||
$data['box_title'] = $setting['name']; | |||
|
|||
$categories_data = array(); | |||
|
|||
foreach ($setting['categoriesadded'] as $category_id) { | |||
$category_info = $this->model_catalog_category->getCategory($category_id); | |||
|
|||
if ($category_info) { | |||
$categories_data[] = $category_info; | |||
} | |||
} | |||
|
|||
$categories = array_slice($categories_data, 0, (int)$setting['limit']); | |||
|
|||
foreach ($categories as $category) { | |||
if ($category['image']) { | |||
$image = $this->model_tool_image->resize($category['image'], $setting['width'], $setting['height']); | |||
} else { | |||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']); | |||
} | |||
|
|||
$data['categories'][] = array( | |||
'category_id' => $category['category_id'], | |||
'thumb' => $image, | |||
'name' => $category['name'], | |||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category['category_id']) | |||
); | |||
} | |||
} | |||
|
|||
$data['language'] = $this->config->get('config_language'); | |||
|
|||
if ($data['categories']) { | |||
return $this->load->view('extension/module/featuredcategory', $data); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
<?php | |||
// Heading | |||
$_['heading_title'] = 'Featured Category'; |
Oops, something went wrong.