Skip to content

Instantly share code, notes, and snippets.

@orlaqp
Created July 31, 2014 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlaqp/ff1af1b523efc2dffff5 to your computer and use it in GitHub Desktop.
Save orlaqp/ff1af1b523efc2dffff5 to your computer and use it in GitHub Desktop.
function editExistingVarient() {
var variantIdentifier = $scope._getVariantIdentifiersBase();
//no product exists with this combination of varient, lets add it to the array.
var productIdCounter = 1;
var productSku = 0;
var barcode = 0;
var barcode2 = 0;
var counter = 1;
var skuCounter = 100;
var barcodeCounter1 = 100;
var barcodeCounter2 = 101;
var variantValues = variantIdentifier;
_.forEach(variantIdentifier, function(variant) {
var productWithVariant = _.find($scope.product.products, function(product) {
return product.variants[0] == variant[0] && product.variants[1] == variant[1];
});
if (!productWithVariant) {
$scope.product.products.push(_createProductVariant(variant));
} else {
//product is found in the combination so lets not remove it
productWithVariant.removeFlag = true;
}
});
//remove any item that was added or found to be in the combination
$scope.product.products = _.remove($scope.product.products, function(product) {return product.removeFlag;});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment