/**
  * There is a special way you can import rateToBase and currencyCode for an amount attribute.
  * if the column data is formatted like: $54.67__1.2__USD  then it will split the column and properly
  * handle rate and currency code.  Eventually this will be exposed in the user interface
  *
  * @param mixed $value
  * @param string $columnName
  * @param array $columnMappingData
  * @param ImportSanitizeResultsUtil $importSanitizeResultsUtil
  * @return array
  */
 public function resolveValueForImport($value, $columnName, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     assert('is_string($columnName)');
     $attributeNames = $this->getRealModelAttributeNames();
     $modelClassName = $this->getModelClassName();
     $parts = explode(FormModelUtil::DELIMITER, $value);
     if (count($parts) == 3) {
         $value = $parts[0];
         $rateToBase = $parts[1];
         try {
             $currency = Currency::getByCode($parts[2]);
         } catch (NotFoundException $e) {
             $currency = null;
             $importSanitizeResultsUtil->addMessage('Currency Code: ' . $parts[2] . ' is invalid.');
             $importSanitizeResultsUtil->setModelShouldNotBeSaved();
         }
     } else {
         $rateToBase = $columnMappingData['mappingRulesData']['CurrencyRateToBaseModelAttributeMappingRuleForm']['rateToBase'];
         $currency = Currency::getById((int) $columnMappingData['mappingRulesData']['CurrencyIdModelAttributeMappingRuleForm']['id']);
     }
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, $this->getModelAttributeName(), $value, $columnName, $columnMappingData, $importSanitizeResultsUtil);
     if ($sanitizedValue == null) {
         $sanitizedValue = 0;
     }
     $currencyValue = new CurrencyValue();
     $currencyValue->setScenario('importModel');
     $currencyValue->value = $sanitizedValue;
     $currencyValue->rateToBase = $rateToBase;
     $currencyValue->currency = $currency;
     return array($this->getModelAttributeName() => $currencyValue);
 }
 public function sanitizeValue($value)
 {
     $resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues());
     if ($value != null) {
         if (!in_array(strtolower($value), $resolvedAcceptableValues)) {
             return null;
         }
         $currency = Currency::getByCode($value);
         if ($currency != null) {
             return $currency;
         }
     }
     if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) {
         $currency = Currency::getById(intval($this->mappingRuleData['defaultValue']));
         if ($currency != null) {
             return $currency;
         }
     }
 }
 /**
  * Utilized to create or update model attribute values after a workflow's triggers are fired as true.
  * @param WorkflowActionProcessingModelAdapter $adapter
  * @param $attribute
  * @throws NotSupportedException
  */
 public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
 {
     assert('is_string($attribute)');
     if ($this->type == static::TYPE_STATIC) {
         $adapter->getModel()->{$attribute}->value = $this->value;
         $adapter->getModel()->{$attribute}->currency = Currency::getById((int) $this->currencyId);
     } else {
         throw new NotSupportedException();
     }
 }
 /**
  * @param $currency__id
  * @throws \Exception
  */
 public function setCurrency__Id($currency__id)
 {
     $currency = null;
     if (is_int($currency__id)) {
         $currency = Currency::getById($currency__id);
         if (!$currency instanceof Currency) {
             throw new \Exception("Currency with ID '{$currency__id}' not found");
         }
     }
     $this->currency__id = $currency__id;
     $this->currency = $currency;
 }