Can't add a Product to an Order where there is no price for the Order currency.
Trying to set up a POC for a Vendr shop with an external product catalog.
The ProductSnapshot looks like this
public class Product : IProductSnapshot
{
public int Id { get; set; }
public string ProductReference => Id.ToString();
public string Sku => Id.ToString();
public string UrlSegment => string.Format("{0}-{1}", Name, Sku).ToSafeAlias();
public Guid StoreId => new Guid("c7624842-d284-464b-aee0-b99e42c1993b"); // hardcoded for speed :)
public IEnumerable<ProductPrice> Prices { get; set; }
public IDictionary<string, string> Properties
{
get
{
var dict = new Dictionary<string, string>();
dict.Add("Category", Category.Name);
dict.Add("Description", Description);
return dict;
}
}
public Category Category { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public Guid? TaxClassId => new Guid("6d12d936-f58a-44ef-a4ee-3b7c60b3d22b"); // hardcoded for speed :)
public bool IsGiftCard => false;
}
And is created from a CSV like this
int.TryParse(x[0], out int id);
decimal.TryParse(x[6].Replace(".", "").Replace(" DKK", ""), out decimal price);
var category = categories.FirstOrDefault(c => c.Name.InvariantEquals(x[1]));
var prices = new List<ProductPrice>();
prices.Add(new ProductPrice(price, new Guid("0beb35b4-f907-49c4-b114-8aecd7f7925e")));
return new Product()
{
Id = id,
Category = category,
Name = x[2],
Prices = prices,
ImageUrl = x[8]
};
And the product adapter looks like this
public IProductSnapshot GetProductSnapshot(string productReference, string languageIsoCode)
{
return ProductRepo.GetProduct(productReference);
}
public string GetProductReference(Guid storeId, string sku)
{
// SKU and ProductReference is the same in the POC, so just return SKU
return sku;
}
When I add the product to the cart, I do it like this:
using (var uow = _unitOfWorkProvider.Create())
{
var store = CurrentPage.GetStore();
var product = ProductRepo.GetProduct(postModel.ProductReference);
var order = _sessionManager.GetOrCreateCurrentOrder(store.Id)
.AsWritable(uow);
order = order.AddProduct(product, postModel.Quantity);
_orderService.SaveOrder(order);
uow.Complete();
}
It then breaks and gives the message Can't add a Product to an Order where there is no price for the Order currency..
I have verified that the currency on the product price is the same as the currency on the order.
That error is coming from a validation rule which is pretty simple in terms of what it checks
var productPrices = _productService.Value.GetProduct(evt.ProductReference)?.Prices;
var currencyPrice = productPrices?.FirstOrDefault(x => x.CurrencyId == evt.Order.CurrencyId);
if (currencyPrice == null)
evt.Fail($"Can't add a Product to an Order where there is no price for the Order currency.");
So I'd initially say to check whether your prices are coming back with the correct currency id set (make sure this is a currency id too, not a country id by mistake), and then also check your order has it's currency id correctly set to the same currency.
I found my problem, I hadn't registered my ProductAdapter correctly, I was missing using Umbraco.Core, and mistakenly written composition.RegisterUniqueFor<>
I keep getting caught out by that myself. There are a lot of extensions in Umbraco.Core (might the same with Vendr.Core) so it always pays to add a using statement for them, but it's so easy to forget.
Can't add a Product to an Order where there is no price for the Order currency.
Trying to set up a POC for a Vendr shop with an external product catalog.
The ProductSnapshot looks like this
And is created from a CSV like this
And the product adapter looks like this
When I add the product to the cart, I do it like this:
It then breaks and gives the message
Can't add a Product to an Order where there is no price for the Order currency.
.I have verified that the currency on the product price is the same as the currency on the order.
Am I missing something on the ProductSnapshot?
Hey Soren,
The product adapter looks correct to me.
That error is coming from a validation rule which is pretty simple in terms of what it checks
So I'd initially say to check whether your prices are coming back with the correct currency id set (make sure this is a currency id too, not a country id by mistake), and then also check your order has it's currency id correctly set to the same currency.
Matt
Thanks Matt,
That seems simple enough :)
I found my problem, I hadn't registered my ProductAdapter correctly, I was missing
using Umbraco.Core
, and mistakenly written composition.RegisterUniqueFor<>Ahhh, yea.
I keep getting caught out by that myself. There are a lot of extensions in
Umbraco.Core
(might the same withVendr.Core
) so it always pays to add a using statement for them, but it's so easy to forget.Glad you got it working though 👍
Matt
is working on a reply...