Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Swipestripe: Showing item count on custom template

Go to End

4 Posts   3514 Views


Community Member, 12 Posts

20 December 2013 at 2:16pm

Edited: 20/12/2013 2:19pm

I am wishing to show the total number of items pre-checkout in the cart which is placed in a sidebar div, Looking at the swipestripe code i would expect that


would pull in this total figure and show it on page, due to the fact that by using an if statement:

<% if Cart.Items %>

I can show or hide content.

if i use


then i can get a figure to show at front end but it seems to be based on product count, ie: if i purchase 2 items from the same product it will show "1" on the page, if then i go purchase items of a different product it will increase by 1 ( counting products, rather than items) which seems logical to me.

Im racking my brains as to why

wont work, it does show a figure, but this again seems to be on number of different products in cart rather than total number of items.

If anybody come across this issue previously and would care to shed light on the issue i would be very appreciative of the help.

Using swipestripe v2.1 and SS v3.1


Forum Moderator, 53 Posts

20 December 2013 at 8:22pm

This is probably due to Items having a quantity, you might have an item in the cart twice which would have Quantity = 2. You might want to add a method to Page_Controller which loops through Cart.Items and tallies the quantity.


Community Member, 12 Posts

28 December 2013 at 12:12am

Hi Frank,

Firstly apologies for the delay in my writing (xmas hols and festivities), i have finally got time to get around to implementing the total item count.

Couldnt realy get much out of Cart.Items for some reason, so i used "Session::get" on Cart.OrderID, The code is below should someone else want to get mileage out of it:

added to "page_controller extends ContentController" mysite/code/page.php

function TotalQuantItems() {
    $quantitems = Session::get('Cart.OrderID');
    $result = DB::query("SELECT SUM(Quantity) FROM Item WHERE OrderID LIKE $quantitems")->value();
     return $result;

Called into with:

seems to be working ok for me, possibly better ways to get the total, but it works ok for my needs. with just a few lines of code.

regards Martin


Forum Moderator, 53 Posts

6 January 2014 at 9:32am

Hi Martin, glad you could get it sorted out without too much trouble. Thanks for posting the solution, you might be able to make use of Cart::get_current_order(). Strange that Cart.Items wasn't really working for you, I'll have to look into it sometime.