Class: ItemBuilderMwh::Modes::Simple::SalePricePolicy

Inherits:
Object
  • Object
show all
Includes:
ItemBuilderMwh::Modes
Defined in:
lib/item_builder_mwh/modes/simple/sale_price_policy.rb

Instance Attribute Summary

Attributes included from ItemBuilderMwh::Modes

#bundles, #existing_alloc_stocks, #item_bundle_variants, #lazada_quantity, #listing, #reserved_stocks, #shipping_providers, #shopify_inventory_location, #stock_allocs, #variant_listings, #variants, #wh_spaces, #zalora_reserved_stock, #zilingo_quantity

Instance Method Summary collapse

Methods included from ItemBuilderMwh::Modes

#base, #bundle, #bundle_variants, #credential, #existing_allocated_stock, #initialize, #listings, #multiwarehouse, #pca, #stock_alloc, #variant, #variant_id, #warehouse, #warehouse_list, #warehouse_mapping, #warehouse_spaces, #warehouses, #wh_mapping, #wh_routing

Instance Method Details

#on_sale?Boolean

Returns:

  • (Boolean)
[View source]

29
30
31
32
33
34
35
# File 'lib/item_builder_mwh/modes/simple/sale_price_policy.rb', line 29

def on_sale?
  return false unless sale_price?

  sale_start_at = listing.sale_start_at || DateTime.now
  sale_end_at = listing.sale_end_at || DateTime.now + 1_000_000.years
  sale_start_at <= DateTime.now && sale_end_at >= DateTime.now
end

#sale_date?Boolean

Returns:

  • (Boolean)
[View source]

25
26
27
# File 'lib/item_builder_mwh/modes/simple/sale_price_policy.rb', line 25

def sale_date?
  listing.sale_start_at && listing.sale_end_at
end

#sale_priceObject

[View source]

10
11
12
13
14
15
16
17
18
19
# File 'lib/item_builder_mwh/modes/simple/sale_price_policy.rb', line 10

def sale_price
  # has sale price but no sale date defined
  # then push sale price immediately
  # assuming it starts today and no end date specified
  return listing.sale_price if sale_price? && !sale_date?

  # has sale price and today is on sale then push sale price immediately
  listing.sale_price if sale_price? && on_sale?
  # don't push / don't return anything if 2 rules above unfulfilled
end

#sale_price?Boolean

Returns:

  • (Boolean)
[View source]

21
22
23
# File 'lib/item_builder_mwh/modes/simple/sale_price_policy.rb', line 21

def sale_price?
  listing.sale_price
end