Jump to:

2076 Posts in 857 Topics by 449 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » [SOLVED] cart on every page

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: 646 Views
  • bones
    Avatar
    Community Member
    103 Posts

    [SOLVED] cart on every page Link to this post

    Hi

    Can somebody point me in the right direction to add a cart to every page. I've tried integrating the "Cart Widget", but can't seem to get it to work.

    I've successfully done this on a much older SilverStripe website, but it seems that with every revision of SS and the eCommerce module so much changes!

    Thanks

  • lanks
    Avatar
    Community Member
    61 Posts

    Re: [SOLVED] cart on every page Link to this post

    Hi

    I don't know the specifics of the cart but one option to explore would be to extend SiteConfig with a function that returns the cart. Then call the function from all of your pages, for example inside the "SideBar" template if you have one e.g. $SiteConfig.ShowCart.

    There are some examples of extending SiteConfig over at SSBits.com here.

    I would start by taking the code from the "Cart Widget" and putting it into a function inside a SiteConfig extension.

    Liam

  • bones
    Avatar
    Community Member
    103 Posts

    Re: [SOLVED] cart on every page Link to this post

    Thanks, Liam.

    I have now sorted it. I decided against using the Cart Widget, as it didn't give me the detail which I needed. Instead, I copied the code from OrderInformation_Editable.ss to where I needed it, making a couple of minor changes, most importantly adding <% control SideCart %>

    <table>
    <tbody>
    <% control SideCart %>
    <% if Items %>
    <% control Items %>
    <% if ShowInTable %>
    <tr id="$TableID" class="$Classes">
    <td<% if Link %><% else %> id="$TableTitleID"<% end_if %> class="product title" scope="row"><% if Link %>
    $Quantity x <a id="$TableTitleID" href="$Link" title="<% sprintf(_t("READMORE","Click here to read more on &quot;%s&quot;"),$TableTitle) %>">$TableTitle</a>
    <% else %>
    $Quantity x $TableTitle
    <% end_if %></td>
    <td<% if Link %><% else %> id="$TableTitleID"<% end_if %> class="product title" scope="row">&nbsp;</td>
    <td class="right total" id="$TableTotalID">$Total.Nice</td>
    <td class="right remove"><strong> <a class="ajaxQuantityLink" href="$removeallLink" title="<% sprintf(_t("REMOVEALL","Remove all of &quot;%s&quot; from your cart"),$TableTitle) %>"> <img src="ecommerce/images/remove.gif" alt="x"/> </a> </strong></td>
    </tr>
    <% end_if %>
    <% end_control %>
    <tr class="gap summary">
    <td scope="row"><% _t("SUBTOTAL","Sub-total") %></td>
    <td scope="row">&nbsp;</td>
    <td class="right" id="$TableSubTotalID">$SubTotal.Nice</td>
    <td>&nbsp;</td>
    </tr>
    <% if Modifiers %>
    <% control Modifiers %>
    <% if ShowInTable %>
    <tr id="$TableID" class="$Classes">
    <td<% if Link %><% else %> id="$TableTitleID"<% end_if %> scope="row"><% if Link %>
    <a id="$TableTitleID" href="$Link" title="<% sprintf(_t("READMORE","Click here to read more on &quot;%s&quot;"),$TableTitle) %>">$TableTitle</a>
    <% else %>
    $TableTitle
    <% end_if %></td>
    <td<% if Link %><% else %> id="$TableTitleID"<% end_if %> scope="row">&nbsp;</td>
    <td<% if Link %><% else %> id="$TableTitleID"<% end_if %> scope="row"><span class="right">
    <% if IsChargable %>
    $Amount.Nice
    <% else %>
    -$Amount.Nice
    <% end_if %>
    </span></td>
    <td><span class="right remove">
    <% if CanRemove %>
    <strong> <a class="ajaxQuantityLink" href="$removeLink" title="<% sprintf(_t("REMOVE","Remove &quot;%s&quot; from your order"),$TableTitle) %>"> <img src="ecommerce/images/remove.gif" alt="x"/></a></strong>
    <% end_if %>
    </span></td>
    </tr>
    <% end_if %>
    <% end_control %>
    <% end_if %>
    <tr class="gap Total">
    <td scope="row"><% _t("TOTAL","Total") %></td>
    <td scope="row">&nbsp;</td>
    <td scope="row"><span class="right">$Total.Nice</span></td>
    <td>&nbsp;</td>
    </tr>
    <% else %>
    <tr>
    <td colspan="6" scope="row" class="center"><% _t("NOITEMS","There are <strong>no</strong> items in your cart.") %></td>
    </tr>
    <% end_if %>
    <% end_control %>
    </tbody>
    </table>

    After that, I added the following to mysite/Page.php

       public function SideCart() {
             return ShoppingCart::current_order();
       }


    And that was it

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