将产品信息添加到购物车

时间:2018-07-16 15:43:09

标签: javascript jquery html opencart

我有一个购物车功能,可以向其中添加项目,但是我无法获取它来添加该项目的详细信息。现在,它只是提取通用数据,我希望它可以获取产品标题,位置和日期。我知道有一种获取HTML文本的方法,但是不知道如何将其添加到此脚本中。这是HTML标记:

[notice] 2018-07-16T14:58:14.936265Z couchdb@127.0.0.1 <0.27495.232> ace657cb79 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 2
[notice] 2018-07-16T14:58:14.938101Z couchdb@127.0.0.1 <0.27714.232> 0f8058a082 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:15.643560Z couchdb@127.0.0.1 <0.27421.232> 7109b0fe1c 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 1
[notice] 2018-07-16T14:58:15.644622Z couchdb@127.0.0.1 <0.29430.232> 62ae5b985c 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 0
[notice] 2018-07-16T14:58:15.676596Z couchdb@127.0.0.1 <0.27058.232> 525bfaef78 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 1
[notice] 2018-07-16T14:58:15.677802Z couchdb@127.0.0.1 <0.27216.232> a5bfb296e2 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:15.729505Z couchdb@127.0.0.1 <0.27325.232> 3a7ef79eee 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 5
[notice] 2018-07-16T14:58:15.730669Z couchdb@127.0.0.1 <0.27271.232> 859e6a7a77 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:15.899331Z couchdb@127.0.0.1 <0.29372.232> bab85b4599 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 2
[notice] 2018-07-16T14:58:15.900569Z couchdb@127.0.0.1 <0.29451.232> a7814fa0d6 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:16.194140Z couchdb@127.0.0.1 <0.27487.232> a33e1cf89a 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 2
[notice] 2018-07-16T14:58:16.195184Z couchdb@127.0.0.1 <0.27437.232> d83fa88258 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:16.374816Z couchdb@127.0.0.1 <0.27374.232> 7e3181a5fe 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 2
[notice] 2018-07-16T14:58:16.375180Z couchdb@127.0.0.1 <0.26122.232> 63dd14607c 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 2
[notice] 2018-07-16T14:58:16.376273Z couchdb@127.0.0.1 <0.26973.232> dbe6cbfbfe 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 0
[notice] 2018-07-16T14:58:16.377752Z couchdb@127.0.0.1 <0.26655.232> 1dc92196a6 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 0
[notice] 2018-07-16T14:58:16.380779Z couchdb@127.0.0.1 <0.26974.232> 6f551e8c54 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 4
[notice] 2018-07-16T14:58:16.381229Z couchdb@127.0.0.1 <0.21323.232> ff863db7bb 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 4
[notice] 2018-07-16T14:58:16.382777Z couchdb@127.0.0.1 <0.26610.232> 05aed374e1 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:16.382818Z couchdb@127.0.0.1 <0.23204.232> 0177b5a85c 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:16.383940Z couchdb@127.0.0.1 <0.26937.232> a62c233ddc 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-a713a2af2eb25c57ba17548 409 ok 5
[notice] 2018-07-16T14:58:16.384476Z couchdb@127.0.0.1 <0.27032.232> e7938336f1 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-dbba7695d17cdec2cc6dc94 409 ok 1
[notice] 2018-07-16T14:58:16.384887Z couchdb@127.0.0.1 <0.26874.232> 3bc9bbc043 127.0.0.1:5984 127.0.0.1 client GET /user-a713a2af2eb25c57ba17548/_security 200 ok 1
[notice] 2018-07-16T14:58:16.385498Z couchdb@127.0.0.1 <0.26751.232> b1644014a0 127.0.0.1:5984 127.0.0.1 client GET /user-dbba7695d17cdec2cc6dc94/_security 200 ok 1
[notice] 2018-07-16T14:58:16.387350Z couchdb@127.0.0.1 <0.27782.232> 9dd4b8a07e 127.0.0.1:5984 127.0.0.1 undefined PUT /_users/org.couchdb.user%3Auser-5cd8241f12f4f91ba20feb3 409 ok 1
[notice] 2018-07-16T14:58:16.388264Z couchdb@127.0.0.1 <0.26625.232> eec2e12357 127.0.0.1:5984 127.0.0.1 client GET /user-5cd8241f12f4f91ba20feb3/_security 200 ok 0
var cartOpen = false;
var numberOfProducts = 0;
$('body').on('click', '.js-toggle-cart', toggleCart);
$('body').on('click', '.js-add-product', addProduct);
$('body').on('click', '.js-remove-product', removeProduct);

function toggleCart(e) {
  e.preventDefault();
  if (cartOpen) {
    closeCart();
    return;
  }
  openCart();
}

function openCart() {
  cartOpen = true;
  $('body').addClass('open');
}

function closeCart() {
  cartOpen = false;
  $('body').removeClass('open');
}

function addProduct(e) {
  e.preventDefault();
  openCart();
  $('.js-cart-empty').addClass('hide');
  var product = $('.js-cart-product-template').html();
  $('.js-cart-products').prepend(product);
  numberOfProducts++;
}

function removeProduct(e) {
  e.preventDefault();
  numberOfProducts--;
  $(this).closest('.js-cart-product').hide(250);
  if (numberOfProducts == 0) {
    $('.js-cart-empty').removeClass('hide');
  }
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:-1)

这将选择product__title的文本

$('.product__title').text()

这将使国家/地区选项选择文本和值

$('#country option:selected').val()
$('#country option:selected').text()

这将获取您的日期

$('#pu-2lc').val()

一旦有了文本,就可以将其放置在所需的位置。只是查看代码,您似乎想在这些代码中获取这些值 addProduct()方法。请让我知道这是否是您想要的。如果我们有自己的购物车代码,我可以提供更多的见识。