S
Size: a a a
S
S
S
A
M
M
S
M
оГ
оГ
оГ
M
оГ
оГ
A
M
S
M
IC
let getPriceControl priceControlOverride
priceControlBrandRules
priceControlCategoryRules
priceControlsManufacturerCatalog
priceControlDefaultRule
taxonomyItems
(approvedCompetitiveSourcesMap: Map<RegionId, string Set>)
(isOnePNode: NodeId->bool)
(brandOption: string option)
(offersMap: Map<RegionId, OfferAndShippingCost[]>)
(retailSku: SlimmedRetailSku)
(marginBasedPricingMap: Map<RegionId, MarginBasedPricingCalculationResults>)
: Map<RegionId, PriceControlResult option> =
let invertMapLevel mapLevel =
match mapLevel with
| PriceControlPolicies.Constants.Msp -> 1
| PriceControlPolicies.Constants.Map -> 2
| PriceControlPolicies.Constants.NoPrice -> 3
| _ -> 4
let sortOffers maybeMarginTarget offers =
offers
|> Seq.choose (fun offer ->
if offer.sourceSkuMapLevel = PriceControlPolicies.Constants.Map then
if Options.checkIfNoneOrNonPostivieDecimal offer.sourceSkuMapPrice then
None
else
let mapPrice = offer.sourceSkuMapPrice.Value * offer.originalSourceSkuFactor
Some { offer with offerKind = OfferKind.Price mapPrice }
else
match offer.offerKind with
| OfferKind.Price price ->
Some { offer with offerKind = OfferKind.Price (price * offer.originalSourceSkuFactor) }
| OfferKind.CostWithOptionalPrice (cost, Some price) ->
Some { offer with offerKind = OfferKind.CostWithOptionalPrice (cost, price * offer.originalSourceSkuFactor |> Some) }
| OfferKind.CostWithOptionalPrice (_, None) ->
Some offer
)
|> Seq.map (fun offer ->
// Amazon 3P offers should have shipping included in their price.
match (offer.source = Sources.Indirect) && (offer.merchantId <> Constants.AmazonMerchantId) with
| true ->
match offer.offerKind with
| OfferKind.Price price ->
{ offer with offerKind = OfferKind.Price (price + Option.getValueOr 0m offer.shippingAmount) }
| OfferKind.CostWithOptionalPrice _ -> offer
| false -> offer)
|> Seq.sortBy(fun offer ->
let priceControlPrice =
Offer.tryGetPriceOrTargetPrice offer maybeMarginTarget |> Option.getValueOr Decimal.MaxValue
priceControlPrice, invertMapLevel offer.sourceSkuMapLevel)
AllRegions
|> Seq.map ^fun regionId ->
//check global override first. This should apply to all regions no matter what
checkPriceControlOverride priceControlOverride retailSku.id
|> Option.orElseWith ^fun _ -> maybe {
let maybeMarginTarget =
marginBasedPricingMap.TryFind regionId
|> Option.map (fun x -> x.marginTarget)
let! notSortedOffers = offersMap.TryFind regionId
let offers =
notSortedOffers
|> Seq.map ^fun x -> x.offer
|> sortOffers maybeMarginTarget
|> Seq.toArray