2017-01-04, 19:40:36
(2017-01-04, 18:36:55)smsHH Wrote: One more question... Is it possible to change an item's category to another category or do I have to create a new item in the category I wish to move it to?
There is no GUI for that, but you can do it by using API, or create your own GUI for it. For this, however, you have to take care of the item fields, they have to be identical or you'll lose the data. It's always best practice to do it manually. So, for your example above, you can create a simple script like follows.
Let's say, that your want to change an item's category id-1 to category id-2 and your item is "1"
PHP Code:
// get the item you want to change the category
$item = $manager->getItemMapper()->findItem(1, array(1));
if($item) {
// create new item in category "2"
$newItem = new Item(2);
// copies the item name of the old item
$newItem->name = $item->name;
// copies the item field "color" value
$newItem->setFieldValue('color', $item->fields->color->value);
// ...
// Let's save new item
if($newItem->save()) {
echo 'The item is created';
// remove the old item
$manager->deleteItem($item->id, $item->categoryid);
}
else {
echo 'The item could not be saved';
}
}
;-)