Hi all,
Here's the deal. I'm trying to couple stores with products.
I have 3 tables 'products' , 'stores' and 'stores_products'. I have a form that updates the data for a store and i also want to store which products are available in a certain store. I'm planning to put that in the table 'store_products' (store_id and product_id);
I made the Xpdo classes with Bob Ray's CreateXpdoClasses.and that all seems to work fine
Now i can create and update records in 'Stores' with a form. (all code here is simplified for clarity)
$store = $modx->newObject('Stores');
$store->set('store_name', $_POST['store_name']);
$store->save();
in that form i also have some checkboxes for products so i can select which products are available in that store.
<input type="text" name="store_name" id="store_name" value=""/>
<input name="Agenda" id="Agenda" value="4" type="checkbox"/>
Now how can i do an update or insert in the table 'store_products' that links the products to the store?
i could make a Xpdo object for that:
$entrie = $modx->newObject('Storesproducts');
$entrie->set('product_id', $_POST['product_id']);
$entrie->set('store_id', $_POST['store_id']);
$entrie->save();
But then i wouldn't now how to prevent duplicate entries in the table 'stores_products'? what is the best way of doing something like this?
I really hope i made myself clear. i find it difficult to explain.
Rdg