Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * wpsc_variation_combinator class.
- * Produces all combinations of variations selected for this product
- * this class is based off the example code from here:
- * http://www.php.net/manual/en/ref.array.php#94910
- * Thanks, phektus, you are awesome, whoever you are.
- */
- class wpsc_variation_combinator {
- var $variation_sets = array();
- var $variation_values = array();
- var $reprocessed_array = array();
- var $combinations= array();
- function wpsc_variation_combinator($variation_sets) {
- if( $variation_sets ) {
- foreach($variation_sets as $variation_set_id => $variation_set) {
- $this->variation_sets[] = absint($variation_set_id);
- $new_variation_set = array();
- if( $variation_set ) {
- foreach($variation_set as $variation => $active) {
- if($active == 1) {
- $new_variation_set[] = array(absint($variation));
- $this->variation_values[] = $variation;
- }
- }
- }
- $this->reprocessed_array[] = $new_variation_set;
- }
- $this->get_combinations(array(), $this->reprocessed_array, 0);
- }
- }
- function get_combinations($batch, $elements, $i) {
- if ($i >= count($elements)) {
- $this->combinations[] = $batch;
- } else {
- foreach ($elements[$i] as $element) {
- $this->get_combinations(array_merge($batch, $element), $elements, $i + 1);
- }
- }
- }
- function return_variation_sets() {
- return $this->variation_sets;
- }
- function return_variation_values() {
- return $this->variation_values;
- }
- function return_combinations() {
- return $this->combinations;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement