Can someone please help me write a proper shop page? I want to create a custom page that I make myself as that is the only way to get the placement I want for the shopkeepers (I don't know how to do it in the default shop files). So I guess I would like to ask if someone can help me write 'get' and 'getview' pages for items.. and where it deducts the price of the item from their inventory and they can also choose the quantity at some point.
The reason I want this is so that I can have a shopkeeper and then images of items underneath, and when they click the image it takes them to another page where they can maybe select the quantity? They then click buy and it deducts the money set by me in the adminCP and adds it to their inventory..
Kyttias was kind enough to help me with doing this for adoptables so I have included them in spoilers in case anyone wants help with the structure.. sorry for asking but I have already tried what I can think of and it hasn't worked >.< Thank you... I really want to get my shops up and running for my beta testers XD
PHP Code:
<?php
use Resource\Native\Integer;
use Resource\Native\String;
class GetController extends AppController{
private $id;
public function __construct(){
parent::__construct("member");
$mysidia = Registry::get("mysidia");
if($mysidia->usergroup->getpermission("canadopt") != "yes"){
throw new NoPermissionException("permission");
}
}
public function index(){
//don't let people access yoursite.com/get
throw new InvalidActionException("global_action");
}
//yoursite.com/get/id
public function id(){
$mysidia = Registry::get("mysidia");
//get ID_NUMBER
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$parts = Explode('/', $pageURL);
$id = $parts[count($parts) - 1];
if(!$id) throw new InvalidIDException("global_id");
//---------- Edit here
/* In this part, we check if the ID is actually part of the IDs available to adopt!
* If you want adoptable 1 and 7 to be available through get/id/number, you gotta add
* 1 and 7 to the array
*/
$id_array = [1,2];//add your OK numbers here
$count = count($id_array);
$found = false;
for($i = 0; $i < $count; $i++)
{
//if ID is inside the array, then it's OK
if($id == $id_array[$i]){
$found = true;
break;
}
}
//the ID wasnt found inside the array, throw error
if(!$found)
throw new NoPermissionException("This adoptable is not available through this method.");
//----------
//after checking:
$this->access = "member";
$this->handleAccess();
//get adoptable information
$adopt = new Adoptable($id);
$conditions = $adopt->getConditions();
if(!$conditions->checkConditions()) throw new NoPermissionException("condition");
$name = $adopt->getType();
$alts = $adopt->getAltStatus();
$code = $adopt->getCode();
$gender = $adopt->getGender();
//insert into database
$mysidia->db->insert("owned_adoptables", array("aid" => NULL, "type" => $name, "name" => $name, "owner" => $mysidia->user->username, "currentlevel" => 0, "totalclicks" => 0, "code" => $code, "imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $gender, "offsprings" => 0, "lastbred" => 0));
//get its info
$aid = $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
$this->setField("aid", new Integer($aid));
$this->setField("name", new String($name));
$this->setField("eggImage", new String($adopt->getEggImage()));
}
}
?>
PHP Code:
<?php
class GetView extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("Adopt a pet");
}
public function id(){
$document = $this->document;
$document->setTitle("Adopt a pet");
$aid = $this->getField("aid")->getValue();
$name = $this->getField("name")->getValue();
$eggImage = $this->getField("eggImage")->getValue();
//display information
$image = new Image($eggImage);
$image->setLineBreak(TRUE);
$document->setTitle("Catching {$id} ");
$document->add($image);
$document->addLangvar("Congratulations! You just adopted {$name}. <br>You can now manage {$name} on the ");
$document->add(new Link("myadopts", "Myadopts Page."));
$document->add(new Comment(""));
$document->add(new Link("myadopts/manage/{$aid}", "Click Here to Manage {$name}"));
$document->add(new Comment(""));
$document->add(new Link("myadopts/bbcode/{$aid}", "Click Here to get BBCodes/HTML Codes for {$name}"));
$document->add(new Comment(""));
$document->addLangvar("Be sure and");
$document->add(new Link("levelup/{$aid}", "feed "));
$document->addLangvar("{$name} with clicks so that they grow!");
}
}
?>
They are both seperate files so I guess items would need to be called getitem and getitemview? Or something like that XD Thanks if someone helps me... this has stumped me for days >.<
(It would also be nice if someone could help me with the 'adopt' shops. Or would it still be the same file? And you just put in their adoptable id? It's just I may not want all of my pets up for free, like they are from the adoptable page at the moment)