Skip to content

Instantly share code, notes, and snippets.

@huoxito
Last active August 29, 2015 14:10
Show Gist options
  • Save huoxito/0cd833e62f2f625ea235 to your computer and use it in GitHub Desktop.
Save huoxito/0cd833e62f2f625ea235 to your computer and use it in GitHub Desktop.
//
var items = payload.shipment.items;
var new_items = [];
for (i = 0; i < items.length; i++) {
var item = items[i];
var quantity = item.quantity;
if (item.bundled_items && item.bundled_items.length > 0) {
for (k = 0; k < item.bundled_items.length; k++) {
var bundle_item = item.bundled_items[k];
var bundle_quantity = bundle_item.quantity;
for (x = 0; x < quantity; x++) {
for (z = 0; z < bundle_quantity; z++) {
bundle_item.quantity = 1;
new_items.push(bundle_item);
}
}
}
} else if (quantity > 1) {
for (x = 0; x < quantity; x++) {
item.quantity = 1;
new_items.push(item);
}
} else {
new_items.push(items[i]);
}
}
payload.shipment.items = new_items;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment