/** * @param $name * @return null|string */ public function getField($name) { if ($this->isCalculatedField($name)) { return $this->calculatedFields->get($name); } return parent::getField($name); }
/** * @param string $name Field name. * @return mixed|null */ public function getField($name) { if ($this->isCalculatedField($name)) { if (isset($this->calculatedFields[$name]) || array_key_exists($name, $this->calculatedFields)) { return $this->calculatedFields->get($name); } return null; } return parent::getField($name); }
/** * * @param array $values * @return Result * @throws Main\ArgumentOutOfRangeException * @throws Main\NotSupportedException * @throws \Exception */ public function setFields(array $values) { $resultData = array(); $result = new Result(); $oldValues = null; foreach ($values as $key => $value) { $oldValues[$key] = $this->fields->get($key); } if ($eventName = static::getEntityEventName()) { $event = new Main\Event('sale', 'OnBefore' . $eventName . 'SetFields', array('ENTITY' => $this, 'VALUES' => $values, 'OLD_VALUES' => $oldValues)); $event->send(); if ($event->getResults()) { /** @var Main\EventResult $eventResult */ foreach ($event->getResults() as $eventResult) { if ($eventResult->getType() == Main\EventResult::SUCCESS) { if ($eventResultData = $eventResult->getParameters()) { if (isset($eventResultData['VALUES'])) { $values = $eventResultData['VALUES']; } } } elseif ($eventResult->getType() == Main\EventResult::ERROR) { $errorMsg = new ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_ON_BEFORE_' . strtoupper($eventName) . '_SET_FIELDS_ERROR'), 'SALE_EVENT_ON_BEFORE_' . strtoupper($eventName) . '_SET_FIELDS_ERROR'); if ($eventResultData = $eventResult->getParameters()) { if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) { $errorMsg = $eventResultData['ERROR']; } } $result->addError($errorMsg); } } } } if (!$result->isSuccess()) { return $result; } $isStartField = $this->isStartField(); foreach ($values as $key => $value) { $r = $this->setField($key, $value); if (!$r->isSuccess()) { $data = $r->getData(); if (!empty($data) && is_array($data)) { $resultData = array_merge($resultData, $data); } $result->addErrors($r->getErrors()); } } if (!empty($resultData)) { $result->setData($resultData); } if ($isStartField) { $hasMeaningfulFields = $this->hasMeaningfulField(); /** @var Result $r */ $r = $this->doFinalAction($hasMeaningfulFields); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } else { if (($data = $r->getData()) && !empty($data) && is_array($data)) { $result->setData($result->getData() + $data); } } } return $result; }
/** * @param $name * @return null|string */ public function getField($name) { return $this->fields->get($name); }