Product price missing on external product when added to order
Hi Matt,
I'm trying to implement adding an external product to vendr order, and it seem to be adding it without any errors, but when I query the orderlines, the price of such product is 0.
Here's the code:
using (var uow = uowProvider.Create())
{
var order = sessionManager.GetOrCreateCurrentOrder(store.Id)?.AsWritable(uow);
if (order != null)
{
var productProperties = new Dictionary<string, string>();
productProperties.Add(VendrOrderProperties.ItemType, CartItemTypeEnum.Accessory.ToString());
ExternalProduct q = new ExternalProduct();
q.Description = "description";
q.Name = "external product";
var prices = new List<ProductPrice>();
prices.Add(new ProductPrice(138m, new Guid("a79ce70d-c9b5-415d-ad3c-5d98283ea7d9")));
q.Prices = prices;
q.ProductReference = "ex1";
q.Sku = "ex1";
q.StoreId = new Guid("536a8ebb-f1e5-4d8e-891a-b902bb21d354");
q.TaxClassId = new Guid("c54c07af-ea58-4143-ac35-21d255686641");
order.AddProduct(q, 1, productProperties);
orderService.SaveOrder(order);
}
uow.Complete();
}
Also, I've implemented custom product adapter as per the docs, where GetProductSnapshot method just returns the same object that I'm adding to the order. The adapter is registered via composition.RegisterUnique<IProductAdapter, CustomProductAdapter>();, so should be no problem.
If you have implemented a product adapter than there shouldn't bee a need to also create a manual product snapshot whilst adding the item to the order. You should be able to pass the product ID and then it requests the product snapshot from the product adapter.
If the price is empty, the usual culprit for this is that the product doesn't have a price defined for the currency the order is in. You might want to check to make sure the currency you define for the price on the snapshot, is the same as the currency of the the order.CurrencyId
Product price missing on external product when added to order
Hi Matt,
I'm trying to implement adding an external product to vendr order, and it seem to be adding it without any errors, but when I query the orderlines, the price of such product is 0. Here's the code:
Also, I've implemented custom product adapter as per the docs, where GetProductSnapshot method just returns the same object that I'm adding to the order. The adapter is registered via
composition.RegisterUnique<IProductAdapter, CustomProductAdapter>();
, so should be no problem.Maybe there is something I'm missing here?
Thanks, Fedor
Hi Fedor
If you have implemented a product adapter than there shouldn't bee a need to also create a manual product snapshot whilst adding the item to the order. You should be able to pass the product ID and then it requests the product snapshot from the product adapter.
If the price is empty, the usual culprit for this is that the product doesn't have a price defined for the currency the order is in. You might want to check to make sure the currency you define for the price on the snapshot, is the same as the currency of the the
order.CurrencyId
Matt
Hi Matt,
thanks for the hint, it all works now.
One thing I've had to add is
[ComposeAfter(typeof(VendrWebComposer))]
to the composer class where I've registered the custom product adapter.Ahh yea, we do document this here https://vendr.net/docs/core/1.7.0/key-concepts/dependency-injection/#registering-dependencies but we don't show it in every example as it detracts from what is being documented. It does mean you have to have read that section first though, which people probably should, but I'll bare that in mind.
Glad you got it all working 👍
Matt
is working on a reply...