Exemple #1
0
 /**
  * Return namespaces with their prefix
  *
  * @return array
  */
 public static function getNamespacesPrefix()
 {
     if (is_null(self::$_namespacesPrefix)) {
         self::$_namespacesPrefix = array();
         $config = Mage::getSingleton('api/config')->getNode('v2/wsdl/prefix')->children();
         foreach ($config as $prefix => $namespace) {
             self::$_namespacesPrefix[$namespace->asArray()] = $prefix;
         }
     }
     return self::$_namespacesPrefix;
 }
Exemple #2
0
 /**
  * Extends one node
  *
  * @param Varien_Simplexml_Element $source
  * @param boolean $overwrite
  * @return Varien_Simplexml_Element
  */
 public function extendChild($source, $overwrite = false, $elmNamespace = '')
 {
     // this will be our new target node
     $targetChild = null;
     // name of the source node
     $sourceName = $source->getName();
     // here we have children of our source node
     $sourceChildren = $this->getChildren($source);
     if ($elmNamespace == '') {
         $elmNamespace = null;
     }
     if (!$source->hasChildren()) {
         // handle string node
         $elm = $this->getElementByName($source, $elmNamespace);
         if (!is_null($elm)) {
             // if target already has children return without regard
             if ($this->getChildren($elm)) {
                 return $this;
             }
             if ($overwrite) {
                 //                    unset($this->$sourceName);
                 unset($elm);
             } else {
                 return $this;
             }
         }
         $targetChild = $this->addChild($sourceName, $source->xmlentities(), $elmNamespace);
         $targetChild->setParent($this);
         foreach ($this->getAttributes($source) as $namespace => $attributes) {
             foreach ($attributes as $key => $value) {
                 $_namespacesPrefix = Mage_Api_Model_Wsdl_Config::getNamespacesPrefix();
                 if ($namespace == '') {
                     $namespace = null;
                 } elseif (array_key_exists($namespace, $_namespacesPrefix)) {
                     $key = $_namespacesPrefix[$namespace] . ':' . $key;
                 }
                 $targetChild->addAttribute($key, $this->xmlentities($value), $namespace);
             }
         }
         return $this;
     }
     $elm = $this->getElementByName($source, $elmNamespace);
     if (!is_null($elm)) {
         $targetChild = $elm;
     }
     if (is_null($targetChild)) {
         // if child target is not found create new and descend
         $targetChild = $this->addChild($sourceName, null, $elmNamespace);
         $targetChild->setParent($this);
         foreach ($this->getAttributes($source) as $namespace => $attributes) {
             foreach ($attributes as $key => $value) {
                 $_namespacesPrefix = Mage_Api_Model_Wsdl_Config::getNamespacesPrefix();
                 if ($namespace == '') {
                     $namespace = null;
                 } elseif (array_key_exists($namespace, $_namespacesPrefix)) {
                     $key = $_namespacesPrefix[$namespace] . ':' . $key;
                 }
                 $targetChild->addAttribute($key, $this->xmlentities($value), $namespace);
             }
         }
     }
     foreach ($sourceChildren as $elmNamespace => $children) {
         foreach ($children as $childKey => $childNode) {
             $targetChild->extendChild($childNode, $overwrite, $elmNamespace);
         }
     }
     return $this;
 }