Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spree promotion rule for properties
<!-- admin/promotions/rules/_property.html.erb -->
<div class="panel-body">
<div class="form-group property_rule_property_id">
<%= label_tag "#{param_prefix}_property_id_string", Spree.t('property_rule.choose_property') %>
<%= select_tag "#{param_prefix}[preferred_property_id]", options_from_collection_for_select(Spree::Property.all, "id", "presentation", promotion_rule.preferred_property_id), class: 'select2' %>
<%= label_tag "#{param_prefix}_value_string", Spree.t('property_rule.insert_value') %>
<%= text_field_tag "#{param_prefix}[preferred_value]", promotion_rule.preferred_value, class: 'form-control' %>
</div>
</div>
# config/locales/es.yml
es:
spree:
promotion_rule_types:
property:
description: La orden incluye productos específicos con las propiedades correspondientes
name: Propiedades
property_rule:
choose_property: Seleccione propiedad
insert_value: Escriba valor para propiedad (nombre autor o editorial)
label: Orden debe contener una cantidad x de estas categorías
module Spree
class Promotion
module Rules
class Property < Spree::PromotionRule
preference :property_id, :integer
preference :value, :string
def applicable?(promotable)
promotable.is_a?(Spree::Order)
end
def eligible?(order, options = {})
order.line_items.any? { |item| actionable?(item) }
end
def actionable?(line_item)
property = Spree::Property.find(preferred_property_id)
line_item.product.property(property.name).downcase == preferred_value.downcase
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.