Esempio n. 1
0
 /** Calculate base data
  * @param $data
  * @return array
  */
 public function calculate($data)
 {
     $this->_error = '';
     $resultCalculation = array();
     if (isset($this->resultLogin)) {
         try {
             $paramCalculation = new \ParamCalculation();
             $paramCalculation->setSenderId($this->resultLogin->getClientId());
             $paramCalculation->setBroughtToOffice($this->config->get('speedy_from_office') && $this->config->get('speedy_office_id'));
             $paramCalculation->setToBeCalled($data['to_office'] && $data['office_id']);
             $paramCalculation->setParcelsCount($data['count']);
             $paramCalculation->setWeightDeclared($data['weight']);
             $paramCalculation->setDocuments($this->config->get('speedy_documents'));
             $paramCalculation->setPalletized(false);
             if (!empty($data['fixed_time'])) {
                 $paramCalculation->setFixedTimeDelivery($data['fixed_time']);
             } else {
                 $paramCalculation->setFixedTimeDelivery(null);
             }
             if (isset($data['loading'])) {
                 if ($data['insurance']) {
                     if ($data['fragile']) {
                         $paramCalculation->setFragile(true);
                     } else {
                         $paramCalculation->setFragile(false);
                     }
                     $paramCalculation->setAmountInsuranceBase($data['totalNoShipping']);
                     $paramCalculation->setPayerTypeInsurance(\ParamCalculation::PAYER_TYPE_RECEIVER);
                 } else {
                     $paramCalculation->setFragile(false);
                 }
             } elseif ($this->config->get('speedy_insurance')) {
                 if ($this->config->get('speedy_fragile')) {
                     $paramCalculation->setFragile(true);
                 } else {
                     $paramCalculation->setFragile(false);
                 }
                 $paramCalculation->setAmountInsuranceBase($data['totalNoShipping']);
                 $paramCalculation->setPayerTypeInsurance(\ParamCalculation::PAYER_TYPE_RECEIVER);
             } else {
                 $paramCalculation->setFragile(false);
             }
             if (!($data['to_office'] && $data['office_id'])) {
                 $paramCalculation->setReceiverSiteId($data['city_id']);
             }
             $paramCalculation->setPayerType(\ParamCalculation::PAYER_TYPE_RECEIVER);
             if ($data['cod']) {
                 $paramCalculation->setAmountCodBase($data['total']);
             } else {
                 $paramCalculation->setAmountCodBase(0);
             }
             $paramCalculation->setTakingDate($data['taking_date']);
             $paramCalculation->setAutoAdjustTakingDate(true);
             if ($this->config->get('speedy_from_office') && $this->config->get('speedy_office_id')) {
                 $paramCalculation->setWillBringToOfficeId($this->config->get('speedy_office_id'));
             }
             if ($data['to_office'] && $data['office_id']) {
                 $paramCalculation->setOfficeToBeCalledId($data['office_id']);
             } else {
                 $paramCalculation->setOfficeToBeCalledId(null);
             }
             $resultCalculation = $this->ePSFacade->calculateMultipleServices($paramCalculation, $this->config->get('speedy_allowed_methods'));
             foreach ($resultCalculation as $key => $service) {
                 if ($service->getErrorDescription()) {
                     unset($resultCalculation[$key]);
                 }
             }
             $resultCalculation = array_values($resultCalculation);
         } catch (\Exception $e) {
             $this->_error = $e->getMessage();
             $this->log->addError('Speedy :: calculate :: ' . $e->getMessage());
         }
     }
     return $resultCalculation;
 }