I am attempting to fetch the product repository item for a commerceItem using getAuxiliaryData().getProductRef() and this is coming as null as is causing a nullPointer exception. Can you please help me with why it is coming as null and what could be the remedy for this.
Thanks in advance.
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.
Thanks a lot, Shaik.
can you kindly help me further with few information?
why does the sku and product catalogKey properties mismatch happen? what causes this scenario?
if, EnforceProductSkuRelationship is set as true and such a mismatch occurs, what happens then?
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.