Ejemplo n.º 1
0
 /**
  * Get telephone used for this language
  *
  * @return string
  */
 public function getPhone()
 {
     if ($this->phone === null) {
         $this->phone = $this->language->getInformation('phone', false);
         if ($iframe = Tools::file_get_contents('http://api.prestashop.com/iframe/install.php?lang=' . $this->language->getLanguageIso())) {
             if (preg_match('/<img.+alt="([^"]+)".*>/Ui', $iframe, $matches) && isset($matches[1])) {
                 $this->phone = $matches[1];
             }
         }
     }
     return $this->phone;
 }
Ejemplo n.º 2
0
 /**
  * Populate an entity
  *
  * @param string $entity
  */
 public function populateEntity($entity)
 {
     if (method_exists($this, 'populateEntity' . Tools::toCamelCase($entity))) {
         $this->{'populateEntity' . Tools::toCamelCase($entity)}();
         return;
     }
     if (substr($entity, 0, 1) == '.' || substr($entity, 0, 1) == '_') {
         return;
     }
     $xml = $this->loadEntity($entity);
     // Read list of fields
     if (!is_object($xml) || !$xml->fields) {
         throw new PrestashopInstallerException('List of fields not found for entity ' . $entity);
     }
     if ($this->isMultilang($entity)) {
         $multilang_columns = $this->getColumns($entity, true);
         $xml_langs = array();
         $default_lang = null;
         foreach ($this->languages as $id_lang => $iso) {
             if ($iso == $this->language->getLanguageIso()) {
                 $default_lang = $id_lang;
             }
             try {
                 $xml_langs[$id_lang] = $this->loadEntity($entity, $iso);
             } catch (PrestashopInstallerException $e) {
                 $xml_langs[$id_lang] = null;
             }
         }
     }
     // Load all row for current entity and prepare data to be populated
     foreach ($xml->entities->{$entity} as $node) {
         $data = array();
         $identifier = (string) $node['id'];
         // Read attributes
         foreach ($node->attributes() as $k => $v) {
             if ($k != 'id') {
                 $data[$k] = (string) $v;
             }
         }
         // Read cdatas
         foreach ($node->children() as $child) {
             $data[$child->getName()] = (string) $child;
         }
         // Load multilang data
         $data_lang = array();
         if ($this->isMultilang($entity)) {
             $xpath_query = $entity . '[@id="' . $identifier . '"]';
             foreach ($xml_langs as $id_lang => $xml_lang) {
                 if (!$xml_lang) {
                     continue;
                 }
                 if (($node_lang = $xml_lang->xpath($xpath_query)) || ($node_lang = $xml_langs[$default_lang]->xpath($xpath_query))) {
                     $node_lang = $node_lang[0];
                     foreach ($multilang_columns as $column => $is_text) {
                         $value = '';
                         if ($node_lang[$column]) {
                             $value = (string) $node_lang[$column];
                         }
                         if ($node_lang->{$column}) {
                             $value = (string) $node_lang->{$column};
                         }
                         $data_lang[$column][$id_lang] = $value;
                     }
                 }
             }
         }
         $data = $this->rewriteRelationedData($entity, $data);
         if (method_exists($this, 'createEntity' . Tools::toCamelCase($entity))) {
             // Create entity with custom method in current class
             $method = 'createEntity' . Tools::toCamelCase($entity);
             $this->{$method}($identifier, $data, $data_lang);
         } else {
             $this->createEntity($entity, $identifier, (string) $xml->fields['class'], $data, $data_lang);
         }
         if ($xml->fields['image']) {
             if (method_exists($this, 'copyImages' . Tools::toCamelCase($entity))) {
                 $this->{'copyImages' . Tools::toCamelCase($entity)}($identifier, $data);
             } else {
                 $this->copyImages($entity, $identifier, (string) $xml->fields['image'], $data);
             }
         }
     }
     $this->flushDelayedInserts();
     unset($this->cache_xml_entity[$this->path_type][$entity]);
 }