Skip to content

Instantly share code, notes, and snippets.

@jparbros
Created September 21, 2018 17:30
Show Gist options
  • Save jparbros/56597eb2f1e18781e8f9bef2329ffa92 to your computer and use it in GitHub Desktop.
Save jparbros/56597eb2f1e18781e8f9bef2329ffa92 to your computer and use it in GitHub Desktop.
importPackage( dw.util );
importPackage( dw.system );
importPackage( dw.catalog );
var ProductUtils = require('app_storefront_core/cartridge/scripts/product/ProductUtils.js');
function execute(Product, CurrentVariationModel) {
var pvm : ProductVariationModel = empty(CurrentVariationModel) ? Product.variationModel : CurrentVariationModel;
if (Product.isMaster()) {
//get the first selected variant
Product = (pvm.getSelectedVariants().length > 0) ? pvm.getSelectedVariants()[0] : pvm.getVariants()[0];
}
var variationGroups : Collection = ProductUtils.getSelectedVariationGroups(Product);
var VariationGroup = (variationGroups.size() > 0) ? variationGroups[0] : null;
return VariationGroup;
}
module.export = {
execute: execute
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment