Reputation: 48258
I'm trying to figure out how to add css classes to the cart table that SimpleCartJS generates. (The cart layout I'm using is this: http://bootsnipp.com/snippets/featured/shopping-cart-bs-3 but it doesn't really matter)
============
This is my js configuration:
simpleCart({
checkout: {
type: "PayPal",
email: "[email protected]"
},
cartStyle: "table",
cartColumns: [
/* Picture (same for every product right now) */
{ view: function( item, column) {
return "<a class=\"thumbnail pull-left\" href=\"#\"> "
+"<img class=\"media-object\" src=\"http://icons.iconarchive.com/icons/custom-icon-design/flatastic-2/72/product-icon.png\" "
+"style=\"width: 72px; height: 72px;\"> </a>";
}, label: false },
/* Name */
{ attr: "name", label: "Product" },
/* Quantity */
{ attr: "quantity" , label: "Qty" } ,
/* Price */
{ attr: "price" , label: "Price", view: 'currency' } ,
/* Remove */
{ view: "remove" , text: "Remove" , label: false }
]
});
and my HTML:
<div class="simpleCart_items"></div>
============
Basically the output is a generic table.
============
Turn <table>
into <table class="table table-hover">
?
Add these rows under the simpleCart_items?
I'd like these to be rows under all the items:
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h5>Subtotal</h5></td>
<td><div class="simpleCart_total"></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h5>Estimated shipping</h5></td>
<td><div class="simpleCart_shipping"></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h3>Total</h3></td>
<td><div class="simpleCart_grandTotal"></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><a href="javascript:;" class="simpleCart_checkout">Checkout</a></td>
</tr>
so it'd end up looking something like:
Any help?
Upvotes: 1
Views: 5315
Reputation: 11
Take a look at the simplecartjs.org cart. The configuration is in the footer. You can use a function to create custom cart views. You can add this to the cart columns array.
simpleCart({
currency: "RUB",
cartColumns: [
{ view: "image" , attr: "thumb", label: false },
{ attr: "name" , label: "Name" },
{ view: function(item, column){
return "<img src='"+ item.get('thumb')+"' alt='product' />" +"<span class='item-format'>"+item.get('total')+"</span>";
}, attr: 'custom' }
],
cartStyle: "div"
});
Also this is discussed in the documentation here
Upvotes: 1
Reputation: 31
I solved the issue inspired by previous comments, without editing the actual simplcart.js file:
First hack simpleCart by adding the afterCartCreate event:
var originalMethod = simpleCart.writeCart;
simpleCart.extend({
// write out cart
writeCart: function (selector) {
originalMethod(selector);
simpleCart.trigger('afterCartCreate');
}
});
than just bind to the event:
simpleCart.on('afterCartCreate',function (){
console.log("After create");
$('.simpleCart_items table').addClass('table');
$('.item-decrement a').addClass('btn').addClass('btn-default');
$('.item-increment a').addClass('btn').addClass('btn-default');
});
and voila ;)
Upvotes: 3
Reputation: 21
In you css add
.simpleCart_items table {
width:100%;
}
This should extend the whole table.
Upvotes: 2
Reputation: 46
useful link: https://github.com/wojodesign/simplecart-js/issues/362
TL;DR
Go to your simplecart.js
Search for items: function (selector)
after simpleCart.writeCart(selector);
add in a new line simpleCart.trigger("afterCreate");
add a new bind:
simpleCart.bind("afterCreate", function(){
$cart_table = $(".simpleCart_items table")
$cart_table.addClass("table").addClass("table-hover")
});
you can add here all you want as always >:3!
Upvotes: 3