Example #1
0
 public function verify()
 {
     if (!isset($this->data->price) || !is_numeric($this->data->price)) {
         throw new \Exception(Lang::txt('No SKU price set'));
     }
     if (!isset($this->data->pId) || !is_numeric($this->data->pId)) {
         throw new \Exception(Lang::txt('No SKU Product Set'));
     }
     // Verify that the SKU has all options set (one option from each option group assigned to the parent product)
     $product = new Product($this->getProductId());
     $productOptionGroups = $product->getOptionGroups();
     // Init the set options array()
     $optionGroupOptionsSet = array();
     // Init the flag whether the extra/useless options are set
     $extraOptionsSet = false;
     foreach ($this->getOptions() as $oId) {
         $option = new Option($oId);
         $optionGroupId = $option->getOptionGroupId();
         if (in_array($optionGroupId, $productOptionGroups)) {
             $optionGroupOptionsSet[] = $optionGroupId;
         } else {
             // There are some options set that are from option groups not applied to this product
             // (most likely due to the removal of the option group from the product.)
             $extraOptionsSet = true;
         }
     }
     // At this point option groups options set must be the same as the product options groups, throw exception if not
     $missingOptions = array_diff($productOptionGroups, $optionGroupOptionsSet);
     if (!empty($missingOptions)) {
         throw new \Exception(Lang::txt('Not all product options are set'));
     }
     if ($extraOptionsSet) {
         throw new \Exception(Lang::txt('Extra options are set'));
     }
     return true;
 }
Example #2
0
 public function verify()
 {
     if (!isset($this->data->price) || !is_numeric($this->data->price)) {
         throw new \Exception(Lang::txt('No SKU price set'));
     }
     if (!isset($this->data->pId) || !is_numeric($this->data->pId)) {
         throw new \Exception(Lang::txt('No SKU Product Set'));
     }
     // Verify that the SKU has all options set (one option from each option group assigned to the parent product)
     $product = new Product($this->getProductId());
     $productOptionGroups = $product->getOptionGroups();
     // Init the set options array()
     $optionGroupOptionsSet = array();
     // Init the flag whether the extra/useless options are set
     $extraOptionsSet = false;
     foreach ($this->getOptions() as $oId) {
         $option = new Option($oId);
         $optionGroupId = $option->getOptionGroupId();
         if (in_array($optionGroupId, $productOptionGroups)) {
             $optionGroupOptionsSet[] = $optionGroupId;
         } else {
             // There are some options set that are from option groups not applied to this product
             // (most likely due to the removal of the option group from the product.) This should never happen.
             $extraOptionsSet = true;
         }
     }
     // At this point option groups options set must be the same as the product options groups, throw exception if not
     $missingOptions = array_diff($productOptionGroups, $optionGroupOptionsSet);
     if (!empty($missingOptions)) {
         throw new \Exception(Lang::txt('Not all product options are set'));
     }
     if ($extraOptionsSet) {
         throw new \Exception(Lang::txt('Extra options are set'));
     }
     // Integrity check
     require_once dirname(__DIR__) . DS . 'helpers' . DS . 'Integrity.php';
     $integrityCheck = \Integrity::skuIntegrityCheck($this);
     if ($integrityCheck->status != 'ok') {
         $errorMessage = "Integrity check error:";
         foreach ($integrityCheck->errors as $error) {
             $errorMessage .= '<br>' . $error;
         }
         throw new \Exception($errorMessage);
     }
     return true;
 }