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']),
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.
I am using opencart 2.3 and in category page, all sub categories have same image. Title is different, in backend and database images are different.
Removed everything from /image/cache with no effect.
Tried to add $image into $data['categories'] array, in controller/product/category.php but is the same.
This is my code from <theme>/product/category.tpl
<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $category['name']; ?>" /><p><?php echo $category['name']; ?></p>
<?php } ?>
<?php } ?>
Can't find nothing else to fix this. Will be very appreciate, if you can help.
Fixed by adding this:
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get($this->config->get('config_theme') . '_image_category_width'), $this->config->get($this->config->get('config_theme') . '_image_category_height'))
to $data['categories'] array.
:)
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>
is there any way to open the product details from category view in a new browser window? The current code for the button is:
<p>
<?php // Product Details Button
echo JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details'));
?>
</p>
I am using Joomla! 2.5.11 and VM 2.0.22a
In addition to title and class, you can pass third parameter to the array:
array('title' => $product->product_name, 'class' => 'product-details', 'target' => '_blank')
I have changed the following code overriding com_virtuemart/views/category/default.php:
<?php // Product Details Button
echo JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details')); ?>
To:
<?php $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component'); ?>
...and for the text link:
<a class="product-details" href="<?php echo $product->link ?>" target="_blank"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_DETAILS') ?></a>