Created
July 19, 2013 19:31
-
-
Save nathanaelphilip/6041776 to your computer and use it in GitHub Desktop.
mahcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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