I am using opencart version 2.0.1.1 and I have modified common cart.tpl according to my requirement I meant alignment so after I changed if I add any product to cart means it will show success message and even product is adding to cart but when I click on cart button it is showing "ul" but inside ul, li is there that is not displaying and If I load page means it will show products in the cart otherwise not showing.
Please any one help me on this.
Below is cart.tpl,
<a id="cart_close_1">X</a>
<div id="cart" class="btn-group btn-block">
<button type="button" data-toggle="dropdown" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-inverse btn-block btn-lg dropdown-toggle animate"><i class="crtIcon animAll"></i><!-- <span id="cart-total"><?php echo $text_items; ?></span> --></button>
<ul class="dropdown-menu pull-right <?php echo $class_cart; ?> " id="remove_cart">
<?php if ($products || $vouchers) { ?>
<li><div class="cart-container cf">
<?php $count=0;
foreach ($products as $product) { $count++;
?>
<div class="qckimg-vd">
<div class="quck-img">
<?php if ($product['thumb']) { ?>
<!-- <img src="image/10-cm-blue-sparklers.jpg" alt="10-cm-blue-sparklers"> -->
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" />
<?php }?>
</div><!-- quck-img -->
<div class="proqty">
<div class="nobTn">
<button type="button" class="btn-number" data-type="minus" data-field="input-quantity_<?php echo $product['product_id']; ?>" data-price="<?php echo $product['product_id']; ?>">
<input type="hidden" class="min_order_amount" data-value="<?php echo "3400";?>"/>
<span>-</span>
</button>
</div>
<input type="text" name="quantity" min="1" max="100" value="1" size="2" id="input-quantity_<?php echo $product['product_id']; ?>" class="pro_class" data-id="<?php echo $product['product_id']; ?>" maxlength="3" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;">
<div class="nobTn">
<button type="button" class="btn-number" data-type="plus" data-field="input-quantity_<?php echo $product['product_id']; ?>" data-price="<?php echo $product['product_id']; ?>">
<span>+</span>
</button>
</div>
<span id="error" style="color: Red; display: none">Input digits (0 - 9)</span>
<input type="hidden" name="product_id" id="p_id" value="<?php echo $product['product_id']; ?>">
</div>
</div><!-- qckimg-vd -->
<div class="shoping-cart-desc">
<h2><?php echo $product['name']; ?></h2>
<h3><?php echo $product['attribute_value']; ?></h3>
<h4><!-- <span class="qty_total <?php echo "count_".$count;?>" data-count="<?php echo $count;?>"><?php echo $product['quantity']; ?> X </span> --><span class="orgprice count_total" id="or_price_<?php echo $product['product_id']; ?>" data-actprice="<?php echo str_replace( ',', '', $product['price'] ); ?>"><?php echo $product['price']; ?></span></h4>
<!-- Remove -->
Remove
</div><!-- shoping-cart-desc -->
<?php }?>
</div><!-- cart-container -->
<div class="sub-tot">
<?php $count=0;foreach($products as $product){$count++;?>
<?php } ?>
<?php foreach ($totals as $total) {?>
<?php }?>
<div class="cf">
<h4 class="lft">Subtotal (<?php echo $count;?> item(s))</h4>
<h4 class="rght total_price" data-type="minus plus" data-total="<?php echo str_replace( ',', '', $total['text'] ); ?>"><?php echo $total['text']; ?></h4>
<!-- <h4 class="lft">Shipping</h4>
<h4 class="rght">NA</h4> -->
</div>
<div class="total cf">
<h4 class="lft">Total</h4>
<h4 class="rght total_price"><?php echo $total['text']; ?></h4>
</div>
</div><!-- sub-tot -->
<div class="shp-btns">
<a class="chckout" href="<?php echo $checkout; ?>">Checkout</a>
</div><!-- shp-btns -->
<div class="min-ordr">
<h3>Minimum order amount should be
Rs.3400 to checkout.</h3>
</div><!-- min-ordr -->
</li>
<?php }else{?>
<li style="height:auto;">
<p class="text-center tCeTxt"><?php echo $text_empty; ?></p>
</li>
<?php }?>
</ul>
</div>
js cart function,
'add': function(product_id, quantity) {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
success: function(json) {
var error_msg = false;
$('.alert, .text-danger').remove();
$('#cart > button').button('reset');
//For Showing Product Stock Error
if (json['error_warning']) {
error_msg = true;
$('#cart_id').parent().before('<div class="alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['error_warning'] + '<button type="button" class="close" data-dismiss="modal">×</button></div>');
$('#cart-total').html(json['total']);
}
if (json['redirect'] && error_msg == false) {
location = json['redirect'];
}
if (json['success']) {
$('#cart_id').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="modal">×</button></div>');
$('#cart-total').html(json['total']);
/*$('html, body').animate({ scrollTop: 0 }, 'slow');*/
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
});
},
Controller,
<?php
class ControllerCommonCart extends Controller {
public function index() {
$this->load->language('common/cart');
// Totals
$this->load->model('extension/extension');
$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_extension_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('total/' . $result['code']);
$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
}
$sort_order = array();
foreach ($total_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $total_data);
}
$data['text_empty'] = $this->language->get('text_empty');
$data['text_cart'] = $this->language->get('text_cart');
$data['text_checkout'] = $this->language->get('text_checkout');
$data['text_recurring'] = $this->language->get('text_recurring');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_minimum_ord_amount'] = $this->language->get('text_minimum_ord_amount');
$data['text_items'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total));
$data['text_loading'] = $this->language->get('text_loading');
$data['button_remove'] = $this->language->get('button_remove');
$this->load->model('tool/image');
$this->load->model('tool/upload');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
} else {
$image = '';
}
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),
'type' => $option['type']
);
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']);
} else {
$total = false;
}
//For Getting Pieces/Items per box
$product_attribute = $this->model_catalog_product->getSpecificProductAttribute($product['product_id']);
$attribute_value = '';
if($product_attribute) {
$attribute_value = $product_attribute['text'];
}
$data['products'][] = array(
'key' => $product['key'],
'product_id'=> $product['product_id'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
'quantity' => $product['quantity'],
'price' => $price,
'attribute_value'=> $attribute_value,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
}
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'])
);
}
}
$data['totals'] = array();
foreach ($total_data as $result) {
$data['totals'][] = array(
'title' => $result['title'],
'text' => $this->currency->format($result['value']),
);
}
$data['cart'] = $this->url->link('checkout/cart');
$data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/cart.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/cart.tpl', $data);
} else {
return $this->load->view('default/template/common/cart.tpl', $data);
}
}
public function info() {
$this->response->setOutput($this->index());
}
}
Related
I am trying to do the following on the product page in opencart 1.5.6.
Load categories of the product, find related category pairs and load products, which are one of those categories
I am thinking the problem could be in the model, how i am referencing the query results into the array
I have tried the following:
In the catalog/model/catalog/product.php
public function getProductPair($product_id) {
//get categories for product
$query_categories = $this->db->query("SELECT category_id FROM oc_product_to_category WHERE product_id = '" . (int)$product_id . "'");
$array_categories = $query_categories->rows;
//get category pairs
$query_category_pairs = $this->db->query("SELECT category_id FROM wb_related_categories WHERE related_category_id IN '" .$array_categories . "'");
$query_category_pairs_result = $query_category_pairs->rows;
//query the related products based on category pairs
$product_data = array();
$query = $this->db->query("SELECT * FROM oc_product_to_category pr LEFT JOIN oc_product p ON (pr.product_id = p.product_id) LEFT JOIN oc_product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.category_id IN '" . $query_category_pairs_result . "' AND p.status = '1' AND p.quantity > '0' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "LIMIT 16'");
foreach ($query->rows as $result) {
$product_data[$result['related_id']] = $this->getProduct($result['related_id']);
}
return $product_data;
}
In the catalog/controller/product.php
$this->data['products2'] = array();
$results2 = $this->model_catalog_product->getProductPair($this->request->get['product_id']);
foreach ($results2 as $result2) {
if ($result2['image']) {
$image2 = $this->model_tool_image->resize($result2['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
} else {
$image2 = false;
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price2 = $this->currency->format($this->tax->calculate($result2['price'], $result2['tax_class_id'], $this->config->get('config_tax')));
} else {
$price2 = false;
}
if ((float)$result2['special']) {
$special2 = $this->currency->format($this->tax->calculate($result2['special'], $result2['tax_class_id'], $this->config->get('config_tax')));
} else {
$special2 = false;
}
if ($this->config->get('config_review_status')) {
$rating2 = (int)$result2['rating'];
} else {
$rating2 = false;
}
$this->data['products2'][] = array(
'product_id' => $result2['product_id'],
'thumb' => $image2,
'name' => $result2['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result2['description'], ENT_QUOTES, 'UTF-8')), 0, 60) . '..',
'price' => $price2,
'special' => $special2,
'rating' => $rating2,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result2['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result2['product_id'])
);
}
In the catalog/template/product.tpl
<div class="box-heading"><?php echo $tab_related; ?></div>
<div class="product-grid product-related-grid">
<?php foreach ($products2 as $product2) { ?>
<div class="three mobile-two columns">
<div>
<?php if ($product2['thumb']) { ?>
<div class="image">
<?php if (($product2['special'])) { ?><span class="sale-icon">Akce</span><?php } ?>
<img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" />
</div>
<?php } ?>
<div class="name"><?php echo $product['name']; ?></div>
<div class="description"><?php echo $product2['description']; ?></div>
<?php if ($product2['price']) { ?>
<div class="price">
<?php if (!$product2['special']) { ?>
<span><?php echo $product2['price']; ?></span>
<?php } else { ?>
<span class="price-old"><?php echo $product2['price']; ?></span> <span class="price-new"><?php echo $product2['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
<div class="cart">
<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product2['product_id']; ?>');" class="button" />
</div>
</div>
</div>
<?php } ?>
</div>
I followed the tutorial here on how to create a duplicate contact form. I created the 3 files needed. This is working as expected when I go to the url information/form. However, I can't make it work when I want it to be included in another page. I added it in the information page and just call it when the page I needed it to appear is clicked/called.
First off, I removed the header and footer inclusions in the .tpl file because it's already in the parent page. Then I called $this->load->controller('information/form') in the catalog controller where I want it to appear but it's not working. I used $this->load->view('information) and it works but the functionalities are not there (which is obvious because it's only calling for the view).
My current code in catalog/controller/information/information:
public function index() {
$this->load->language('information/information');
$this->load->language('information/form');
$this->load->model('catalog/information');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$information_id = 0;
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
}
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$this->document->setTitle($information_info['meta_title']);
$this->document->setDescription($information_info['meta_description']);
$this->document->setKeywords($information_info['meta_keyword']);
$data['breadcrumbs'][] = array(
'text' => $information_info['title'],
'href' => $this->url->link('information/information', 'information_id=' . $information_id)
);
$data['heading_title'] = $information_info['title'];
$data['button_continue'] = $this->language->get('button_continue');
$data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
$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');
$contact_data['text_location'] = $this->language->get('text_location');
$contact_data['text_store'] = $this->language->get('text_store');
$contact_data['text_contact'] = $this->language->get('text_contact');
$contact_data['text_address'] = $this->language->get('text_address');
$contact_data['text_telephone'] = $this->language->get('text_telephone');
$contact_data['text_fax'] = $this->language->get('text_fax');
$contact_data['text_open'] = $this->language->get('text_open');
$contact_data['text_comment'] = $this->language->get('text_comment');
$contact_data['text_contact_info'] = $this->language->get('text_contact_info');
$contact_data['entry_name'] = $this->language->get('entry_name');
$contact_data['error_name'] = '';
$contact_data['name'] = '';
$contact_data['entry_email'] = $this->language->get('entry_email');
$contact_data['error_email'] = '';
$contact_data['email'] = '';
$contact_data['entry_telephone'] = $this->language->get('entry_telephone');
$contact_data['error_telephone'] = '';
$contact_data['telephone'] = '';
$contact_data['entry_subject'] = $this->language->get('entry_subject');
$contact_data['error_subject'] = '';
$contact_data['subject'] = '';
$contact_data['entry_enquiry'] = $this->language->get('entry_enquiry');
$contact_data['error_enquiry'] = '';
$contact_data['enquiry'] = '';
$contact_data['captcha'] = '';
$contact_data['button_submit'] = 'SUBMIT';
$contact_data['action'] = $this->url->link('information/form');
/*THIS IS WHERE I CALL THE CUSTOM CONTACT FORM VIEW*/
$data['contact'] = $this->load->view('information/form', $contact_data); //$this->load->controller('information/form');
$this->response->setOutput($this->load->view('information/information', $data));
}
}
Is it achievable? Or do I really need to double everything?
I tell you some steps to duplicate the contact form.
First, you need to create 3 files in their Information directories.
Note: Please Give a Proper Filename like form or etc if you want.
1. catalog\controller\information\form.php
<?php
class ControllerInformationForm extends Controller {
private $error = array();
public function index() {
$this->load->language('information/form');
$this->document->setTitle($this->language->get('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->request->post['enquiry']);
$mail->send();
$this->response->redirect($this->url->link('information/form/success'));
}
$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('heading_title'),
'href' => $this->url->link('information/form')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_location'] = $this->language->get('text_location');
$data['text_store'] = $this->language->get('text_store');
$data['text_contact'] = $this->language->get('text_contact');
$data['text_address'] = $this->language->get('text_address');
$data['text_telephone'] = $this->language->get('text_telephone');
$data['text_fax'] = $this->language->get('text_fax');
$data['text_open'] = $this->language->get('text_open');
$data['text_comment'] = $this->language->get('text_comment');
$data['entry_name'] = $this->language->get('entry_name');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_enquiry'] = $this->language->get('entry_enquiry');
$data['button_map'] = $this->language->get('button_map');
if (isset($this->error['name'])) {
$data['error_name'] = $this->error['name'];
} else {
$data['error_name'] = '';
}
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['enquiry'])) {
$data['error_enquiry'] = $this->error['enquiry'];
} else {
$data['error_enquiry'] = '';
}
$data['button_submit'] = $this->language->get('button_submit');
$data['action'] = $this->url->link('information/form', '', true);
$this->load->model('tool/image');
if ($this->config->get('config_image')) {
$data['image'] = $this->model_tool_image->resize($this->config->get('config_image'), $this->config->get($this->config->get('config_theme') . '_image_location_width'), $this->config->get($this->config->get('config_theme') . '_image_location_height'));
} else {
$data['image'] = false;
}
$data['store'] = $this->config->get('config_name');
$data['address'] = nl2br($this->config->get('config_address'));
$data['geocode'] = $this->config->get('config_geocode');
$data['geocode_hl'] = $this->config->get('config_language');
$data['telephone'] = $this->config->get('config_telephone');
$data['fax'] = $this->config->get('config_fax');
$data['open'] = nl2br($this->config->get('config_open'));
$data['comment'] = $this->config->get('config_comment');
$data['locations'] = array();
$this->load->model('localisation/location');
foreach((array)$this->config->get('config_location') as $location_id) {
$location_info = $this->model_localisation_location->getLocation($location_id);
if ($location_info) {
if ($location_info['image']) {
$image = $this->model_tool_image->resize($location_info['image'], $this->config->get($this->config->get('config_theme') . '_image_location_width'), $this->config->get($this->config->get('config_theme') . '_image_location_height'));
} else {
$image = false;
}
$data['locations'][] = array(
'location_id' => $location_info['location_id'],
'name' => $location_info['name'],
'address' => nl2br($location_info['address']),
'geocode' => $location_info['geocode'],
'telephone' => $location_info['telephone'],
'fax' => $location_info['fax'],
'image' => $image,
'open' => nl2br($location_info['open']),
'comment' => $location_info['comment']
);
}
}
if (isset($this->request->post['name'])) {
$data['name'] = $this->request->post['name'];
} else {
$data['name'] = $this->customer->getFirstName();
}
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = $this->customer->getEmail();
}
if (isset($this->request->post['enquiry'])) {
$data['enquiry'] = $this->request->post['enquiry'];
} else {
$data['enquiry'] = '';
}
// Captcha
if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'), $this->error);
} else {
$data['captcha'] = '';
}
$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');
$this->response->setOutput($this->load->view('information/form', $data));
}
protected function validate() {
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
$this->error['name'] = $this->language->get('error_name');
}
if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
$this->error['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
$this->error['enquiry'] = $this->language->get('error_enquiry');
}
// Captcha
if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');
if ($captcha) {
$this->error['captcha'] = $captcha;
}
}
return !$this->error;
}
public function success() {
$this->load->language('information/form');
$this->document->setTitle($this->language->get('heading_title'));
$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('heading_title'),
'href' => $this->url->link('information/form')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_message'] = $this->language->get('text_success');
$data['button_continue'] = $this->language->get('button_continue');
$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');
$this->response->setOutput($this->load->view('common/success', $data));
}
}
2. catalog\view\theme\default\template\information\form.tpl
<?php echo $header; ?>
<div class="container">
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
<h1><?php echo $heading_title; ?></h1>
<h3><?php echo $text_location; ?></h3>
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<?php if ($image) { ?>
<div class="col-sm-3"><img src="<?php echo $image; ?>" alt="<?php echo $store; ?>" title="<?php echo $store; ?>" class="img-thumbnail" /></div>
<?php } ?>
<div class="col-sm-3"><strong><?php echo $store; ?></strong><br />
<address>
<?php echo $address; ?>
</address>
<?php if ($geocode) { ?>
<i class="fa fa-map-marker"></i> <?php echo $button_map; ?>
<?php } ?>
</div>
<div class="col-sm-3"><strong><?php echo $text_telephone; ?></strong><br>
<?php echo $telephone; ?><br />
<br />
<?php if ($fax) { ?>
<strong><?php echo $text_fax; ?></strong><br>
<?php echo $fax; ?>
<?php } ?>
</div>
<div class="col-sm-3">
<?php if ($open) { ?>
<strong><?php echo $text_open; ?></strong><br />
<?php echo $open; ?><br />
<br />
<?php } ?>
<?php if ($comment) { ?>
<strong><?php echo $text_comment; ?></strong><br />
<?php echo $comment; ?>
<?php } ?>
</div>
</div>
</div>
</div>
<?php if ($locations) { ?>
<h3><?php echo $text_store; ?></h3>
<div class="panel-group" id="accordion">
<?php foreach ($locations as $location) { ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><?php echo $location['name']; ?> <i class="fa fa-caret-down"></i></h4>
</div>
<div class="panel-collapse collapse" id="collapse-location<?php echo $location['location_id']; ?>">
<div class="panel-body">
<div class="row">
<?php if ($location['image']) { ?>
<div class="col-sm-3"><img src="<?php echo $location['image']; ?>" alt="<?php echo $location['name']; ?>" title="<?php echo $location['name']; ?>" class="img-thumbnail" /></div>
<?php } ?>
<div class="col-sm-3"><strong><?php echo $location['name']; ?></strong><br />
<address>
<?php echo $location['address']; ?>
</address>
<?php if ($location['geocode']) { ?>
<i class="fa fa-map-marker"></i> <?php echo $button_map; ?>
<?php } ?>
</div>
<div class="col-sm-3"> <strong><?php echo $text_telephone; ?></strong><br>
<?php echo $location['telephone']; ?><br />
<br />
<?php if ($location['fax']) { ?>
<strong><?php echo $text_fax; ?></strong><br>
<?php echo $location['fax']; ?>
<?php } ?>
</div>
<div class="col-sm-3">
<?php if ($location['open']) { ?>
<strong><?php echo $text_open; ?></strong><br />
<?php echo $location['open']; ?><br />
<br />
<?php } ?>
<?php if ($location['comment']) { ?>
<strong><?php echo $text_comment; ?></strong><br />
<?php echo $location['comment']; ?>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" class="form-horizontal">
<fieldset>
<legend><?php echo $text_contact; ?></legend>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-name"><?php echo $entry_name; ?></label>
<div class="col-sm-10">
<input type="text" name="name" value="<?php echo $name; ?>" id="input-name" class="form-control" />
<?php if ($error_name) { ?>
<div class="text-danger"><?php echo $error_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-email"><?php echo $entry_email; ?></label>
<div class="col-sm-10">
<input type="text" name="email" value="<?php echo $email; ?>" id="input-email" class="form-control" />
<?php if ($error_email) { ?>
<div class="text-danger"><?php echo $error_email; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-enquiry"><?php echo $entry_enquiry; ?></label>
<div class="col-sm-10">
<textarea name="enquiry" rows="10" id="input-enquiry" class="form-control"><?php echo $enquiry; ?></textarea>
<?php if ($error_enquiry) { ?>
<div class="text-danger"><?php echo $error_enquiry; ?></div>
<?php } ?>
</div>
</div>
<?php echo $captcha; ?>
</fieldset>
<div class="buttons">
<div class="pull-right">
<input class="btn btn-primary" type="submit" value="<?php echo $button_submit; ?>" />
</div>
</div>
</form>
<?php echo $content_bottom; ?></div>
<?php echo $column_right; ?></div>
</div>
<?php echo $footer; ?>
3. catalog\language\en-gb\information\form.php
<?php
// Heading
$_['heading_title'] = 'Contact Us';
// Text
$_['text_location'] = 'Our Location';
$_['text_store'] = 'Our Stores';
$_['text_contact'] = 'Contact Form';
$_['text_address'] = 'Address';
$_['text_telephone'] = 'Telephone';
$_['text_fax'] = 'Fax';
$_['text_open'] = 'Opening Times';
$_['text_comment'] = 'Comments';
$_['text_success'] = '<p>Your enquiry has been successfully sent to the store owner!</p>';
// Entry
$_['entry_name'] = 'Your Name';
$_['entry_email'] = 'E-Mail Address';
$_['entry_enquiry'] = 'Enquiry';
// Email
$_['email_subject'] = 'Enquiry %s';
// Errors
$_['error_name'] = 'Name must be between 3 and 32 characters!';
$_['error_email'] = 'E-Mail Address does not appear to be valid!';
$_['error_enquiry'] = 'Enquiry must be between 10 and 3000 characters!';
Here are the changes applied according to #daniel's Answer.
In \catalog\view\theme\default\template\extension\module\sibling_category.tpl
<div class="box box-with-categories">
<div class="box-heading check_2"><?php echo $heading_title; ?></div>
<div class="strip-line"></div>
<div class="box-content box-category">
<ul class="accordion" id="accordion-category">
<?php $i = 0; foreach ($categories as $category) { $i++; ?>
<li class="panel">
<?php if ($category['category_id'] == $category_id) { ?>
<?php echo $category['name']; ?>
<?php } else { ?>
<?php echo $category['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
\catalog\controller\extension\module\sibling_category.php
<!--Have changed the controller logic, like you said -->
And In \catalog\language\en-gb\extension\module\sibling_category.php
<?php
// Heading
$_['heading_title'] = 'Sibling Categories';
So, Now what to do for appearing on list -> inside Category Layout.
And is there any way we can do this in coding so this appear in product/category.tpl file, so we don't need to create all files in admin folder.
EDIT: I've rewritten this answer to make it simpler to follow.
Your best bet here is to create a new Module rather than including this in the template. There are two stages: creating admin files & creating front-end files.
FRONT END
Start by duplicating all the front-end files of the standard "Category" module which consist of the following files, rename them according to your own definition e.g. sibling_category wherever you have category:
\catalog\view\theme\default\template\extension\module\category.tpl
\catalog\controller\extension\module\category.php
\catalog\language\en-gb\extension\module\category.php
We don't need a model here as the model for this as the ModelCatalogCategory class has the desired ability already.
So now you need to change the controller logic, edit the newly created sibling_category.php controller file. What we're doing here is getting the current category data ($current_id & $current_category), extracting the Parent category's id (parent_id) and then getting all children of the parent_id aka "siblings"
<?php
class ControllerExtensionModuleSiblingCategory extends Controller {
public function index() {
$this->load->language('extension/module/category');
$data['heading_title'] = $this->language->get('heading_title');
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
if (isset($parts[0])) {
$data['category_id'] = $parts[0];
} else {
$data['category_id'] = 0;
}
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$current_id = $parts[count($parts) - 1];
$current_category = $this->model_catalog_category->getCategory($current_id);
$siblings = $this->model_catalog_category->getCategories($current_category['parent_id']);
foreach ($siblings as $category) {
$data['sibling_categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] ,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
$data['current_id'] = $current_id;
return $this->load->view('extension/module/sibling_category', $data);
}
}
Here's the default OC template's category.tpl modules file adjusted (edit for your template file accordingly replacing "$category_id" with "$current_id":
<div class="list-group">
<?php foreach ($sibling_categories as $category) { ?>
<?php if ($category['category_id'] == $current_id) { ?>
<?php echo $category['name']; ?>
<?php if ($category['children']) { ?>
<?php foreach ($category['children'] as $child) { ?>
<?php if ($child['category_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } else { ?>
<?php echo $category['name']; ?>
<?php } ?>
<?php } ?>
</div>
ADMIN AREA
In order to manage the module in the admin area, you will need to duplicate the language file and create a controller and the view:
\admin\language\en-gb\extension\module\category.php
Create a new file in the path \admin\controller\extension\module\sibling_category.php and insert this code:
<?php
class ControllerExtensionModuleSiblingCategory extends Controller {
private $error = array();
public function index() {
$this->load->language('extension/module/sibling_category');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('extension/module');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
if (!isset($this->request->get['module_id'])) {
$this->model_extension_module->addModule('sibling_category', $this->request->post);
} else {
$this->model_extension_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('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['entry_status'] = $this->language->get('entry_status');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/html', 'token=' . $this->session->data['token'], true)
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/html', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true)
);
}
if (!isset($this->request->get['module_id'])) {
$data['action'] = $this->url->link('extension/module/sibling_category', 'token=' . $this->session->data['token'], true);
} else {
$data['action'] = $this->url->link('extension/module/sibling_category', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true);
}
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true);
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$module_info = $this->model_extension_module->getModule($this->request->get['module_id']);
}
if (isset($this->request->post['name'])) {
$data['name'] = $this->request->post['name'];
} elseif (!empty($module_info)) {
$data['name'] = $module_info['name'];
} else {
$data['name'] = '';
}
if (isset($this->request->post['module_description'])) {
$data['module_description'] = $this->request->post['module_description'];
} elseif (!empty($module_info)) {
$data['module_description'] = $module_info['module_description'];
} else {
$data['module_description'] = array();
}
$this->load->model('localisation/language');
$data['languages'] = $this->model_localisation_language->getLanguages();
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/sibling_category', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/category')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
Finally create the view file at the path \admin\view\template\extension\module\sibling_category.tpl and insert the following:
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-category" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<i class="fa fa-reply"></i></div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-html" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
<div class="col-sm-10">
<input type="hidden" name="name" value="<?php echo $heading_title; ?>" id="input-name" class="form-control" />
<select name="status" id="input-status" class="form-control">
<?php if ($status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } ?>
</select>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php echo $footer; ?>
Once you've done this, you may need to update your admin permissions. Navigate to "Settings=>Users=>UserGroups" and edit your Admin user type. Make sure you either "Select All" for read and modify permission or select it manually.
You need to then "Install" this module and then edit it, set it to enabled and Save. You'll notice a "Sub-module" listed below the "Sibling Category" this is to get the module in the 'Layouts' page. Do not create multiple instances of the module as it may cause confusion on the layouts - unless you understand what you're doing.
NB When duplicating the language files, remember to find & replace all instances of "Category" with "Sibling Category"
This is my code in actionCheckout():
public function actionCheckout() {
$proInfo = Yii::app()->session['cart'];
if (Yii::app()->user->isGuest) {
$model = new Payment;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Payment'])) {
$model->attributes = $_POST['Payment'];
$model->thoigian = date('Y-m-d H:i:s');
if ($model->save()) {
foreach ($proInfo as $key => $value) {
$order = new Order;
$order->id_sp = $key;
$order->soluong = $value;
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
$order->thanhtien = $price * $value;
$order->id_payment = $model->id_hoadon;
$order->save();
}
unset(Yii::app()->session['cart']);
$this->redirect(Yii::app()->request->baseUrl . '/cart/success/' . $model->id_hoadon);
}
}
$this->render('checkout', array(
'cart' => $proInfo,
'model' => $model,
));
} else {
$model = new Payment;
$user = User::model()->findByPk(Yii::app()->user->id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Payment'])) {
$model->attributes = $_POST['Payment'];
$model->id_user = Yii::app()->user->id;
$model->hoten = $user->hoten;
$model->email = $user->email;
$model->dienthoai = $user->dienthoai;
$model->diachi = $user->dia_chi;
$model->thoigian = date('Y-m-d H:i:s');
$model->xuly = "Chưa xử lý";
if ($model->save()) {
foreach ($proInfo as $key => $value) {
$order = new Order;
$order->id_sp = $key;
$order->soluong = $value;
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
$order->thanhtien = $price * $value;
$order->id_payment = $model->id_hoadon;
$order->save();
}
unset(Yii::app()->session['cart']);
$this->redirect(Yii::app()->request->baseUrl . '/cart/success/' . $model->id_hoadon);
}
}
$this->render('checkout', array(
'user' => $user,
'cart' => $proInfo,
'model' => $model,
));
}
}
And this is my "checkout.php" file in views:
<link rel="stylesheet" type="text/css" href="<?= Yii::app()->request->baseUrl ?>/css/cart.css"/>
<?php
$this->breadcrumbs = array(
'Giỏ hàng' => array('cart/index'),
'Thanh toán'
);
$this->pageTitle = "Thanh Toán";
$items = 0;
$total = 0;
$i = 0;
?>
<h1>Thanh toán</h1>
<?php
if (empty($cart)) {
echo "<p>Bạn chưa có sản phẩm nào trong giỏ hàng</p>";
} else {
$form = $this->beginWidget('CActiveForm', array(
'id' => 'payment-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => false,
));
?>
<div class="payment">
<?php
if (!Yii::app()->user->isGuest) {
?>
<div class="paymentCustomer">
<h3>Thông tin thanh toán</h3>
<div style="padding: 10px; clear:both; float:left">Họ tên:<?= Yii::app()->user->name ?></div>
<div style="padding: 10px; clear:both; float:left">Email:<?= $user->email ?></div>
<div style="padding: 10px; clear:both; float:left">Địa chỉ:<?= $user->dia_chi ?></div>
<div style="padding: 10px; clear:both; float:left">Điện thoại:<?= $user->dienthoai ?></div>
</div>
<?php
} else {
?>
<div class="paymentCustomer">
<h3>Thông tin thanh toán</h3>
<div class="inputUser"><div>Họ tên <span>*</span></div><?php echo $form->textField($model, 'hoten', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'hoten'); ?>
<div class="inputUser"><div>Email <span>*</span></div><?php echo $form->textField($model, 'email', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'email'); ?>
<div class="inputUser"><div>Địa chỉ <span>*</span></div><?php echo $form->textField($model, 'diachi', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'diachi'); ?>
<div class="inputUser"><div>Điện thoại <span>*</span></div><?php echo $form->textField($model, 'dienthoai', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'dienthoai'); ?>
</div>
<?php
}
?>
<div class="paymentCustomer">
<h3>Hình thức thanh toán</h3>
<p class="paymentYour">
<?php
echo $form->radioButtonList($model, 'phuongthuc', array(
'Tại Cửa hàng' => 'Thanh toán tại cửa hàng',
'Khi Nhận hàng' => 'Thanh toán khi nhận được hàng',
'Tài khoản Ngân hàng' => 'Thanh toán qua tài khoản Ngân hàng'
), array("class" => "myCheck"));
?>
<?php echo $form->error($model, 'phuongthuc'); ?>
</p>
<h3 style="margin: 50px 0 5px 0;">Mã khuyến mãi</h3>
<?php echo $form->textField($model, 'coupon', array('class' => "inputText loginText")); ?>
<?php echo $form->error($model, 'coupon'); ?>
</div>
</div>
<div class="cartInfo">
<div class="headCart">
<div class="cartField1">Mã sản phẩm</div>
<div class="cartField2">Tên sản phẩm</div>
<div class="cartField3">Đơn giá</div>
<div class="cartField3">Số lượng</div>
<div class="cartField3">Thành tiền</div>
</div>
<?php
foreach ($cart as $key => $value) {
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
?>
<div class="bodyCart">
<div class="cartField1" data-label="Mã sản phẩm"><?= $product->ma_sp ?></div>
<div class="cartField2" data-label="Tên sản phẩm"><span><?= $product->ten_sp ?></span></div>
<div class="cartField3" data-label="Đơn giá"><?= $price . "đ" ?></div>
<div class="cartField3" data-label="Số lượng"><?= $value ?></div>
<div class="cartField3" data-label="Thành tiền"><?= $price * $value . "đ" ?></div>
</div>
<?php
$items +=$value;
$total +=$price * $value;
}
?>
<div class="footCart">
<div class="cartField1">Tổng cộng</div>
<div class="cartField2"></div>
<div class="cartField3"><?= $items ?></div>
<div class="cartField3"><?= $total . "đ" ?></div>
</div>
</div>
<div>
<a href="<?= Yii::app()->request->urlReferrer ?>">
<input type="button" class="cartLeftButton button" value="Quay trở lại"/>
</a>
<?php echo CHtml::submitButton('Xác nhận và gửi đơn hàng', array("class" => "cartRightButton button")); ?>
</div>
<?php
$this->endWidget();
}
?>
But when submit that form it not direct to success page. I have try to insert die("abc") to each line in Controller and find out that it not run from the line
if($model->save()){....
How can I fix that now?
I'm using opencart 1.5.6.4.
I copied from latest module in opencart to create a module which shows popular products.
In catalog side's controller i replaced the code below
$data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit']
);
$results = $this->model_catalog_product->getProducts($data);
by
$results = $this->model_catalog_product->getPopularProducts($setting['limit']);
and ofcourse did a find-replace of latest/popular
Everything is working ok, But if i click on a product of the popular module to see the details of it and then come back to the layout where the popular module is set, that product is being disappeared.
Whats wrong am i doing ?
EDIT
I'm using default model which stays in catalog/model/catalog/product.php. Code of getPopularProducts() is as below
public function getPopularProducts($limit) {
$product_data = array();
$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit);
foreach ($query->rows as $result) {
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}
return $product_data;
}
and the catalog/view/theme/default/template/module/popula.tpl is as below
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-product">
<?php foreach ($products as $product) { ?>
<div>
<?php if ($product['thumb']) { ?>
<div class="image"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></div>
<?php } ?>
<div class="name"><?php echo $product['name']; ?></div>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['rating']) { ?>
<div class="rating"><img src="catalog/view/theme/default/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
<?php } ?>
<div class="cart"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" /></div>
</div>
<?php } ?>
</div>
</div>
</div>
EDIT 2
Here is the full code of the controller popular
<?php
class ControllerModulePopular extends Controller {
protected function index($setting) {
$this->language->load('module/popular');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['button_cart'] = $this->language->get('button_cart');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$this->data['products'] = array();
$results = $this->model_catalog_product->getPopularProducts($setting['limit']);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
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_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/popular.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/popular.tpl';
} else {
$this->template = 'default/template/module/popular.tpl';
}
$this->render();
}
}
?>