Guest User

Untitled

a guest
Oct 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. def tcat_delivery_list
  2. @tcat_delivery_list or begin
  3. delivery_option = DeliveryOption.valid.find_by(owner_type: 'Merchant', owner_id: merchant.id, region_type: 'tw_tcat')
  4. return @tcat_delivery_list = TcatDeliveryList.new('tw_tcat', nil) if delivery_option.blank?
  5. contract_code = delivery_option.config_data['contract_code'].tap { |code| raise "DeliveryOption #{delivery_option.id} has no contract_code" if code.blank? }
  6. @tcat_delivery_list = TcatDeliveryList.new('tw_tcat', contract_code)
  7. end
  8. end
  9.  
  10. def tcat_pay_delivery_list
  11. @tcat_pay_delivery_list or begin
  12. delivery_option = DeliveryOption.valid.find_by(owner_type: 'Merchant', owner_id: merchant.id, region_type: 'tw_tcat_pay')
  13. return @tcat_pay_delivery_list = TcatDeliveryList.new('tw_tcat_pay', nil) if delivery_option.blank?
  14. contract_code = delivery_option.config_data['contract_code'].tap { |code| raise "DeliveryOption #{delivery_option.id} has no contract_code" if code.blank? }
  15. @tcat_pay_delivery_list = TcatDeliveryList.new('tw_tcat_pay', contract_code)
  16. end
  17. end
  18.  
  19. %w(tcat tcat_pay).each do |type|
  20. class_eval <<-RUBY, __FILE__, __LINE__ + 1
  21. def #{type}_delivery_list
  22. @#{type}_delivery_list or begin
  23. region_type = "tw_%s" % :#{type}.to_s
  24. delivery_option = DeliveryOption.valid.find_by(owner_type: 'Merchant', owner_id: merchant.id, region_type: region_type)
  25. return @#{type}_delivery_list = TcatDeliveryList.new(region_type, nil) if delivery_option.blank?
  26. contract_code = delivery_option.config_data['contract_code'].tap { |code| raise "DeliveryOption %s has no contract_code" % delivery_option.id if code.blank? }
  27. @#{type}_delivery_list = TcatDeliveryList.new(region_type, contract_code)
  28. end
  29. end
  30. RUBY
  31. end
Add Comment
Please, Sign In to add comment