Created
November 14, 2014 22:33
-
-
Save muub/4a140f6d21c9f6aaf2ad to your computer and use it in GitHub Desktop.
Logic for Creating All the Size Color Combinations
This file contains hidden or 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
| <?php | |
| // 1. Find All Possible Size Color Combinations | |
| // 2. Determine which of those skus need to be created. | |
| // 3. Treat that set as the style. | |
| main() { | |
| ... | |
| $allSizeColorCombos = $this->GenerateAllSizeColorCombinationsFrom($newSkus and $existingSkus); | |
| $style = $this->CreateSkusThatDoNotExistInJob($allSizeColorCombos); | |
| // ..after this all the statuses should be set. | |
| } | |
| function GenerateAllSizeColorCombinations($newSkus, $existingSkus) | |
| { | |
| $skus = array_merge($newSkus, $existingSkus); | |
| $allSizes = $this->findAllSizes($skus); | |
| $allColors = $this->findAllColors($skus); | |
| $allColorSizeCombos = []; | |
| foreach ($allColors as $color) { | |
| $allColorSizeCombos[$color] = $sizes; | |
| } | |
| $this->createSkusThatDoNotExistInJob($style, $allColorSizeCombos); | |
| } | |
| function findAllSizes($skus) | |
| { | |
| $sizes = []; | |
| foreach ($skus as $sku) { //find the range of skus size combinations | |
| $sizes[$sku->getSize()] = true; | |
| } | |
| return $sizes; | |
| } | |
| function findAllColors($skus) | |
| { | |
| $colors = []; | |
| foreach ($skus as $sku) { //find the range of skus color combinations | |
| $colors[$sku->getColor()] = true; | |
| } | |
| return $colors; | |
| } | |
| function createSkusThatDoNotExistInStyle(Style $style, array $allColorSizeCombos) | |
| { | |
| $allSkus = []; | |
| // Generate the entire universe of color size combinatinos, the color size big bang | |
| foreach ($allColorSizeCombos as $color => $size) { | |
| $allSkus[$color][$size] = $this->createSku($color, $size); | |
| } | |
| //replace new skus with existing skus | |
| foreach ($allSkus as $color => $size) { | |
| foreach($style->getSkus() as $sku) { | |
| if ($color === $sku->getColor() && $size === $sku->getSize()) { | |
| $allSkus[$color][$size] = $sku; | |
| } | |
| } | |
| } | |
| return $allSkus; | |
| } | |
| //replace all those skus with the set we just went through |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment