Hello! This is my first ever tutorial on here lol. Anyway, I wanted the ability to make a promocode to give a user some money (and even premium currency) so I managed to do that.
It also has adminCP functions so you can just add promos like you normally would!
First of all, open
admincp/view/promoview.php.
Find this, in public function add():
PHP Code:
$typesList = new RadioList("type");
$typesList->add(new RadioButton(" Adoptables", "type", "Adopt"));
$typesList->add(new RadioButton(" Items", "type", "Item"));
$typesList->add(new RadioButton(" Pages", "type", "Page"));
Change those 4 lines to:
PHP Code:
$typesList = new RadioList("type");
$typesList->add(new RadioButton(" Adoptables", "type", "Adopt"));
$typesList->add(new RadioButton(" Items", "type", "Item"));
$typesList->add(new RadioButton("Currency", "type", "Currency"));
$typesList->add(new RadioButton(" Pages", "type", "Page"));
See where I just added a currency line?
Now, scroll down further until you find the public function edit() section. Find the same 3 lines and add the new currency line. Save the file.
Find and open
classes/class_promocode.
Find public function execute(){ and replace it with this:
PHP Code:
public function execute(){
// This method will execute the promocode and give users their desired adoptables or items, need to be used after validation is completed
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
if($this->valid != TRUE) throw new NoPermissionException($mysidia->lang->validate);
switch($this->type){
case "Adopt":
// The user will receive an adoptable from the promocode now.
$code = codegen(10, 0);
$genders = array('f', 'm');
$rand = rand(0,1);
$mysidia->db->insert("owned_adoptables", array("aid" => NULL, "type" => $this->reward, "name" => $this->reward, "owner" => $this->user, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "alternate" => 0, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $genders[$rand], "lastbred" => 0, "originalowner" => $mysidia->user->username, "birthday" => date("F jS, Y")));
$document->addLangvar("Congrats, you have acquired the adoptable {$this->reward} by entering promocode.");
$this->usepromo();
break;
case "Item":
// The user will receive an item from the promocode now.
$item = new StockItem($this->reward, 1);
$item->assign($this->user);
$newquantity = $item->getoldquantity() + 1;
if($item->cap != 0 and $newquantity > $item->cap){
throw new NoPermissionException("It appears that you cannot add one more of item {$this->reward} to your inventory, its quantity has already exceeded the upper limit.");
}
else{
$item->append();
$document->addLangvar("Congrats, you have acquired the item {$this->reward} by entering promocode.");
$this->usepromo();
}
break;
case "Page":
$this->usepromo();
break;
case "Currency":
// The user will receive currency from the promocode now.
$cost = $mysidia->settings->cost; //The name of your site's currency
$cash = $mysidia->db->select("users", array("money"), "username ='{$mysidia->user->username}'")->fetchColumn(); //How much cash the user has
$new_cash = $cash + $this->reward; //Simple sum to calculate user's current cash + reward
$mysidia->db->update("users", array("money" => $new_cash), "username ='{$mysidia->user->username}'"); //Update the database with the new cash amount
$document->addLangvar("Congrats, you have acquired {$this->reward} {$cost} by entering promocode.");
$this->usepromo();
break;
default:
throw new InvalidIDException($mysidia->lang->type);
}
// All done, we're good to go!
}
You can see the part that I added at the bottom there. That section makes it so that currency can be given!
Premium currency tutorial on next comment!