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.

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

[SOLVED] cart on every page


Reply


3 Posts   921 Views

Avatar
bones

Community Member, 104 Posts

20 September 2011 at 11:18pm

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

Avatar
lanks

Community Member, 61 Posts

23 September 2011 at 7:45pm

Edited: 23/09/2011 7:46pm

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 [url=http://www.ssbits.com/tutorials/2010/2-4-working-with-siteconfig/]here[/url].

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

Liam

Avatar
bones

Community Member, 104 Posts

4 October 2011 at 4:37am

Edited: 04/10/2011 4:41am

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 :)