I have a extension that worked perfect on opencart 1.5.x
Now with opencart 2.0 with the changes made Adding an admin page on OpenCart version 2 that I've read from here "shadyyx" only few inputs save and the others don't.
Example:
Controller ( not complete ) :
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('advanced_stock_notification', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
if (isset($this->request->post['notify_mode'])) {
$data['notify_mode'] = $this->request->post['notify_mode'];
} else {
$data['notify_mode'] = $this->config->get('notify_mode');
}
Template ( not complete )
<input name="notify_mode" id="notify_mode" value="<?php echo $notify_mode; ?>" />
Form:
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
Related
I wish to add a review function in my old e-commerce website. However, the "write a review" button does not seems to be working, it will not bring me to a review page; seems like a broken link. I followed the opencart documentation review but there is just this bug.
I am using opencart Version 2.0.3.1.
I think, there is something wrong with review tab on your product page.
Due to may OpenCart experience. The best code for this "Write a review" button is:
Write a review
It should work better, then a standard one.
If this wouldn't help - please, write a link to your website and i'll correct the answer.
UPDATED
No your product.tpl find <div id="tab-review" class="tab-content">. It should be like
<?php if ($review_status) { ?>
<div id="tab-review" class="tab-content">
<div id="review"></div>
On the bottom of this file you can look for script
<script type="text/javascript"><!--
$('#review .pagination a').live('click', function() {
$('#review').fadeOut('slow');
$('#review').load(this.href);
$('#review').fadeIn('slow');
return false;
});
$('#review').load('index.php?route=product/product/review&product_id=<?php echo $product_id; ?>');
$('#button-review').bind('click', function() {
$.ajax({
url: 'index.php?route=product/product/write&product_id=<?php echo $product_id; ?>',
type: 'post',
dataType: 'json',
data: 'name=' + encodeURIComponent($('input[name=\'name\']').val()) + '&text=' + encodeURIComponent($('textarea[name=\'text\']').val()) + '&rating=' + encodeURIComponent($('input[name=\'rating\']:checked').val() ? $('input[name=\'rating\']:checked').val() : '') + '&captcha=' + encodeURIComponent($('input[name=\'captcha\']').val()),
beforeSend: function() {
$('.success, .warning').remove();
$('#button-review').attr('disabled', true);
$('#review-title').after('<div class="attention"><img src="catalog/view/theme/default/image/loading.gif" alt="" /> <?php echo $text_wait; ?></div>');
},
complete: function() {
$('#button-review').attr('disabled', false);
$('.attention').remove();
},
success: function(data) {
if (data['error']) {
$('#review-title').after('<div class="warning">' + data['error'] + '</div>');
}
if (data['success']) {
$('#review-title').after('<div class="success">' + data['success'] + '</div>');
$('input[name=\'name\']').val('');
$('textarea[name=\'text\']').val('');
$('input[name=\'rating\']:checked').attr('checked', '');
$('input[name=\'captcha\']').val('');
}
}
});
});
//--></script>
If there is no such script - add it.
Then, in the same folder as product.tpl find review.tpl with code
<?php if ($reviews) { ?>
<?php foreach ($reviews as $review) { ?>
<div class="review-list">
<div class="author"><b><?php echo $review['author']; ?></b> <?php echo $text_on; ?> <?php echo $review['date_added']; ?></div>
<div class="rating"><img src="catalog/view/theme/default/image/stars-<?php echo $review['rating'] . '.png'; ?>" alt="<?php echo $review['reviews']; ?>" /></div>
<div class="text"><?php echo $review['text']; ?></div>
</div>
<?php } ?>
<div class="pagination"><?php echo $pagination; ?></div>
<?php } else { ?>
<div class="content"><?php echo $text_no_reviews; ?></div>
<?php } ?>
If there is no such file - add id.
If all the conditions are OK, but it still not working - here a screenshot of your console errors.
UPDATED 2
check your config.php in foot folder ans set both HTTP_SERVER and HTTPS_SERVER to the same protocol you are using, like
// HTTP
define('HTTP_SERVER', 'https://yoursite.com/');
// HTTPS
define('HTTPS_SERVER', 'https://yoursite.com/');
Make sure that you don't have any http->https redirects in your .htaccess.
How can I add extra input fields in OpenCart contact form (under information)? Specially I want to add a telephone number field in my contact form and I've followed a tutorial but it didn't work for me. Is there any alternative?
I know it's possible that you already resolved this issue, but this is for those who still want to add custom field to contact form.
In OpenCart 2.0 default Contact Us page (/index.php?route=information/contact) - Contact Form has only 3 fields: Your Name, E-Mail Address, and Enquiry
To add custom fields to Contact Form, you can
Buy an extension (as of 5/9/2015, it seems that I can't find one that modify directly Contact Us form)
Do it yourself: To do it yourself you can follow your tutorial link or follow instructions below
To add custom Telephone field to "Contact Form" in OpenCart 2.0, you would need to edit 3 files:
\catalog\language\english\information\contact.php
\catalog\controller\information\contact.php
\catalog\view\theme[YourThemeName]\template\information\contact.tpl
[YourThemeName] = Whatever theme that you selected for your store, default is "default"
(You can verify or set it here: /Admin => Systems => Settings => Select your store and click Edit => Store tab => Default Layout)
1. Edit language file: \catalog\language\english\information\contact.php
a. Under line:
$_['entry_email'] = 'E-Mail Address';
Add code:
$_['entry_phone'] = 'Telephone';
b. Under line
$_['error_email'] = 'E-Mail Address does not appear to be valid!';
Add code:
$_['error_phone'] = 'Telephone is required!';
2. Edit control file: \catalog\controller\information\contact.php
a. Under code:
$data['entry_email'] = $this->language->get('entry_email');
Add code:
$data['entry_phone'] = $this->language->get('entry_phone');
b. Under code
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
Add code
if (isset($this->error['phone'])) {
$data['error_phone'] = $this->error['phone'];
} else {
$data['error_phone'] = '';
}
c. Under code:
if (!preg_match('/^[^\#]+#.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
Add code:
if ((utf8_strlen($this->request->post['phone']) < 1)) {
$this->error['phone'] = $this->language->get('error_phone');
}
d. FIND code
$mail->setText($this->request->post['enquiry']);
UPDATE code to
$mail->setText($this->request->post['enquiry'] . $mail->newline . 'Telephone: ' . $this->request->post['phone']);
3. Edit template file: \catalog\view\theme[YourThemeName]\template\information\contact.tpl
a. Under line:
<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>
Add code:
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-phone"><?php echo $entry_phone; ?></label>
<div class="col-sm-10">
<input type="text" name="phone" value="<?php echo $phone; ?>" id="input-phone" class="form-control" />
<?php if ($error_phone) { ?>
<div class="text-danger"><?php echo $error_phone; ?></div>
<?php } ?>
</div>
</div>
After update above 3 files, just upload to your server and test. Good luck!
In OC 2.x the telephone number is available to the contact template by default. I'm guessing you upgraded from an older version and kept your old theme?
To add your telephone number open up:
catalog/view/theme/YOUR THEME/template/information/contact.tpl
And use the following to add telephone info (which will come from the phone # assigned in store settings).
Display the language string for "Telephone":
<?php echo $text_telephone; ?>
Display the telephone number from settings:
<?php echo $telephone; ?>
Under File - \catalog\controller\information\contact.php : NEW CODES ADDED TO FIX Undefined variable: phone
Under Code :
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = $this->customer->getEmail();
}
Add code:
if (isset($this->request->post['phone'])) {
$data['phone'] = $this->request->post['phone'];
} else {
$data['phone'] = '';
}
Thanks for every one...
Actually I faced the same problem but when I used these above mentioned codes in 3 different places I got another problem which shows "<b>Notice</b>: Undefined variable: phone in <b>/home/gwbpsuxl/public_html/catalog/view/theme/default/template/information/contact.tpl</b> on line <b>127</b>" this error in **Phone option**.
I used this code "if (isset($this->request->post['phone'])) {
$data['phone'] = $this->request->post['phone'];
} else {
$data['phone'] = $this->customer->getTelephone();
}" 2 times in **contact.php** file
1 is above from it and 2 is below this code "$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']
);
}
}"
so edit it and make it clear.
Thanks for anyone who helps or points me in the right direction.
I want to show Order Status in opencart user (My Account) page. It will show status by status ID. My Pending Status ID:1 and I want to show only Pending Status. Other status will not appear.
<?php echo $order_statuses['order_status_id']; ?>
I put this at account.tpl but result error. Please help me.
Maybe need to modify
*english/account/account.php
controller/account/account.php
template/module/account.tpl*
My Open cart Version 1.5.6.3 with custom Theme.
In account.php you have add this.
$this->load->model('account/order');
$results = $this->model_account_order->getOrders(0, 5);
foreach ($results as $result) {
$product_total = $this->model_account_order->getTotalOrderProductsByOrderId($result['order_id']);
$voucher_total = $this->model_account_order->getTotalOrderVouchersByOrderId($result['order_id']);
$this->data['orders'][] = array(
'order_id' => $result['order_id'],
'name' => $result['firstname'] . ' ' . $result['lastname'],
'status' => $result['status'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'products' => ($product_total + $voucher_total),
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'href' => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], 'SSL'),
'reorder' => $this->url->link('account/order', 'order_id=' . $result['order_id'], 'SSL')
);
}
In account.tpl add this code
<div id="resent_order" class="recent_order">
<a style="float:right; margin-bottom:15px;" href="<?php echo $manage_order; ?>" class="button">Manage your orders</a><h4>Recent Order</h4>
<ul style="clear:both;">
<?php if( isset($orders) && count($orders > 0 ) ){
foreach ($orders as $order) { ?>
<li>
<div><strong>Order:#</strong><?php echo $order['order_id']; ?></div>
<div><strong>Date:</strong> <?php echo $order['date_added']; ?></div>
<div><strong>Amount:</strong> <?php echo $order['total']; ?></div>
<div><strong>Status:</strong> <?php echo $order['status']; ?></div>
<div class="editPan"><a class="" title="Edit" href="<?php echo $order['href']; ?>">Edit</a></div>
</li>
<?php } ?>
<?php }else{?> <li>You have no recent orders.</li><?php } ?>
</ul>
</div>
Currently my Opencart site only lets me 'Add to Cart' on the categories page, however if a product has options like 'colour' etc I want it to say 'View Product' instead.
Does anyone know how this can be achieved? I have tried editing the category.php controller to check if a product has options but cannot seem to get it working properly.
Thanks.
Update
So far I have added:
$options = $this->model_catalog_product->getProductOptions($result['product_id']);
Above this array $this->data['products'] = array(); in catalog>controller>product>category.php
This was my attempt to check if a product has options or not. Then I added in catalog>view>theme>mytheme>template>product>category.tpl
<?php if ($product['options']) { ?>
<a href="<?php echo $product['href']; ?>" class="button" />View Product</a>
<?php } else { // EO CATALOGUE MODE ?>
<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
<?php } ?>
But it is not quite cutting the mustard.
You need to add the options to the $products array which is what you are checking in category.tpl:
Look for:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
and add the options as an index to each product array
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'options' => $this->model_catalog_product->getProductOptions($result['product_id']),
Opencart 1.5.5.1
I added a new field to may checkout register page:
-added to catalog/view/theme/default/template/checkout/register.tpl:
<span class="required">*</span> <?php echo $entry_cnp; ?><br />
<input type="text" name="cnp" value="" class="large-field" />
<br />
<br />
and to catalog/controller/checkout/register.php:
$this->data['entry_cnp'] = $this->language->get('entry_cnp');
and
if ((utf8_strlen($this->request->post['cnp']) < 3) || (utf8_strlen($this->request->post['cnp']) > 32)) {
$json['error']['cnp'] = $this->language->get('error_cnp');
}
If I register on checkout it works great, my problem is when I do not complete this field: I'm not aloud to proceed further but I do not get an error message like on the other requested fields
First add 'error_cnp' variable in language file if you had not added it yet like this
$_['error_cnp'] = 'some error text';
Second, in catalog/view/theme/default/template/checkout/checkout.tpl:
find
$('#button-register').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/register/validate',
// some code
success: function() {
and inside this success function paste following lines
if (json['error']['cnp']) {
$('#payment-address input[name=\'cnp\'] + br').after('<span class="error">' + json['error']['cnp'] + '</span>');
}
in between the similar looking lines (inside the else if (json['error']) { )