Status
Not open for further replies.
To do that you'd need to create a new item type, like the ones found in /dbtech/vbshop/items :)

There's no other template available than those files in that folder at this point in time.
 
What is required to create such a template? All of the files I see in that directory are highly customized to what they do. I can't tell which variables I need to include and which I can safely ignore.

I just want something like a gift that, when purchased, executes a custom SQL function. I want this for a separate add-on that I am creating. When a user purchases said item in VBShop a quick SQL query (or short php script) is called that executes my custom code. This will allow me to use VBShop as my in-game shop. The alternative is to create a custom shop for selling my in-game items but then I will end up with two shops when I only want one.
 
The easiest thing to do would be to copy/paste usertitlechange.php

For the purpose of this example we'll name the new file ingameitem.php

Change:
vBShop_Item_usertitlechange
To:
vBShop_Item_ingameitem (must match the file name sans .php extension)

If you need a custom template:
---
Change:
$this->config['purchasetemplate'] = 'dbtech_vbshop_purchase_usertitlechange';
To:
$this->config['purchasetemplate'] = 'dbtech_vbshop_purchase_ingameitem';
---

If you don't need a custom template:
---
Remove:
$this->config['purchasetemplate'] = 'dbtech_vbshop_purchase_usertitlechange';
---

Change the values of the 'name' and 'description' array elements as needed.

Replace the pre_purchase function with this:
PHP:
	protected function pre_purchase(&$buyer, &$recipient)
	{
		global $vbphrase;
		
		$this->registry->db->query_write("
### YOUR SQL QUERY HERE ###
		");
	}

Note that $buyer is the full user info of the person purchasing the item, and $recipient is everything from the user table (e.g., it does not contain forum/usergroup permissions but it does contain basic values like userid, username, and everything else you could do if you query the user table into an array.)


If all goes well, once that file is on your web server in the same directory as the file you copy/pasted, you should be able to create a new item using In-Game Item as an item type.
 
Last edited:
How would I handle multiple items? If the user can purchase a "sword" or "shield" item how does this know which item they have purchased so that I may run the correct query?

So far this works great for my in-game item but I need to enable multiple in-game items. I could create a file for each one but I would rather edit one file and provide for something that tells me which item was purchased.
 
Last edited:
Then create multiple items based on the same item type, you can access all the item info (like name, etc) via $this->config inside the function I posted in the previous post :)
 
So I can check the status of $this->config['itemname'] to find out what item they purchased?

IS $recipient always the user who gets the item whether it is a gift or not?
 
Indeed it is :)

And it's $this->config['title'] to get the name of the item you added :)
 
Status
Not open for further replies.
Top