Hi, how can I load $text_items variable in footer.tpl?
i want to do something like this:
<?php if (substr($text_items,0)==0) {
echo "<img src=\"catalog/view/theme/default/image/emptycart.png\">";
}else{
echo "<img src=\"catalog/view/theme/default/image/cart.png\">";
}
?>
But $text_items is an undefined variable.
Thanks.
i want to do something like this:
<?php if (substr($text_items,0)==0) {
echo "<img src=\"catalog/view/theme/default/image/emptycart.png\">";
}else{
echo "<img src=\"catalog/view/theme/default/image/cart.png\">";
}
?>
But $text_items is an undefined variable.
Thanks.
Open your footer language file:
/catalog/language/english/common/footer.php
Add your variable like so:
Then open your footer controller:
/catalog/controller/common/footer.php
Add your variable to the data array of the controller:
Now your variable is available as $text_variable in your footer view.
You can also run tests against the raw text variable in the controller prior to setting the data variable.
Then in the view just echo the image:
Hope this helps.
-V
/catalog/language/english/common/footer.php
Add your variable like so:
Code: Select all
$_['your_text_variable'] = 'Text to appear in your footer';
/catalog/controller/common/footer.php
Add your variable to the data array of the controller:
Code: Select all
$this->data['text_variable'] = $this->language->get('your_text_variable');
Code: Select all
<?php echo $text_variable; ?>
Code: Select all
if (substr($this->language->get('your_text_variable'), 0) == 0):
$this->data['your_image'] = '<img src="catalog/view/theme/default/image/emptycart.png">';
else:
$this->data['your_image'] = '<img src="catalog/view/theme/default/image/cart.png">';
endif;
Code: Select all
<?php echo $your_image; ?>
-V
Thanks for your answer but i think that i haven't explained right.
$text_items variable is written (echoed) in catalog/view/theme/["mytemplate"]/template/module/cart.tpl
$text_items says the number of products you have inside the cart.
I need $text_items in footer.tpl but i don't know how load it.
$text_items variable is written (echoed) in catalog/view/theme/["mytemplate"]/template/module/cart.tpl
Code: Select all
<span id="cart-total"><?php echo $text_items; ?></span></a></div>
I need $text_items in footer.tpl but i don't know how load it.
Ah, I see.
You can get this information directly from the cart class which is available globally.
Open: /catalog/language/english/common/footer.php and add the following:
(copied from modules/cart.php)
Open: /catalog/controller/common/footer.php and add the following:
Open: catalog/view/theme/*/template/footer.tpl and add:
Keep in mind this won't update with javascript when you add a new item, to do that you'll need to give the container an id and add that to the update section of the addToCart() method in your javascript controller.
Hope that helps.
-V
You can get this information directly from the cart class which is available globally.
Open: /catalog/language/english/common/footer.php and add the following:
Code: Select all
$_['text_items'] = '%s item(s) - %s';
Open: /catalog/controller/common/footer.php and add the following:
Code: Select all
// Totals
$this->load->model('setting/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_setting_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);
}
}
$this->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));
Code: Select all
<?php echo $text_items; ?>
Hope that helps.
-V
Just missing a line to complete your instructions in "/catalog/controller/common/footer.php"
copied from modules/cart.php:
it works! Now I undestand a bit more the opencart code, thankyou very much! :-)
It would be interesting update with javascript when adding the cart but i don't know how to do it
If you help me i'll be thanful
copied from modules/cart.php:
Code: Select all
$this->language->load('module/cart');
It would be interesting update with javascript when adding the cart but i don't know how to do it

If you help me i'll be thanful
Hi Subdivide,
Thanks again!
I tried to duplicate this procedure to add some text to the product page and it didn't work. Could you help?
This is what I did:
Step 1: opened /catalog/language/english/product/product.php and added this: $_['your_text_variable'] = 'Text to appear in your product page';
Step 2: opened catalog/controller/product/product.php and added this: $this->data['text_variable'] = $this->language->get('your_text_variable');
Step 3: added <?php echo $text_variable; ?> to the catalog/view/template/product/product.tpl file where I wanted the text to appear.
I cleared my cache and loaded a page but no text appeared. Am I missing something or did I add the code to the wrong pages?
I was able to get it to work in the footer but not the product page.
Thanks if you could help!
Davidicus
Thanks again!
I tried to duplicate this procedure to add some text to the product page and it didn't work. Could you help?
This is what I did:
Step 1: opened /catalog/language/english/product/product.php and added this: $_['your_text_variable'] = 'Text to appear in your product page';
Step 2: opened catalog/controller/product/product.php and added this: $this->data['text_variable'] = $this->language->get('your_text_variable');
Step 3: added <?php echo $text_variable; ?> to the catalog/view/template/product/product.tpl file where I wanted the text to appear.
I cleared my cache and loaded a page but no text appeared. Am I missing something or did I add the code to the wrong pages?
I was able to get it to work in the footer but not the product page.
Thanks if you could help!
Davidicus
The only thing I can think of is that perhaps your language file hasn't been loaded at the point where you placed your declaration.
Make sure you place your declaration:
After:
Other than that, I can't explain why it wouldn't render.
Make sure you place your declaration:
Code: Select all
$this->data['text_variable'] = $this->language->get('your_text_variable');
Code: Select all
$this->language->load('product/product');
Who is online
Users browsing this forum: No registered users and 9 guests