Heroes For Hire logo Cartcake
show menu
Plugins
v1
v1.1
v1.2
v1.3
v1.4
v1.5

Cartcake now has support for plugins. To install them, put them in the functions/ folder.

All plugins are already included in the download of Cartcake on Gitlab



Compatible with v1.2
Aboutpl_Filename
Limit Downloads
Make it so that people can only download products X amount of times.
Author: desbest // Twitter: @tynamite
plugin_limitdownloads


How can I make plugins myself, or have more hooks?
There isn't enough hooks inside CartCake right now, so its functionality can't be modified much.
Because of this, you unfortunately cannot make your own plugins yet.
However if you contact us asking what plugin you want, we'll make it for you.

Guide for desbest about writing plugins
Step 1: Tabula Rasa
Use this code below to create a plugin, tabula rasa.


It should be a php file called plugin_X.php, where X is a unique string/word/letters that is not taken.
You'll have to make sure that your Cartcake plugin, doesn't conflict with the filename of an already existing plugin.
You can check which plugin names are taken, by scrolling up and looking for pl_Filename.


Step 2: About Your Plugin
In the about section, fill in the fields with the relevant plugin information.
PropertyWhat it does
pl_VersionYour plugin version.
pl_CompatibilityThe minimum version of Cartcake, that the plugin is compatible with.
pl_FilenameFile name of the plugin, minus the .php
pl_DateDate the plugin was made. Make sure you fill this in dd/mm/yyyy format.
pl_TwitterYour Twitter username.
pl_HookAll the hooks that your plugin uses, seperated by a forward slash (/).
(We will get to this later.)


Step 3: Plugin Settings
Plugins allow there to be configurable settings, for they should be run.
The admin of the shopping cart, will be able to change these settings from the admin panel.
These settings are stored in a key/value manner. Below is an example.
plugins section

To give your own plugin settings, simply make a numerically indexed array called $ph_Settings, and place it in the settings section.
The value of the array, will be considered as a key, where the admin would enter the value.

information Only text input settings are supported.

information Plugin settings are not validated.


Step 4: Hooks
Cartcake plugins use hooks to be able to interject themselves into the core Cartcake code.
There are various hooks inside the Cartcake core code, and once reached, all the plugins that use that hook are executed.
This means that you can have your code running as if it was in the core, whilst not being in the core.
You will find this much easier to deal with, than other so called plugin systems, ahem, phpBB.
Below are the hooks that are in Cartcake.
HookWhat it does
beforeDownload
afterDownload
Executed before/after a download happens of a virtual file.
Variables from download.php
Variable: $orderid
Content: The id of the order, also known as the order number.
Format: Integer


Step 5: Plugin Storage
   The predicament
So you've got your hooks to modify the files, but how are you going to modify the database?
You don't have the rights to create a new database table, or mess with the table structure.
How can you store data efficently for your plugin, that relates to existing rows in the database?
The answer is plugin storage.

   How plugin storage works
Every entry of information you store in plugin storage, is called a plugin storage entry.

There is a database table called pluginsettings, which stores the plugin settings. Below are its columns.
ColumnWhat do I use it for?
id (You know, really you do.)
pluginid Every plugin storage entry is assigned to the plugin that created it, and pluginid lets Cartcake know which plugin the plugin storage entry applies for.

You do not know what id your plugin your have in advance, and will never know.
You'll find out how to fetch the pluginid later on.
  
xtable
xid
Optional

xtable refers to the table with the entry, that your plugin storage entry is referring to.

For example, for the "Limit Downloads" plugin, this is set to ordered, as each item a person orders is listed there.
The same applies to xid, except that it refers to the id of the row, within that table (specified in xtable).
  
attribute
value
attribute and value allow you to store data about your plugin, in a key/value manner.

There are 2 code samples regarding plugin storage in the next section, which will greatly assist you about this.

Activity
   First things first
Now it's the time for you to write the part of the plugin that does stuff, the activity.
First things first, do a find and replace for /* blank plugin and *///// and delete them.
What I would do instead of that, is to delete those 4 lines, as it makes the file look nicer.

   Using hooks
You will need (or should have) this code in the activity section of the plugin, for each hook that you have.
Inbetween the braces, is where you place the code you want your plugin to execute once the hook is called.
Replace XX with the name of the hook that you are using.

   Getting the pluginid
Here's how to get the pluginid.

   Using plugin storage
Here is a code sample to help you fetch information from plugin storage.

   Debugging your pluginid
As plugins cannot print text on the webpage you visit with a web browser, you'll have to view their variables in another way.
You can use functions/test.txt for this.
But first, make sure that functions/test.txt is writeable. Once it is, don't use it for sensitive information.
Be sure to wipe it clean afterwards.

And that's it! :)
footer Heroes For Hire - design agency
Heroes For Hire logo
For Heroes For Hire, made by desbest