# Issue with custom site price agent item factory not being invoked while calling price agent

**URL:** <https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415>\
**Category:** Questions\
**Created:** [March 31, 2020, 10:29am UTC](https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415 "2020-03-31T10:29:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishnu\_kj](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/vishnu_kj/32/685_2.png) [@vishnu\_kj](https://forum.litium.com/u/vishnu_kj)\
**Post date:** [March 31, 2020, 10:29am UTC](https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415/1 "2020-03-31T10:29:15Z")

</div>

Please see my code. Am I doing something wrong?

**TapwellProductPriceAgentFeed.cs**

```auto
using Litium.Owin.InversionOfControl;
using Litium.Web.Products.PriceAgents;
using System;
using System.Collections.Generic;
using System.IO;
using Tapwell.Integration.TapwellPriceAgent;
using Tapwell.Integration.Utilities;

namespace Tapwell.Integration
{
    [Plugin("TapwellProductFeed")]
    public class TapwellProductPriceAgentFeed : IPriceAgent
    {
        public TapwellProductPriceAgentFeed()
        {
        }

        /// <summary>
        /// Gets the type of the content.
        /// </summary>
        /// <value>
        /// The type of the content.
        /// </value>
        public string ContentType
        {
            get { return "text/plain"; }
        }

        /// <summary>
        /// Render price agent
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="priceAgentItemResults">The price agent item results.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void Render(TextWriter writer, IEnumerable<PriceAgentItemResult> priceAgentItemResults)
        {
            //DO NOT fetch the product name, or price or any other article information here,
            //instead specify them in the PriceAgentItemFactory implementation.
            TapwellChannelFeedDto feed = new TapwellChannelFeedDto()
            {
                Title = "Tapwell Product Feed",
                Description = "Tapwell Product Feed For External Websites",
                Items = new List<TapwellPriceAgentItemResult>()
            };

            try
            {
                foreach (PriceAgentItemResult priceAgentItemResult in priceAgentItemResults)
                {
                    var item = priceAgentItemResult as TapwellPriceAgentItemResult;
                    if (item == null)
                        continue;

                    feed.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }

            string sb = feed.ObjectToXmlSerialize();

            writer.Write(sb);
        }
    }
}
```

**SitePRiceAgentItemFactory.cs**

```auto
using Litium.Accelerator.Builders.Framework;
using Litium.Accelerator.Extensions;
using Litium.Account;
using Litium.Common;
using Litium.FieldFramework;
using Litium.Foundation.Modules.ECommerce.Plugins.Orders;
using Litium.Foundation.Modules.ECommerce.Plugins.PriceCalculator;
using Litium.Foundation.Modules.ExtensionMethods;
using Litium.Foundation.Settings;
using Litium.Globalization;
using Litium.Media;
using Litium.Products;
using Litium.Products.PriceCalculator;
using Litium.Products.StockStatusCalculator;
using Litium.Web;
using Litium.Web.Models.Products;
using Litium.Web.Products.PriceAgents;
using Litium.Web.Routing;
using Litium.Websites;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;

namespace Tapwell.Integration.TapwellPriceAgent
{
	public class SitePriceAgentItemFactory : PriceAgentItemFactory, IPriceAgentItemFactory
	{
		private readonly ChannelService _channelService;
		private ProductModelBuilder _productModelBuider;
		private readonly FileService _fileService;
		private string _baseUrl;
		private readonly RouteRequestLookupInfoAccessor _routeRequestLookupInfoAccessor;
		private readonly UnitOfMeasurementService _unitOfMeasurementService;
		private readonly SiteSettingViewModelBuilder _siteSettingViewModelBuilder;
		private readonly ProductListService _productListService;
		private readonly ProductListItemService _productListItemService;
		private readonly KeyLookupService _keyLookupService;
		List<Guid> activeVariantsList = null;
		public SitePriceAgentItemFactory(IPriceCalculator priceCalculator, IStockStatusCalculator stockStatusCalculator, ICampaignPriceCalculator campaignPriceCalculator, 
			IOrderFactory orderFactory, LanguageService languageService, UrlService urlService, CategoryService categoryService, CurrencyService currencyService, 
			FieldDefinitionService fieldDefinitionService, ISettingService settingService, WebsiteService websiteService, CountryService countryService, 
			ChannelService channelService, DomainNameService domainNameService, Litium.Application.Security.AuthorizationOperationHelperService authorizationOperationHelperService, 
			AccountService accountService, Litium.Application.Security.AccessControlService accessControlService, RouteRequestLookupInfoAccessor routeRequestLookupInfoAccessor, 
			FileService fileService, UnitOfMeasurementService unitOfMeasurementService, SiteSettingViewModelBuilder siteSettingViewModelBuilder,
			ProductListService productListService, ProductListItemService productListItemService, KeyLookupService keyLookupService, ProductModelBuilder productModelBuider)
			: base(priceCalculator, stockStatusCalculator, campaignPriceCalculator, orderFactory, languageService, urlService, categoryService, currencyService,
				  fieldDefinitionService, settingService, websiteService, countryService, channelService, domainNameService, authorizationOperationHelperService, 
				  accountService, accessControlService)
		{
			_productModelBuider = productModelBuider;
			_channelService = channelService;
			_siteSettingViewModelBuilder = siteSettingViewModelBuilder;
			_productListService = productListService;
			_productListItemService = productListItemService;
			_keyLookupService = keyLookupService;
			_fileService = fileService;
			_routeRequestLookupInfoAccessor = routeRequestLookupInfoAccessor;
			_unitOfMeasurementService = unitOfMeasurementService;

			Guid? productFeedProductListId = _siteSettingViewModelBuilder.GetProductFeedProductListId();

			if (productFeedProductListId != null)
			{
				var existProductList = _productListService.Get<ProductList>((Guid)productFeedProductListId);
				if (existProductList != null)
				{
					activeVariantsList = _productListItemService.GetByProductList(existProductList.SystemId)
						.SelectMany(x => x.ActiveVariantSystemIds).ToList();
				}
			}
		}

		PriceAgentItemResult IPriceAgentItemFactory.Create(PriceAgentItemArgs priceAgentItemArgs)
        {
			try
			{
				var variant = priceAgentItemArgs.Variant;
				if (!activeVariantsList.Contains(variant.SystemId) || !variant.IsPublished())
					return null;

				var productModel = _productModelBuider.BuildFromVariant(variant);
				var baseProduct = productModel.BaseProduct;
				

				//Unhandled exception in here
				var item = Create(priceAgentItemArgs);

				//var nordicFeelItem = ConvertToNordicFeelItem(item, priceAgentItemArgs.BaseProduct, language);
				var drawing2DFileId = baseProduct.Fields
								.GetValue<Guid>("Drawing2D");
				var drawing2DUrl = drawing2DFileId != Guid.Empty
					? GetAbsoluteUrl(_fileService.Get(drawing2DFileId)?.GetUrl(true))
					: "";

				var drawing3DFileId = baseProduct.Fields
					.GetValue<Guid>("Drawing3D");
				var drawing3DUrl = drawing3DFileId != Guid.Empty
					? GetAbsoluteUrl(_fileService.Get(drawing3DFileId)?.GetUrl(true))
					: "";

				var drawingPDFFileId = baseProduct.Fields
					.GetValue<Guid>("DrawingPDF", CultureInfo.CurrentUICulture);
				var drawingPDFUrl = drawingPDFFileId != Guid.Empty
					? GetAbsoluteUrl(_fileService.Get(drawingPDFFileId)?.GetUrl(true))
					: "";

				var connectionInlet = baseProduct.Fields.GetValue<string>("ConnectionInlet", CultureInfo.CurrentUICulture);
				var numberOfGrips = baseProduct.Fields.GetValue<string>("NumberOfGrips", CultureInfo.CurrentUICulture);
				var buildingHeightUnderneathOutlet = baseProduct.Fields.GetValue<decimal>("BuildingHeightUnderneathOutlet");
				var builtIn = baseProduct.Fields.GetValue<bool>("BuiltIn");
				var classificationBK04 = baseProduct.Fields.GetValue<string>("ClassificationBK04");
				var classificationBSAB = baseProduct.Fields.GetValue<string>("ClassificationBSAB");
				var color = variant.Fields.GetValue<string>("Color", CultureInfo.CurrentUICulture);
				var commodityCode = variant.Fields.GetValue<string>("CommodityCode");
				var diameterCeilingShowerHead = baseProduct.Fields.GetValue<decimal>("DiameterCeilingShowerHead");

				var explodedViewPDFFileId = baseProduct.Fields
					.GetValue<Guid>("DrawingPDF", CultureInfo.CurrentUICulture);
				var explodedViewPDFUrl = explodedViewPDFFileId != Guid.Empty
					? GetAbsoluteUrl(_fileService.Get(explodedViewPDFFileId)?.GetUrl(true))
					: "";

				var flowClass = baseProduct.Fields.GetValue<string>("FlowClass");
				var gtin = variant.Fields.GetValue<string>("GTIN");

				var installationGuidePDFFileId = baseProduct.Fields
					.GetValue<Guid>("InstallationGuide", CultureInfo.CurrentUICulture);
				var installationGuidePDFUrl = installationGuidePDFFileId != Guid.Empty
					? GetAbsoluteUrl(_fileService.Get(installationGuidePDFFileId)?.GetUrl(true))
					: "";

				var lengthProtrusionOutletHead = baseProduct.Fields.GetValue<decimal>("LengthProtrusionOutletHead");
				var lockableHead = baseProduct.Fields.GetValue<IList<string>>("LockableHead");
				var machineShutdown = baseProduct.Fields.GetValue<bool>("MachineShutdown");
				var maxFlow = baseProduct.Fields.GetValue<string>("MaxFlow");
				var packageDepth = baseProduct.Fields.GetValue<decimal>("PackageDepth");
				var packageHeight = baseProduct.Fields.GetValue<decimal>("PackageHeight");
				var packageWeight = baseProduct.Fields.GetValue<decimal>("PackageWeight");
				var packageWidth = baseProduct.Fields.GetValue<decimal>("PackageWidth");
				var packageVolume = baseProduct.Fields.GetValue<decimal>("PackageVolume");
				var preasureControlled = baseProduct.Fields.GetValue<bool>("PreasureControlled");

				var pressureDropDiagramId = baseProduct.Fields
					.GetValue<Guid>("PressureDropDiagram", CultureInfo.CurrentUICulture);
				var pressureDropDiagramPDFUrl = pressureDropDiagramId != Guid.Empty
					? GetAbsoluteUrl(_fileService.Get(pressureDropDiagramId)?.GetUrl(true))
					: "";

				var productDepth = baseProduct.Fields.GetValue<decimal>("ProductDepth");
				var productDescription = baseProduct.Fields.GetValue<string>("ProductDescription", CultureInfo.CurrentUICulture);
				var productHeight = baseProduct.Fields.GetValue<decimal>("ProductHeight");

				var productSheetFileId = baseProduct.Fields
					.GetValue<Guid>("ProductSheet", CultureInfo.CurrentUICulture);
				var productSheetPDFUrl = productSheetFileId != Guid.Empty
					? GetAbsoluteUrl(_fileService.Get(productSheetFileId)?.GetUrl(true))
					: "";

				var productWidth = baseProduct.Fields.GetValue<decimal>("ProductWidth");
				var rskNumber = variant.Fields.GetValue<int>("RSKNumber");
				var sizeCeilingShowerHead = baseProduct.Fields.GetValue<string>("SizeCeilingShowerHead");
				var temperatureControl = baseProduct.Fields.GetValue<bool>("TemperatureControl");

				var totalBuildingHeight = variant.Fields.GetValue<decimal>("TotalBuildingHeight");
				var turnableHead = baseProduct.Fields.GetValue<bool>("TurnableHead");
				var unitOfMeasurement = _unitOfMeasurementService.Get(variant.UnitOfMeasurementSystemId.GetValueOrDefault());

				TapwellPriceAgentItemResult resultItem = new TapwellPriceAgentItemResult()
				{
					ArticleNumber = item.ArticleNumber,
					ConnectionInlet = connectionInlet,
					NumberOfGrips = numberOfGrips,
					ProductName = item.ProductName,
					ProductDescription = productDescription,
					ProductImageUrl = item.ProductImageUrl,
					BuildingHeightUnderneathOutlet = buildingHeightUnderneathOutlet,
					BuiltIn = builtIn,
					ClassificationBK04 = classificationBK04,
					ClassificationBSAB = classificationBSAB,
					Color = color,
					CommodityCode = commodityCode,
					DiameterCeilingShowerHead = diameterCeilingShowerHead,
					Drawing2D = drawing2DUrl,
					Drawing3D = drawing3DUrl,
					DrawingPDF = drawingPDFUrl,
					ExplodedViewUrl = explodedViewPDFUrl,
					FlowClass = flowClass,
					GTIN = gtin,
					InstallationGuideUrl = installationGuidePDFUrl,
					LengthProtrusionOutletHead = lengthProtrusionOutletHead,
					LockableHead = lockableHead,
					MachineShutdown = machineShutdown,
					MaxFlow = maxFlow,
					PackageDepth = packageDepth,
					PackageHeight = packageHeight,
					PackageWeight = packageWeight,
					PackageWidth = packageWidth,
					PackageVolume = packageVolume,
					PreasureControlled = preasureControlled,
					PressureDropDiagramPDFUrl = pressureDropDiagramPDFUrl,
					ProductDepth = productDepth,
					ProductHeight = productHeight,
					ProductSheetPDFUrl = productSheetPDFUrl,
					ProductWidth = productWidth,
					RSKNumber = rskNumber,
					SizeCeilingShowerHead = sizeCeilingShowerHead,
					TemperatureControl = temperatureControl,
					TotalBuildingHeight = totalBuildingHeight,
					TurnableHead = turnableHead,
					ProductCategory = item.ProductCategory,
					PriceWithVat = item.PriceWithVat,
					VatPercentage = item.VatPercentage,
					UnitOfMeasurement = unitOfMeasurement?.Localizations.CurrentCulture.Name ?? unitOfMeasurement?.Id
				};

				return resultItem;
			}
			catch (Exception ex)
			{
				//this.Log().Error("Create item for variant " + (priceAgentItemArgs.Variant?.Id ?? string.Empty), ex);
				return null;
			}
		}

		private string GetBaseUrl()
		{
			if (_baseUrl != null)
			{
				return _baseUrl;
			}

			var hostName = _routeRequestLookupInfoAccessor.RouteRequestLookupInfo.DomainName.Id;

			if (hostName.Contains("/"))
			{
				hostName = hostName.Substring(0, hostName.IndexOf("/", StringComparison.Ordinal));
			}

			int? port = null;
			if (hostName.Contains(":"))
			{
				var s = hostName.Split(':');
				hostName = s.First();
				port = int.Parse(s.Last());
			}

			var uriBuilder = new UriBuilder(_routeRequestLookupInfoAccessor.RouteRequestLookupInfo.IsSecureConnection ? Uri.UriSchemeHttps : Uri.UriSchemeHttp, hostName, port ?? (_routeRequestLookupInfoAccessor.RouteRequestLookupInfo.IsSecureConnection ? 443 : 80));

			_baseUrl = new Uri(uriBuilder.Uri.ToString()).AbsoluteUri.TrimEnd('/');
			return _baseUrl;
		}

		private string GetAbsoluteUrl(string url)
		{
			if (!string.IsNullOrEmpty(url))
			{
				return url.Contains("//") ? url : GetBaseUrl() + VirtualPathUtility.ToAbsolute(url);
			}

			return string.Empty;
		}
	}
}

```

**TapwellPriceAgentItemResult.cs**

```auto
using Litium.Web.Products.PriceAgents;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tapwell.Integration.TapwellPriceAgent
{
    [Serializable]
    public class TapwellPriceAgentItemResult : PriceAgentItemResult
    {
        public string ConnectionInlet { get; set; }
        public string NumberOfGrips { get; set; }
        public decimal BuildingHeightUnderneathOutlet { get; set; }
        public bool BuiltIn { get; set; }
        public string ClassificationBK04 { get; set; }
        public string ClassificationBSAB { get; set; }
        public string Color { get; set; }
        public string CommodityCode { get; set; }
        public decimal DiameterCeilingShowerHead { get; set; }
        public string Drawing2D { get; set; }
        public string Drawing3D { get; set; }
        public string DrawingPDF { get; set; }
        public string ExplodedViewUrl { get; set; }
        public string FlowClass { get; set; }
        public string GTIN { get; set; }
        public string InstallationGuideUrl { get; set; }
        public decimal LengthProtrusionOutletHead { get; set; }
        public IList<string> LockableHead { get; set; }
        public bool MachineShutdown { get; set; }
        public string MaxFlow { get; set; }
        public decimal PackageDepth { get; set; }
        public decimal PackageHeight { get; set; }
        public decimal PackageWeight { get; set; }
        public decimal PackageWidth { get; set; }
        public decimal PackageVolume { get; set; }
        public bool PreasureControlled { get; set; }
        public string PressureDropDiagramPDFUrl { get; set; }
        public decimal ProductDepth { get; set; }
        public decimal ProductHeight { get; set; }
        public string ProductSheetPDFUrl { get; set; }
        public decimal ProductWidth { get; set; }
        public int RSKNumber { get; set; }
        public string SizeCeilingShowerHead { get; set; }
        public bool TemperatureControl { get; set; }
        public decimal TotalBuildingHeight { get; set; }
        public bool TurnableHead { get; set; }
        public string UnitOfMeasurement { get; set; }
    }
}
```

**TapwellChannelFeedDTO.cs**

```auto
using Litium.Web.Products.PriceAgents;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tapwell.Integration.TapwellPriceAgent
{
    [Serializable()]
    [System.ComponentModel.DesignerCategory("code")]
    [System.Xml.Serialization.XmlType(AnonymousType = true)]
    [System.Xml.Serialization.XmlRoot(ElementName = "Channel", Namespace = "", IsNullable = false)]
    public class TapwellChannelFeedDto
    {
        //[System.Xml.Serialization.XmlElement("title")]
        public string Title { get; set; }
        //[System.Xml.Serialization.XmlElement("description")]
        public string Description { get; set; }
        //[System.Xml.Serialization.XmlElement("items")]
        public List<TapwellPriceAgentItemResult> Items { get; set; }
    }
}

```

Litium version: _[7.4.0]_

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [March 31, 2020, 11:38am UTC](https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415/2 "2020-03-31T11:38:09Z")

</div>

Please check this topic and see if you have similar issue:

> [@Extended Price Agent Item Factory not triggering](https://forum.litium.com/t/extended-price-agent-item-factory-not-triggering/628):
>
> Hey, I 've extended the default PriceAgentItemFactory as the instructions say in Litium Docs but for some reason the PriceAgentScheduler is ignoring my extension and only running the default factory every time it runs. Am I missing something? Do I need to refer my extension of the factory somewhere? Litium version: 6.2.2

---

<div class="post-metadata">

**Author:** ![vishnu\_kj](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/vishnu_kj/32/685_2.png) [@vishnu\_kj](https://forum.litium.com/u/vishnu_kj)\
**Post date:** [March 31, 2020, 12:59pm UTC](https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415/3 "2020-03-31T12:59:30Z")

</div>

I have added like this. Do i need to add types too That too didn’t invoke

```auto
<plugins>
        <assemblies>
          <add assembly="Tapwell.Integration.TapwellPriceAgent"/>
        </assemblies>
        <types>
        </types>
</plugins>
```

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [March 31, 2020, 4:07pm UTC](https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415/4 "2020-03-31T16:07:46Z")

</div>

Not sure why you inherit both from IPriceAgentItemFactory and PriceAgentItemFactory since you only use the Create method.  
And also Create method should override the base Virtual method.

```auto
public override PriceAgentItemResult Create(PriceAgentItemArgs priceAgentItemArgs)

```

---

<div class="post-metadata">

**Author:** ![vishnu\_kj](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/vishnu_kj/32/685_2.png) [@vishnu\_kj](https://forum.litium.com/u/vishnu_kj)\
**Post date:** [April 1, 2020, 7:05am UTC](https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415/5 "2020-04-01T07:05:28Z")

</div>

Seems like i gave the wrong assembly

it worked when i corrected it

```auto
<plugins>
        <assemblies>
          <add assembly="Tapwell.Integration"/>
        </assemblies>
        <types>
        </types>
</plugins>
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [April 29, 2020, 7:09am UTC](https://forum.litium.com/t/issue-with-custom-site-price-agent-item-factory-not-being-invoked-while-calling-price-agent/1415/6 "2020-04-29T07:09:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
