In Drupal 6 how do i automatically create CCK fields on a node when a new node of a referenced node type is created?
I'm using Drupa开发者_运维百科l 6 and Views 2, along with CCK, Panels and Node Relationships. (so far)
I have two basic content types defined:
- User Profile (using Content Profile module)
- Product
Each of these content types has a node reference to two other content types, Tier and Commission:
- User Profile content references "Tier" content
- Product content references "Commission Category" content
There may be 5-10 of each of these, and up to 100 of each of users/products.
When a Commission Category is added, dollar values need to be added for each currently existing Tier node.
When a Tier node is added, dollar values for this Tier need to be added to each currently existing Commission Category node.
The desired effect is that users with a "staff" role can administrate both Tiers of users and Categories of Product.
Users will see a value when they view a product that is displayed as a combination of both their Tier and the Commission Category.
For Example:
Category A => Tier 1 ($100), Tier 2 ($200), Tier 3 ($300)
Category B => Tier 1 ($120), Tier 2 ($250), Tier 3 ($300)
Is there a way to do what I'm suggesting? or do I need to try a different approach altogether to achieve the desired effect?
I assume that you also want to be able to later edit those amounts from either the Tier node page or the Commission Category node page.
To make those values easier to manage, you will probably need to create another content type (called Commission for example) which references a Tier and a Commission Category, and holds a dollar value.
What I would do then is to use hook_form_alter() so that in the Tier form, an input field is added for each Commission Category. That way, whenever you add a new Tier (or edit an existing one), you can update all those values at once. Use hook_nodeapi() to insert/update all of the corresponding Commission nodes.
Then you can do the same thing for the Commission Category form, but in the other direction.
If you expect to have a large number of tiers or categories, this may be a heavy operation, but otherwise it should be fine since I'm assuming you wouldn't be changing these values that frequently.
精彩评论