jeudi 13 juin 2019

how to add if statement in form with rails

I am trying to implement this logic into form based on the sku (where sku will determine the country and the country will determine the shipping option)

country = order&.shop&.country
    if (READY_FOR_SCHOOL_SKUS + STICKER_BOOK_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "RoyalMail48")
      else
        shipping_option = ShippingOption.find_by(name: "TPLP")
      end
      return shipping_option
    end
    if (DICTIONARY_SKUS + WORD_OF_DAY_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "RoyalMail48")
      else
        shipping_option = ShippingOption.find_by(name: "standard_3_to_10_days")
      end
      return shipping_option
    end
    if (RFS_STICKER_BOOK_SKUS + USA_SUBSCRIPTION_SKUS + UK_SUBSCRIPTION_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "dhl")
      else
        shipping_option = ShippingOption.find_by(name: "TPLP")
      end
      return shipping_option
    end

<% @product.product_shop_shipping_options.uniq(&:shop).each_with_index do |psso, i|%>
  <%= f.fields_for :product_shop_shipping_options, psso do |s| %>
    <%= s.label psso.shop.shopify_shop_name %>
    <%= s.hidden_field :shop_id %>
    <%= s.grouped_collection_select :shipping_option_id, @fulfilment_centres, :shipping_options, :name, :id, :name, {prompt: 'Select shipping option'}, { class: 'form-control'} %>
  <% end %>
<% end %>

Aucun commentaire:

Enregistrer un commentaire