Module: ItemBuilder::Modes

Included in:
ActiveService, Price::SalePricePolicy, PriceService, QuantityService, SimpleService, UpdateService
Defined in:
lib/item_builder/modes.rb,
lib/item_builder/modes/price/base.rb,
lib/item_builder/modes/update/base.rb,
lib/item_builder/modes/base_service.rb,
lib/item_builder/modes/price_service.rb,
lib/item_builder/modes/quantity/base.rb,
lib/item_builder/modes/active_service.rb,
lib/item_builder/modes/simple_service.rb,
lib/item_builder/modes/update_service.rb,
lib/item_builder/modes/price/jd_service.rb,
lib/item_builder/modes/quantity_service.rb,
lib/item_builder/modes/update/jd_service.rb,
lib/item_builder/modes/price/blibli_service.rb,
lib/item_builder/modes/price/zalora_service.rb,
lib/item_builder/modes/price/shopify_service.rb,
lib/item_builder/modes/update/blibli_service.rb,
lib/item_builder/modes/update/lazada_service.rb,
lib/item_builder/modes/update/zalora_service.rb,
lib/item_builder/modes/update/shopify_service.rb,
lib/item_builder/modes/price/bukalapak_service.rb,
lib/item_builder/modes/price/sale_price_policy.rb,
lib/item_builder/modes/quantity/lazada_service.rb,
lib/item_builder/modes/quantity/zalora_service.rb,
lib/item_builder/modes/quantity/zilingo_service.rb,
lib/item_builder/modes/update/bukalapak_service.rb,
lib/item_builder/modes/update/tokopedia_service.rb

Defined Under Namespace

Modules: Price, Quantity, Update Classes: ActiveService, BaseService, PriceService, QuantityService, SimpleService, UpdateService

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bundlesObject (readonly)

Returns the value of attribute bundles.



15
16
17
# File 'lib/item_builder/modes.rb', line 15

def bundles
  @bundles
end

#existing_alloc_stocksObject (readonly)

Returns the value of attribute existing_alloc_stocks.



17
18
19
# File 'lib/item_builder/modes.rb', line 17

def existing_alloc_stocks
  @existing_alloc_stocks
end

#item_bundle_variantsObject (readonly)

Returns the value of attribute item_bundle_variants.



16
17
18
# File 'lib/item_builder/modes.rb', line 16

def item_bundle_variants
  @item_bundle_variants
end

#lazada_quantityObject (readonly)

Returns the value of attribute lazada_quantity.



21
22
23
# File 'lib/item_builder/modes.rb', line 21

def lazada_quantity
  @lazada_quantity
end

#listingObject (readonly)

Returns the value of attribute listing.



11
12
13
# File 'lib/item_builder/modes.rb', line 11

def listing
  @listing
end

#reserved_stocksObject (readonly)

Returns the value of attribute reserved_stocks.



19
20
21
# File 'lib/item_builder/modes.rb', line 19

def reserved_stocks
  @reserved_stocks
end

#shopify_inventory_locationObject (readonly)

Returns the value of attribute shopify_inventory_location.



23
24
25
# File 'lib/item_builder/modes.rb', line 23

def shopify_inventory_location
  @shopify_inventory_location
end

#stock_allocsObject (readonly)

Returns the value of attribute stock_allocs.



14
15
16
# File 'lib/item_builder/modes.rb', line 14

def stock_allocs
  @stock_allocs
end

#variant_listingsObject (readonly)

Returns the value of attribute variant_listings.



18
19
20
# File 'lib/item_builder/modes.rb', line 18

def variant_listings
  @variant_listings
end

#variantsObject (readonly)

Returns the value of attribute variants.



13
14
15
# File 'lib/item_builder/modes.rb', line 13

def variants
  @variants
end

#wh_idObject (readonly)

Returns the value of attribute wh_id.



24
25
26
# File 'lib/item_builder/modes.rb', line 24

def wh_id
  @wh_id
end

#wh_spacesObject (readonly)

Returns the value of attribute wh_spaces.



12
13
14
# File 'lib/item_builder/modes.rb', line 12

def wh_spaces
  @wh_spaces
end

#zalora_reserved_stockObject (readonly)

Returns the value of attribute zalora_reserved_stock.



22
23
24
# File 'lib/item_builder/modes.rb', line 22

def zalora_reserved_stock
  @zalora_reserved_stock
end

#zilingo_quantityObject (readonly)

Returns the value of attribute zilingo_quantity.



20
21
22
# File 'lib/item_builder/modes.rb', line 20

def zilingo_quantity
  @zilingo_quantity
end

Instance Method Details

#baseObject



42
43
44
45
46
47
48
49
# File 'lib/item_builder/modes.rb', line 42

def base
  {
    id: listing.id,
    local_id: listing.local_id,
    local_item_id: listing.local_item_id,
    sku: listing.sku
  }
end

#bundleObject



69
70
71
# File 'lib/item_builder/modes.rb', line 69

def bundle
  bundles.select { |b| b.variant_id == listing.variant_id }.first
end

#bundle_variantsObject



63
64
65
66
67
# File 'lib/item_builder/modes.rb', line 63

def bundle_variants
  if bundle.present?
    item_bundle_variants.select { |ibv| ibv.bundle_id == bundle.id }
  end
end

#existing_allocated_stockObject



51
52
53
54
55
56
57
# File 'lib/item_builder/modes.rb', line 51

def existing_allocated_stock
  existing_alloc_stocks.map do |els|
    if listings.pluck(:id).include?(els.variant_association_id)
      els
    end
  end.compact
end

#initialize(args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/item_builder/modes.rb', line 25

def initialize(args)
  @listing = args.fetch(:listing)
  @wh_spaces = args.fetch(:wh_spaces, [])
  @variants = args.fetch(:variants, [])
  @stock_allocs = args.fetch(:stock_allocs, [])
  @bundles = args.fetch(:bundles, [])
  @item_bundle_variants = args.fetch(:item_bundle_variants, [])
  @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
  @variant_listings = args.fetch(:variant_listings, [])
  @reserved_stocks = args.fetch(:reserved_stocks, [])
  @zilingo_quantity = args.fetch(:zilingo_quantity, [])
  @lazada_quantity = args.fetch(:lazada_quantity, [])
  @zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
  @shopify_inventory_location = args.fetch(:shopify_inventory_location, [])
  @wh_id = args.fetch(:wh_id, [])
end

#listingsObject



59
60
61
# File 'lib/item_builder/modes.rb', line 59

def listings
  variant_listings.select { |vl| vl.variant_id == listing.variant_id}
end

#stock_allocObject



73
74
75
# File 'lib/item_builder/modes.rb', line 73

def stock_alloc
  stock_allocs.select { |sa| sa.variant_association_id == listing.id }.first
end

#variantObject



85
86
87
# File 'lib/item_builder/modes.rb', line 85

def variant
  variants.select { |v| v.id == listing.variant_id }.first
end

#warehouseObject



77
78
79
80
81
82
83
# File 'lib/item_builder/modes.rb', line 77

def warehouse
  if wh_id.present?
    wh_spaces.where(warehouse_id: wh_id).first
  else
    wh_spaces.select { |ws| ws.item_variant_id == listing.variant_id }.first
  end
end