I have a simple component following the hello world tutorial for the most part, and everything works except i've added a publish / unpublish icons to the toolbar and to the list itself (the small green / red circles).
The toolbar icons work and they can change the state no problem, but the small icons do not, here is the code I have:
view.html.php:
protected function addToolBar()
{
JToolBarHelper::title(JText::_('COM_MADS_MANAGER_OBJECTS'));
JToolBarHelper::publishList($task = 'objects.publish', $alt = 'Publish');
JToolBarHelper::unpublishList($task = 'objects.unpublish', $alt = 'Unpublish');
JToolBarHelper::deleteListX('', 'objects.delete');
JToolBarHelper::editListX('object.edit');
JToolBarHelper::addNewX('object.add');
}
tmpl > body:
<?php
// No direct access to this file
defined('_JEXEC') or die;
?>
<?php foreach($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2; ?>">
<td><?php echo $item->id; ?></td>
<td><?php echo JHtml::_('grid.id', $i, $item->id); ?></td>
<td><?php echo $item->title; ?></td>
<td><?php echo $item->description; ?></td>
<td align="center"><?php $published = JHTML::_('grid.published', $item, $i); echo $published;?></td>
</tr>
<?php endforeach; ?>
I am using the built in publish / unpublish function and did not create one of my own.
Tables:
<?php
// No direct access to this file
defined('_JEXEC') or die;
jimport('joomla.database.table');
class MAdsTableObjects extends JTable
{
var $id = null;
var $title = null;
var $description = null;
var $published = 0;
function __construct(&$db)
{
parent::__construct('#__mads_objects', 'id', $db);
}
}
?>
I figured it out after A LOT OF FREKIN HEADACHE and wasted time, it should be:
<?php echo JHtml::_('jgrid.published', $item->published, $i, 'objects.',true); ?>
where objects. is the name of my view / controller / model for the listing.
I think you should have a state field in the db, to store the status
state tinyint(3)
Than try using:
echo JHtml::_('grid.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder);
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.
:)
Opencart 2.3.02
How can I hide the subcategories from showing in the sidebar module? I have it on the left hand column. It shows up in the main top menu under main categories and thats fine but i want it hidden in the side menu.
Thanks
Category is one of default Opencart modules, you can edit its tpl file to achieve what you want, so open this file:
catalog/view/theme/default/template/extension/module/category.tpl
remove this section:
<?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 } ?>
If you are using different theme and still see subcategories, try to edit this file:
catalog/view/theme/YOUR-THEME/template/extension/module/category.tpl
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>
I just start with Opencart. I need to have list of brands, like llist of catgories. I try so:
<div class="box">
<div class="box-heading"><?php echo "По брендам" ?></div>
<div class="box-content">
<ul class="box-category">
<?php foreach ($manufacturers as $manufacturer) { ?>
<li>
<?php if ($manufacturer['manufacturer_id'] == $manufacturer_id) { ?>
<?php echo $manufacturer['name']; ?>
<?php } else { ?>
<?php echo $manufacturer['name']; ?>
<?php } ?>
<?php if ($manufacturer['children']) { ?>
<ul>
<?php foreach ($manufacturer['children'] as $child) { ?>
<li>
<?php if ($child['manufacturer_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
I add this code in default/template/module/category.tpl file.
I get this error: Notice: Undefined variable: manufacturers in....
How should I do this???
Thanks.
category.tpl is the template for the category controller. Its purpose is to show categories. Try to direct your browser to the http://your.site/index.php?route=product/manufacturer and you will get list of manufacturers. The template is /catalog/view/theme/default/template/product/manufacturer_list.tpl.
Your error is a result of one simple thing: the $manufacturers variable is not defined in ControllerModuleCategory controller (aka category.php). If you want use a variable in a template, you must define it in a relevant controller.
In order to obtain list of manufacturers exactly in the /catalog/view/theme/default/template/module/category.tpl (even if it isn't the purpose of this module), you need be done with few things:
1) In the /catalog/model/catalog/manufacturer.php file (model ModelCatalogManufacturer) add function (this function will help you to obtain the list of manufacturers from the database):
public function getManufacturerByCategory($category_id) {
$query = $this->db->query("SELECT m.*
FROM " . DB_PREFIX . "product p
RIGHT JOIN " . DB_PREFIX . "product_to_category p2c ON
p.product_id = p2c.product_id
LEFT JOIN " . DB_PREFIX . "manufacturer m ON
p.manufacturer_id = m.manufacturer_id
WHERE
p2c.category_id = " . (int)$category_id . " AND
m.manufacturer_id IS NOT NULL
GROUP BY m.manufacturer_id");
return $query->rows;
}
2) In the /catalog/controller/module/category.php file (aka ControllerModuleCategory controller), prior to if (file_exists(DIR_TEMPLATE . $this->config->get('confi... insert the code:
if (isset($this->request->get['path'])) {
$category_id = array_pop($parts);
$this->load->model('catalog/manufacturer');
$this->data['manufacturers'] = $this->model_catalog_manufacturer->getManufacturerByCategory($category_id);
} else {
$this->data['manufacturers'] = array();
}
(Keep in mind $this->data['manufacturers'] from the controller will be available in the template as $manufacturers. $this->data['categories'] will be $categories, $this->data['another_var'] will be $another_var and so on.)
And since the moment you can use your foreach ($manufacturers as $manufacturer) in the category module template (the place where you did try the foreach, when you've received "Undefined variable" error) in order to output list of manufacturers which are applied to products from current category.
Best way is create another module, "manufacturer" module, instead of illegitimate using of category module. But I'm not sure that right now you are ready for this challenge.
BTW, I'm all for shadyyx's link to the Jay Gilford's guide. It is awesome quick start guide for beginners.
I have light solution:
Just add code in Controller:category.php:
$this->load->model('catalog/manufacturer');
$this->data['mans'] = $this->data['manufacturers'] =
$this->model_catalog_manufacturer->getManufacturers();
And View: category.tpl:
<?php
foreach($mans as $mans_value)
{
var_dump($mans_value);
}
?>