Post by Maansy » Sat Aug 07, 2010 2:49 pm

1st, i want to thank my bro kroozing for figuring this out. its totally credited to him and to Q for giving the heads up.

This add-on will show cart total (items & prices) in header. SEE EXAMPLE HERE

lets begin.
BACKUP BACKUP BACKUP

Files need to alter: 3

STEP 1
open: catalog\view\theme\default12\template\common\header.tpl
Add this anywhere you want to disply the info:

Code: Select all

<?php if ($products) { ?>    
    <a href="index.php?route=checkout/cart" alt="Item(s)">(<?php echo $this->cart->countProducts(); ?>) <?php echo $text_shoppingbag; ?></a>
    <?php
    $count=count($totals);
    $cartinfo = $totals[$count-1]['text'];
    echo $cartinfo;
    ?>   
    <?php } else { ?>  
     <a href="index.php?route=checkout/cart" alt="Item(s)">(<?php echo $this->cart->countProducts(); ?>) <?php echo $text_shoppingbag; ?></a>   
    <?php
    foreach ($totals as $total) { 
    if ($total['title'] != 'Sub-Total:') {
            echo $total['text']; 
        }
       }     
    } ?> 
STEP 2
open: catalog\controller\common\header.php
after:

Code: Select all

class ControllerCommonHeader extends Controller {
   protected function index() {
 
add:

Code: Select all

$this->data['products'] = array();
        
        foreach ($this->cart->getProducts() as $result) {
            $option_data = array();

            foreach ($result['option'] as $option) {
                  $option_data[] = array(
                    'name'  => $option['name'],
                    'value' => $option['value']
                  );
            }
            
              $this->data['products'][] = array(
                'key'          => $result['key'],
                'name'       => $result['name'],
                'option'     => $option_data,
                'quantity'   => $result['quantity'],
                'stock'      => $result['stock'],
                'price'      => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
                'href'       => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']),
              );
        }
        
   $total_data = array();
        $total = 0;
        $taxes = $this->cart->getTaxes();
        
        $this->load->model('checkout/extension');
        
        $sort_order = array(); 
        
        $results = $this->model_checkout_extension->getExtensions('total');
        
        foreach ($results as $key => $value) {
            $sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
        }
        
        array_multisort($sort_order, SORT_ASC, $results);
    
    foreach ($results as $result) {
            $this->load->model('total/' . $result['key']);

            $this->{'model_total_' . $result['key']}->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['totals'] = $total_data;
        
        if (isset($this->session->data['coupon'])) {
            $this->load->model('checkout/coupon');
        
            $coupon = $this->model_checkout_coupon->getCoupon($this->session->data['coupon']);
            
            if ($coupon) {
                $data['coupon_id'] = $coupon['coupon_id'];
            } else {
                $data['coupon_id'] = 0;
            }
        } else {
            $data['coupon_id'] = 0;
        }
        
    $this->data['ajax'] = $this->config->get('cart_ajax');
        
        $this->id = 'cart';
 
and after:

Code: Select all

$this->data['text_advanced'] = $this->language->get('text_advanced');
 
add:

Code: Select all

$this->data['text_shoppingbag'] = $this->language->get('text_shoppingbag');
 
STEP 3
open: catalog\language\english\common\header.php (do this step to every language file you have)
add this before the closing ?>:

Code: Select all

$_['text_shoppingbag']   = 'Item(s):';
 

Thats it. Enjoy it :)
Last edited by i2Paq on Mon Aug 09, 2010 5:09 pm, edited 1 time in total.
Reason: Topic moved

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by lxgenius » Mon Aug 09, 2010 3:53 pm

Hi Maansy

Thank you for that! That is really good! :)

I wonder if it is possible that the counter updates when I put something into the cart(press add to cart button)?!
It only updates when i reload the page or leave it.

greetz

User avatar
Newbie

Posts

Joined
Mon Aug 09, 2010 3:41 pm

Post by Maansy » Tue Aug 10, 2010 6:14 am

well right now, if you add to cart from any page or catagory page then the site reloads then the cart it updated.
the only page the ajax is implamented is in the product page and in order to update the header cart same way as the box cart would be to let ajax send the js to the header cart which i dont think its a good idea leting to do that.
i am thinking maybe we need to add a 2nd id:

Code: Select all

$this->data['ajax'] = $this->config->get('cart_ajax');
        
        $this->id = 'cart';

 
you can disable the box cart and try to see when you click add to cart from the product page does the product fly to the top instead?

so many things can be done here :)

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by nnestor » Tue Aug 10, 2010 11:05 pm

Hello. I do not know whether it just makes me, but I'm getting 2x the price for them. Where can be the problem? already when I click the add to cart so there is only one price. Please help

New member

Posts

Joined
Tue Aug 10, 2010 10:57 pm

Post by Maansy » Wed Aug 11, 2010 12:10 am

please provide a link to the issue so i can see

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by nnestor » Wed Aug 11, 2010 12:20 am

http://roxy.begyben.sk
Thank you. and sorry for the English

New member

Posts

Joined
Tue Aug 10, 2010 10:57 pm

Post by Maansy » Wed Aug 11, 2010 12:51 am

its doing what it suppose to do.
cart_issue1.png

cart_issue1.png (80.86 KiB) Viewed 39653 times

what seems to be the problem?

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by nnestor » Wed Aug 11, 2010 12:55 am

But if I have 0 products in your cart so I get the following:
(0) Položiek: 0.00€0.00€

New member

Posts

Joined
Tue Aug 10, 2010 10:57 pm

Post by Maansy » Wed Aug 11, 2010 1:12 am

důvody etry najít někoho, které mohou vysvětlit lépe problém.

i am sorry. i am still trying to understand the problem that you have.
when you add product in the cart, does it show 2x the price? (it didnt when i tried it)
or
doesnt show anything? (when no pruduct it shows 0, normal)
or
another thing is happening?
Last edited by Maansy on Wed Aug 11, 2010 1:17 am, edited 1 time in total.

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by nnestor » Wed Aug 11, 2010 1:16 am

When you reach the page, so you see two prices in the basket. (€ 0.00 € 0.00). feeder when you add something to cart it works 100%

New member

Posts

Joined
Tue Aug 10, 2010 10:57 pm

Post by Maansy » Wed Aug 11, 2010 1:21 am

ok i get the issue.
ok let see.
please try to add this to a default them and to an un-touch header.php in controller and see if the problem is gone.

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by lxgenius » Fri Aug 13, 2010 6:34 am

@maansy

Sorry, that I did't respond. I don't get email notification from this forum. I changed that.
I will try that in the weekend, .....

@nnestor

just change the code in the header.tpl like that:

Code: Select all

<?php if ($products) { ?>    
    <a href="index.php?route=checkout/cart" alt="Item(s)"><?php echo $text_cart;?>&nbsp;<?php echo $this->cart->countProducts();?>&nbsp;<?php echo $text_shoppingbag; ?></a>
    <?php
    $count=count($totals);
    $cartinfo = $totals[$count-1]['text'];
    echo $cartinfo
    ?>   
    <?php } else { ?>  
     <a href="index.php?route=checkout/cart" alt="Item(s)"><?php echo $text_cart;?>&nbsp;<?php echo $this->cart->countProducts();?>&nbsp;<?php echo $text_shoppingbag; ?></a>   
    <?php
    foreach ($totals as $total) { 
    if ($total['title'] != 'Sub-Total:') {
           //remove from here//
        }
       }
        echo $total['text']; <--//place here//
    } ?> 
you just move the echo $total['text']; two lines down
et voila

User avatar
Newbie

Posts

Joined
Mon Aug 09, 2010 3:41 pm

Post by Maansy » Fri Aug 13, 2010 7:32 am

i dont know why it wasnt working with you before. its working fine with all my stores thu, but i am glad you got that fixed for you in case someone face the same issue you did :)

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by nnestor » Fri Aug 13, 2010 9:11 pm

ok, now it's very good. I would have needed if it is with Ajax. thank you

no help, huh? :-\

New member

Posts

Joined
Tue Aug 10, 2010 10:57 pm

Newbie

Posts

Joined
Fri Aug 20, 2010 10:15 pm
Location - London

Post by grassm » Tue Aug 31, 2010 3:46 am

How would you go about taking out the price and just showing the total number? I've tried taking out pieces in the tpl file but it results in a php error.

Newbie

Posts

Joined
Tue Aug 31, 2010 3:42 am

Post by tarkanlar » Sun Sep 26, 2010 3:47 am

in 1.4.9.1 i only add this in header.tpl

Code: Select all

(<?php echo $this->cart->countProducts(); ?>)<?php echo $this->currency->format($this->cart->getTotal()); ?>
and some how it works great ))

New member

Posts

Joined
Sun Nov 22, 2009 8:17 am

Post by TAC » Sun Sep 26, 2010 6:13 pm

Hi tarkanlar, I tried your version and it works great except that I cannot get it to go where I would like it on the page. I don't really know what I am doing with code so are you able to tell me where to place the code exactly so that it appears at the far right of the header bar?
Thanks

User avatar
TAC
Active Member

Posts

Joined
Sun Sep 26, 2010 1:33 am
Location - England

Post by guisauer » Tue Oct 19, 2010 3:32 pm

tarkanlar, your method is so simple, and it works great if you just want to show the subtotal!

But if i want it to show:

1 item ($30.00) or
2 items ($60.00)

how do I make it change the word from item to items for more than 1 product?

thanks!!!

New member

Posts

Joined
Sun Dec 06, 2009 7:51 am

Post by harryo40 » Fri Oct 29, 2010 5:17 am

Hi,
Hope this helps people out in this thread ;)
I have updated my Mod from working with OC1.3.2 to OC1.4.9.1 which can be downloaded for FREE from here.....
http://www.opencart.com/index.php?route ... ion_id=716
It shows the cart in the header & to the right of the search box & also shows the Item count & Sub-Total that updates when the main add to cart buttons are clicked.
I have also started a Thread which can be seen here.....
http://forum.opencart.com/viewtopic.php?f=112&t=22043
Please post question, issues or any problems with the 'Cart In Header' Mod & I will reply to them from within the thread ;)
cheers
harryo

Add To Cart Confirm Ajax Popup for OC 1.5.1.3 --> 1.5.5.1 - Add to Cart Confirmation Popup
Image Map Banner Module - Image Map Banner Module
----------------------------------------------------------------------
Womens Famous Name Fashion Clothing at bargain prices - Next2nowt.com


Active Member

Posts

Joined
Wed Oct 21, 2009 3:37 am
Location - Blackburn, Lancashire
Who is online

Users browsing this forum: No registered users and 3 guests