Extend product/category
Extend IProduct
public class ProductFac : IPerStoreFactory<IProduct>
{
public IProduct Create(UmbracoContent item, IStore store)
{
return new ExtendProduct(item, store);
}
}
public class ExtendProduct : Product
{
public ExtendProduct(UmbracoContent item, IStore store) : base(item, store)
{
}
public string NewProperty
{
get
{
return "";
}
}
public override List<IPrice> Prices
{
get
{
var list = new List<IPrice>();
if (_contextAccessor.HttpContext.User.Identity.IsAuthenticated)
{
var _cs = _contextAccessor.HttpContext.RequestServices.GetService<CustomerService>();
var _discountService = _contextAccessor.HttpContext.RequestServices.GetService<DiscountService>();
var customer = _cs.Get();
if (customer != null)
{
var discountPrice = _discountService.GetDiscountPricePerCustomer(customer.Id, SKU).Result;
if (discountPrice != null && discountPrice.Price != 0)
{
list.Add(new Price(
discountPrice.Price,
Store.Currency,
Vat,
Store.VatIncludedInPrice,
null,
1
));
return list;
}
}
}
list.Add(ListPrice);
return list;
}
}
}
Extend ICategory
public class CategoryFac : IPerStoreFactory<ICategory>
{
public ICategory Create(UmbracoContent item, IStore store)
{
return new ExtendCategory(item, store);
}
}
public class ExtendCategory: Category
{
public ExtendCategory(UmbracoContent item, IStore store) : base(item, store)
{
}
public string CustomProperty
{
get
{
return this.GetValue<string>("number");
}
}
}
Register the override
[ComposeAfter(typeof(Ekom.Umb.EkomComposer))]
class EkomOverrides : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddSingleton<IPerStoreFactory<IProduct>, ProductFac>();
builder.Services.AddSingleton<IPerStoreFactory<ICategory>, CategoryFac>();
}
}
Last updated