Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 04-25-2017 08:32:21

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19122
Website

Using Custom Data Fields

Both product offers and inventory items have custom data fields available.  These custom data fields are stored in the ecom_prod.customdata and ecom_inventory.customdata columns, respectively.  Custom data can be used to tag offers and inventory with *anything* you want.  Custom data is saved with items in the shopping cart, and available in checkout to all custom scripts, etc.  Offer level custom data is saved to the cart for items which are services (belonging to the Service/Download offer type).  Inventory item level custom data is saved to the cart for items which are inventory items (belonging to Inventory Item / Custom Package / Package Deal offers).

Building for the future, we would assume that you may want to add one or more pieces of custom data to an item.  Using a comma-separated format for your data entry is a great way to do this.  This example uses a format where keys are separated from their values with a colon, and separate key-value pairs are separated by a comma:

Code:

KeyA:value a, KeyB:value b, KeyC:value c

How do we make this meaningful?  Assuming you're editing a display like the main product offer display ({private}/apps/ecom/ECOM/includes/prodshow.php), we can get the custom data for our offer into an array to work with it as follows:

Code:

$proddisp   = $this->globals('ecom.prod_proddetail');
$customdata = array();

if (!(empty($proddisp['customdata']))) {

     $list_customdata = $this->make_list($proddisp['customdata']);

     foreach ($list_customdata as $lcdnum => $lcditem) {list($lcditemid,$lcditemdata) = preg_split('/\:/s', $lcditem, 2); $customdata[$lcditemid] = $lcditemdata;}

} // End of if statement.

foreach ($proddisp['xpricemap'] as $xpmid => $xpmdata) {

     if (empty($xpmdata['xinvid'])) {continue;}

     $customdata = array();

     if (empty($xpmdata['xinvid']['customdata']))) {coninue;}

     $list_customdata = $this->make_list($xpmdata['xinvid']['customdata']);

     foreach ($list_customdata as $lcdnum => $lcditem) {list($lcditemid,$lcditemdata) = preg_split('/\:/s', $lcditem, 2); $customdata[$lcditemid] = $lcditemdata;}

     break 1;

} // End of foreach statement.

Note that custom data is built here from offer level custom data, then replaced by the custom data for the first inventory item seen in the offer (if it is an inventory type offer).  Now we have an array called $customdata.  In it, we will have:

Code:

[KeyA] => value a
[KeyB] => value b
[KeyC] => value c

Which means you can do something like:

Code:

if ($customdata['KeyA'] == 'value a') {}

Have fun with this!


Nick Hendler

Offline

 

Board footer