Example #1
0
 /**
  * Validate rule data
  *
  * @param \Magento\Framework\DataObject $dataObject
  * @return bool|string[] - return true if validation passed successfully. Array with errors description otherwise
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function validateData(\Magento\Framework\DataObject $dataObject)
 {
     $result = [];
     $fromDate = $toDate = null;
     if ($dataObject->hasFromDate() && $dataObject->hasToDate()) {
         $fromDate = $dataObject->getFromDate();
         $toDate = $dataObject->getToDate();
     }
     if ($fromDate && $toDate) {
         $fromDate = new \DateTime($fromDate);
         $toDate = new \DateTime($toDate);
         if ($fromDate > $toDate) {
             $result[] = __('End Date must follow Start Date.');
         }
     }
     if ($dataObject->hasWebsiteIds()) {
         $websiteIds = $dataObject->getWebsiteIds();
         if (empty($websiteIds)) {
             $result[] = __('Please specify a website.');
         }
     }
     if ($dataObject->hasCustomerGroupIds()) {
         $customerGroupIds = $dataObject->getCustomerGroupIds();
         if (empty($customerGroupIds)) {
             $result[] = __('Please specify Customer Groups.');
         }
     }
     return !empty($result) ? $result : true;
 }