0

Folks:

In this scenario, a main product has multiple accessories (which are, of course, related to the main product through relationships). Only certain accessories are related to the main product. The user can place main products and unrelated accessories into the cart. I'd like to display a warning that they are ordering incompatible items.

I understand that you can use empty or relatedTo to find out if a relationship exists between entries but in this case, I need to know if accessories unrelated to the main product are in the cart.

Is this possible?

1

In essence, if I am reading that right, can you reverse the question? I.e. it seems that what you want to know is, for each accessory in the cart, is there a reverse relation back to at least one product in the cart.

This is definitely possible - you can read about reverse relations here: https://straightupcraft.com/articles/introduction-to-relations-and-reverse-relations-in-craft-cms-with-examples and of course at https://craftcms.com/docs/relations

..basically just loop through each accessory and check the |length of the result of a relatedTo that specifies what you want it to be related to (.e.g a product category).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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