Пример #1
0
 /**
  * Validate a form page's values via AJAX
  *
  * @return void
  */
 public function validatePageAction()
 {
     $return = array();
     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
     $postData = $this->getRequest()->getParams();
     $page = $postData['page'];
     switch ($page) {
         case '1':
             $ajaxForm = new TenantsInsuranceQuoteB_Form_Step1();
             break;
         case '2':
             $ajaxForm = new TenantsInsuranceQuoteB_Form_Step2();
             // Update unspecified possessions SI
             $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $pageSession->PolicyNumber);
             $unspecPossessionsSI = preg_replace('/\\/\\d+/', '', $postData['possessions_cover']);
             $unspecPossessionsSI = is_numeric($unspecPossessionsSI) ? $unspecPossessionsSI : 0;
             $quoteManager->setCoverAmount($unspecPossessionsSI, Manager_Insurance_TenantsContentsPlus_Quote::UNSPECIFIEDPOSSESSIONS);
             break;
         case '3':
             $ajaxForm = new TenantsInsuranceQuoteB_Form_Step3();
             // Update unspecified possessions SI from upsell, if...
             $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $pageSession->PolicyNumber);
             $unspecPossessionsSI = $quoteManager->getCoverAmount(Manager_Insurance_TenantsContentsPlus_Quote::UNSPECIFIEDPOSSESSIONS);
             if ($unspecPossessionsSI == 0) {
                 if (isset($postData['upsell']) && $postData['upsell'] == 'yes') {
                     $quoteManager->setCoverAmount(2000, Manager_Insurance_TenantsContentsPlus_Quote::UNSPECIFIEDPOSSESSIONS);
                 }
             } elseif ($unspecPossessionsSI == 2000) {
                 if (isset($postData['upsell']) && $postData['upsell'] == 'no') {
                     $quoteManager->setCoverAmount(0, Manager_Insurance_TenantsContentsPlus_Quote::UNSPECIFIEDPOSSESSIONS);
                 }
             }
             $quoteManager->setPropertyPostcode($postData['ins_postcode']);
             /*
             	Display Minimum Security Protection wording on step3 page
             	based on the property postcode
             */
             $postcode = explode(' ', $postData['ins_postcode']);
             $mspManager = new Manager_Insurance_MinimumSecurityProtection();
             $msp = $mspManager->isHighRiskPostcode($postcode[0]);
             $return['msp'] = $msp;
             break;
         case '4':
             $ajaxForm = new TenantsInsuranceQuoteB_Form_Step4();
             break;
         case '5':
             $ajaxForm = new TenantsInsuranceQuoteB_Form_Step5();
             break;
         case 'dd':
             $ajaxForm = new TenantsInsuranceQuoteB_Form_DirectDebit();
             break;
         default:
             return;
     }
     $valid = $ajaxForm->isValid($postData);
     // Get the agent scheme number from the agentSchemeNumber if it is set
     $session = new Zend_Session_Namespace('homelet_global');
     $agentSchemeNumber = $session->agentSchemeNumber;
     if (isset($pageSession->CustomerRefNo)) {
         Application_Core_Logger::log('Customer Reference Number : ' . $pageSession->CustomerRefNo);
         $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote($pageSession->CustomerRefNo, $agentSchemeNumber, $pageSession->PolicyNumber);
     } else {
         // We don't have a customer record so we'll do a non-committal quick quote for now
         $quoteManager = new Manager_Insurance_TenantsContentsPlus_QuickQuote($agentSchemeNumber);
     }
     if (!$valid) {
         $errorMessages = $ajaxForm->getMessagesFlattened();
         // We need to strip out some complex messages that the end user won't care about
         if (isset($errorMessages['email_address'])) {
             if (isset($errorMessages['email_address']['hostnameUnknownTld'])) {
                 unset($errorMessages['email_address']['hostnameUnknownTld']);
             }
             if (isset($errorMessages['email_address']['hostnameLocalNameNotAllowed'])) {
                 unset($errorMessages['email_address']['hostnameLocalNameNotAllowed']);
             }
         }
         /*
         				isset($errorMessages->hostnameUnknownTld) ||
         				isset($errorMessages->hostnameLocalNameNotAllowed)) {
         				die('foo');*/
         $return['errorJs'] = $errorMessages;
         $return['errorCount'] = count($errorMessages);
         $return['errorHtml'] = $this->view->partial('/partials/error-list.phtml', array('errors' => $errorMessages));
         $return['premiums'] = '';
         $return['fees'] = '';
         $return['postData'] = $postData;
         if ($page > 1) {
             // On pages after the first quick quote we can show prices even when the form is invalid - I think!
             $premiums = $quoteManager->calculatePremiums();
             $fees = $quoteManager->getFees();
             $return['premiums'] = $premiums;
             $return['fees'] = $fees;
         }
     } else {
         $return['errorJs'] = '';
         $return['errorCount'] = '';
         $return['errorHtml'] = '';
         $return['postData'] = $postData;
         // Form was valid - so calculate prices and fee's to return
         // Calculate premiums
         if ($page == 1) {
             // Special processing for quick- and full-quotes' contents SI
             $input = $this->getRequest()->getPost();
             $cover = 0;
             if ($input['contents_cover_a'] != '') {
                 if ($input['contents_cover_a'] == '15000+') {
                     if ($input['contents_cover_b'] != '' && (int) $input['contents_cover_b'] > 15000) {
                         $cover = (int) $input['contents_cover_b'];
                     }
                 } else {
                     $cover = (int) $input['contents_cover_a'];
                 }
             }
             if ($cover > 0) {
                 $quoteManager->setCoverAmount($cover, Manager_Insurance_TenantsContentsPlus_Quote::CONTENTS);
                 $premiums = $quoteManager->calculatePremiums();
             }
         }
         $premiums = $quoteManager->calculatePremiums();
         $fees = $quoteManager->getFees();
         $return['premiums'] = $premiums;
         $return['fees'] = $fees;
     }
     echo Zend_Json::encode($return);
 }