I have following code in Silverstripe
<?php
$product= Product::get()->filter("ProductCode", $UniqueCode)->First();
if($product){
$product->Stock = "250";
$product->Name = "Abcd 123";
$product->write();
echo "New Stock = ".$product->Stock; //this prints the OLD value not the NEW one. Nor database is updated.
}
?>
Update:
If I do $product->Name = "Abcd 123";, the Name' field is getting updated, but not theStock`
This didn't work. The Stock field of Product table is not updated. Can anybody tell me where I went wrong?
debug::dump($product);or evendebug::show($UniqueCode);into your code to analyze. - munomonovar_dump($product)orecho $product->IDafter the query, or use a proper tool like xdebug to debug your code. - wmk$productreturns the record - WatsMyName$productreturns the record - WatsMyNameStockis integer field. I have fixed this issue, thanks - WatsMyName