create.js.erb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <% if @error.blank? %>
  2. //toastr["error"]("Error, El cliente ya tiene asignado el producto seleccionado.");
  3. var table = $('#products_table').DataTable();
  4. var newRow = '<%= j render (@special_price) %>';
  5. table.row.add($(newRow)).draw();
  6. //agregar variantes
  7. <% @variantes.each do |v| %>
  8. <% existing_variant = SpecialPrice.find_by_product_id(v) %> //ver si ya está agregado el producto
  9. <% if existing_variant.blank? %>
  10. <% special_price = SpecialPrice.new %>
  11. <% special_price.product_id = v.id %>
  12. <% special_price.customer_id = @special_price.customer_id %>
  13. <% special_price.user_id = current_user.id %>
  14. <% special_price.save %>
  15. var newRow = '<%= j render (special_price) %>';
  16. table.row.add($(newRow)).draw();
  17. <% end %>
  18. <% end %>
  19. //
  20. <% else %>
  21. //agregar variantes
  22. <% @variantes.each do |va| %>
  23. <% existing_variant = SpecialPrice.find_by_product_id(va) %> //ver si ya está agregado el producto
  24. <% if existing_variant.blank? %>
  25. <% special_price = SpecialPrice.new %>
  26. <% special_price.product_id = va.id %>
  27. <% special_price.customer_id = @special_price.customer_id %>
  28. <% special_price.user_id = current_user.id %>
  29. <% special_price.save %>
  30. var newRow = '<%= j render (special_price) %>';
  31. table.row.add($(newRow)).draw();
  32. <% end %>
  33. <% end %>
  34. //
  35. <% end %>