Class: ItemBuilder::Modes::QuantityService
- Inherits:
-
Object
- Object
- ItemBuilder::Modes::QuantityService
- Includes:
- ItemBuilder::Modes
- Defined in:
- lib/item_builder/modes/quantity_service.rb
Constant Summary collapse
- QUANTITY_CHANNEL =
{}.tap do |hash| hash[3] = :Lazada hash[9] = :Blibli hash[13] = :Zalora end.freeze
Instance Attribute Summary
Attributes included from ItemBuilder::Modes
Instance Method Summary collapse
- #available_quantity ⇒ Object
- #channel_name ⇒ Object
- #perform ⇒ Object
- #qty ⇒ Object
- #qty_channel ⇒ Object
- #to_h ⇒ Object
- #variant ⇒ Object
- #warehouse ⇒ Object
Methods included from ItemBuilder::Modes
Instance Method Details
#available_quantity ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/item_builder/modes/quantity_service.rb', line 49 def available_quantity ItemBuilder::GetQuantityService.new( listing: listing, variant: variant, wh_sp: warehouse ).perform end |
#channel_name ⇒ Object
45 46 47 |
# File 'lib/item_builder/modes/quantity_service.rb', line 45 def channel_name QUANTITY_CHANNEL[listing.channel_id].to_s end |
#perform ⇒ Object
21 22 23 |
# File 'lib/item_builder/modes/quantity_service.rb', line 21 def perform to_h.merge(base) end |
#qty ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/item_builder/modes/quantity_service.rb', line 31 def qty if channel_name.empty? available_quantity else qty_channel end end |
#qty_channel ⇒ Object
39 40 41 42 43 |
# File 'lib/item_builder/modes/quantity_service.rb', line 39 def qty_channel class_name = "ItemBuilder::Modes::Quantity::#{channel_name}Service" qty_channel_service = class_name.constantize qty_channel_service.new(listing, available_quantity).perform end |
#to_h ⇒ Object
25 26 27 28 29 |
# File 'lib/item_builder/modes/quantity_service.rb', line 25 def to_h { quantity: qty } end |
#variant ⇒ Object
61 62 63 |
# File 'lib/item_builder/modes/quantity_service.rb', line 61 def variant @variant ||= Variant.find(listing.variant_id) end |
#warehouse ⇒ Object
57 58 59 |
# File 'lib/item_builder/modes/quantity_service.rb', line 57 def warehouse WarehouseSpace.find_by(item_variant_id: listing.variant_id) end |