简体   繁体   English

如何在狂欢商务购物车中修改输入的值

[英]How to modify the value of an input in spree commerce cart

I have the following cart view that i addapted with bootstrap. 我有以下我添加了引导程序的购物车视图。

  <div class="row line_item">

    <div class="col-md-4 cart-item-image" data-hook="cart_item_image">
      <% if variant.images.length == 0 %>
        <%= link_to small_image(variant.product), variant.product %>
      <% else %>
        <%= link_to image_tag(variant.images.first.attachment.url(:product)), variant.product %>
      <% end %>
    </div>
    <div class="col-md-4 cart-item-image" data-hook="cart_item_description">
      <h4><%= link_to line_item.name, product_path(variant.product) %></h4>
      <%= variant.options_text %>
      <% if line_item.insufficient_stock? %>
        <span class="out-of-stock">
          <%= Spree.t(:out_of_stock) %>&nbsp;&nbsp;<br />
        </span>
      <% end %>
      <span class="line-item-description" data-hook="line_item_description">
        <%= line_item_description_text(line_item.description) %>
      </span>
    </div>
    <div class="col-md-1 cart-item-price" data-hook="cart_item_price">
      <%= line_item.single_money.to_html %>
    </div>
    <div class="col-md-1 cart-item-quantity" data-hook="cart_item_quantity" valign="center">
      <%= item_form.number_field :quantity, min: 0, class: "form-control line_item_quantity", size: 5 %>
    </div>
    <div class="col-md-2">
      <div class="cart-item-total" data-hook="cart_item_total">
        <%= line_item.display_amount.to_html unless line_item.quantity.nil? %>
      </div>
      <div class="cart-item-delete" data-hook="cart_item_delete">
        <%= link_to content_tag(:span, '', class: 'glyphicon glyphicon-minus-sign'), '#', class: 'delete', id: "delete_#{dom_id(line_item)}" %>
      </div>
    </div>
  </div>

and the following coffeescript that goes along with it 以及随之而来的以下咖啡脚本

    Spree.ready ($) ->
  if ($ 'form#update-cart').is('*')
    ($ 'form#update-cart a.delete').show().one 'click', ->
      ($ this).parents('.line-item').first().find('input.line_item_quantity').val 0
      ($ this).parents('form').first().submit()
      false

  ($ 'form#update-cart').submit ->
     ($ 'form#update-cart #update-button').attr('disabled', true)

Now the delete button does not work with this cart html ( while it is working with the original view a following) 现在,“删除”按钮不适用于此购物车html(与以下原始视图一起使用时)

<div style="margin-top: 35px;">
  <div class="row">
  <tr class="line-item">
    <td class="col-md-4 cart-item-image" data-hook="cart_item_image">
      <% if variant.images.length == 0 %>
        <%= link_to small_image(variant.product), variant.product %>
      <% else %>
        <%= link_to image_tag(variant.images.first.attachment.url(:small)), variant.product %>
      <% end %>
    </td>
    <td class="col-md-4 cart-item-description" data-hook="cart_item_description">
      <h4><%= link_to line_item.name, product_path(variant.product) %></h4>
      <%= variant.options_text %>
      <% if line_item.insufficient_stock? %>
        <span class="out-of-stock">
          <%= Spree.t(:out_of_stock) %>&nbsp;&nbsp;<br />
        </span>
      <% end %>
      <span class="line-item-description" data-hook="line_item_description">
        <%= line_item_description_text(line_item.description) %>
      </span>
    </td>
    <td class="col-md-1 lead text-primary cart-item-price" data-hook="cart_item_price">
      <%= line_item.single_money.to_html %>
    </td>
    <td class="col-md-1 cart-item-quantity" data-hook="cart_item_quantity" valign="center">
      <%= item_form.number_field :quantity, min: 0, class: "form-control line_item_quantity", size: 5 %>
    </td>
    <td class="col-md-1 lead text-primary cart-item-total" data-hook="cart_item_total">
      <%= line_item.display_amount.to_html unless line_item.quantity.nil? %>
     </td>
    <td class="col-md-1 cart-item-delete" data-hook="cart_item_delete">
      <%= link_to content_tag(:span, '', class: 'glyphicon glyphicon-minus-sign'), '#', class: 'delete', id: "delete_#{dom_id(line_item)}" %>
    </td>
  </tr>
</div>
</div>

It seems to me that the coffeescript should work in both cases! 在我看来,咖啡脚本在两种情况下都应该起作用!

What am i missing after i modify the view ? 修改视图后我缺少什么? It seems to me that the coffeescript should perform the search in both cases... 在我看来,在两种情况下,coffescript都应执行搜索...

It doesn't look like you've done anything wrong when it comes to keeping the markup for the javascript the same. 保持javascript的标记不变,看起来您没有做错任何事情。 My guess would be that Spree.ready ($) -> isn't actually firing. 我的猜测是Spree.ready ($) ->实际上并未触发。 That could be caused by you removing javascript files during your view customization by accident. 这可能是由于您在视图自定义过程中意外删除了javascript文件引起的。 You should try checking your web developer console to see if there are any javascript errors like Spree not being defined or something like that. 您应该尝试检查Web开发人员控制台,以查看是否存在未定义Spree之类的javascript错误或类似错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM