Is there a way to create mutually exclusive categories in uCommerce? For example, I have a 'Shoe' product definition. Among the categories for this shoe are 'Mens' and 'Womens'. But a shoe can only be one or the other. So is there a way to ensure that if a user checks off the 'Mens' category that the 'Womens' category is unchecked? Perhaps there is a pipeline or something I can override to add my own logic ? The case cited is just an example; I have other mutually exclusive categories that have 5 or 6 possibilities.
Still struggling with this one. Looks like there is a SaveProduct pipeline I can hook into, but I still need a way to update the UI (i.e. if both Men's and Women's are checked when the user saves, I can override that in the pipeline, but the UI will still show both as checked). I'd prefer a JavaScript method, but hacking the uCommerce UI looks messy!
You can do the data check in the pipeline, as you sugests. But there is no way to update the UI.
One possibility would be to ovrewrite the category handling in uCommerce. This is a bit bigger change, but it is possible.
Yet another option would be to have all the shoes in one category, and have the "Mens"/"Womens" options as a product property. And then have two virtual categories for "Mens shoes" and "Womens shoes".
The last option would also work pretty well with the soon-to-be-released facettet search.
Jesper, some clever rearranging of categories has gotten me partially there. First, I created a new category definition called 'CategoryGroup' and added a boolean property to it called 'MutuallyExclusive'. Then I nested my existing categories under some newly created CategoryGroup's (by setting the ParentCategoryId column in the db). Here is a screenshot that shows the category tree on the left and the EditProductCategory view on the right. So now at least there is a visual separation of categories, BUT it does not enforce any sort of mutual exclusivity.
The next step is to create my own Categories tab so that I can write my own custom logic to enforce mutual exclusivity(via the 'MutuallyExclusive' property on the parent category). Problem now is...how do I modify products programatically? Is there an API to change a product's categories, properties, etc?
Assuming you have a product object in hand, you can:
Add/remove ProductProperty instances through the "ProductProperties" property. And in the end simply call product.Save().
The product categories are handled using the CategoryProductRelations property. There is actually a helper method called RemoveCategory(Category) on Product, to help you remove a product from a category. To add it to a category add a new CategoryProductRelation object to the CategoryProductRelations property. (A similar helper method for adding a category is on its way in the near future! :-) ) In the end again simply call product.Save() to save the changes.
How to create mutually exclusive categories
Is there a way to create mutually exclusive categories in uCommerce? For example, I have a 'Shoe' product definition. Among the categories for this shoe are 'Mens' and 'Womens'. But a shoe can only be one or the other. So is there a way to ensure that if a user checks off the 'Mens' category that the 'Womens' category is unchecked? Perhaps there is a pipeline or something I can override to add my own logic ? The case cited is just an example; I have other mutually exclusive categories that have 5 or 6 possibilities.
bump.
Still struggling with this one. Looks like there is a SaveProduct pipeline I can hook into, but I still need a way to update the UI (i.e. if both Men's and Women's are checked when the user saves, I can override that in the pipeline, but the UI will still show both as checked). I'd prefer a JavaScript method, but hacking the uCommerce UI looks messy!
Hi Kent,
You can do the data check in the pipeline, as you sugests. But there is no way to update the UI.
One possibility would be to ovrewrite the category handling in uCommerce. This is a bit bigger change, but it is possible.
Yet another option would be to have all the shoes in one category, and have the "Mens"/"Womens" options as a product property. And then have two virtual categories for "Mens shoes" and "Womens shoes".
The last option would also work pretty well with the soon-to-be-released facettet search.
Kind regards,
Jesper
Jesper, some clever rearranging of categories has gotten me partially there. First, I created a new category definition called 'CategoryGroup' and added a boolean property to it called 'MutuallyExclusive'. Then I nested my existing categories under some newly created CategoryGroup's (by setting the ParentCategoryId column in the db). Here is a screenshot that shows the category tree on the left and the EditProductCategory view on the right. So now at least there is a visual separation of categories, BUT it does not enforce any sort of mutual exclusivity.
The next step is to create my own Categories tab so that I can write my own custom logic to enforce mutual exclusivity(via the 'MutuallyExclusive' property on the parent category). Problem now is...how do I modify products programatically? Is there an API to change a product's categories, properties, etc?
Hej Kent,
Yes you can modify the products programmatically.
Assuming you have a product object in hand, you can:
Add/remove ProductProperty instances through the "ProductProperties" property. And in the end simply call product.Save().
The product categories are handled using the CategoryProductRelations property. There is actually a helper method called RemoveCategory(Category) on Product, to help you remove a product from a category. To add it to a category add a new CategoryProductRelation object to the CategoryProductRelations property. (A similar helper method for adding a category is on its way in the near future! :-) ) In the end again simply call product.Save() to save the changes.
Kind regards,
Jesper
This worked great. Thanks Jesper!
Glad iit worked! :-) Happy to help.
If there is nothing else, could you please mark the question as answered?
Kind regards,
Jesper
is working on a reply...