Umbraco: how to create nested categories? - umbraco

I'm pretty new to Umbraco but I need an answer from someone else more expert than me. I need to creare a sort of hierarchy, something like:
CATALOG > FIRST LEVEL (1...n) > SECOND LEVEL (1...n) > PRODUCT
From the basics I would create a documentType for the product (last item) and something else for each level. Would be enough another documentType? the use of tags might be useful?

If you are sure that you have only 100% sure that there is only one subcategory, you could create docTypes for each level:
catalog
category
category
subcategory
product
product
If you really have nesting categories, then create just one category document type and allow the same category document type as child node (in the structure tab).
catalog
category
category
category
category
category
...
product
From a programming perspective, you don't have much more work with the second option, while allowing the user to decide and play with the categories much more freely.
Remember if all these pages are also webpages, start with a "master" or "webpage" document type where you put all shared properties (fields) on.

Related

Using CMF DynamicRouter for Doctrine entities

I have the following two Doctrine (ORM) entities:
Product
Category
Category contains one or more segment (level):
category
category/sub-category
Product contains a name and possibly a color. A Product either has a color or not.
product
product/red
I'd like to have both Category pages and Product pages.
The Category URL should be made up as {locale}/{category_path}, e.g.
/en_US/category
/en_US/category/sub-category
The Product URL should be made up as {locale}/{category_path}/{product_path}, e.g.
/en_US/category/product
/en_US/category/product/red
/en_US/category/sub-category/product
/en_US/category/sub-category/product/red
The problem with using Symfony's routing is that there maybe matching confusion between the following routes since they have the same number of segments:
/en_US/category/sub-category
/en_US/category/product
Is this something I can use the CMF DynamicRouter for? If so, at a high level, what pieces do I need to build? Do I need to use a RouteProvider for each Entity?
to use the dynamic router out of the box, your entities need to be able to implement the RouteReferrersReadInterface. That is, they need to return route objects. And you will need to implement the RouteProviderInterface so that you can find the documents in the database.
With the Doctrine ORM, you probably want separate route entities (one per language) that contain the manifested path and link to the products / categories. Afaik the ORM can only link between known entities - one way to use the same route object would be to make category and product share a common base class that is a Mapped Super Class. The product color variants could be done as a variable part of the URL, so you end up with a pattern saying .../{color}
With the CMF route enhancer, you can configure different controllers for category and product pages.
A limited example of ORM routes is provided with the RoutingBundle. You might extend the base entity, or do your own starting with that. The documentation on symfony.com is often first mentioning how to work with the default storage of the CMF, the Doctrine PHPCR-ODM, but things should work with the ORM as well. Open issues on the cmf github project if something does not work.

Grails: Intercept form request

My Grails domain model consists of something like the following:
Competition - with name String property
Club - with name String property
Team - with club and competition properties
Game - with teamOne and teamTwo properties
I'm looking to create a Game form that contains the following:
a competition drop-down
a team one drop-down
a team two drop-down
For my team drop-downs though I wish to just have a list of Club names e.g. ${Club.all}
However, I then wish to have some interceptor that will use the Competition and Club name to construct the appropriate Team before the Game entity is constructed
I do not wish to introduce any Ajax/Javascript to my application, I want to keep the UI work as minimal as possible.
How can I achieve this?
You could use the beforeInterceptor available in controllers. I'm not exactly sure if this is what you are looking for, but it sounds like you can do what you describe.

How can I link to multiple different tables with one id column in Rails?

I have a table that stores in-app purchases. Model name is Item. It stores some thing like price, description, etc.
Now, there are a few different Item types. There are Themes and Settings. A theme example would be like Night Theme which changes the color of the app to very dark colors. A setting example would be like gold which gives the user premium access.
So in model Item, I need to store both the Themes and Settings, and possibly other purchases. When the user goes to the 'Store' in the app, it will pull in all items from Item.
However, if the user goes to their Account in the app, there is a "Themes" section and a "Settings" section.
I thought of using an actual_id on the Item model. I would create a new ItemType model. id=1, type=Theme, id=2, type=Setting.
Then on Item, I would store both the item_type_id, and the actual_id. The actual_id would be a reference to the proper table. So if item.item_type_id = 1 (Theme), then actual_id would reference the Themes table. If item.item_type_id = 2 (Setting), then actual_id would reference the Settings table.
1) Is this a good way of setting things up? Can anyone think of anything better?
Here's some sample data to show what I mean.
ItemType
id|type
:--|:--
1|Theme
2|Setting
Theme
id|description|...
:--|:--|:--
1|Night Theme|...
2|Ice Theme|...
Setting
id|description|...
:--|:--|:--
1|Gold|...
2|Remove Ads|...
Item
id|actual_id|item_type_id|cost
:--|:--|:--|:--
1|1|1|99
2|2|1|99
3|1|2|299
4|2|2|99
Then, if the user goes to the "Themes" or "Settings" section, I will fetch from the Item table where item_type_id = appropriateSection, and then tie actual_id to the appropriate table's id. (I actually have a UserItem model that holds ownership as well as a Purchase model that holds purchase history, but for simplicity sake, let's just say we use Item table for this)
2) How would I create an ActiveModelSerializer around this? Typically, a serializer might look like this...
class Api::V1::ItemSerializer < ActiveModel::Serializer
attributes :id, :cost
has_one :item_type, serializer: Api::V1::ItemTypeSerializer
end
but how would we include the actual_id reference to either A) model Theme or B) model Setting ?
Actually, I think what you are looking for is Single Table Inheritance: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#class-ActiveRecord::Base-label-Single+table+inheritance
This allows you to store multiple different subclasses of the same base class in the same table.
So, in your example, you would have the following models:
class Item < ActiveRecord::Base
end
class Theme < Item
end
class Setting < Item
end
Item becomes your base class for two other models (Theme and Setting), all of which will get stored in the same table (items).
The only thing you will need to add to your items table is a string column called "type". Rails / ActiveRecord handles setting that column to the appropriate thing (Theme or Setting) as well as scoping queries appropriately for you.
As for the ActiveModelSerializer part, you would just make separate serializers for each of the two subclasses.
This is a good use case for has_many_through.
Example

Validate many-to-many circle

I have this object association here:
Entry *--1 Category *--1 Project *--* User 1--* Entry
Explanation: An entry belongs to a category which has many entries, a category belongs to a project which has many categories - many users can have many projects. This user also has many entries and one entry belongs to one user.
When an entry is saved with a category and user association, I want to make sure, that the category belongs to a project a user is assigned to.
I thought about implementing a custom validator that fetches the project of the worklog and checks if it's in the list of the user's projects.
Is there a more Rails-like way to it or am I on the right track?

How to make users be able to choose/create and save their own categories?

How do i make it so users who are filling out their form when adding new prices can select categories they already made or create a new one.
I have an Add_Prices controller,model and views. The Model holds the price name, date and price as of now.
I don't know if the category should be a string or integer.
I also don't know how to make the form so the user can select a scroll down list on the form of past categories they saved or in the scroll down list they select "New" and a text box pops up next to it and they can save it when they fill out everything.
Everything(price,date,etc) including the category will go to the Data Controller/View so they can see everything there.
Please help a newbie!
Thank you!
Well, you would ideally name your controller (Link just so you can see naming conventions) the name of your resource so consider using just Price instead of Add_Prices. And as for adding categories, consider adding another resource for categories and use rails associations to associate the categories to other objects. Using this type of relationship is demonstrated over in this question here.
The category should have a name that is text and it should also have an ID generated by default.
Good luck, If you still need help feel free to let me know.

Resources