This my manufacturer.php(controller file)
<?php
class ControllerProductManufacturer extends Controller {
public function index() {
$this->load->language('product/manufacturer');
$this->load->model('catalog/manufacturer');
$this->load->model('tool/image');
$this->document->setTitle($this->language->get('heading_title'));
$data['heading_title'] = $this->language->get('heading_title');
$data['text_index'] = $this->language->get('text_index');
$data['text_empty'] = $this->language->get('text_empty');
$data['button_continue'] = $this->language->get('button_continue');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_brand'),
'href' => $this->url->link('product/manufacturer')
);
$data['categories'] = array();
$results = $this->model_catalog_manufacturer->getManufacturers();
foreach ($results as $result) {
if (is_numeric(utf8_substr($result['name'], 0, 1))) {
$key = '0 - 9';
} else {
$key = utf8_substr(utf8_strtoupper($result['name']), 0, 1);
}
if (!isset($data['categories'][$key])) {
$data['categories'][$key]['name'] = $key;
}
$data['categories'][$key]['manufacturer'][] = array(
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
);
}
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/manufacturer_list.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/manufacturer_list.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/manufacturer_list.tpl', $data));
}
}
public function info() {
$this->load->language('product/manufacturer');
$this->load->model('catalog/manufacturer');
$this->load->model('catalog/product');
$this->load->model('tool/image');
if (isset($this->request->get['manufacturer_id'])) {
$manufacturer_id = (int)$this->request->get['manufacturer_id'];
} else {
$manufacturer_id = 0;
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
if (isset($this->request->get['limit'])) {
$limit = $this->request->get['limit'];
} else {
$limit = $this->config->get('config_product_limit');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_brand'),
'href' => $this->url->link('product/manufacturer')
);
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if ($manufacturer_info) {
$this->document->setTitle($manufacturer_info['name']);
$this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id']), 'canonical');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $manufacturer_info['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
);
$data['heading_title'] = $manufacturer_info['name'];
$data['text_empty'] = $this->language->get('text_empty');
$data['text_quantity'] = $this->language->get('text_quantity');
$data['text_manufacturer'] = $this->language->get('text_manufacturer');
$data['text_model'] = $this->language->get('text_model');
$data['text_price'] = $this->language->get('text_price');
$data['text_weight'] = $this->language->get('text_weight');
$data['text_tax'] = $this->language->get('text_tax');
$data['text_points'] = $this->language->get('text_points');
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
$data['text_sort'] = $this->language->get('text_sort');
$data['text_limit'] = $this->language->get('text_limit');
$data['button_cart'] = $this->language->get('button_cart');
$data['button_wishlist'] = $this->language->get('button_wishlist');
$data['button_compare'] = $this->language->get('button_compare');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_list'] = $this->language->get('button_list');
$data['button_grid'] = $this->language->get('button_grid');
$data['compare'] = $this->url->link('product/compare');
$data['products'] = array();
$filter_data = array(
'filter_manufacturer_id' => $manufacturer_id,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = (int)$result['rating'];
} else {
$rating = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'weight' => $result['weight'],
'weight_class'=> $result['weight_class'],
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'] . $url)
);
}
$url = '';
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['sorts'] = array();
$data['sorts'][] = array(
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url)
);
if ($this->config->get('config_review_status')) {
$data['sorts'][] = array(
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=DESC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=ASC' . $url)
);
}
$data['sorts'][] = array(
'text' => $this->language->get('text_model_asc'),
'value' => 'p.model-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_model_desc'),
'value' => 'p.model-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url)
);
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['limits'] = array();
$limits = array_unique(array($this->config->get('config_product_limit'), 25, 50, 75, 100));
sort($limits);
foreach($limits as $value) {
$data['limits'][] = array(
'text' => $value,
'value' => $value,
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $value)
);
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->url = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}');
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/manufacturer_info.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/manufacturer_info.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/manufacturer_info.tpl', $data));
}
} else {
$url = '';
if (isset($this->request->get['manufacturer_id'])) {
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_error'),
'href' => $this->url->link('product/manufacturer/info', $url)
);
$this->document->setTitle($this->language->get('text_error'));
$data['heading_title'] = $this->language->get('text_error');
$data['text_error'] = $this->language->get('text_error');
$data['button_continue'] = $this->language->get('button_continue');
$data['continue'] = $this->url->link('common/home');
$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
$data['header'] = $this->load->controller('common/header');
$data['footer'] = $this->load->controller('common/footer');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/error/not_found.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/error/not_found.tpl', $data));
}
}
}
}
And this my html code(manufacturer.tpl file)
this code get all manufactures from db and displays in frontend via manufacturer.php(controller).
<?php echo $category['manufacturer'][$i]['name']; ?>
BUT i want to display the above html code into my header.tpl(html)file but it displays undefined variable.i cannot access that manufacturer,so please help me how to display manufacturer value in header.tpl file using my header.php(controller).
this my header.php controller code:
<?php
class ControllerCommonHeader extends Controller {
public function index() {
$data['title'] = $this->document->getTitle();
if ($this->request->server['HTTPS']) {
$server = $this->config->get('config_ssl');
} else {
$server = $this->config->get('config_url');
}
$data['base'] = $server;
$data['description'] = $this->document->getDescription();
$data['keywords'] = $this->document->getKeywords();
$data['links'] = $this->document->getLinks();
$data['styles'] = $this->document->getStyles();
$data['scripts'] = $this->document->getScripts();
$data['lang'] = $this->language->get('code');
$data['direction'] = $this->language->get('direction');
if ($this->config->get('config_google_analytics_status')) {
$data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8');
} else {
$data['google_analytics'] = '';
}
$data['name'] = $this->config->get('config_name');
if (is_file(DIR_IMAGE . $this->config->get('config_icon'))) {
$data['icon'] = $server . 'image/' . $this->config->get('config_icon');
} else {
$data['icon'] = '';
}
if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
$data['logo'] = $server . 'image/' . $this->config->get('config_logo');
} else {
$data['logo'] = '';
}
$this->load->language('common/header');
$data['text_home'] = $this->language->get('text_home');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
$data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
$data['text_account'] = $this->language->get('text_account');
$data['text_register'] = $this->language->get('text_register');
$data['text_login'] = $this->language->get('text_login');
$data['text_order'] = $this->language->get('text_order');
$data['text_transaction'] = $this->language->get('text_transaction');
$data['text_download'] = $this->language->get('text_download');
$data['text_logout'] = $this->language->get('text_logout');
$data['text_checkout'] = $this->language->get('text_checkout');
$data['text_category'] = $this->language->get('text_category');
$data['text_all'] = $this->language->get('text_all');
$data['home'] = $this->url->link('common/home');
$data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
$data['logged'] = $this->customer->isLogged();
$data['account'] = $this->url->link('account/account', '', 'SSL');
$data['register'] = $this->url->link('account/register', '', 'SSL');
$data['login'] = $this->url->link('account/login', '', 'SSL');
$data['order'] = $this->url->link('account/order', '', 'SSL');
$data['transaction'] = $this->url->link('account/transaction', '', 'SSL');
$data['download'] = $this->url->link('account/download', '', 'SSL');
$data['logout'] = $this->url->link('account/logout', '', 'SSL');
$data['shopping_cart'] = $this->url->link('checkout/cart');
$data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
$data['contact'] = $this->url->link('information/contact');
$data['telephone'] = $this->config->get('config_telephone');
$status = true;
if (isset($this->request->server['HTTP_USER_AGENT'])) {
$robots = explode("\n", str_replace(array("\r\n", "\r"), "\n", trim($this->config->get('config_robots'))));
foreach ($robots as $robot) {
if ($robot && strpos($this->request->server['HTTP_USER_AGENT'], trim($robot)) !== false) {
$status = false;
break;
}
}
}
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');
// For page specific css
if (isset($this->request->get['route'])) {
if (isset($this->request->get['product_id'])) {
$class = '-' . $this->request->get['product_id'];
} elseif (isset($this->request->get['path'])) {
$class = '-' . $this->request->get['path'];
} elseif (isset($this->request->get['manufacturer_id'])) {
$class = '-' . $this->request->get['manufacturer_id'];
} else {
$class = '';
}
$data['class'] = str_replace('/', '-', $this->request->get['route']) . $class;
} else {
$data['class'] = 'common-home';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/header.tpl', $data);
} else {
return $this->load->view('default/template/common/header.tpl', $data);
}
}
}
And this my header.tpl file:
<li><?php echo $category['manufacturer'][$i]['name']; ?></li>
Here is your header.php code
<?php
class ControllerCommonHeader extends Controller {
public function index() {
$data['title'] = $this->document->getTitle();
if ($this->request->server['HTTPS']) {
$server = $this->config->get('config_ssl');
} else {
$server = $this->config->get('config_url');
}
$data['base'] = $server;
$data['description'] = $this->document->getDescription();
$data['keywords'] = $this->document->getKeywords();
$data['links'] = $this->document->getLinks();
$data['styles'] = $this->document->getStyles();
$data['scripts'] = $this->document->getScripts();
$data['lang'] = $this->language->get('code');
$data['direction'] = $this->language->get('direction');
if ($this->config->get('config_google_analytics_status')) {
$data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8');
} else {
$data['google_analytics'] = '';
}
$data['name'] = $this->config->get('config_name');
if (is_file(DIR_IMAGE . $this->config->get('config_icon'))) {
$data['icon'] = $server . 'image/' . $this->config->get('config_icon');
} else {
$data['icon'] = '';
}
if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
$data['logo'] = $server . 'image/' . $this->config->get('config_logo');
} else {
$data['logo'] = '';
}
$this->load->language('common/header');
$data['text_home'] = $this->language->get('text_home');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
$data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
$data['text_account'] = $this->language->get('text_account');
$data['text_register'] = $this->language->get('text_register');
$data['text_login'] = $this->language->get('text_login');
$data['text_order'] = $this->language->get('text_order');
$data['text_transaction'] = $this->language->get('text_transaction');
$data['text_download'] = $this->language->get('text_download');
$data['text_logout'] = $this->language->get('text_logout');
$data['text_checkout'] = $this->language->get('text_checkout');
$data['text_category'] = $this->language->get('text_category');
$data['text_all'] = $this->language->get('text_all');
$data['home'] = $this->url->link('common/home');
$data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
$data['logged'] = $this->customer->isLogged();
$data['account'] = $this->url->link('account/account', '', 'SSL');
$data['register'] = $this->url->link('account/register', '', 'SSL');
$data['login'] = $this->url->link('account/login', '', 'SSL');
$data['order'] = $this->url->link('account/order', '', 'SSL');
$data['transaction'] = $this->url->link('account/transaction', '', 'SSL');
$data['download'] = $this->url->link('account/download', '', 'SSL');
$data['logout'] = $this->url->link('account/logout', '', 'SSL');
$data['shopping_cart'] = $this->url->link('checkout/cart');
$data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
$data['contact'] = $this->url->link('information/contact');
$data['telephone'] = $this->config->get('config_telephone');
$status = true;
if (isset($this->request->server['HTTP_USER_AGENT'])) {
$robots = explode("\n", str_replace(array("\r\n", "\r"), "\n", trim($this->config->get('config_robots'))));
foreach ($robots as $robot) {
if ($robot && strpos($this->request->server['HTTP_USER_AGENT'], trim($robot)) !== false) {
$status = false;
break;
}
}
}
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');
// For page specific css
if (isset($this->request->get['route'])) {
if (isset($this->request->get['product_id'])) {
$class = '-' . $this->request->get['product_id'];
} elseif (isset($this->request->get['path'])) {
$class = '-' . $this->request->get['path'];
} elseif (isset($this->request->get['manufacturer_id'])) {
$class = '-' . $this->request->get['manufacturer_id'];
} else {
$class = '';
}
$data['class'] = str_replace('/', '-', $this->request->get['route']) . $class;
} else {
$data['class'] = 'common-home';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/header.tpl', $data);
} else {
return $this->load->view('default/template/common/header.tpl', $data);
}
}
// I have added this
$data['categories'] = array();
$results = $this->model_catalog_manufacturer->getManufacturers();
foreach ($results as $result) {
if (is_numeric(utf8_substr($result['name'], 0, 1))) {
$key = '0 - 9';
} else {
$key = utf8_substr(utf8_strtoupper($result['name']), 0, 1);
}
if (!isset($data['categories'][$key])) {
$data['categories'][$key]['name'] = $key;
}
$data['categories'][$key]['manufacturer'][] = array(
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
);
}
}
I believe that sessions would be the best solution for this
You can fetch and store all data in your model only and then put it in $_SESSION super-variable
$this->load->library('session');
$_SESSION['anything']=$your-data;
echo $_SESSION['anything'];
this will work please check..
<?php
class ControllerCommonHeader extends Controller {
public function index() {
$data['title'] = $this->document->getTitle();
if ($this->request->server['HTTPS']) {
$server = $this->config->get('config_ssl');
} else {
$server = $this->config->get('config_url');
}
$data['base'] = $server;
$data['description'] = $this->document->getDescription();
$data['keywords'] = $this->document->getKeywords();
$data['links'] = $this->document->getLinks();
$data['styles'] = $this->document->getStyles();
$data['scripts'] = $this->document->getScripts();
$data['lang'] = $this->language->get('code');
$data['direction'] = $this->language->get('direction');
if ($this->config->get('config_google_analytics_status')) {
$data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8');
} else {
$data['google_analytics'] = '';
}
$data['name'] = $this->config->get('config_name');
if (is_file(DIR_IMAGE . $this->config->get('config_icon'))) {
$data['icon'] = $server . 'image/' . $this->config->get('config_icon');
} else {
$data['icon'] = '';
}
if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
$data['logo'] = $server . 'image/' . $this->config->get('config_logo');
} else {
$data['logo'] = '';
}
$this->load->language('common/header');
$data['text_home'] = $this->language->get('text_home');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
$data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
$data['text_account'] = $this->language->get('text_account');
$data['text_register'] = $this->language->get('text_register');
$data['text_login'] = $this->language->get('text_login');
$data['text_order'] = $this->language->get('text_order');
$data['text_transaction'] = $this->language->get('text_transaction');
$data['text_download'] = $this->language->get('text_download');
$data['text_logout'] = $this->language->get('text_logout');
$data['text_checkout'] = $this->language->get('text_checkout');
$data['text_category'] = $this->language->get('text_category');
$data['text_all'] = $this->language->get('text_all');
$data['manufacturer'] = $this->language->get('manufacturer');
$data['home'] = $this->url->link('common/home');
$data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
$data['logged'] = $this->customer->isLogged();
$data['account'] = $this->url->link('account/account', '', 'SSL');
$data['register'] = $this->url->link('account/register', '', 'SSL');
$data['login'] = $this->url->link('account/login', '', 'SSL');
$data['order'] = $this->url->link('account/order', '', 'SSL');
$data['transaction'] = $this->url->link('account/transaction', '', 'SSL');
$data['download'] = $this->url->link('account/download', '', 'SSL');
$data['logout'] = $this->url->link('account/logout', '', 'SSL');
$data['shopping_cart'] = $this->url->link('checkout/cart');
$data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
$data['contact'] = $this->url->link('information/contact');
$data['telephone'] = $this->config->get('config_telephone');
$status = true;
if (isset($this->request->server['HTTP_USER_AGENT'])) {
$robots = explode("\n", str_replace(array("\r\n", "\r"), "\n", trim($this->config->get('config_robots'))));
foreach ($robots as $robot) {
if ($robot && strpos($this->request->server['HTTP_USER_AGENT'], trim($robot)) !== false) {
$status = false;
break;
}
}
}
$this->load->model('catalog/manufacturer');
$results = $this->model_catalog_manufacturer->getManufacturers();
$data['manufacturer'] = array();
foreach ($results as $result) {
$data['manufacturer'][] = array(
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
);
}
//print_r($data['manufacturer']);exit;
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');
// For page specific css
if (isset($this->request->get['route'])) {
if (isset($this->request->get['product_id'])) {
$class = '-' . $this->request->get['product_id'];
} elseif (isset($this->request->get['path'])) {
$class = '-' . $this->request->get['path'];
} elseif (isset($this->request->get['manufacturer_id'])) {
$class = '-' . $this->request->get['manufacturer_id'];
} else {
$class = '';
}
$data['class'] = str_replace('/', '-', $this->request->get['route']) . $class;
} else {
$data['class'] = 'common-home';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/header.tpl', $data);
} else {
return $this->load->view('default/template/common/header.tpl', $data);
}
}
}
put this tpl code into your file:
<?php foreach ($manufacturer as $manufacturers) { ?>
<?php if ($manufacturers['name']){ ?>
<li><?php echo $manufacturers['name']; ?></li>
<?php }?>
<?php }?>
It will depend on the circumstances. If you want to retain the data for some time, then session data would be the way to go. However, if you only need to use it once, flash data might be more appropriate.
First step would be to initialize the session library:
$this->load->library('session');
Then store the information in flash data:
$this->session->set_flashdata('item', $myVar);
Finally, in the second controller, fetch the data:
$myVar = $this->session->flashdata('item');
Obviously this would mean you'd have to either initialize the session library again from the second controller, or create your own base controller that loads the session library and have both of your controllers inherit from that one.
Related
I have a school web app that has an online exam feature## Heading ##Students are given a number of times they can attempt the exam.
However, when a student attempts the exam two or more times and saves, the scores are duplicated in the database instead of being updated.
I will like that when a student attempts an exam again, the previous scores are overwritten or replaced not duplicated.
Controller:
public function save()
{
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$total_rows = $this->input->post('total_rows');
if (!empty($total_rows)) {
$save_result = array();
foreach ($total_rows as $row_key => $row_value) {
if (($_POST['question_type_' . $row_value]) == "singlechoice") {
if (isset($_POST['radio' . $row_value])) {
$save_result[] = array(
'onlineexam_student_id' => $this->input->post('onlineexam_student_id'),
'onlineexam_question_id' => $this->input->post('question_id_' . $row_value),
'select_option' => $_POST['radio' . $row_value],
'attachment_name' => "",
'attachment_upload_name' => "",
);
}
} elseif (($_POST['question_type_' . $row_value]) == "true_false") {
# code...
if (isset($_POST['radio' . $row_value])) {
$save_result[] = array(
'onlineexam_student_id' => $this->input->post('onlineexam_student_id'),
'onlineexam_question_id' => $this->input->post('question_id_' . $row_value),
'select_option' => $_POST['radio' . $row_value],
'attachment_name' => "",
'attachment_upload_name' => "",
);
}
} elseif (($_POST['question_type_' . $row_value]) == "multichoice") {
# code...
if (isset($_POST['checkbox' . $row_value])) {
$save_result[] = array(
'onlineexam_student_id' => $this->input->post('onlineexam_student_id'),
'onlineexam_question_id' => $this->input->post('question_id_' . $row_value),
'select_option' => json_encode($_POST['checkbox' . $row_value]),
'attachment_name' => "",
'attachment_upload_name' => "",
);
}
} elseif (($_POST['question_type_' . $row_value]) == "descriptive") {
# code...
if (isset($_POST['answer' . $row_value]) || (isset($_FILES["attachment" . $row_value]) && !empty($_FILES["attachment" . $row_value]['name']))) {
$inst_array = array(
'onlineexam_student_id' => $this->input->post('onlineexam_student_id'),
'onlineexam_question_id' => $this->input->post('question_id_' . $row_value),
'select_option' => $_POST['answer' . $row_value],
);
$file_name = "";
$upload_file_name = "";
if (isset($_FILES["attachment" . $row_value]) && !empty($_FILES["attachment" . $row_value]['name'])) {
$file_name = $_FILES["attachment" . $row_value]["name"];
$fileInfo = pathinfo($_FILES["attachment" . $row_value]["name"]);
$upload_file_name = time() . uniqid(rand()) . '.' . $fileInfo['extension'];
move_uploaded_file($_FILES["attachment" . $row_value]["tmp_name"], "./uploads/onlinexam_images/" . $upload_file_name);
}
$inst_array['attachment_name'] = $file_name;
$inst_array['attachment_upload_name'] = $upload_file_name;
$save_result[] = $inst_array;
}
}
}
$this->onlineexamresult_model->add($save_result);
$this->onlineexam_model->updateExamResult($this->input->post('onlineexam_student_id'));
redirect('user/onlineexam', 'refresh');
}
} else {
}
}
model:
public function add($data_insert)
{
$this->db->trans_begin();
if (!empty($data_insert)) {
$this->db->insert_batch('onlineexam_student_results', $data_insert);
}
if ($this->db->trans_status() === false) {
$this->db->trans_rollback();
return false;
} else {
$this->db->trans_commit();
return true;
}
}
(I know there are questions on this for previous versions of Opencart but I am using 3.0.3.2. I am getting a php error when I alter the code to incorporate images in the Refine Search. (The linked computer images are just placeholders.)
I tried altering code in catalog/controller/product/category.php
if ($category_info['image']) {
$data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_height'));
} else {
$data['thumb'] = '';
}
$data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
$data['compare'] = $this->url->link('product/compare');
$url = '';
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
I get an undefined variable error on lines 135 and 137 (last lines of code above).
I think the error related to variable $filter_data
It should be declared before these two lines
$filter_data = array(
'filter_category_id' => $category_id,
'filter_sub_category' => $this->config->get('config_product_category') ? true : false,
'filter_filter' => $filter,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
Undefined variable category and Undefined variable i. error occurs .I cannot display array values from controller,so please help me how to solve this error
This my header.php controller file:
<?php
class ControllerCommonHeader extends Controller {
public function index() {
$data['title'] = $this->document->getTitle();
if ($this->request->server['HTTPS']) {
$server = $this->config->get('config_ssl');
} else {
$server = $this->config->get('config_url');
}
$data['base'] = $server;
$data['description'] = $this->document->getDescription();
$data['keywords'] = $this->document->getKeywords();
$data['links'] = $this->document->getLinks();
$data['styles'] = $this->document->getStyles();
$data['scripts'] = $this->document->getScripts();
$data['lang'] = $this->language->get('code');
$data['direction'] = $this->language->get('direction');
if ($this->config->get('config_google_analytics_status')) {
$data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8');
} else {
$data['google_analytics'] = '';
}
$data['name'] = $this->config->get('config_name');
if (is_file(DIR_IMAGE . $this->config->get('config_icon'))) {
$data['icon'] = $server . 'image/' . $this->config->get('config_icon');
} else {
$data['icon'] = '';
}
if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
$data['logo'] = $server . 'image/' . $this->config->get('config_logo');
} else {
$data['logo'] = '';
}
$this->load->language('common/header');
$data['text_home'] = $this->language->get('text_home');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
$data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
$data['text_account'] = $this->language->get('text_account');
$data['text_register'] = $this->language->get('text_register');
$data['text_login'] = $this->language->get('text_login');
$data['text_order'] = $this->language->get('text_order');
$data['text_transaction'] = $this->language->get('text_transaction');
$data['text_download'] = $this->language->get('text_download');
$data['text_logout'] = $this->language->get('text_logout');
$data['text_checkout'] = $this->language->get('text_checkout');
$data['text_category'] = $this->language->get('text_category');
$data['text_all'] = $this->language->get('text_all');
$data['home'] = $this->url->link('common/home');
$data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
$data['logged'] = $this->customer->isLogged();
$data['account'] = $this->url->link('account/account', '', 'SSL');
$data['register'] = $this->url->link('account/register', '', 'SSL');
$data['login'] = $this->url->link('account/login', '', 'SSL');
$data['order'] = $this->url->link('account/order', '', 'SSL');
$data['transaction'] = $this->url->link('account/transaction', '', 'SSL');
$data['download'] = $this->url->link('account/download', '', 'SSL');
$data['logout'] = $this->url->link('account/logout', '', 'SSL');
$data['shopping_cart'] = $this->url->link('checkout/cart');
$data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
$data['contact'] = $this->url->link('information/contact');
$data['telephone'] = $this->config->get('config_telephone');
$status = true;
if (isset($this->request->server['HTTP_USER_AGENT'])) {
$robots = explode("\n", str_replace(array("\r\n", "\r"), "\n", trim($this->config->get('config_robots'))));
foreach ($robots as $robot) {
if ($robot && strpos($this->request->server['HTTP_USER_AGENT'], trim($robot)) !== false) {
$status = false;
break;
}
}
}
$this->load->model('catalog/manufacturer');
$data['categories'] = array();
$results = $this->model_catalog_manufacturer->getManufacturers(); //here getting manufacturer values from database.
foreach ($results as $result) {
if (is_numeric(utf8_substr($result['name'], 0, 1))) {
$key = '0 - 9';
} else {
$key = utf8_substr(utf8_strtoupper($result['name']), 0, 1);
}
if (!isset($data['categories'][$key])) {
$data['categories'][$key]['name'] = $key;
}
$data['categories'][$key]['manufacturer'][] = array( //i can't able to display this array values
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
);
}
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');
// For page specific css
if (isset($this->request->get['route'])) {
if (isset($this->request->get['product_id'])) {
$class = '-' . $this->request->get['product_id'];
} elseif (isset($this->request->get['path'])) {
$class = '-' . $this->request->get['path'];
} elseif (isset($this->request->get['manufacturer_id'])) {
$class = '-' . $this->request->get['manufacturer_id'];
} else {
$class = '';
}
$data['class'] = str_replace('/', '-', $this->request->get['route']) . $class;
} else {
$data['class'] = 'common-home';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/header.tpl', $data);
} else {
return $this->load->view('default/template/common/header.tpl', $data);
}
}
}
And this my html code:
<li><?php echo $category['manufacturer'][$i]['name']; ?></li>
As I understand in controller you seek $key as a string '0 - 9' or as a single uppercase letter gotten from $result['name'].?
If Ok, now?
Where did you get the $i from? Because I haven't seen it in your controller! And is your html line in a $categories foreach loop?
For $i to be accesible in your view, in your controller you would have to have $data['i'] = something;
I have a part of code:
<?php
class ControllerProductProduct extends Controller {
private $error = array();
public function index() {
$this->load->language('product/product');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$this->load->model('catalog/category');
if (isset($this->request->get['path'])) {
$path = '';
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
foreach ($parts as $path_id) {
if (!$path) {
$path = $path_id;
} else {
$path .= '_' . $path_id;
}
$category_info = $this->model_catalog_category->getCategory($path_id);
if ($category_info) {
$data['breadcrumbs'][] = array(
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $path)
);
}
}
// Set the last category breadcrumb
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url)
);
}
}
$this->load->model('catalog/manufacturer');
if (isset($this->request->get['manufacturer_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_brand'),
'href' => $this->url->link('product/manufacturer')
);
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
if ($manufacturer_info) {
$data['breadcrumbs'][] = array(
'text' => $manufacturer_info['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
);
}
}
if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . $this->request->get['tag'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_search'),
'href' => $this->url->link('product/search', $url)
);
}
if (isset($this->request->get['product_id'])) {
$product_id = (int)$this->request->get['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['manufacturer_id'])) {
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
}
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . $this->request->get['tag'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $product_info['name'],
'href' => $this->url->link('product/product', $url . '&product_id=' . $this->request->get['product_id'])
);
$this->document->setTitle($product_info['meta_title']);
$this->document->setDescription($product_info['meta_description']);
$this->document->setKeywords($product_info['meta_keyword']);
$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
$this->document->addScript('catalog/view/javascript/jquery/magnific/jquery.magnific-popup.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/magnific/magnific-popup.css');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
$data['heading_title'] = $product_info['name'];
$data['text_select'] = $this->language->get('text_select');
$data['text_manufacturer'] = $this->language->get('text_manufacturer');
$data['text_model'] = $this->language->get('text_model');
$data['text_reward'] = $this->language->get('text_reward');
$data['text_points'] = $this->language->get('text_points');
$data['text_stock'] = $this->language->get('text_stock');
$data['text_discount'] = $this->language->get('text_discount');
$data['text_tax'] = $this->language->get('text_tax');
$data['text_option'] = $this->language->get('text_option');
$data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
$data['text_write'] = $this->language->get('text_write');
$data['text_login'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
$data['text_note'] = $this->language->get('text_note');
$data['text_tags'] = $this->language->get('text_tags');
$data['text_related'] = $this->language->get('text_related');
$data['text_payment_recurring'] = $this->language->get('text_payment_recurring');
$data['text_loading'] = $this->language->get('text_loading');
$this->load->language('checkout/checkout');
$data['text_address_existing'] = $this->language->get('text_address_existing');
$data['text_address_new'] = $this->language->get('text_address_new');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
$data['text_title'] = $this->language->get('text_title');
$data['text_titulofrete'] = $this->language->get('text_titulofrete');
$data['text_loading'] = $this->language->get('text_loading');
$data['text_shipping_method'] = $this->language->get('text_shipping_method');
$data['entry_postcode'] = $this->language->get('entry_postcode');
$data['button_shipping'] = $this->language->get('button_shipping');
$data['button_cancel'] = $this->language->get('button_cancel');
$this->load->model('account/address');
$data['addresses'] = $this->model_account_address->getAddresses();
if (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
$this->load->model('setting/setting');
$data['freteproduto'] = $this->model_setting_setting->getSetting('freteproduto', $store_id = 0);
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
if (isset($this->session->data['shipping_method'])) {
$data['shipping_method'] = $this->session->data['shipping_method']['code'];
} else {
$data['shipping_method'] = '';
} $data['entry_qty'] = $this->language->get('entry_qty');
$data['entry_name'] = $this->language->get('entry_name');
$data['entry_review'] = $this->language->get('entry_review');
$data['entry_rating'] = $this->language->get('entry_rating');
$data['entry_good'] = $this->language->get('entry_good');
$data['entry_bad'] = $this->language->get('entry_bad');
$data['button_cart'] = $this->language->get('button_cart');
$data['button_wishlist'] = $this->language->get('button_wishlist');
$data['button_compare'] = $this->language->get('button_compare');
$data['button_upload'] = $this->language->get('button_upload');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_question'] = $this->language->get('button_question');
$this->load->model('catalog/review');
$data['tab_description'] = $this->language->get('tab_description');
$data['tab_attribute'] = $this->language->get('tab_attribute');
$data['tab_review'] = sprintf($this->language->get('tab_review'), $product_info['reviews']);
$data['product_id'] = (int)$this->request->get['product_id'];
$data['manufacturer'] = $product_info['manufacturer'];
$data['manufacturers'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $product_info['manufacturer_id']);
$data['model'] = $product_info['model'];
$data['reward'] = $product_info['reward'];
$data['points'] = $product_info['points'];
$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
if ($product_info['quantity'] <= 0) {
$data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$data['stock'] = $product_info['quantity'];
} else {
$data['stock'] = $this->language->get('text_instock');
}
$this->load->model('tool/image');
if ($product_info['image']) {
$data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
} else {
$data['popup'] = '';
}
if ($product_info['image']) {
$data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
} else {
$data['thumb'] = '';
}
$data['images'] = array();
$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
foreach ($results as $result) {
$data['images'][] = array(
'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
);
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$data['price'] = false;
}
if ((float)$product_info['special']) {
$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$data['special'] = false;
}
if ($this->config->get('config_tax')) {
$data['tax'] = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price']);
} else {
$data['tax'] = false;
}
$discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
$data['discounts'] = array();
foreach ($discounts as $discount) {
$data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
);
}
$data['options'] = array();
foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false));
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
if ($product_info['minimum']) {
$data['minimum'] = $product_info['minimum'];
} else {
$data['minimum'] = 1;
}
$data['review_status'] = $this->config->get('config_review_status');
if ($this->config->get('config_review_guest') || $this->customer->isLogged()) {
$data['review_guest'] = true;
} else {
$data['review_guest'] = false;
}
if ($this->customer->isLogged()) {
$data['customer_name'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
} else {
$data['customer_name'] = '';
}
$this->document->addStyle('catalog/view/javascript/jquery/magnific/ask_question.css');
$data['ask_status'] = $this->config->get('ask_question_status');
$data['ask_question'] = $this->url->link('product/ask_question', 'product_id=' . $result['product_id']);
$data['reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']);
$data['rating'] = (int)$product_info['rating'];
// Captcha
if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('review', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('captcha/' . $this->config->get('config_captcha'));
} else {
$data['captcha'] = '';
}
$data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
$data['products'] = array();
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
foreach ($results as $result) {
if ($result['products'] = 1) {
continue;
}
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
On the product page appears the error: Notice: Undefined variable: result in /home/www/catalog/controller/product/product.php on line 430
line 430: $data['ask_question'] = $this->url->link('product/ask_question', 'product_id=' . $result['product_id']);
Does anynone know what am I doing wrong? Thanks.
$result is not defined.
The only place where it is defined in your code is at line 335:
foreach ($results as $result)
Presumably, $results was empty, because
$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
returned no result.
I have built an OpenCart module to add "articles" to the site. I have done this by cloning the "information" module and then adapting it to my needs.
I have made a lot of progress - pretty much finished what I set out to do - and everything works fine on my local dev server. Problem is I've pushed it up to the live server and when I enter the article details and press save (in the admin area) it immediately logs me out, and nothing is saved at all.
My feeling is that it has something to do with the token that gets added when I log in because when I save and I get logged out that token number (appended to the url) is different.
I don't know php all that well (have a background in C# and .NET) but generally understand what's going on. I hope someone can help out.
The Controller file for article: (let me know if any other files/info is needed)
class ControllerCatalogArticle extends Controller {
private $error = array();
public function index() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
$this->getList();
}
public function insert() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$this->model_catalog_article->addArticle($this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->redirect($this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->getForm();
}
public function update() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$this->model_catalog_article->editArticle($this->request->get['article_id'], $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->redirect($this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->getForm();
}
public function delete() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
if (isset($this->request->post['selected']) && $this->validateDelete()) {
foreach ($this->request->post['selected'] as $article_id) {
$this->model_catalog_article->deleteArticle($article_id);
}
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->redirect($this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->getList();
}
private function getList() {
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'id.title';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'),
'separator' => ' :: '
);
$this->data['insert'] = $this->url->link('catalog/article/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
$this->data['delete'] = $this->url->link('catalog/article/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
$this->data['articles'] = array();
$data = array(
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_admin_limit'),
'limit' => $this->config->get('config_admin_limit')
);
$article_total = $this->model_catalog_article->getTotalArticles();
$results = $this->model_catalog_article->getArticles($data);
$this->load->model('catalog/article_category');
foreach ($results as $result) {
$action = array();
$action[] = array(
'text' => $this->language->get('text_edit'),
'href' => $this->url->link('catalog/article/update', 'token=' . $this->session->data['token'] . '&article_id=' . $result['article_id'] . $url, 'SSL')
);
$this->data['articles'][] = array(
'article_id' => $result['article_id'],
'category_id' => $result['category_id'],
'title' => $result['title'],
'sort_order' => $result['sort_order'],
'selected' => isset($this->request->post['selected']) && in_array($result['article_id'], $this->request->post['selected']),
'action' => $action,
'article_category' => $this->model_catalog_article_category->getArticleCategoryTitle($result['category_id'])
);
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_no_results'] = $this->language->get('text_no_results');
$this->data['column_title'] = $this->language->get('column_title');
$this->data['column_article_category'] = $this->language->get('column_article_category');
$this->data['column_sort_order'] = $this->language->get('column_sort_order');
$this->data['column_action'] = $this->language->get('column_action');
$this->data['button_insert'] = $this->language->get('button_insert');
$this->data['button_delete'] = $this->language->get('button_delete');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['sort_title'] = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . '&sort=id.title' . $url, 'SSL');
$this->data['sort_sort_order'] = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . '&sort=i.sort_order' . $url, 'SSL');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$pagination = new Pagination();
$pagination->total = $article_total;
$pagination->page = $page;
$pagination->limit = $this->config->get('config_admin_limit');
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
$this->data['pagination'] = $pagination->render();
$this->data['sort'] = $sort;
$this->data['order'] = $order;
$this->template = 'catalog/article_list.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
private function getForm() {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_default'] = $this->language->get('text_default');
$this->data['text_enabled'] = $this->language->get('text_enabled');
$this->data['text_disabled'] = $this->language->get('text_disabled');
$this->data['entry_title'] = $this->language->get('entry_title');
$this->data['entry_description'] = $this->language->get('entry_description');
$this->data['entry_meta_title'] = $this->language->get('entry_meta_title');
$this->data['entry_meta_description'] = $this->language->get('entry_meta_description');
$this->data['entry_meta_keywords'] = $this->language->get('entry_meta_keywords');
$this->data['entry_abstract'] = $this->language->get('entry_abstract');
$this->data['entry_article_category'] = $this->language->get('entry_article_category');
$this->data['entry_store'] = $this->language->get('entry_store');
$this->data['entry_keyword'] = $this->language->get('entry_keyword');
$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['entry_layout'] = $this->language->get('entry_layout');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['tab_general'] = $this->language->get('tab_general');
$this->data['tab_data'] = $this->language->get('tab_data');
$this->data['tab_design'] = $this->language->get('tab_design');
$this->data['token'] = $this->session->data['token'];
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->error['title'])) {
$this->data['error_title'] = $this->error['title'];
} else {
$this->data['error_title'] = array();
}
if (isset($this->error['description'])) {
$this->data['error_description'] = $this->error['description'];
} else {
$this->data['error_description'] = array();
}
if (isset($this->error['category'])) {
$this->data['error_category'] = $this->error['category'];
} else {
$this->data['error_category'] = array();
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'),
'separator' => ' :: '
);
if (!isset($this->request->get['article_id'])) {
$this->data['action'] = $this->url->link('catalog/article/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
} else {
$this->data['action'] = $this->url->link('catalog/article/update', 'token=' . $this->session->data['token'] . '&article_id=' . $this->request->get['article_id'] . $url, 'SSL');
}
$this->data['cancel'] = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL');
if (isset($this->request->get['article_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$article_info = $this->model_catalog_article->getArticle($this->request->get['article_id']);
}
$this->load->model('localisation/language');
$this->data['languages'] = $this->model_localisation_language->getLanguages();
if (isset($this->request->post['article_description'])) {
$this->data['article_description'] = $this->request->post['article_description'];
} elseif (isset($this->request->get['article_id'])) {
$this->data['article_description'] = $this->model_catalog_article->getArticleDescriptions($this->request->get['article_id']);
} else {
$this->data['article_description'] = array();
}
$this->load->model('catalog/article');
$this->data['article_categories'] = $this->model_catalog_article->getArticleCategoriesSort();
if (isset($this->request->post['select_categories'])) {
$this->data['category_id'] = $this->request->post['select_categories'];
} elseif (!empty($article_info)) {
$this->data['category_id'] = $article_info['category_id'];
} else {
$this->data['category_id'] = 0;
}
if (isset($this->request->post['status'])) {
$this->data['status'] = $this->request->post['status'];
} elseif (!empty($article_info)) {
$this->data['status'] = $article_info['status'];
} else {
$this->data['status'] = 1;
}
$this->load->model('setting/store');
$this->data['stores'] = $this->model_setting_store->getStores();
if (isset($this->request->post['article_store'])) {
$this->data['article_store'] = $this->request->post['article_store'];
} elseif (isset($this->request->get['article_id'])) {
$this->data['article_store'] = $this->model_catalog_article->getArticleStores($this->request->get['article_id']);
} else {
$this->data['article_store'] = array(0);
}
if (isset($this->request->post['keyword'])) {
$this->data['keyword'] = $this->request->post['keyword'];
} elseif (!empty($article_info)) {
$this->data['keyword'] = $article_info['keyword'];
} else {
$this->data['keyword'] = '';
}
if (isset($this->request->post['sort_order'])) {
$this->data['sort_order'] = $this->request->post['sort_order'];
} elseif (!empty($article_info)) {
$this->data['sort_order'] = $article_info['sort_order'];
} else {
$this->data['sort_order'] = '';
}
if (isset($this->request->post['article_layout'])) {
$this->data['article_layout'] = $this->request->post['article_layout'];
} elseif (isset($this->request->get['article_id'])) {
$this->data['article_layout'] = $this->model_catalog_article->getArticleLayouts($this->request->get['article_id']);
} else {
$this->data['article_layout'] = array();
}
$this->load->model('design/layout');
$this->data['layouts'] = $this->model_design_layout->getLayouts();
$this->template = 'catalog/article_form.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
private function validateForm() {
if (!$this->user->hasPermission('modify', 'catalog/article')) {
$this->error['warning'] = $this->language->get('error_permission');
}
foreach ($this->request->post['article_description'] as $language_id => $value) {
if ((utf8_strlen($value['title']) < 3) || (utf8_strlen($value['title']) > 64)) {
$this->error['title'][$language_id] = $this->language->get('error_title');
}
if (utf8_strlen($value['description']) < 3) {
$this->error['description'][$language_id] = $this->language->get('error_description');
}
}
if ($this->error && !isset($this->error['warning'])) {
$this->error['warning'] = $this->language->get('error_warning');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
private function validateDelete() {
if (!$this->user->hasPermission('modify', 'catalog/article')) {
$this->error['warning'] = $this->language->get('error_permission');
}
$this->load->model('setting/store');
foreach ($this->request->post['selected'] as $article_id) {
if ($this->config->get('config_account_id') == $article_id) {
$this->error['warning'] = $this->language->get('error_account');
}
if ($this->config->get('config_checkout_id') == $article_id) {
$this->error['warning'] = $this->language->get('error_checkout');
}
if ($this->config->get('config_affiliate_id') == $article_id) {
$this->error['warning'] = $this->language->get('error_affiliate');
}
$store_total = $this->model_setting_store->getTotalStoresByArticleId($article_id);
if ($store_total) {
$this->error['warning'] = sprintf($this->language->get('error_store'), $store_total);
}
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}