How to show count items in cart in header Open Cart? - opencart

I need to show count of items in cart in Header.
I tried to edit header.php file as:
$products = $this->cart->getProducts();
$data['total'] = count($products);
And after to display this in template header.tpl:
<?php echo $total?>

Your code should work, but you can also use command $this->cart->countProducts()

Related

opencart 1.5 show count store in admin setting/store page

I'm using multistore in Opencart 1.5. I want to show the total number of store that I have made and I want to show it in the setting/store page. Can anybody help?
The function $this->model_setting_store->getTotalStores() will return the number of stores excluding the default store.
So total number of stores:
In controller add the line:
$this->data['total_stores'] = $this->model_setting_store->getTotalStores()+1;
In template file use it as below:
<?php
echo $total_stores;
?>
However, to get it working in the controller file and avoid any errors first you need to load your model:
$this->load->model('setting/store');

Custom fields in confirmation email Opencart 2.0

I have created custom fields for my registration/checkout form with Opencart 2.0. They show up on the admin section under each order, and I have successfully added them to the order_invoice.tpl, but I need to add them to the confirmation email that is sent to the customer. I think I have located the correct controller file: catalog>controller>account>order.tpl But I think the issue is that the code used to print it out in the order_invoice.tpl is referencing a folder or file in the admin side.
This is the code I am trying to execute in catalog>view>theme>yourtheme>template>mail>order.tpl
<?php foreach ($account_custom_fields as $custom_field) { ?>
<strong><?php echo $custom_field['name']; ?></strong>:
<?php echo $custom_field['value']; ?><br />
<?php } ?>
This is the error I get:
Notice: Undefined variable: account_custom_fields in
/home/raphaelseventworks.com/www/ncbaorders/catalog/view/theme/journal2/template/mail/order.tpl
on line 70Warning: Invalid argument supplied for foreach() in
/home/raphaelseventworks.com/www/ncbaorders/catalog/view/theme/journal2/template/mail/order.tpl
on line 70
Does anyone know how print out custom fields in the order confirmation email? Or what code I need to add to catalog>controller>account>order.tpl to make this work?
Thanks!
If i am correct you are trying to send additional values to confirmation email after checkout
you need to work on
catalog/model/checkout/order.php::addOrderHistory()
After order is placed, the order history is changed, here you can load your view file and pass custom values form controller according to your need.
Good Luck

Add a new field in virtuemart new product form

I want to add a new field in virtuemart new product form, how can i do that ?
I add:
var $is_act = 1;
in "components\com_virtuemart\tables\products.php"
And
<?php echo VmHTML::checkbox('is_act', $this->product->is_act); ?>
And in database but what is appear is a checkbox without a string behind it, what is the wrong ?!
The VMHTL::checkbox function just create a check box without strings.
If you want to add string behind it you have to do something like this.
<?php echo JText::_('COM_VIRTUEMART_PRODUCT_IS_ACT') ?>
<?php echo VmHTML::checkbox('is_act', $this->product->is_act); ?>
And then COM_VIRTUEMART_PRODUCT_IS_ACT should be added inside language file too.
for more clearness just check VM default product_edit_information.php page inside
administrator/components/com_virtuemart/views/product/tmpl/
Hope its helps..

Opencart product.tpl

Where did I miss to add a line of code if I try to echo php variable inside OPENCART product.tpl file and it doesn't show up on site?
Notes: there is a field in database. I am able to save to this field from admin panel ( i added a custom field there).
Did You edit also the product controller to load the variable and pass it to the template? I guess not... Edit catalog/controller/product/product.php and add $this->data['MYVARIABLE'] = $product_info['MYVARIABLE']; somewhere before $this->render() is called.

How can I add a "trending topics" section to my site's homepage?

I would like to add a custom "trending topics" section to my news website at the top of the homepage. An existing example that shows precisely what I am looking for is the Daily Beast homepage.
I would like to do this with custom code or with a plugin, but not as a widget. Does anyone know how I can do this in a flexible way that can easily customize to style and look of my website.
My site is a Spanish language 24/7 news website called Yasta.pr. Thx!
it depends on how you are storing your data in your database but you can try this:
add a div section in the header of your webpage above the menu bar.
then you can dynamically add the most trending topic to it automatically when the page starts by inserting this code inside it:
<div id="*id_name">
$query = "SELECT * FROM *table_name ORDER BY *most_trending_column LIMIT 1";
mysql_select_db(*database_name, *connection);
$result = mysql_query($query) or die(mysql_error());
$data = mysql_fetch_assoc($result);
echo "<h3 id='*id_name'>" . $data['*title_column_name'] . "</h3>";
</div>
dont forget to connect to your database first.