Skip to content

Instantly share code, notes, and snippets.

@jsieber
Created April 23, 2014 22:39
Show Gist options
  • Save jsieber/11234973 to your computer and use it in GitHub Desktop.
Save jsieber/11234973 to your computer and use it in GitHub Desktop.
Add and remove Slatwall Pricegroups based on Mura extended Attribute
<cfscript>
// Helper function meant to be used by events to get a mura scope
private any function getMuraScope() {
if(structKeyExists(request, "siteID")) {
arguments.siteID = request.siteID;
} else if(structKeyExists(form, "siteID")) {
arguments.siteID = form.siteID;
} else if(structKeyExists(url, "siteID")) {
arguments.siteID = url.siteID;
} else if(structKeyExists(session, "siteID")) {
arguments.siteID = session.siteID;
}
var $ = application.serviceFactory.getBean('$').init( arguments );
$.setCustomMuraScopeKey("slatwall", arguments.slatwallScope);
return $;
}
public void function onSessionAccountLogin() {
// Load Mura scope
var $ = getMuraScope(argumentCollection=arguments);
// Load memberPriceGroup by ID
var memberPriceGroup = $.slatwall.getService("PriceGroupService").getPriceGroup("8aeecd093b0bf0d2013b3f3eca46013e");
// Add or remove Price Group based on current membership status and if they already exist within the group
if($.currentUser("memberStatus") neq -1 and $.slatwall.getcurrentAccount().hasPriceGroup(memberPriceGroup)) {
$.slatwall.getcurrentAccount().removePriceGroup(memberPriceGroup);
}else if($.currentUser("memberStatus") eq -1 and !$.slatwall.getcurrentAccount().hasPriceGroup(memberPriceGroup)){
$.slatwall.getcurrentAccount().addPriceGroup(memberPriceGroup);
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment