Sha256: e9e172a4a74e3061fd5e8b9bfaee3f5549babdba8d93ed86ddcf3621612dcab2

Contents?: true

Size: 1.82 KB

Versions: 8

Compression:

Stored size: 1.82 KB

Contents

require 'warehouse'
module SuperFormatter
  module Shopline
    class Order
      attr_accessor :row
      attr_accessor :items_array, :warehouse_items

      delegate :recipient, to: :row
      delegate :mobile, to: :row
      delegate :total_order_amount, to: :row
      delegate :store_id, to: :row
      delegate :note, to: :row

      def order_id
        row.order_id.gsub("#", '')
      end

      def initialize(row)
        self.row = row
        merge!(row)
      end

      def provider
        @provider ||= case
        when row.shipping_method.include?('7-11')
          :UNIMART
        when row.shipping_method.include?('全家')
          :FAMI
        when row.shipping_method.include?('新竹')
          :HCT
        when row.shipping_method.include?('黑貓')
          :TCAT
        else
          nil
        end
      end

      def ref_id
        order_id
      end

      def destination
        @destination ||= case provider
        when :UNIMART, :FAMI
          store_id
        when :HCT, :TCAT
          address
        end
      end

      def address
        row.address.gsub("台灣", "")
      end

      def order_created_at
        row.order_created
      end

      def cash_on_delivery?
        if row.payment_method.include?('取貨付款')
          true
        else
          false
        end
      end

      def only_delivery?
        !cash_on_delivery?
      end

      def paid?
        row.payment_status == '已付款'
      end

      def items
        items_array.join(" ")
      end

      def merge!(row)
        self.items_array ||= []
        self.warehouse_items ||= Warehouse::List.new

        self.items_array << "#{row.item_title}-#{row.item_option}*#{row.item_qty}"
        self.warehouse_items += Warehouse::Item::Code.new(row.item_code, row.item_code, row.item_qty)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
super_tools-0.0.8 lib/super_formatter/shopline/order.rb
super_tools-0.0.7 lib/super_formatter/shopline/order.rb
super_tools-0.0.6 lib/super_formatter/shopline/order.rb
super_tools-0.0.5 lib/super_formatter/shopline/order.rb
super_tools-0.0.4 lib/super_formatter/shopline/order.rb
super_tools-0.0.3 lib/super_formatter/shopline/order.rb
super_tools-0.0.2 lib/super_formatter/shopline/order.rb
super_tools-0.0.1 lib/super_formatter/shopline/order.rb