item_builder_mwh 0.1.0 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/item_builder_mwh/modes.rb +9 -1
- data/lib/item_builder_mwh/modes/active_service.rb +1 -0
- data/lib/item_builder_mwh/modes/price/base.rb +26 -0
- data/lib/item_builder_mwh/modes/price/blibli_service.rb +27 -0
- data/lib/item_builder_mwh/modes/price/bukalapak_service.rb +61 -0
- data/lib/item_builder_mwh/modes/price/jd_service.rb +31 -0
- data/lib/item_builder_mwh/modes/price/sale_price_policy.rb +40 -0
- data/lib/item_builder_mwh/modes/price/shopify_service.rb +28 -0
- data/lib/item_builder_mwh/modes/price/zalora_service.rb +27 -0
- data/lib/item_builder_mwh/modes/price_service.rb +44 -4
- data/lib/item_builder_mwh/modes/quantity/base.rb +75 -0
- data/lib/item_builder_mwh/modes/quantity/blibli_service.rb +51 -0
- data/lib/item_builder_mwh/modes/quantity/lazada_service.rb +14 -0
- data/lib/item_builder_mwh/modes/quantity/zalora_service.rb +14 -0
- data/lib/item_builder_mwh/modes/quantity_service.rb +29 -1
- data/lib/item_builder_mwh/modes/simple/base.rb +84 -0
- data/lib/item_builder_mwh/modes/simple/blibli_service.rb +66 -0
- data/lib/item_builder_mwh/modes/simple/bukalapak_service.rb +69 -0
- data/lib/item_builder_mwh/modes/simple/jd_service.rb +35 -0
- data/lib/item_builder_mwh/modes/simple/lazada_service.rb +25 -0
- data/lib/item_builder_mwh/modes/simple/sale_price_policy.rb +39 -0
- data/lib/item_builder_mwh/modes/simple/shopee_service.rb +25 -0
- data/lib/item_builder_mwh/modes/simple/shopify_service.rb +31 -0
- data/lib/item_builder_mwh/modes/simple/zalora_service.rb +31 -0
- data/lib/item_builder_mwh/modes/simple_service.rb +81 -7
- data/lib/item_builder_mwh/version.rb +1 -1
- metadata +28 -8
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b7959404e655216093aa4627d166ee6c18b7651b7c4d92d37b6cd1ce69e8825d
         | 
| 4 | 
            +
              data.tar.gz: 224d6f83a4a52895337aed2680813907d9393f8509242c70475852b638d68f98
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6859bbde6689fe1b762166a2eec5b88a4922bd00a95f8b81912447ab31ebecc57e269e6c33e61edd872b623ebf635b77ee6c852e0c580170b977b71b9caef5c3
         | 
| 7 | 
            +
              data.tar.gz: 4b5006d249a5754af1d80d438cc1a2d1de86518a954ef2d277d81238f029e95435dc2079adad96d84ae4b95e93f0b9d8d804b39b227f70529bd974f80ea0a8b8
         | 
| @@ -29,7 +29,15 @@ module ItemBuilderMwh | |
| 29 29 | 
             
                end
         | 
| 30 30 |  | 
| 31 31 | 
             
                def warehouse_spaces
         | 
| 32 | 
            -
                  WarehouseSpace | 
| 32 | 
            +
                  WarehouseSpace
         | 
| 33 | 
            +
                    .joins('JOIN warehouse_mappings ON
         | 
| 34 | 
            +
                      warehouse_spaces.warehouse_id = warehouse_mappings.warehouse_id')
         | 
| 35 | 
            +
                    .where("warehouse_mappings.profile_channel_association_id=#{pca}")
         | 
| 36 | 
            +
                    .where("warehouse_spaces.item_variant_id=#{listing.variant_id}")
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def pca
         | 
| 40 | 
            +
                  listing.profile_channel_association_id.to_s
         | 
| 33 41 | 
             
                end
         | 
| 34 42 |  | 
| 35 43 | 
             
                def warehouse_mapping(warehouse_id)
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price_service'
         | 
| 6 | 
            +
            require 'item_builder_mwh/modes/price/sale_price_policy'
         | 
| 7 | 
            +
            module ItemBuilderMwh
         | 
| 8 | 
            +
              module Modes
         | 
| 9 | 
            +
                module Price
         | 
| 10 | 
            +
                  class Base
         | 
| 11 | 
            +
                    attr_reader :listing
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    def initialize(listing)
         | 
| 14 | 
            +
                      raise 'listing is not set' if listing.nil?
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                      @listing = listing
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    def sale_price_policy
         | 
| 20 | 
            +
                      @sale_price_policy ||=
         | 
| 21 | 
            +
                        ItemBuilderMwh::Modes::Price::SalePricePolicy.new(listing: listing)
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Price
         | 
| 9 | 
            +
                  class BlibliService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: sale_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at
         | 
| 16 | 
            +
                      }
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    private
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    def sale_price
         | 
| 22 | 
            +
                      sale_price_policy.on_sale? ? listing.sale_price : listing.price
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,61 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Price
         | 
| 9 | 
            +
                  class BukalapakService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      if listing.sale_price.nil?
         | 
| 12 | 
            +
                        bukalapak_price
         | 
| 13 | 
            +
                      else
         | 
| 14 | 
            +
                        deal
         | 
| 15 | 
            +
                      end
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    def bukalapak_price
         | 
| 19 | 
            +
                      {
         | 
| 20 | 
            +
                        price: listing.price,
         | 
| 21 | 
            +
                        sale_price: listing.sale_price,
         | 
| 22 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 23 | 
            +
                        sale_end_at: listing.sale_end_at
         | 
| 24 | 
            +
                      }
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    def deal
         | 
| 28 | 
            +
                      {
         | 
| 29 | 
            +
                        percentage: deal_percentage,
         | 
| 30 | 
            +
                        sale_start_at: sale_start_at,
         | 
| 31 | 
            +
                        sale_end_at: sale_end_at,
         | 
| 32 | 
            +
                        price: listing.price,
         | 
| 33 | 
            +
                        sale_price: listing.sale_price
         | 
| 34 | 
            +
                      }
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    def deal_percentage
         | 
| 38 | 
            +
                      price = listing.price.to_f
         | 
| 39 | 
            +
                      sale_price = listing.sale_price.to_f
         | 
| 40 | 
            +
                      100 - (sale_price / price * 100)
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    def sale_start_at
         | 
| 44 | 
            +
                      return DateTime.now if listing.sale_start_at.nil?
         | 
| 45 | 
            +
                      return DateTime.now if listing.sale_start_at < DateTime.now
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                      listing.sale_start_at
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    def sale_end_at
         | 
| 51 | 
            +
                      month_later = DateTime.now + 1.month
         | 
| 52 | 
            +
                      return month_later if listing.sale_end_at.nil?
         | 
| 53 | 
            +
                      return month_later if listing.sale_end_at > month_later
         | 
| 54 | 
            +
                      return month_later if listing.sale_end_at < DateTime.now
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                      listing.sale_end_at
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Price
         | 
| 9 | 
            +
                  class JdService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: jd_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at
         | 
| 16 | 
            +
                      }
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    def jd_price
         | 
| 20 | 
            +
                      increment_price =
         | 
| 21 | 
            +
                        if (listing.price % 1000).positive?
         | 
| 22 | 
            +
                          1000
         | 
| 23 | 
            +
                        else
         | 
| 24 | 
            +
                          0
         | 
| 25 | 
            +
                        end
         | 
| 26 | 
            +
                      (listing.price.to_i / 1000) * 1000 + increment_price
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price_service'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Price
         | 
| 9 | 
            +
                  class SalePricePolicy
         | 
| 10 | 
            +
                    include Modes
         | 
| 11 | 
            +
                    def sale_price
         | 
| 12 | 
            +
                      # has sale price but no sale date defined
         | 
| 13 | 
            +
                      # then push sale price immediately
         | 
| 14 | 
            +
                      # assuming it starts today and no end date specified
         | 
| 15 | 
            +
                      return listing.sale_price if sale_price? && !sale_date?
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                      # has sale price and today is on sale then push sale price immediately
         | 
| 18 | 
            +
                      listing.sale_price if sale_price? && on_sale?
         | 
| 19 | 
            +
                      # don't push / don't return anything if 2 rules above unfulfilled
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    def sale_price?
         | 
| 23 | 
            +
                      listing.sale_price
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    def sale_date?
         | 
| 27 | 
            +
                      listing.sale_start_at && listing.sale_end_at
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    def on_sale?
         | 
| 31 | 
            +
                      return false unless sale_price?
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                      sale_start_at = listing.sale_start_at || DateTime.now
         | 
| 34 | 
            +
                      sale_end_at = listing.sale_end_at || DateTime.now + 1_000_000.years
         | 
| 35 | 
            +
                      sale_start_at <= DateTime.now && sale_end_at >= DateTime.now
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price/base'
         | 
| 6 | 
            +
            require 'item_builder_mwh/modes/price/sale_price_policy'
         | 
| 7 | 
            +
            module ItemBuilderMwh
         | 
| 8 | 
            +
              module Modes
         | 
| 9 | 
            +
                module Price
         | 
| 10 | 
            +
                  class ShopifyService < Base
         | 
| 11 | 
            +
                    def perform
         | 
| 12 | 
            +
                      {
         | 
| 13 | 
            +
                        price: listing.price,
         | 
| 14 | 
            +
                        sale_price: sale_price,
         | 
| 15 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 16 | 
            +
                        sale_end_at: listing.sale_end_at
         | 
| 17 | 
            +
                      }
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    private
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    def sale_price
         | 
| 23 | 
            +
                      sale_price_policy.on_sale? ? listing.sale_price : listing.price
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Price
         | 
| 9 | 
            +
                  class ZaloraService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: sale_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at
         | 
| 16 | 
            +
                      }
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    private
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    def sale_price
         | 
| 22 | 
            +
                      sale_price_policy.on_sale? ? listing.sale_price : listing.price
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -1,11 +1,26 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'item_builder_mwh/modes.rb'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes/price/base'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/price/blibli_service'
         | 
| 6 | 
            +
            require 'item_builder_mwh/modes/price/bukalapak_service'
         | 
| 7 | 
            +
            require 'item_builder_mwh/modes/price/zalora_service'
         | 
| 8 | 
            +
            require 'item_builder_mwh/modes/price/shopify_service'
         | 
| 9 | 
            +
            require 'item_builder_mwh/modes/price/sale_price_policy'
         | 
| 10 | 
            +
            require 'item_builder_mwh/modes/price/jd_service'
         | 
| 4 11 | 
             
            module ItemBuilderMwh
         | 
| 5 12 | 
             
              module Modes
         | 
| 6 13 | 
             
                class PriceService
         | 
| 7 14 | 
             
                  include Modes
         | 
| 8 15 |  | 
| 16 | 
            +
                  PRICE_CHANNEL = {}.tap do |hash|
         | 
| 17 | 
            +
                    hash[2]       = :Shopify
         | 
| 18 | 
            +
                    hash[9]       = :Blibli
         | 
| 19 | 
            +
                    hash[11]      = :Bukalapak
         | 
| 20 | 
            +
                    hash[13]      = :Zalora
         | 
| 21 | 
            +
                    hash[16]      = :Jd
         | 
| 22 | 
            +
                  end.freeze
         | 
| 23 | 
            +
             | 
| 9 24 | 
             
                  def perform
         | 
| 10 25 | 
             
                    base.merge!(
         | 
| 11 26 | 
             
                      warehouse: warehouses
         | 
| @@ -13,16 +28,41 @@ module ItemBuilderMwh | |
| 13 28 | 
             
                  end
         | 
| 14 29 |  | 
| 15 30 | 
             
                  def to_h(warehouse_space)
         | 
| 31 | 
            +
                    warehouse_ids(warehouse_space).merge(
         | 
| 32 | 
            +
                      price
         | 
| 33 | 
            +
                    )
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def warehouse_ids(warehouse_space)
         | 
| 16 37 | 
             
                    {
         | 
| 17 | 
            -
                      price: listing.price,
         | 
| 18 | 
            -
                      sale_price: listing.sale_price,
         | 
| 19 | 
            -
                      sale_start_at: listing.sale_start_at,
         | 
| 20 | 
            -
                      sale_end_at: listing.sale_end_at,
         | 
| 21 38 | 
             
                      warehouse_id: wh_mapping(
         | 
| 22 39 | 
             
                        warehouse_space.warehouse_id
         | 
| 23 40 | 
             
                      )
         | 
| 24 41 | 
             
                    }
         | 
| 25 42 | 
             
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def price
         | 
| 45 | 
            +
                    if channel_name.empty?
         | 
| 46 | 
            +
                      {
         | 
| 47 | 
            +
                        price: listing.price,
         | 
| 48 | 
            +
                        sale_price: listing.sale_price,
         | 
| 49 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 50 | 
            +
                        sale_end_at: listing.sale_end_at
         | 
| 51 | 
            +
                      }
         | 
| 52 | 
            +
                    else
         | 
| 53 | 
            +
                      price_channel
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  def price_channel
         | 
| 58 | 
            +
                    class_name = "ItemBuilderMwh::Modes::Price::#{channel_name}Service"
         | 
| 59 | 
            +
                    price_channel_service = class_name.constantize
         | 
| 60 | 
            +
                    price_channel_service.new(listing).perform
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  def channel_name
         | 
| 64 | 
            +
                    PRICE_CHANNEL[listing.channel_id].to_s
         | 
| 65 | 
            +
                  end
         | 
| 26 66 | 
             
                end
         | 
| 27 67 | 
             
              end
         | 
| 28 68 | 
             
            end
         | 
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ItemBuilderMwh
         | 
| 4 | 
            +
              module Modes
         | 
| 5 | 
            +
                module Quantity
         | 
| 6 | 
            +
                  class Base
         | 
| 7 | 
            +
                    attr_reader :listing
         | 
| 8 | 
            +
                    attr_reader :available_quantity
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    def initialize(listing, available_quantity)
         | 
| 11 | 
            +
                      raise 'listing is not set' if listing.nil?
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                      @listing = listing
         | 
| 14 | 
            +
                      @available_quantity = available_quantity
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    def order_host
         | 
| 18 | 
            +
                      url = ENV['ORDERS_URL'] || 'orders.forstok.com'
         | 
| 19 | 
            +
                      url + '/api/v2/item_line/reserved_stock'
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    def reserved_params
         | 
| 23 | 
            +
                      "account_id=#{listing.profile_channel_association_id}
         | 
| 24 | 
            +
                      &item_variant_id=#{listing.variant_id}"
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    def reserved_stock
         | 
| 28 | 
            +
                      RestClient.get("#{order_host}?#{reserved_params}")
         | 
| 29 | 
            +
                    rescue RestClient::ExceptionWithResponse => e
         | 
| 30 | 
            +
                      e.response
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def apigateway_get
         | 
| 34 | 
            +
                      RestClient.get("#{host}?#{params}")
         | 
| 35 | 
            +
                    rescue RestClient::ExceptionWithResponse => e
         | 
| 36 | 
            +
                      e.response
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    def headers
         | 
| 40 | 
            +
                      {
         | 
| 41 | 
            +
                        content_type: :json,
         | 
| 42 | 
            +
                        accept: :json
         | 
| 43 | 
            +
                      }
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    def credential
         | 
| 47 | 
            +
                      account_id = listing.profile_channel_association_id
         | 
| 48 | 
            +
                      host = ENV['CREDENTIAL_URL'] || 'user.forstok.com'
         | 
| 49 | 
            +
                      begin
         | 
| 50 | 
            +
                        RestClient.get("#{host}/credential?account_id=#{account_id}")
         | 
| 51 | 
            +
                      rescue RestClient::ExceptionWithResponse => e
         | 
| 52 | 
            +
                        e.response
         | 
| 53 | 
            +
                      end
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    def data
         | 
| 57 | 
            +
                      {
         | 
| 58 | 
            +
                        "credential": JSON.parse(credential)['credential'],
         | 
| 59 | 
            +
                        "data": request
         | 
| 60 | 
            +
                      }
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                    def api_data
         | 
| 64 | 
            +
                      data.to_json
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    def apigateway_post
         | 
| 68 | 
            +
                      RestClient.post(url, api_data, headers)
         | 
| 69 | 
            +
                    rescue RestClient::ExceptionWithResponse => e
         | 
| 70 | 
            +
                      e.response
         | 
| 71 | 
            +
                    end
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'item_builder_mwh/modes/quantity/base'
         | 
| 4 | 
            +
            module ItemBuilderMwh
         | 
| 5 | 
            +
              module Modes
         | 
| 6 | 
            +
                module Quantity
         | 
| 7 | 
            +
                  class BlibliService < Base
         | 
| 8 | 
            +
                    def perform
         | 
| 9 | 
            +
                      local_variant
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    def local_variant
         | 
| 13 | 
            +
                      qty = 0
         | 
| 14 | 
            +
                      local_product['value']['items'].each do |item|
         | 
| 15 | 
            +
                        qty = total_quantity(item) if item['itemSku'] == listing.local_id
         | 
| 16 | 
            +
                      end
         | 
| 17 | 
            +
                      qty
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def total_quantity(item)
         | 
| 21 | 
            +
                      # Make stock 0
         | 
| 22 | 
            +
                      # if local reserved quantity is bigger than available quantity
         | 
| 23 | 
            +
                      if item['reservedStockLevel2'] > available_quantity
         | 
| 24 | 
            +
                        0
         | 
| 25 | 
            +
                      else
         | 
| 26 | 
            +
                        available_quantity
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    # Find local product based on id
         | 
| 31 | 
            +
                    # @return [Hash] Local Blibli product
         | 
| 32 | 
            +
                    def local_product
         | 
| 33 | 
            +
                      @local_product ||= JSON.parse(apigateway_post)
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    private
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    def request
         | 
| 39 | 
            +
                      {
         | 
| 40 | 
            +
                        "gdnSku": listing.local_id
         | 
| 41 | 
            +
                      }
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    def url
         | 
| 45 | 
            +
                      url = ENV['API_GATEWAY_URL'] || 'apigateway.forstok.com'
         | 
| 46 | 
            +
                      url + '/blibli/item'
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'item_builder_mwh/modes/quantity/base'
         | 
| 4 | 
            +
            module ItemBuilderMwh
         | 
| 5 | 
            +
              module Modes
         | 
| 6 | 
            +
                module Quantity
         | 
| 7 | 
            +
                  class LazadaService < Base
         | 
| 8 | 
            +
                    def perform
         | 
| 9 | 
            +
                      available_quantity + reserved_stock.to_i
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'item_builder_mwh/modes/quantity/base'
         | 
| 4 | 
            +
            module ItemBuilderMwh
         | 
| 5 | 
            +
              module Modes
         | 
| 6 | 
            +
                module Quantity
         | 
| 7 | 
            +
                  class ZaloraService < Base
         | 
| 8 | 
            +
                    def perform
         | 
| 9 | 
            +
                      available_quantity + reserved_stock.to_i
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -2,11 +2,21 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require 'warehouse_models'
         | 
| 4 4 | 
             
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/quantity/base'
         | 
| 6 | 
            +
            require 'item_builder_mwh/modes/quantity/lazada_service'
         | 
| 7 | 
            +
            require 'item_builder_mwh/modes/quantity/blibli_service'
         | 
| 8 | 
            +
            require 'item_builder_mwh/modes/quantity/zalora_service'
         | 
| 5 9 | 
             
            module ItemBuilderMwh
         | 
| 6 10 | 
             
              module Modes
         | 
| 7 11 | 
             
                class QuantityService
         | 
| 8 12 | 
             
                  include Modes
         | 
| 9 13 |  | 
| 14 | 
            +
                  QUANTITY_CHANNEL = {}.tap do |hash|
         | 
| 15 | 
            +
                    hash[3]       = :Lazada
         | 
| 16 | 
            +
                    hash[9]       = :Blibli
         | 
| 17 | 
            +
                    hash[13]      = :Zalora
         | 
| 18 | 
            +
                  end.freeze
         | 
| 19 | 
            +
             | 
| 10 20 | 
             
                  def perform
         | 
| 11 21 | 
             
                    base.merge!(
         | 
| 12 22 | 
             
                      warehouse: warehouses
         | 
| @@ -15,12 +25,30 @@ module ItemBuilderMwh | |
| 15 25 |  | 
| 16 26 | 
             
                  def to_h(warehouse_space)
         | 
| 17 27 | 
             
                    {
         | 
| 18 | 
            -
                      quantity: warehouse_space.quantity,
         | 
| 28 | 
            +
                      quantity: qty(warehouse_space.quantity),
         | 
| 19 29 | 
             
                      warehouse_id: wh_mapping(
         | 
| 20 30 | 
             
                        warehouse_space.warehouse_id
         | 
| 21 31 | 
             
                      )
         | 
| 22 32 | 
             
                    }
         | 
| 23 33 | 
             
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  def qty(available_qty)
         | 
| 36 | 
            +
                    if channel_name.empty?
         | 
| 37 | 
            +
                      available_qty
         | 
| 38 | 
            +
                    else
         | 
| 39 | 
            +
                      qty_channel(available_qty)
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  def qty_channel(available_qty)
         | 
| 44 | 
            +
                    class_name = "ItemBuilderMwh::Modes::Quantity::#{channel_name}Service"
         | 
| 45 | 
            +
                    qty_channel_service = class_name.constantize
         | 
| 46 | 
            +
                    qty_channel_service.new(listing, available_qty).perform
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  def channel_name
         | 
| 50 | 
            +
                    QUANTITY_CHANNEL[listing.channel_id].to_s
         | 
| 51 | 
            +
                  end
         | 
| 24 52 | 
             
                end
         | 
| 25 53 | 
             
              end
         | 
| 26 54 | 
             
            end
         | 
| @@ -0,0 +1,84 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple_service'
         | 
| 6 | 
            +
            require 'item_builder_mwh/modes/simple/sale_price_policy'
         | 
| 7 | 
            +
            module ItemBuilderMwh
         | 
| 8 | 
            +
              module Modes
         | 
| 9 | 
            +
                module Simple
         | 
| 10 | 
            +
                  class Base
         | 
| 11 | 
            +
                    attr_reader :listing
         | 
| 12 | 
            +
                    attr_reader :available_quantity
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    def initialize(listing, available_quantity)
         | 
| 15 | 
            +
                      raise 'listing is not set' if listing.nil?
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                      @listing = listing
         | 
| 18 | 
            +
                      @available_quantity = available_quantity
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    def order_host
         | 
| 22 | 
            +
                      url = ENV['ORDERS_URL'] || 'orders.forstok.com'
         | 
| 23 | 
            +
                      url + '/api/v2/item_line/reserved_stock'
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    def reserved_params
         | 
| 27 | 
            +
                      "account_id=#{listing.profile_channel_association_id}
         | 
| 28 | 
            +
                      &item_variant_id=#{listing.variant_id}"
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    def reserved_stock
         | 
| 32 | 
            +
                      RestClient.get("#{order_host}?#{reserved_params}")
         | 
| 33 | 
            +
                    rescue RestClient::ExceptionWithResponse => e
         | 
| 34 | 
            +
                      e.response
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    def apigateway_get
         | 
| 38 | 
            +
                      RestClient.get("#{host}?#{params}")
         | 
| 39 | 
            +
                    rescue RestClient::ExceptionWithResponse => e
         | 
| 40 | 
            +
                      e.response
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    def headers
         | 
| 44 | 
            +
                      {
         | 
| 45 | 
            +
                        content_type: :json,
         | 
| 46 | 
            +
                        accept: :json
         | 
| 47 | 
            +
                      }
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    def credential
         | 
| 51 | 
            +
                      account_id = listing.profile_channel_association_id
         | 
| 52 | 
            +
                      host = ENV['CREDENTIAL_URL'] || 'user.forstok.com'
         | 
| 53 | 
            +
                      begin
         | 
| 54 | 
            +
                        RestClient.get("#{host}/credential?account_id=#{account_id}")
         | 
| 55 | 
            +
                      rescue RestClient::ExceptionWithResponse => e
         | 
| 56 | 
            +
                        e.response
         | 
| 57 | 
            +
                      end
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    def data
         | 
| 61 | 
            +
                      {
         | 
| 62 | 
            +
                        "credential": JSON.parse(credential)['credential'],
         | 
| 63 | 
            +
                        "data": request
         | 
| 64 | 
            +
                      }
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    def api_data
         | 
| 68 | 
            +
                      data.to_json
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    def sale_price_policy
         | 
| 72 | 
            +
                      @sale_price_policy ||=
         | 
| 73 | 
            +
                        ItemBuilderMwh::Modes::Simple::SalePricePolicy.new(listing: listing)
         | 
| 74 | 
            +
                    end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                    def apigateway_post
         | 
| 77 | 
            +
                      RestClient.post(url, api_data, headers)
         | 
| 78 | 
            +
                    rescue RestClient::ExceptionWithResponse => e
         | 
| 79 | 
            +
                      e.response
         | 
| 80 | 
            +
                    end
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
            end
         | 
| @@ -0,0 +1,66 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Simple
         | 
| 9 | 
            +
                  class BlibliService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: sale_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at,
         | 
| 16 | 
            +
                        quantity: local_variant,
         | 
| 17 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 18 | 
            +
                          warehouse_space.warehouse_id
         | 
| 19 | 
            +
                        )
         | 
| 20 | 
            +
                      }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    def local_variant
         | 
| 24 | 
            +
                      qty = 0
         | 
| 25 | 
            +
                      local_product['value']['items'].each do |item|
         | 
| 26 | 
            +
                        qty = total_quantity(item) if item['itemSku'] == listing.local_id
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
                      qty
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    def total_quantity(item)
         | 
| 32 | 
            +
                      # Make stock 0
         | 
| 33 | 
            +
                      # if local reserved quantity is bigger than available quantity
         | 
| 34 | 
            +
                      if item['reservedStockLevel2'] > available_quantity
         | 
| 35 | 
            +
                        0
         | 
| 36 | 
            +
                      else
         | 
| 37 | 
            +
                        item['availableStockLevel2'] + item['reservedStockLevel2']
         | 
| 38 | 
            +
                      end
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                    # Find local product based on id
         | 
| 42 | 
            +
                    # @return [Hash] Local Blibli product
         | 
| 43 | 
            +
                    def local_product
         | 
| 44 | 
            +
                      @local_product ||= JSON.parse(apigateway_post)
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    private
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    def request
         | 
| 50 | 
            +
                      {
         | 
| 51 | 
            +
                        "gdnSku": listing.local_id
         | 
| 52 | 
            +
                      }
         | 
| 53 | 
            +
                    end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    def url
         | 
| 56 | 
            +
                      url = ENV['API_GATEWAY_URL'] || 'apigateway.forstok.com'
         | 
| 57 | 
            +
                      url + '/blibli/item'
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    def sale_price
         | 
| 61 | 
            +
                      sale_price_policy.on_sale? ? listing.sale_price : listing.price
         | 
| 62 | 
            +
                    end
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
            end
         | 
| @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Simple
         | 
| 9 | 
            +
                  class BukalapakService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      if listing.sale_price.nil?
         | 
| 12 | 
            +
                        bukalapak_price
         | 
| 13 | 
            +
                      else
         | 
| 14 | 
            +
                        deal
         | 
| 15 | 
            +
                      end
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    def bukalapak_price
         | 
| 19 | 
            +
                      {
         | 
| 20 | 
            +
                        price: listing.price,
         | 
| 21 | 
            +
                        sale_price: listing.sale_price,
         | 
| 22 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 23 | 
            +
                        sale_end_at: listing.sale_end_at,
         | 
| 24 | 
            +
                        quantity: available_quantity,
         | 
| 25 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 26 | 
            +
                          warehouse_space.warehouse_id
         | 
| 27 | 
            +
                        )
         | 
| 28 | 
            +
                      }
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    def deal
         | 
| 32 | 
            +
                      {
         | 
| 33 | 
            +
                        percentage: deal_percentage,
         | 
| 34 | 
            +
                        sale_start_at: sale_start_at,
         | 
| 35 | 
            +
                        sale_end_at: sale_end_at,
         | 
| 36 | 
            +
                        price: listing.price,
         | 
| 37 | 
            +
                        sale_price: listing.sale_price,
         | 
| 38 | 
            +
                        quantity: available_quantity,
         | 
| 39 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 40 | 
            +
                          warehouse_space.warehouse_id
         | 
| 41 | 
            +
                        )
         | 
| 42 | 
            +
                      }
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                    def deal_percentage
         | 
| 46 | 
            +
                      price = listing.price.to_f
         | 
| 47 | 
            +
                      sale_price = listing.sale_price.to_f
         | 
| 48 | 
            +
                      100 - (sale_price / price * 100)
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                    def sale_start_at
         | 
| 52 | 
            +
                      return DateTime.now if listing.sale_start_at.nil?
         | 
| 53 | 
            +
                      return DateTime.now if listing.sale_start_at < DateTime.now
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                      listing.sale_start_at
         | 
| 56 | 
            +
                    end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                    def sale_end_at
         | 
| 59 | 
            +
                      month_later = DateTime.now + 1.month
         | 
| 60 | 
            +
                      return month_later if listing.sale_end_at.nil?
         | 
| 61 | 
            +
                      return month_later if listing.sale_end_at > month_later
         | 
| 62 | 
            +
                      return month_later if listing.sale_end_at < DateTime.now
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                      listing.sale_end_at
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
            end
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Simple
         | 
| 9 | 
            +
                  class JdService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: jd_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at,
         | 
| 16 | 
            +
                        quantity: available_quantity,
         | 
| 17 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 18 | 
            +
                          warehouse_space.warehouse_id
         | 
| 19 | 
            +
                        )
         | 
| 20 | 
            +
                      }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    def jd_price
         | 
| 24 | 
            +
                      increment_price =
         | 
| 25 | 
            +
                        if (listing.price % 1000).positive?
         | 
| 26 | 
            +
                          1000
         | 
| 27 | 
            +
                        else
         | 
| 28 | 
            +
                          0
         | 
| 29 | 
            +
                        end
         | 
| 30 | 
            +
                      (listing.price.to_i / 1000) * 1000 + increment_price
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Simple
         | 
| 9 | 
            +
                  class LazadaService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: listing.sale_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at,
         | 
| 16 | 
            +
                        quantity: available_quantity + reserved_stock.to_i,
         | 
| 17 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 18 | 
            +
                          warehouse_space.warehouse_id
         | 
| 19 | 
            +
                        )
         | 
| 20 | 
            +
                      }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes/simple_service'
         | 
| 5 | 
            +
            module ItemBuilderMwh
         | 
| 6 | 
            +
              module Modes
         | 
| 7 | 
            +
                module Simple
         | 
| 8 | 
            +
                  class SalePricePolicy
         | 
| 9 | 
            +
                    include Modes
         | 
| 10 | 
            +
                    def sale_price
         | 
| 11 | 
            +
                      # has sale price but no sale date defined
         | 
| 12 | 
            +
                      # then push sale price immediately
         | 
| 13 | 
            +
                      # assuming it starts today and no end date specified
         | 
| 14 | 
            +
                      return listing.sale_price if sale_price? && !sale_date?
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                      # has sale price and today is on sale then push sale price immediately
         | 
| 17 | 
            +
                      listing.sale_price if sale_price? && on_sale?
         | 
| 18 | 
            +
                      # don't push / don't return anything if 2 rules above unfulfilled
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    def sale_price?
         | 
| 22 | 
            +
                      listing.sale_price
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def sale_date?
         | 
| 26 | 
            +
                      listing.sale_start_at && listing.sale_end_at
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    def on_sale?
         | 
| 30 | 
            +
                      return false unless sale_price?
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                      sale_start_at = listing.sale_start_at || DateTime.now
         | 
| 33 | 
            +
                      sale_end_at = listing.sale_end_at || DateTime.now + 1_000_000.years
         | 
| 34 | 
            +
                      sale_start_at <= DateTime.now && sale_end_at >= DateTime.now
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Simple
         | 
| 9 | 
            +
                  class ShopeeService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: listing.sale_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at,
         | 
| 16 | 
            +
                        quantity: available_quantity,
         | 
| 17 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 18 | 
            +
                          warehouse_space.warehouse_id
         | 
| 19 | 
            +
                        )
         | 
| 20 | 
            +
                      }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Simple
         | 
| 9 | 
            +
                  class ShopifyService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: sale_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at,
         | 
| 16 | 
            +
                        quantity: available_quantity,
         | 
| 17 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 18 | 
            +
                          warehouse_space.warehouse_id
         | 
| 19 | 
            +
                        )
         | 
| 20 | 
            +
                      }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    private
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def sale_price
         | 
| 26 | 
            +
                      sale_price_policy.on_sale? ? listing.sale_price : listing.price
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'date'
         | 
| 4 | 
            +
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/base'
         | 
| 6 | 
            +
            module ItemBuilderMwh
         | 
| 7 | 
            +
              module Modes
         | 
| 8 | 
            +
                module Simple
         | 
| 9 | 
            +
                  class ZaloraService < Base
         | 
| 10 | 
            +
                    def perform
         | 
| 11 | 
            +
                      {
         | 
| 12 | 
            +
                        price: listing.price,
         | 
| 13 | 
            +
                        sale_price: sale_price,
         | 
| 14 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 15 | 
            +
                        sale_end_at: listing.sale_end_at,
         | 
| 16 | 
            +
                        quantity: available_quantity + reserved_stock.to_i,
         | 
| 17 | 
            +
                        warehouse_id: wh_mapping(
         | 
| 18 | 
            +
                          warehouse_space.warehouse_id
         | 
| 19 | 
            +
                        )
         | 
| 20 | 
            +
                      }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    private
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def sale_price
         | 
| 26 | 
            +
                      sale_price_policy.on_sale? ? listing.sale_price : listing.price
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -1,13 +1,34 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require ' | 
| 4 | 
            -
            require 'item_builder_mwh/modes/price_service.rb'
         | 
| 3 | 
            +
            require 'warehouse_models'
         | 
| 5 4 | 
             
            require 'item_builder_mwh/modes.rb'
         | 
| 5 | 
            +
            require 'item_builder_mwh/modes/simple/blibli_service'
         | 
| 6 | 
            +
            require 'item_builder_mwh/modes/simple/bukalapak_service'
         | 
| 7 | 
            +
            require 'item_builder_mwh/modes/simple/zalora_service'
         | 
| 8 | 
            +
            require 'item_builder_mwh/modes/simple/shopify_service'
         | 
| 9 | 
            +
            require 'item_builder_mwh/modes/simple/jd_service'
         | 
| 10 | 
            +
            require 'item_builder_mwh/modes/simple/lazada_service'
         | 
| 11 | 
            +
            require 'item_builder_mwh/modes/simple/shopee_service'
         | 
| 6 12 | 
             
            module ItemBuilderMwh
         | 
| 7 13 | 
             
              module Modes
         | 
| 8 14 | 
             
                class SimpleService
         | 
| 9 15 | 
             
                  include Modes
         | 
| 10 16 |  | 
| 17 | 
            +
                  QUANTITY_CHANNEL = {}.tap do |hash|
         | 
| 18 | 
            +
                    hash[3]       = :Lazada
         | 
| 19 | 
            +
                    hash[9]       = :Blibli
         | 
| 20 | 
            +
                    hash[12]      = :Shopee
         | 
| 21 | 
            +
                    hash[13]      = :Zalora
         | 
| 22 | 
            +
                  end.freeze
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  PRICE_CHANNEL = {}.tap do |hash|
         | 
| 25 | 
            +
                    hash[2]       = :Shopify
         | 
| 26 | 
            +
                    hash[9]       = :Blibli
         | 
| 27 | 
            +
                    hash[11]      = :Bukalapak
         | 
| 28 | 
            +
                    hash[13]      = :Zalora
         | 
| 29 | 
            +
                    hash[16]      = :Jd
         | 
| 30 | 
            +
                  end.freeze
         | 
| 31 | 
            +
             | 
| 11 32 | 
             
                  def perform
         | 
| 12 33 | 
             
                    base.merge!(
         | 
| 13 34 | 
             
                      warehouse: warehouses
         | 
| @@ -15,17 +36,70 @@ module ItemBuilderMwh | |
| 15 36 | 
             
                  end
         | 
| 16 37 |  | 
| 17 38 | 
             
                  def to_h(warehouse_space)
         | 
| 39 | 
            +
                    warehouse_ids(warehouse_space).merge(
         | 
| 40 | 
            +
                      simple(warehouse_space)
         | 
| 41 | 
            +
                    )
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def warehouse_ids(warehouse_space)
         | 
| 18 45 | 
             
                    {
         | 
| 19 | 
            -
                      quantity: warehouse_space.quantity,
         | 
| 20 | 
            -
                      price: listing.price,
         | 
| 21 | 
            -
                      sale_price: listing.sale_price,
         | 
| 22 | 
            -
                      sale_start_at: listing.sale_start_at,
         | 
| 23 | 
            -
                      sale_end_at: listing.sale_end_at,
         | 
| 24 46 | 
             
                      warehouse_id: wh_mapping(
         | 
| 25 47 | 
             
                        warehouse_space.warehouse_id
         | 
| 26 48 | 
             
                      )
         | 
| 27 49 | 
             
                    }
         | 
| 28 50 | 
             
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  def simple(warehouse_space)
         | 
| 53 | 
            +
                    available_qty = warehouse_space.quantity
         | 
| 54 | 
            +
                    qty(available_qty).merge(
         | 
| 55 | 
            +
                      price
         | 
| 56 | 
            +
                    )
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  def qty(available_qty)
         | 
| 60 | 
            +
                    if quantity_name.empty?
         | 
| 61 | 
            +
                      {
         | 
| 62 | 
            +
                        quantity: available_qty
         | 
| 63 | 
            +
                      }
         | 
| 64 | 
            +
                    else
         | 
| 65 | 
            +
                      {
         | 
| 66 | 
            +
                        quantity: qty_channel(available_qty)
         | 
| 67 | 
            +
                      }
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  def price
         | 
| 72 | 
            +
                    if price_name.empty?
         | 
| 73 | 
            +
                      {
         | 
| 74 | 
            +
                        price: listing.price,
         | 
| 75 | 
            +
                        sale_price: listing.sale_price,
         | 
| 76 | 
            +
                        sale_start_at: listing.sale_start_at,
         | 
| 77 | 
            +
                        sale_end_at: listing.sale_end_at
         | 
| 78 | 
            +
                      }
         | 
| 79 | 
            +
                    else
         | 
| 80 | 
            +
                      price_channel
         | 
| 81 | 
            +
                    end
         | 
| 82 | 
            +
                  end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                  def price_channel
         | 
| 85 | 
            +
                    class_name = "ItemBuilderMwh::Modes::Price::#{price_name}Service"
         | 
| 86 | 
            +
                    simple_channel_service = class_name.constantize
         | 
| 87 | 
            +
                    simple_channel_service.new(listing, available_qty).perform
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                  def qty_channel(available_qty)
         | 
| 91 | 
            +
                    class_name = "ItemBuilderMwh::Modes::Quantity::#{quantity_name}Service"
         | 
| 92 | 
            +
                    qty_channel_service = class_name.constantize
         | 
| 93 | 
            +
                    qty_channel_service.new(listing, available_qty).perform
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                  def price_name
         | 
| 97 | 
            +
                    PRICE_CHANNEL[listing.channel_id].to_s
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                  def quantity_name
         | 
| 101 | 
            +
                    QUANTITY_CHANNEL[listing.channel_id].to_s
         | 
| 102 | 
            +
                  end
         | 
| 29 103 | 
             
                end
         | 
| 30 104 | 
             
              end
         | 
| 31 105 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: item_builder_mwh
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.8
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Kevin Ivander
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020- | 
| 11 | 
            +
            date: 2020-10-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -86,14 +86,14 @@ dependencies: | |
| 86 86 | 
             
                requirements:
         | 
| 87 87 | 
             
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version: 0.0. | 
| 89 | 
            +
                    version: 0.0.11
         | 
| 90 90 | 
             
              type: :runtime
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 94 | 
             
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version: 0.0. | 
| 96 | 
            +
                    version: 0.0.11
         | 
| 97 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 98 | 
             
              name: warehouse_models
         | 
| 99 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -119,14 +119,34 @@ files: | |
| 119 119 | 
             
            - lib/item_builder_mwh/modes.rb
         | 
| 120 120 | 
             
            - lib/item_builder_mwh/modes/active_service.rb
         | 
| 121 121 | 
             
            - lib/item_builder_mwh/modes/base_service.rb
         | 
| 122 | 
            +
            - lib/item_builder_mwh/modes/price/base.rb
         | 
| 123 | 
            +
            - lib/item_builder_mwh/modes/price/blibli_service.rb
         | 
| 124 | 
            +
            - lib/item_builder_mwh/modes/price/bukalapak_service.rb
         | 
| 125 | 
            +
            - lib/item_builder_mwh/modes/price/jd_service.rb
         | 
| 126 | 
            +
            - lib/item_builder_mwh/modes/price/sale_price_policy.rb
         | 
| 127 | 
            +
            - lib/item_builder_mwh/modes/price/shopify_service.rb
         | 
| 128 | 
            +
            - lib/item_builder_mwh/modes/price/zalora_service.rb
         | 
| 122 129 | 
             
            - lib/item_builder_mwh/modes/price_service.rb
         | 
| 130 | 
            +
            - lib/item_builder_mwh/modes/quantity/base.rb
         | 
| 131 | 
            +
            - lib/item_builder_mwh/modes/quantity/blibli_service.rb
         | 
| 132 | 
            +
            - lib/item_builder_mwh/modes/quantity/lazada_service.rb
         | 
| 133 | 
            +
            - lib/item_builder_mwh/modes/quantity/zalora_service.rb
         | 
| 123 134 | 
             
            - lib/item_builder_mwh/modes/quantity_service.rb
         | 
| 135 | 
            +
            - lib/item_builder_mwh/modes/simple/base.rb
         | 
| 136 | 
            +
            - lib/item_builder_mwh/modes/simple/blibli_service.rb
         | 
| 137 | 
            +
            - lib/item_builder_mwh/modes/simple/bukalapak_service.rb
         | 
| 138 | 
            +
            - lib/item_builder_mwh/modes/simple/jd_service.rb
         | 
| 139 | 
            +
            - lib/item_builder_mwh/modes/simple/lazada_service.rb
         | 
| 140 | 
            +
            - lib/item_builder_mwh/modes/simple/sale_price_policy.rb
         | 
| 141 | 
            +
            - lib/item_builder_mwh/modes/simple/shopee_service.rb
         | 
| 142 | 
            +
            - lib/item_builder_mwh/modes/simple/shopify_service.rb
         | 
| 143 | 
            +
            - lib/item_builder_mwh/modes/simple/zalora_service.rb
         | 
| 124 144 | 
             
            - lib/item_builder_mwh/modes/simple_service.rb
         | 
| 125 145 | 
             
            - lib/item_builder_mwh/version.rb
         | 
| 126 | 
            -
            homepage: | 
| 146 | 
            +
            homepage:
         | 
| 127 147 | 
             
            licenses: []
         | 
| 128 148 | 
             
            metadata: {}
         | 
| 129 | 
            -
            post_install_message: | 
| 149 | 
            +
            post_install_message:
         | 
| 130 150 | 
             
            rdoc_options: []
         | 
| 131 151 | 
             
            require_paths:
         | 
| 132 152 | 
             
            - lib
         | 
| @@ -142,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 142 162 | 
             
                  version: '0'
         | 
| 143 163 | 
             
            requirements: []
         | 
| 144 164 | 
             
            rubygems_version: 3.0.6
         | 
| 145 | 
            -
            signing_key: | 
| 165 | 
            +
            signing_key:
         | 
| 146 166 | 
             
            specification_version: 4
         | 
| 147 167 | 
             
            summary: Item Builder Multiwarehouse
         | 
| 148 168 | 
             
            test_files: []
         |