Exemplo n.º 1
0
 /**
  * @param SimpleXMLElement $xml
  * @param bool $install_mode
  * @return bool
  * @throws PrestaShopException
  */
 protected function _installCurrencies($xml, $install_mode = false)
 {
     if (isset($xml->currencies->currency)) {
         foreach ($xml->currencies->currency as $data) {
             /** @var SimpleXMLElement $data */
             $attributes = $data->attributes();
             if (Currency::exists($attributes['iso_code'], (int) $attributes['iso_code_num'])) {
                 continue;
             }
             $currency = new Currency();
             $currency->name = (string) $attributes['name'];
             $currency->iso_code = (string) $attributes['iso_code'];
             $currency->iso_code_num = (int) $attributes['iso_code_num'];
             $currency->sign = (string) $attributes['sign'];
             $currency->blank = (int) $attributes['blank'];
             $currency->conversion_rate = 1;
             // This value will be updated if the store is online
             $currency->format = (int) $attributes['format'];
             $currency->decimals = (int) $attributes['decimals'];
             $currency->active = true;
             if (!$currency->validateFields()) {
                 $this->_errors[] = Tools::displayError('Invalid currency properties.');
                 return false;
             }
             if (!Currency::exists($currency->iso_code, $currency->iso_code_num)) {
                 if (!$currency->add()) {
                     $this->_errors[] = Tools::displayError('An error occurred while importing the currency: ') . strval($attributes['name']);
                     return false;
                 }
                 PaymentModule::addCurrencyPermissions($currency->id);
             }
         }
         if (($error = Currency::refreshCurrencies()) !== null) {
             $this->_errors[] = $error;
         }
         if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->currencies->currency) == 1) {
             $this->iso_currency = $attributes['iso_code'];
         }
     }
     return true;
 }
 protected function _installCurrencies($xml, $install_mode = false)
 {
     if (isset($xml->currencies->currency)) {
         if (!($feed = Tools::simplexml_load_file('http://www.prestashop.com/xml/currencies.xml')) and !($feed = @simplexml_load_file(dirname(__FILE__) . '/../localization/currencies.xml'))) {
             $this->_errors[] = Tools::displayError('Cannot parse the currencies XML feed.');
             return false;
         }
         foreach ($xml->currencies->currency as $data) {
             $attributes = $data->attributes();
             if (Currency::exists($attributes['iso_code'])) {
                 continue;
             }
             $currency = new Currency();
             $currency->name = strval($attributes['name']);
             $currency->iso_code = strval($attributes['iso_code']);
             $currency->iso_code_num = (int) $attributes['iso_code_num'];
             $currency->sign = strval($attributes['sign']);
             $currency->blank = (int) $attributes['blank'];
             $currency->conversion_rate = 1;
             // This value will be updated if the store is online
             $currency->format = (int) $attributes['format'];
             $currency->decimals = (int) $attributes['decimals'];
             $currency->active = $install_mode;
             if (!$currency->validateFields()) {
                 $this->_errors[] = Tools::displayError('Invalid currency properties.');
                 return false;
             }
             if (!Currency::exists($currency->iso_code)) {
                 if (!$currency->add()) {
                     $this->_errors[] = Tools::displayError('An error occurred while importing the currency: ') . strval($attributes['name']);
                     return false;
                 }
                 PaymentModule::addCurrencyPermissions($currency->id);
             }
         }
         Currency::refreshCurrencies();
         if (!sizeof($this->_errors) and $install_mode and isset($attributes['iso_code']) and sizeof($xml->currencies->currency) == 1) {
             $this->iso_currency = $attributes['iso_code'];
         }
     }
     return true;
 }