Sha256: 7852d27b481a300080ac0f42349e83a02215e6b793f3577d8350b56b3d457177

Contents?: true

Size: 1.85 KB

Versions: 13

Compression:

Stored size: 1.85 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
      delegate :complete?, 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

13 entries across 13 versions & 1 rubygems

Version Path
super_tools-2.1.0 lib/super_formatter/shopline/order.rb
super_tools-0.0.26 lib/super_formatter/shopline/order.rb
super_tools-0.0.25 lib/super_formatter/shopline/order.rb
super_tools-0.0.21 lib/super_formatter/shopline/order.rb
super_tools-0.0.20 lib/super_formatter/shopline/order.rb
super_tools-0.0.17 lib/super_formatter/shopline/order.rb
super_tools-0.0.15 lib/super_formatter/shopline/order.rb
super_tools-0.0.14 lib/super_formatter/shopline/order.rb
super_tools-0.0.13 lib/super_formatter/shopline/order.rb
super_tools-0.0.12 lib/super_formatter/shopline/order.rb
super_tools-0.0.11 lib/super_formatter/shopline/order.rb
super_tools-0.0.10 lib/super_formatter/shopline/order.rb
super_tools-0.0.9 lib/super_formatter/shopline/order.rb