【问题标题】:Add products to cart using drag & drop in magento使用magento中的拖放将产品添加到购物车
【发布时间】:2013-02-06 10:39:08
【问题描述】:

我想使用拖放将产品添加到购物车。 为此,我正在使用 jQuery UI Droppable 。代码是:-

  <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
     $(function() {
$( ".category-products" ).accordion();
$( ".product-name" ).draggable({
  appendTo: "body",
  helper: "clone"
});
$( ".block-content ol" ).droppable({
  activeClass: "ui-state-default",
  hoverClass: "ui-state-hover",
  accept: ":not(.ui-sortable-helper)",
  drop: function( event, ui ) {
    $( this ).find( ".placeholder" ).remove();
    $( "<li></li>" ).text( ui.draggable.text() ).appendTo( this );
  }
}).sortable({
  items: "li:not(.placeholder)",
  sort: function() {
    // gets added unintentionally by droppable interacting with sortable
    // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
    $( this ).removeClass( "ui-state-default" );
  }
});

});

使用此代码产品名称可放入购物车,但不会添加到购物车。我尝试但无法将产品名称添加到购物车。请帮帮我。

【问题讨论】:

  • 这些产品有没有产品选择?

标签: jquery jquery-ui magento magento-1.7 jquery-droppable


【解决方案1】:

假设您的产品没有任何自定义选项。

将您的产品 ID 存储为产品列表中的隐藏字段(可拖动的 li)

      <li>Lolcat Shirt
          <input type='hidden' value='2' name='pid' />
      </li>

那么做

  drop: function( event, ui ) {
    $( this )
      .addClass( "ui-state-highlight" )
      .find( "> p" )
        .html( "Dropped!" );

    add product to cart
    p_id = ui.draggable.find('input[name="pid"]').val();
    $.get("/path/to/app/checkout/cart/add?qty=1&product=" + p_id)

    return false;
  }

http://jsfiddle.net/C2Ufk/

你需要做一些类似的事情来删除项目

【讨论】:

  • 感谢您的回答。产品名称和购物车框在不同的 phtml 文件中。当我将传递 p_id 值时,它会显示未定义的值。请帮帮我
  • 由于这是使用 javascript 来完成的,因此它不应改变它所在的 phtml 文件。请添加屏幕截图,以便我更好地了解您的尝试
  • 对不起,我弄错了。现在我在警告框中得到了正确的网址。
  • 现在我正在获取网址,但我必须将产品添加到购物车。我认为为此我必须使用 ajax 将产品添加到购物车。请帮帮我
【解决方案2】:

我有一个相同的模块..

Drag & Drop Sort Products 对我来说效果很好.. 真的很棒。

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2012-09-14
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    相关资源
    最近更新 更多