Hello Blesta Community,
Here's a quick snippet of being able to link directly to configurable options within the AJAX Boxes order forms template:
Example Link:
example.com/order/main/packages/EXAMPLE/?..etc-data...&group_id=[Your Group ID]&configoptions[1]=[Option Value 1]&configoptions[2]=[Option Value 2]
Edit File: /plugins/order/views/templates/ajax/main_packages.pdt
Add the following code after the "// Process change currency request" portion of the javascript code:
// GET URL Variables as associative array
function getURLVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
//Change Config Options in URL: &configoptions[1]=VALUE&configoptions[2]=VALUE...etc
$(document).ready(function() {
setTimeout(function(){
configCount = 0;
while (configCount < 10) {
var ConfigVar = getURLVars()["configoptions[" + configCount + "]"];
if(ConfigVar) {
$("#configoption_" + configCount).val(ConfigVar).change();
}
configCount++;
}
}, 5000);
//Secondary call after 10s
//This helps resolve issues with coupon codes. Prices would show up correct, but drop downs would show incorrect
setTimeout(function(){
configCount = 0;
while (configCount < 10) {
var ConfigVar = getURLVars()["configoptions[" + configCount + "]"];
if(ConfigVar) {
$("#configoption_" + configCount).val(ConfigVar).change();
}
configCount++;
}
}, 10000);
});
Edit the "configCount < 10" based on how many variables your site requires.
Please note there is a 5 second delay where it updates the configurable options.
I'm aware there is probably a better method to do this and I'd love to see the community improve upon this idea by sharing below
(Note: It does seem AJAX Boxes order form does have an issue where you login/create account it blanks out the config options)