/**
  * Validate submitted product data to ensure that products can be properly loaded to appear on the front end
  *
  * @param array $data
  * @throws Exception\BundleBuildException     Throws exception if data for a required field is missing
  * @throws Exception\BundleBuildException     Throws exception if either an option name or an option value is set
  *                                            without the other being set
  * @throws Exception\BundleBuildException     Throws exception if the product loaded has no units matching the
  *                                            options submitted
  */
 private function _validateProductData(array $data)
 {
     foreach ($this->_requiredProductFields as $required) {
         if (!array_key_exists($required, $data)) {
             throw new Exception\BundleBuildException('Product data is missing `' . $required . '` field');
         }
     }
     if (!empty($data[Form\BundleProductForm::OPTION_NAME]) xor !empty($data[Form\BundleProductForm::OPTION_VALUE])) {
         throw new Exception\BundleBuildException('Product (' . $data[Form\BundleProductForm::PRODUCT] . ') data must contain either both option name and value, or neither');
     }
     if ($data[Form\BundleProductForm::OPTION_NAME] && $data[Form\BundleProductForm::OPTION_VALUE]) {
         $product = $this->_productLoader->getByID($data[Form\BundleProductForm::PRODUCT]);
         $optionName = $data[Form\BundleProductForm::OPTION_NAME];
         $optionValue = $data[Form\BundleProductForm::OPTION_VALUE];
         $optionExists = false;
         foreach ($product->getUnits() as $unit) {
             if ($unit->hasOption($optionName) && $unit->getOption($optionName) === $optionValue) {
                 $optionExists = true;
                 break;
             }
         }
         if (false === $optionExists) {
             throw new Exception\BundleBuildException('Product `' . $product->name . '` does not have any units with an option name of `' . $optionName . '` and value of ' . $optionValue . '`');
         }
     }
 }
 public function reverseTransform($products)
 {
     $products = (array) $products;
     return $this->_productLoader->getByID($products);
 }