Please note: The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please post in our forum, but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.
Depending on which version of MODx you're working with - please review the different sections below, with approaches for MODx Revo and Evolution.
Automatically validates all links and forms on pages generated by MODX Revolution, according to FoxyCart's HMAC Price Validation functionality.
This plugin is easy to install, and should “just work”, so it is recommended for all MODX Revo installs.
Thanks to pixelchutes on our forums for this solution.
assets/plugins
directory called foxycart_validation
(creating the plugins/
folder if it doesn't already exist).foxycart.cart_validation.php
file here and put it into the newly created assets/plugins/foxycart_validation/
directory.$secret
and $cart_url
values. (The $secret
value is your store's API / datafeed key.)OnWebPagePrerender
checkbox.
After creating the plugin - any add to cart link or forms on your website should be automatically signed for you.
code
attribute, and it should not have leading or trailing whitespace.<?php /** * FoxyCart Validation Plugin for MODx 2.x (Revolution) */ $e = &$modx->event; switch ($e->name) { case 'OnWebPagePrerender': include $modx->config["base_path"].'assets/plugins/foxycart_validation/foxycart.cart_validation.php'; $modx->resource->_output = FoxyCart_Helper::fc_hash_html($modx->resource->_output); break; } return;
Automatically validates all links and forms on pages generated by MODX Evolution, according to FoxyCart's HMAC Price Validation functionality.
This plugin is easy to install, and should “just work”, so it is recommended for all MODX Evolution installs.
assets/plugins/
directory called foxycart_validation
.assets/plugins/foxycart_validation/
directory.$secret
and $cart_url
values. (The $secret
value is your store's API / datafeed key.)OnWebPagePrerender
checkbox./** * FoxyCart Validation Plugin for MODx 1.x (Evolution) * * @author FoxyCart.com * @copyright FoxyCart.com LLC, 2010 * @version 0.7.0.20100730 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @example http://wiki.foxycart.com/docs/cart/validation * * Requirements: * - Form "code" values should not have leading or trailing whitespace. * - Cannot use double-pipes in an input's name * - Empty textareas are assumed to be "open" */ $e = &$modx->Event; switch ($e->name) { case "OnWebPagePrerender": $validate = $modx->config["base_path"].'assets/plugins/foxycart_validation/foxycart.cart_validation.php'; if (file_exists($validate)) { include_once($validate); $doc = $modx->documentOutput; $modx->documentOutput = FoxyCart_Helper::fc_hash_html($doc); } break; default: // stop here return; break; }
Creates a snippet to manually validates links and forms in your pages, according to FoxyCart's HMAC Price Validation functionality.
Snippet Name: FoxyCartGetHMAC
Snippet Code (paste into text box):
<?php if(!function_exists(get_verification)) { function get_verification($var_name, $var_value, $var_code) { $api_key = 'KEY HERE'; $encodingval = htmlspecialchars($var_code) . htmlspecialchars($var_name) . htmlspecialchars($var_value); return '||'.hash_hmac('sha256', $encodingval, $api_key).($var_value === "--OPEN--" ? "||open" : ""); //Use the following to test whether api_key has a value or not (only use in safe, sandbox scenarios!) //return '$api_key||'.hash_hmac('sha256', $encodingval, $api_key).($var_value === "--OPEN--" ? "||open" : ""); } } ( isset($varName) ) ? $varName : $varName = ''; ( isset($varValue) ) ? $varValue : $varValue = ''; ( isset($varCode) ) ? $varCode : $varCode = ''; if (empty($varName) || empty($varValue) || empty($varCode)) { return; } return get_verification($varName, $varValue, $varCode); ?>
[[FoxyCartGetHMAC &varName=`input-name-attrib-tag-here` &varValue=`input-value-attrib-tag-here` &varCode=`sku-code-here` ]]
Example:
<input type="hidden" name="code[[FoxyCartGetHMAC &varName=`code` &varValue=`[*sku*]` &varCode=`[*sku*]`]]" value="[*sku*]"/>
Notice the parts where the variable name code is the same: name=“code and &varName=`code`
and where the value is the same: value=”[*sku*]“ and &varValue=`[*sku*]`
and where &varCode=`[*sku*]`
should be something unique to your product, like the SKU code
Assuming you're using template variables price as [*price*]
and sku as [*sku*]
and using the pagetitle and SKU for the product name as [*pagetitle*] - [*sku*]
, and that there's only a single SKU for a single product represented by a resource in the MODX Tree:
<form name="buypanel" class="buypanel" id="buypanel" action="https://SHOPNAME.foxycart.com/cart" method="post" accept-charset="utf-8"> <input type="hidden" name="code[[FoxyCartGetHMAC &varName=`code` &varValue=`[*sku*]` &varCode=`[*sku*]`]]" value="[*sku*]"/> <input type="hidden" name="name" value="[*pagetitle*] - [*sku*][[FoxyCartGetHMAC &varName=`name` &varValue=`[*pagetitle*] - [*sku*]` &varCode=`[*sku*]`]]"/> <input type="hidden" name="price[[FoxyCartGetHMAC &varName=`price` &varValue=`[*price*]` &varCode=`[*sku*]`]]" value="[*price*]"/> <input type="input" name="quantity[[FoxyCartGetHMAC &varName=`quantity` &varValue=`--OPEN--` &varCode=`[*sku*]`]]" value="1"/> <input type="submit" name="submit[[FoxyCartGetHMAC &varName=`submit` &varValue=`--OPEN--` &varCode=`[*sku*]`]]" value="BUY NOW"/> </form>