title: Magento eliminating child products to get applicable price
body: <p>I have a script that dynamically retrieves price of configurable products that I have written, and now I am going back and making sure that it takes into account any configurable attributes that there may be. The following is called via ajax and I have debugged it down to the most central part of the loop (therefore all magento methods are working). It should be removing children that do not match the attributes. The end goal is to have one child left, and echo the price. Each child DOES contain a unique price (this I know). Can you see why this is not working right now?</p>
  
  <pre><code>&lt;?php
  require_once('/var/www/Staging/public_html/app/Mage.php');
  umask(0);
  Mage::app(); 
  
  $product_id = $_POST['productID'];
  $optionSelectionArray = $_POST['optionSelectionArray']; //the ids of configurable options selected
  
  
  //var_dump($optionSelectionArray);
  
  $product =  Mage::getModel('catalog/product')-&gt;load($product_id); // no need to use the _ here, it's not protected/private; additonally Mage::registry won't work because you're technically not on a product detail page
  $attributes = $product-&gt;getTypeInstance(true)-&gt;getConfigurableAttributes($product);
  $childProducts = Mage::getModel('catalog/product_type_configurable')-&gt;getUsedProducts(null,$product); 
  
  //Gather all attribute ids for given product    
  $availAttrs=[];
  foreach($attributes as $attribute){ 
          $availAttrs[] = $attribute-&gt;getAttributeId();
  }
  
  foreach($availAttrs as $attr){//cycle available attributes
          foreach ($optionSelectionArray as $key =&gt; $value) {//cycle option for key
              if ($attr == $key){//if available attribute and key of optionSelectionArray match
                  for($i=0; $i&lt;sizeof($childProducts); $i++){//for each child in children
                      //get label of attribute code
                      foreach($attributes as $attribute){ 
                          if ($attr == $attribute-&gt;getAttributeId()){
                              $attrName = strtolower($attribute-&gt;getLabel());//get code name from attribute id
                          }//end if attribute matches attribute id
                      }//end attributes cycle
  
                      //CAITLIN LEFT OFF echoing the next line here to see if it is doing what it should
  
                      if($childProducts[$i]-&gt;getData($attrName) != $value){
                          array_splice($childProducts, $i, 1);
                      }//end if attribute values match
                      else{
                          echo("This is a match! : ");
                          echo('The vendor is ' . $childProducts[$i]-&gt;getData('vendor'). ";");
                          echo (" The price is " . $childProducts[$i]-&gt;getPrice());   
                      }
                  }//end childproducts loop
              }//end if
          }//end foreach optionSelectionArray
      }//end foreach availattrs
  
  //Echo final price $childProducts[0]
  ?&gt;
  </code></pre>