Sha256: f5b2554f2aea3284e1a31e4e7696899466bd85b8aee1013bf32021d06ae643dd
Contents?: true
Size: 1020 Bytes
Versions: 10
Compression:
Stored size: 1020 Bytes
Contents
module MageRecord # add custom FitLion-specific order methods class Order < ActiveRecord::Base # mysql regex for postal codes that are in town TOWN_REGEX = '^(0[1-9]|10|1[78]|2[2-4])' # ignore canceled orders default_scope { where state: [:processing, :complete] } scope :prepaid, -> { joins(:payment).where("#{OrderPayment.table_name}.method NOT IN (?, ?)", 'cashondelivery', 'checkmo') } scope :delivery, -> { where shipping_method: [:flatrate_flatrate, :addon_addon] } scope :collection, -> { where "#{Order.table_name}.shipping_method LIKE 'selfcollect%'" } scope :town, -> { joins(:shipping_address).where("sales_flat_order_address.postcode RLIKE ?", TOWN_REGEX) } scope :residential, -> { joins(:shipping_address).where("sales_flat_order_address.postcode NOT RLIKE ?", TOWN_REGEX) } def for_delivery? %w{flatrate addon}.include? shipping_method.split('_').first end def for_collection? shipping_method.include? 'selfcollect' end end end
Version data entries
10 entries across 10 versions & 1 rubygems