SimpleCart.js item link undefined, can't get the link to work

岁酱吖の 提交于 2019-12-08 10:06:14

问题


I'm trying to set up SimpleCart for my website and everything is working 100% fine except when I try to add my products respective links to their own page in the "cart colummns". I am following the documentation (this link takes you to their documentation page explaining how to setup the cart columns including the item link) on how to include the product link but the link keeps saying it's "undefined".

Please take a look at my fiddle (sorry for the lack of styling):

FIDDLE

According to the documentation if you put:

{ view: "link", label: "Details", attr: "pageLink", text: "View Product Page" }

as a cart column (as you can see on line 98 in the fiddle)

and then add the class:

class="item-pageLink">

(Which I presume gleans the following href link as shown below) to the product that can be added to the cart - So in my example and in the js fiddle, I've got:

<div class="item-pageLink"><a href="http://www.google.com">View More</a></div>

...when you click "buy me"... you will see that this item will be added to the cart below but when you hover your mouse over "View Product Page" it shows that the link is "undefined"! It should point / link to google!

I don't know where the problem lies? Please see line 525 in the js panel of the fiddle - this is the only other reference to "getting" the link that I could see.

I've tried googling this issue and although there were others who had experienced the same problem, I cannot find one clear cut solution.

Can anyone help me here?


回答1:


I've been playing around with simpleCart js and here's how I add a link the name of a product in the shopping cart: https://github.com/wojodesign/simplecart-js/issues/476

I pass in item_link <span class="item_link">http://www.example.com</span> in the page HTML and then in the simpleCartSetup.js file I add the view function to attr: "name"

// simpleCartSetup.js

simpleCart({

    // array representing the format and columns of the cart, see 
    // the cart columns documentation
    cartColumns: [
        { attr: "name" , label: "Name",
          // Link function
          view: function (item, column) {
            return "<a href='" + item.get("link") + "'>" + item.get(column.attr) + "</a>"; 
          }
        },
        { attr: "price" , label: "Price", view: 'currency' },
        { view: "decrement" , label: false },
        { attr: "quantity" , label: "Qty" },
        { view: "increment" , label: false },
        { attr: "total" , label: "SubTotal", view: 'currency' },
        { view: "remove" , text: "Remove" , label: false }
    ],

    // "div" or "table" - builds the cart as a table or collection of divs
    cartStyle: "div", 

    // how simpleCart should checkout, see the checkout reference for more info 
    checkout: { 
        type: "PayPal" , 
        email: "you@yours.com" 
    },

    // set the currency, see the currency reference for more info
    currency: "AUD"

});


来源:https://stackoverflow.com/questions/31149969/simplecart-js-item-link-undefined-cant-get-the-link-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!