Class: Transporter

Inherits:
Ruleby::Rulebook
  • Object
show all
Defined in:
lib/transporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cart=(value) ⇒ Object (writeonly)

Sets the attribute cart

Parameters:

  • value

    the value to set the attribute cart to.



4
5
6
# File 'lib/transporter.rb', line 4

def cart=(value)
  @cart = value
end

#order=(value) ⇒ Object (writeonly)

Sets the attribute order

Parameters:

  • value

    the value to set the attribute order to.



4
5
6
# File 'lib/transporter.rb', line 4

def order=(value)
  @order = value
end

#transporter_ids=(value) ⇒ Object (writeonly)

Sets the attribute transporter_ids

Parameters:

  • value

    the value to set the attribute transporter_ids to.



4
5
6
# File 'lib/transporter.rb', line 4

def transporter_ids=(value)
  @transporter_ids = value
end

Instance Method Details

#rulesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/transporter.rb', line 6

def rules
  TransporterRule.find_all_by_active(true).each do |transporter|
    condition = transporter.conditions
    condition.gsub!(/Cart/,'Order') unless @cart
    rule eval(condition) do |context|

      if @cart && @cart.address_delivery && !transporter.geo_zones.empty? && transporter.geo_zones.map(&:id).include?(@cart.address_delivery.country.id)
        @transporter_ids << transporter.id
      elsif @cart && @cart.address_delivery && transporter.geo_zones.empty?
        p 'skipped'
      elsif @cart && @cart.address_delivery && !transporter.geo_zones.empty? && !transporter.geo_zones.map(&:id).include?(@cart.address_delivery.country.id)
        p 'skipped'
      else
        @transporter_ids << transporter.id
      end
    end
  end
  @transporter_ids
end