Skip to content

Instantly share code, notes, and snippets.

@nathanaelphilip
Created July 19, 2013 19:31
Show Gist options
  • Save nathanaelphilip/6041776 to your computer and use it in GitHub Desktop.
Save nathanaelphilip/6041776 to your computer and use it in GitHub Desktop.
mahcodes
$products = array();
// add new products to the array;
foreach ($new_products as $key => $product) {
// does this prodcut have a variation?
if ($product['variation']) {
// it this variation is already in the cart, add the qty to the previous and move on.
if ($products[$key][$product['variation']]) {
$products[$key][$product['variation']]['qty'] = $products[$key][$product['variation']]['qty'] + $product['qty'];
continue;
}
// this a new variation of the product
$products[$key][$product['variation']] = $product;
continue;
}
// this is just a normal product,
// we can overwrite it because there’s only one way to do the qty
$products[$key] = $product;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment