This content has been marked as final. Show 3 replies
enable EnforceProductSkuRelationship flag on CommerceItemManager from dyn/admin and then reproduce the issue.
It looks the sku and product catalogKey properties are not same.
This will throw exception while creating the commerceItem.
If flag is false then productRef is set as null if its not able to find product with same catalogKey as sku.
Your problem may not be related to the catalogKey property. Most applications don't do anything with catalogKey, so it's not likely to take on more than one value.
A simpler way to get a null productRef is if the product ID in the commerce item is null or refers to a non-existent product. The DCS code requires SKU items to exist but is more forgiving about products.
Do you ever delete product items from the catalog? Are you working with an order that was submitted some time in the past? There are ways to handle orders that refer to deleted products and SKUs in the refreshOrder pipeline chain when the orders are loaded into memory. The options are described in the Commerce Programming Guide.