November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Have you validated your cart (_orderValidationService.ValidateOrder(cart) )before to convert into purchase order?
@shella - Just checked on a running solution and Primary category is not required. I have added product directly to catalogue with no primary category and it works fine.
We are using IPurchaseOrder to convert to PO
var po = _orderRepository.Load<IPurchaseOrder>(orderReference.OrderGroupId);
I can see you have extended PO metaclass. Do any of these properties are required field.
As @Sanjay mentioned; are you validating cart before converting it to purchase order.
Check Episerver Foundation code from line #679
Yes, we validate the cart.
As @Naveed said, Primary Category is not required. But on the Commerce Database - CatalogNode is a non-nullable column in the LineItem database table.
The extended PO metaclasses are not required and are even marked mandatory on the meta fields.
The error message specifically says: "Cannot insert the value NULL into column 'CatalogNode', table 'epicommerce.dbo.LineItem'; column does not allow nulls. UPDATE fails."
Thus, the error is not related to the extended meta fields.
I think what I don't get at this point is why purchaseOrder.AcceptChanges() work and _orderRepository.Save(iPurchaseOrder) fails -- with the same .
Those are different classes and source codes, I know, but, they have different behaviour -- it's just that I thought we're moving away from the MediaChase concrete classes.
I have tried again, Created a product in catalogue root and successfully complete its purchase. I have looked at the database & LineItem table. Yes, the CatalogNode column does not allow null but I "think" OrderRepository is saving empty string. I can clearly see in the table, there is no value in CatalogueNode but _orderRepository.save does not give any exception.
see screenshot https://ibb.co/tPsN5nt
In my point of view the difference between purchaseOrder.AcceptChanges() and _orderRepository.Save(iPurchaseOrder) is _orderRepository.Save(iPurchaseOrder) do necessary validation before saving PO
Recently, we were encountering save issues on purchase order update - that we narrowed down to a missing primary category (see following error message):
"Cannot insert the value NULL into column 'CatalogNode', table 'epicommerce.dbo.LineItem'; column does not allow nulls. UPDATE fails."
The code looks like below:
It makes me think now: Is Primary Category required?
If yes, then why did Add To Cart work -- should it validate that the primary category is required? Why did SaveAsPurchaseOrder() also work? Then fail on orderRepository.Save(purchaseOrder)?
When I looked at the database, the CatalogNode has empty blank string value (which seems to be a workaround on the NULL).
What's the best way to prevent this error from happening? I'm a bit torn on this -- it feels like firefighting to me if I forcefully validate the primary category.
Then, I tried using PurchaseOrder instead of IPurchaseOrder and it did not throw the error.
Which should be the approach?