I’m using a static page to perform some actions and am wondering how I can update certain data from a model.
For this example I want to process a virtual payment. The logged in user has a certain amount of credits (‘credits’ column in tbl_profiles from yii-user extension), the code checks the price of the product and subtracts it from the user’s credits:
$productid = $_GET['product'];
$user = Yii::app()->getModule('user')->user()->profile;
$userid = Yii::app()->user->id;
$credits = Yii::app()->getModule('user')->user()->profile->credits;
$product = Product::model()->findByPk($productid);
$price = Product::model()->findByPk($productid)->price_total;
if($credits >= $product){
$newcredits = ($credits - $price);
//Update 'credits' for logged in user
}else{
//Payment Failed
echo "Not enough credits";
}
How do I update the credits for the logged in user in this example?