Jump to:

2084 Posts in 1005 Topics by 453 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Swipestripe: Showing item count on custom template

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, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 629 Views
  • Martinjj
    Avatar
    Community Member
    12 Posts

    Swipestripe: Showing item count on custom template Link to this post

    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

    $Cart.Items.Count

    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

    $Cart.Products.Count

    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

    $Cart.Items.Count

    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.
    Thanks

    Using swipestripe v2.1 and SS v3.1

  • frankmullenger
    Avatar
    Forum Moderator
    51 Posts

    Re: Swipestripe: Showing item count on custom template Link to this post

    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.

  • Martinjj
    Avatar
    Community Member
    12 Posts

    Re: Swipestripe: Showing item count on custom template Link to this post

    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 Sidebar.ss with:
    $TotalQuantItems

    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

  • frankmullenger
    Avatar
    Forum Moderator
    51 Posts

    Re: Swipestripe: Showing item count on custom template Link to this post

    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.

    629 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.