Module: Spree::Api::ApiHelpers
- Defined in:
- app/helpers/spree/api/api_helpers.rb
Constant Summary collapse
- ATTRIBUTES =
[ :product_attributes, :product_property_attributes, :variant_attributes, :image_attributes, :option_value_attributes, :order_attributes, :line_item_attributes, :option_type_attributes, :payment_attributes, :payment_method_attributes, :shipment_attributes, :taxonomy_attributes, :taxon_attributes, :address_attributes, :country_attributes, :state_attributes, :adjustment_attributes, :inventory_unit_attributes, :customer_return_attributes, :return_authorization_attributes, :creditcard_attributes, :payment_source_attributes, :user_attributes, :property_attributes, :stock_location_attributes, :stock_movement_attributes, :stock_item_attributes, :promotion_attributes, :store_attributes, :store_credit_history_attributes, :variant_property_attributes ]
Instance Method Summary collapse
- #authorized_attributes(resource, config_attribute) ⇒ Object
- #required_fields_for(model) ⇒ Object
- #total_on_hand_for(object) ⇒ Object
- #variant_attributes ⇒ Object
Instance Method Details
#authorized_attributes(resource, config_attribute) ⇒ Object
52 53 54 |
# File 'app/helpers/spree/api/api_helpers.rb', line 52 def (resource, config_attribute) can?(:admin, resource) ? Spree::Api::Config.public_send(config_attribute) + [:admin_metadata] : Spree::Api::Config.public_send(config_attribute) end |
#required_fields_for(model) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/spree/api/api_helpers.rb', line 56 def required_fields_for(model) required_fields = model._validators.select do |_field, validations| validations.any? { |validation| validation.is_a?(ActiveModel::Validations::PresenceValidator) } end.map(&:first) # get fields that are invalid # Permalinks presence is validated, but are really automatically generated # Therefore we shouldn't tell API clients that they MUST send one through required_fields.map!(&:to_s).delete("permalink") # Do not require slugs, either required_fields.delete("slug") required_fields end |
#total_on_hand_for(object) ⇒ Object
77 78 79 |
# File 'app/helpers/spree/api/api_helpers.rb', line 77 def total_on_hand_for(object) object.total_on_hand.finite? ? object.total_on_hand : nil end |
#variant_attributes ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'app/helpers/spree/api/api_helpers.rb', line 68 def variant_attributes preference_attributes = Spree::Api::Config.variant_attributes if @current_user_roles&.include?("admin") preference_attributes + [:cost_price] else preference_attributes end end |