I have added status field in sale_flat_quote_item table and trying to save updated status by changing in my custom module's Controller.php(EntitycodesaarnaController.php) file but it not saving updated status.
You can load the sales_flat_quote_item objetc by it's id
$quote_item = Mage::getModel('sales/quote_item')->load($quoteitem_id);
$quote_item->setStatus('status');
$quote_item->save();
Hope this helps!
Related
I am using Laravel 5.8. I have this function in my api controller
$bill=new Bill();
$bill->msisdn =$msisdn;
$bill->trans_id =$transReference;
$bill->ext_id =$ref_id;
$bill->amount=$game_check->amount;
$bill->answer=$useroption;
$bill->game_code=$useresponse;
$bill->is_complete_transactions =1;
$bill->billing_channel="Unity-7799";
$bill->save();
I have another table user_response, the model class is User_Response. It has these fields:
id, msisdn, answer, answer_code
I want to get the last record from $bill=new Bill() where $bill->msisdn is equal to msisdn in User_Response. Then update answer in User_Response with $bill->answer.
Please how do I achieve this?
So save() method always return the recently save data in database.
if you do $bill->save()
so the last inserted record can be achive by the same object you trigger save() from.
For eg i need last inserted id from the database after insertion.
so
$bill = new Bill();
$bill->myFileds = $request->myfields;
$bill->save();
$lastInsertedId = $bill->id;
as you can see from above code. the last inserted record is $bill. you can use it for User_Repsonse
User_Response::where('msisdn',$bill->msisdn)->update(['answer'=>$bill->answer]);
Here you go
Is it possible to use the table settings? I was able to add a table field, but after pressing the Add Value and Trash nothing happens. Save button saves NULL in column value in database.
field in settings table:
{ "name":"value", "label":"Value", "type":"table", "columns":{"name":"Name", "desc":"Desc", "price":"Price"}, "max":"5", "min":"0" }
and with entity_singular:
{ "name":"value", "label":"Value", "type":"table", "entity_singular":"price", "columns":{"name":"Name", "desc":"Desc", "price":"Price"}, "max":"5", "min":"0" }
Your code works for me perfectly in the latest Backpack. You could try:
1) checking if there are any javascript errors on page (that stop the table from working properly);
2) a composer update to get the latest version;
I'm trying to update a record just after I get it from database.
$item = Model::find($id);
$item->field = 'foo';
$item->save();
it do finds the requested record, but the query generated to update the record is not correct:
update `Models` set `field` = ? where `id` is null
I don't know why this is happening!
what is wrong ?
Update:
I just renamed the primary-Key from ID to id in the database table. and then it worked! I didn't know it's case-sensitive
update `bannerads_orders` set `ViewedCount` = ? where `id` = ?
Well, I found the problem. as Laravel documents says:
Note: Eloquent will also assume that each table has a primary key
column named id. You may define a primaryKey property to override this
convention
but in my table it was ID not id. so after I changed it to id, everything works as expected.
Laravel uses prepared statements. There is nothing wrong with this. Additionally you don't actually specify an error.
You should probably use in this case:
$item = Model::findOrfail($id);
$item->field = 'foo';
$item->save();
It seems that $id might be null or user cannot be found and than saving it doesn't make any sense.
If user is not found exception will be thrown and this save won't be executed
How to add a custom reason message for a reward action ?
I have created :
$customerId = 1303177;
$points = 10;
$customer = Mage::getModel('customer/customer')->load($customerId);
$reward = Mage::getModel('enterprise_reward/reward')
->setCustomer($customer)
->setWebsiteId(2)
->loadByCustomer();
$reward->setPointsDelta($points)
->setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_ADMIN)
->setComment('Added programmatically')
->updateRewardPoints();
i like to add something like
$reward->setReason('bonus point');
that would be visible in the reason column of the customer reward history ( back office )
If reason column already exists in the Rewards database table, then all you need is to use
$reward->setReason('bonus point');
$reward->save();
to save the values.
But if reason column doesn't exist then first create a new column reason in the database and then use the above code to save the values in that field.
I am trying to update a custom field of customer_entity in magento I am using the following code:
$customer = Mage::getModel('customer/customer')->load($customerId);
print_r($customer->getData());
try {
$customer->setData('field', $flag);
$insertId = $customer->save()->getId();
echo "Data successfully inserted. Insert ID: ".$insertId;
print_r($customer->getData());
} catch (Exception $e){
echo $e->getMessage();
}
Now I does not get why it is not saving in a database, when i write the log customer data has the updated value, but when i try to see in the database it is not reflecting.
Any Idea?
Edited:
$write = Mage::getSingleton("core/resource")->getConnection("core_write");
$sql = "update `customer_entity` set `field` = ".$flag." where`entity_id` =".$customerId;
$write->query($sql);
This code is working with charm but the above code nention at the top does work.
Does any body have any idea?
Try clearing your cache once and reindexing from magento admin! Hope it works
first check the following
1. check you made the database table defined in the config.xml in the resource model.
2.get the value for $flag and check whether the field is present or not.
Step1:- Check your resource table name in config.xml file,and Clear your cache folder inside /var folder and than check.
Step2:- If step 1 is not working than reindex your project and than check.
Step3:- If step 1 and 2 is not working, than check your table Engine type if it's InnoDB than change it to MyISAM and than check.
For more Info click here