I have a product variation "Apparel", and a corresponding content type provided by kickstart "Apparel".

I have added a new content type "Product kit", which has an entity reference field pointing to "Commerce product" entity and "Apparel" is one of them. A single product kit node, can contain products of different types : "Apparel", "Luggage", "Cups", etc.

Using the newly created Commerce Product Kit module I have an option to add all the products stored in the entity reference field in a "product kit" node to cart.

I need to find a way to check if a product has been added from the "Product display" node or "Product kit" node. Is there a way to do this? I checked into hook_commerce_cart_product_add, but it doesn't help me identifying the source node type of the product. Any pointers would be appreciated.

1 Answer 1


Generally speaking, the line item for each product in the cart has a data array with a context sub-array that includes information identifying the context from which the product was added to the cart. In the case of a product added from a node's Add to Cart form, this array would point to the specific node ID and even name the reference field responsible for generating the form.

If I were you, I'd use the Devel module's dpm() function to inspect the contents of the line item's data array. Drilling down through the context array you should discover how to get the information you're needing. Just make sure to use a !empty() check before assuming a particular key in the array exists!

  • Thanks for the help! And sorry for the late reply. Unfortunately the project had to be paused due to some issues from the client side.
    – AjitS
    Commented Apr 13, 2016 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.