Class: ItemBuilder::Modes::Price::SalePricePolicy

Inherits:
Object
  • Object
show all
Includes:
ItemBuilder::Modes
Defined in:
lib/item_builder/modes/price/sale_price_policy.rb

Instance Attribute Summary

Attributes included from ItemBuilder::Modes

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

Instance Method Summary collapse

Methods included from ItemBuilder::Modes

#base, #bundle, #bundle_variants, #existing_allocated_stock, #initialize, #listings, #stock_alloc, #variant, #warehouse

Instance Method Details

#on_sale?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/item_builder/modes/price/sale_price_policy.rb', line 30

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)


26
27
28
# File 'lib/item_builder/modes/price/sale_price_policy.rb', line 26

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

#sale_priceObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/item_builder/modes/price/sale_price_policy.rb', line 11

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)


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

def sale_price?
  listing.sale_price
end