Created
November 21, 2012 15:14
-
-
Save underscorephil/4125357 to your computer and use it in GitHub Desktop.
Get required price options for package
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 | |
require_once('softlayer-api-php-client/SoftLayer/SoapClient.class.php'); | |
/** | |
* Set your SoftLayer API username and key. | |
*/ | |
$apiUsername = ''; | |
$apiKey = ''; | |
$packageId = 46; | |
$client = Softlayer_SoapClient::getClient('SoftLayer_Product_Package', $packageId, $apiUsername, $apiKey); | |
try { | |
$mask = new SoftLayer_ObjectMask(); | |
$mask->configuration->itemCategory; | |
$client->setObjectMask($mask); | |
$configs = $client->getConfiguration(); | |
$requiredCategories = array(); | |
foreach ($configs as $config) { | |
if ($config->isRequired == 1) { | |
$requiredCategories[$config->itemCategory->id]['name'] = $config->itemCategory->name; | |
} | |
} | |
$categories = array(); | |
$mask = new SoftLayer_ObjectMask(); | |
$mask->itemPrices->categories; | |
$client->setObjectMask($mask); | |
$prices = $client->getItemPrices(); | |
foreach ($requiredCategories as $category => $categoryName) { | |
$i = 0; | |
foreach ($prices as $price) { | |
foreach ($price->categories as $priceCategory) { | |
if ($priceCategory->id == $category) { | |
$requiredCategories[$category]['itemPrices'][$i]['id'] = $price->id; | |
$requiredCategories[$category]['itemPrices'][$i]['description'] = $price->item->description; | |
asort($requiredCategories[$category]['itemPrices'][$i]); | |
asort($requiredCategories); | |
$i++; | |
} | |
} | |
} | |
} | |
print_r($requiredCategories); | |
} catch ( Exception $e) { | |
die( $e->getMessage()); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment