in cron (or observer) I'm getting wishlist items and I'm updating them. I have strange behaviour, when I set field value and call save() item record disappears from database.
This is my code:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$collection = $objectManager->get('Magento\Wishlist\Model\ResourceModel\Item\Collection')->addFieldToFilter('product_change', ['neq' => 'NULL']);
$collection->getSelect()->join(
['wishlist' => $collection->getTable('wishlist')],
"wishlist.wishlist_id = main_table.wishlist_id AND email IS NOT NULL",
[]);
foreach ($collection as $item)
{
$item->setDescription("test");
$item->save();
}
but in foreach, when I change code to this:
$i = $objectManager->create('Magento\Wishlist\Model\Item')->load($item->getId());
$i->setProductChange("test");
$i->save();
item is correctly saved.
Why this second code works and the first not?