Skip to content

Instantly share code, notes, and snippets.

@khurramkhang
Created December 22, 2016 12:44
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save khurramkhang/d1c38ad45eeb19287321818e41d802ae to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using CommerceExtensions.Order;
using Mediachase.Commerce;
using Mediachase.Commerce.Catalog;
using Mediachase.Commerce.Pricing;
namespace CommerceExtensions.Pricing
{
public class CustomPriceService : IPriceService
{
private readonly string customerKey = "817A0F75-62D8-4BF3-B5F1-46AE3F974719";
private readonly string apiKey = "CD152686-BA55-46E2-A6B1-52FFA99F22DF";
private readonly string apiSecret = "451ED988-8F9E-40C2-836C-8BE53174167B";
private readonly IServiceBasedPricing _serviceBasedPricing;
public CustomPriceService(IServiceBasedPricing serviceBasedPricing)
{
_serviceBasedPricing = serviceBasedPricing;
}
public IPriceValue GetDefaultPrice(MarketId market, DateTime validOn, CatalogKey catalogKey, Currency currency)
{
return _serviceBasedPricing.GetPrices(catalogKey, 1, currency, customerKey, apiKey, apiSecret);
}
public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, CatalogKey catalogKey, PriceFilter filter)
{
return new List<IPriceValue>() { _serviceBasedPricing.GetPrices(catalogKey, 1, null, customerKey, apiKey, apiSecret) , _serviceBasedPricing.GetPrices(catalogKey, 1, null, customerKey, apiKey, apiSecret) };
}
public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, IEnumerable<CatalogKey> catalogKeys, PriceFilter filter)
{
return catalogKeys.Select(catalogKey => _serviceBasedPricing.GetPrices(catalogKey, 1, null, customerKey, apiKey, apiSecret)).ToList();
}
public IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, IEnumerable<CatalogKeyAndQuantity> catalogKeysAndQuantities, PriceFilter filter)
{
return catalogKeysAndQuantities.Select(catalogKeyAndQuantity => _serviceBasedPricing.GetPrices(catalogKeyAndQuantity.CatalogKey, catalogKeyAndQuantity.Quantity, null, customerKey, apiKey, apiSecret)).ToList();
}
public IEnumerable<IPriceValue> GetCatalogEntryPrices(CatalogKey catalogKey)
{
return new List<IPriceValue>() { _serviceBasedPricing.GetPrices(catalogKey, 1, null, customerKey, apiKey, apiSecret), _serviceBasedPricing.GetPrices(catalogKey, 1, null, customerKey, apiKey, apiSecret) };
}
public IEnumerable<IPriceValue> GetCatalogEntryPrices(IEnumerable<CatalogKey> catalogKeys)
{
return catalogKeys.Select(catalogKey => _serviceBasedPricing.GetPrices(catalogKey, 1, null, customerKey, apiKey, apiSecret)).ToList();
}
public void SetCatalogEntryPrices(CatalogKey catalogKey, IEnumerable<IPriceValue> priceValues)
{
throw new NotImplementedException();
}
public void SetCatalogEntryPrices(IEnumerable<CatalogKey> catalogKeys, IEnumerable<IPriceValue> priceValues)
{
throw new NotImplementedException();
}
public void ReplicatePriceDetailChanges(IEnumerable<CatalogKey> catalogKeys, IEnumerable<IPriceValue> priceValues)
{
throw new NotImplementedException();
}
public bool IsReadOnly {
get
{
return true;
}
}
}
}
using Mediachase.Commerce;
using Mediachase.Commerce.Catalog;
using Mediachase.Commerce.Pricing;
namespace CommerceExtensions.Order
{
public interface IServiceBasedPricing
{
Money GetPrice(string productCode, decimal quantity, Currency currency, string agentKey, string apiKey, string apiSecret);
IPriceValue GetPrices(CatalogKey catalogKey, decimal quantity, Currency currency, string agentKey, string apiKey, string apiSecret);
}
}
using System;
using Mediachase.Commerce;
using Mediachase.Commerce.Catalog;
using Mediachase.Commerce.Pricing;
namespace CommerceExtensions.Order
{
public class ServiceBasedPricing : IServiceBasedPricing
{
public Money GetPrice(string productCode, decimal quantity, Currency currency, string customerKey, string apiKey, string apiSecret)
{
Random random = new Random();
Money m = new Money(random.Next(0, 100), currency);
return m;
}
public IPriceValue GetPrices(CatalogKey catalogKey, decimal quantity, Currency currency, string agentKey, string apiKey, string apiSecret)
{
Random random = new Random();
Money m = new Money(random.Next(0, 100), new Currency("GBP"));
var pVal = new PriceDetailValue()
{
CatalogKey = catalogKey,
MarketId = new MarketId(),
CustomerPricing = null,
MinQuantity = 1,
PriceValueId = random.Next(1, Int32.MaxValue),
UnitPrice = m,
ValidFrom = DateTime.Now.AddDays(-1),
ValidUntil = DateTime.Now.AddDays(+1)
};
return pVal;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment