Spree - how to add multiple products to cart

让人想犯罪 __ 提交于 2020-01-07 03:03:11

问题


I have created a semi-custom Addon function for products. I created a new relationship table in the backend which connects one product to another product (through a checkbox and an ajax request in the backend).

What I am having trouble with is how to manipulate the populate_orders_path so that I can pass various variant/product id's to the cart at the same time.

Currently in my cart form partial I have this:

  <div id="product-addons" class="col-md-6">
    <h3 class="product-section-title">Add Ons</h3>
    <%= image_tag('short-line-2.png', class: 'hundy') %>
    <% addons = Addon.where(product_id: @product.id) %>
    <% addons.each_with_index do |a, index| %>
        <%= a.inspect %>
        <% product_addon = Spree::Product.where(id: a.product_addon_id).first %>
        <% addon_variant = Spree::Variant.where(product_id: a.product_addon_id).first %>
        <% addon_image = Spree::Asset.where(viewable_id: addon_variant.id).first %>
        <div class="col-lg-12">
          <%= image_tag('/spree/products/' + addon_image.id.to_s + '/mini/' + product_addon.images[0].attachment_file_name) %>
          <%= check_box_tag "products[#{a.id}][]", addon_variant.id, index == 0 %>

          <span style="margin-left: 6px;"><%= product_addon.name %></span>
          <br/>
        </div>
    <% end %>
  </div>

But I am not sure what to do with <%= hidden_field_tag "variant_id", @product.master.id %> in order for it to use multiple ID's. Any help would be much appreciated.


回答1:


You can get above functionality by Spree promotion. Configure the item added to cart rule and add another item to cart by action in promotion section.

it will work like this if Variant A is added to cart then Variant B will be added to cart automatically.



来源:https://stackoverflow.com/questions/33202564/spree-how-to-add-multiple-products-to-cart

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