Class: ItemBuilderMwh::Modes::Simple::BukalapakService
- Inherits:
-
Base
- Object
- Base
- ItemBuilderMwh::Modes::Simple::BukalapakService
show all
- Defined in:
- lib/item_builder_mwh/modes/simple/bukalapak_service.rb
Instance Attribute Summary
Attributes inherited from Base
#available_quantity, #listing
Instance Method Summary
collapse
Methods inherited from Base
#api_data, #apigateway_get, #apigateway_post, #credential, #data, #headers, #initialize, #order_host, #reserved_params, #reserved_stock, #sale_price_policy
Instance Method Details
#bukalapak_price ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/item_builder_mwh/modes/simple/bukalapak_service.rb', line 18
def bukalapak_price
{
price: listing.price,
sale_price: listing.sale_price,
sale_start_at: listing.sale_start_at,
sale_end_at: listing.sale_end_at,
quantity: available_quantity,
warehouse_id: wh_mapping(
warehouse_space.warehouse_id
)
}
end
|
#deal ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/item_builder_mwh/modes/simple/bukalapak_service.rb', line 31
def deal
{
percentage: deal_percentage,
sale_start_at: sale_start_at,
sale_end_at: sale_end_at,
price: listing.price,
sale_price: listing.sale_price,
quantity: available_quantity,
warehouse_id: wh_mapping(
warehouse_space.warehouse_id
)
}
end
|
#deal_percentage ⇒ Object
45
46
47
48
49
|
# File 'lib/item_builder_mwh/modes/simple/bukalapak_service.rb', line 45
def deal_percentage
price = listing.price.to_f
sale_price = listing.sale_price.to_f
100 - (sale_price / price * 100)
end
|
10
11
12
13
14
15
16
|
# File 'lib/item_builder_mwh/modes/simple/bukalapak_service.rb', line 10
def perform
if listing.sale_price.nil?
bukalapak_price
else
deal
end
end
|
#sale_end_at ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/item_builder_mwh/modes/simple/bukalapak_service.rb', line 58
def sale_end_at
month_later = DateTime.now + 1.month
return month_later if listing.sale_end_at.nil?
return month_later if listing.sale_end_at > month_later
return month_later if listing.sale_end_at < DateTime.now
listing.sale_end_at
end
|
#sale_start_at ⇒ Object
51
52
53
54
55
56
|
# File 'lib/item_builder_mwh/modes/simple/bukalapak_service.rb', line 51
def sale_start_at
return DateTime.now if listing.sale_start_at.nil?
return DateTime.now if listing.sale_start_at < DateTime.now
listing.sale_start_at
end
|