5325 Posts in 1596 Topics by 1167 members
|Go to End|
27 February 2009 at 11:43am
Good evening SS community.
I'm getting started with SS and hope to find some help here. Yep, I'm totally stuck today.
I'm making an admin with some not too complex database relations.
Say I have a pricelist with one-to-many products.
Each product has got a many-to-many relationship to the attributes that define it.
The pricelist Extends siteTree and is where I want to add my products. The HasManyComplexTableField works great, even if I have the feeling I'm not totally in control yet How can I get the product-popup to set data for the product_attribute connection-table?
MY next problem will be that I wish to have the pricelist split in categories, maybe even in different tabs. And to do that without ID-conflicts. If anyone have some good advice for me there I'm very grateful.
3 March 2009 at 2:06am Last edited: 3 March 2009 10:58pm
I will answer myself to maybe help someone else.
What I did eventually was to extend the HasManyComplexField class (to ProductComplexTableField) and override saveComplexTableField(). From there I save all the attributes I get from the form manually using $product->ProductAttributes()->add($attribute).
Although, for some reason it seems that $product->write() clears the attribute relations before they get saved to DB. That is why I first did $product->write() and then I added the attributes.
For my second problem. I solved it by registring the data relation once per category. If I used the same on all tabs, one would overwrite the other.
static $db = array(
'Category1Products' => 'Product',
'Category2Products' => 'Product'
This is not a very good solution because it will crash when I get a new Category. If anyone has a more dynamic way to solve this pls let me know.
|Go to Top|