0

我试图弄清楚如何将 css 类添加到SimpleCartJS生成的购物车表中。(我使用的购物车布局是这样的: http: //bootsnipp.com/snippets/featured/shopping-cart-bs-3但这并不重要)

=============

输入

这是我的js配置:

simpleCart({
    checkout: {
      type: "PayPal",
      email: "you@yours.com"
    },
    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 }
        ]
  });

和我的 HTML:

<div class="simpleCart_items"></div>

=============

输出

在此处输入图像描述

基本上输出是一个通用表。

=============

我如何能:

  1. 变成? <table>_<table class="table table-hover">

  2. 在 simpleCart_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>

所以它最终看起来像:

在此处输入图像描述

有什么帮助吗?

4

4 回答 4

3

有用的链接: https ://github.com/wojodesign/simplecart-js/issues/362

TL;博士

  1. 转到您的 simplecart.js

  2. 搜索items: function (selector)

  3. simpleCart.writeCart(selector);添加新行后simpleCart.trigger("afterCreate");

  4. 添加一个新的绑定:

    simpleCart.bind("afterCreate", function(){
       $cart_table = $(".simpleCart_items table")
       $cart_table.addClass("table").addClass("table-hover")
    });
    

    你可以像往常一样在这里添加所有你想要的>:3!

于 2014-08-24T03:00:37.230 回答
2

我解决了受先前评论启发的问题,而没有编辑实际的 simplcart.js 文件:

首先通过添加 afterCartCreate 事件来破解 simpleCart:

    var originalMethod = simpleCart.writeCart;
    simpleCart.extend({
      // write out cart
      writeCart: function (selector) {
        originalMethod(selector);
        simpleCart.trigger('afterCartCreate');
      }
  });

不仅仅是绑定到事件:

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');
  });

瞧;)

于 2017-06-24T15:27:20.980 回答
2

在你的CSS中添加

.simpleCart_items table { width:100%; }

这应该扩展整个表。

于 2016-06-09T20:25:53.033 回答
1

看看 simplecartjs.org 购物车。配置在页脚中。您可以使用函数来创建自定义购物车视图。您可以将其添加到购物车列数组中。

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"
});

这也在此处的文档中进行了讨论

于 2017-09-25T20:26:17.203 回答