コード例 #1
0
ファイル: googleproducts.php プロジェクト: annggeel/tienda
 /**
  * Generates the xml for the update request
  * @param unknown_type $product
  * @param string $etag - etag of the product
  */
 protected function getUpdateXML($product, $etag)
 {
     // perform the insertion
     Tienda::load('TiendaArrayToXML', 'library.xml');
     // Populate the xml request
     $xml = array();
     $xml['app:control']['sc:required_destination']['attributes']['dest'] = 'ProductSearch';
     // Title, id and description
     $xml['title'] = $product->product_name;
     $xml['content']['attributes']['type'] = 'text/html';
     $xml['content'] = $product->product_description;
     $xml['sc:id'] = $product->product_id;
     // Link to the product
     Tienda::load('TiendaHelperRoute', 'helpers.route');
     $xml['link']['attributes']['rel'] = 'alternate';
     $xml['link']['attributes']['type'] = 'text/html';
     $baseurl = str_replace("/administrator/", "/", JURI::base());
     $xml['link']['attributes']['href'] = $baseurl . TiendaHelperRoute::product($product->product_id);
     //$xml['link']['attributes']['href'] = 'http://www.weble.it/products/'.$product->product_id;
     // Condition
     $xml['scp:condition'] = 'new';
     // Price
     $currency_id = Tienda::getInstance()->get('default_currencyid', '1');
     Tienda::load('TiendaTableCurrencies', 'tables.currencies');
     $currency = JTable::getInstance('Currencies', 'TiendaTable');
     $currency->load((int) $currency_id);
     $xml['scp:price']['attributes']['unit'] = trim(strtoupper($currency->currency_code));
     $xml['scp:price']['@value'] = TiendaHelperBase::number(TiendaHelperProduct::getPrice($product->product_id)->product_price, array('num_decimals', '0'));
     // Manufacturer
     Tienda::load('TiendaTableManufacturers', 'tables.manufacturers');
     $manufacturer = JTable::getInstance('Manufacturers', 'TiendaTable');
     if ($manufacturer->load($product->manufacturer_id)) {
         $xml['scp:brand'] = $manufacturer->manufacturer_name;
     }
     $xml['entry']['attributes']['gd:etag'] = $etag;
     // Create the request
     $null = null;
     $helper = new TiendaArrayToXML();
     $ns = array(array('name' => 'app', 'url' => "http://www.w3.org/2007/app"), array('name' => 'gd', 'url' => "http://schemas.google.com/g/2005"), array('name' => 'sc', 'url' => "http://schemas.google.com/structuredcontent/2009"), array('name' => 'scp', 'url' => "http://schemas.google.com/structuredcontent/2009/products"));
     $xml = $helper->toXml($xml, 'entry', $null, $ns, "http://www.w3.org/2005/Atom");
     return $xml;
 }
コード例 #2
0
ファイル: helper.php プロジェクト: annggeel/tienda
 /**
  * The main function for converting to an array.
  * Pass in a XML document and this recrusively loops through and builds up an array.
  *
  * @static
  * @param  string $obj - XML document string (at start point)
  * @param  array  $arr - Array to generate
  * @return array - Array generated
  */
 public static function toArray($obj, &$arr = NULL)
 {
     if (is_null($arr)) {
         $arr = array();
     }
     if (is_string($obj)) {
         $obj = new SimpleXMLElement($obj);
     }
     // Get attributes for current node and add to current array element
     $attributes = $obj->attributes();
     foreach ($attributes as $attrib => $value) {
         $arr[TiendaArrayToXML::attr_arr_string][$attrib] = (string) $value;
     }
     $children = $obj->children();
     $executed = FALSE;
     // Check all children of node
     foreach ($children as $elementName => $node) {
         // Check if there are multiple node with the same key and generate a multiarray
         if ($arr[$elementName] != NULL) {
             if ($arr[$elementName][0] !== NULL) {
                 $i = count($arr[$elementName]);
                 TiendaArrayToXML::toArray($node, $arr[$elementName][$i]);
             } else {
                 $tmp = $arr[$elementName];
                 $arr[$elementName] = array();
                 $arr[$elementName][0] = $tmp;
                 $i = count($arr[$elementName]);
                 TiendaArrayToXML::toArray($node, $arr[$elementName][$i]);
             }
         } else {
             $arr[$elementName] = array();
             TiendaArrayToXML::toArray($node, $arr[$elementName]);
         }
         $executed = TRUE;
     }
     // Check if is already processed and if already contains attributes
     if (!$executed && $children->getName() == "" && !isset($arr[TiendaArrayToXML::attr_arr_string])) {
         $arr = (string) $obj;
     }
     return $arr;
 }
コード例 #3
0
ファイル: unex.php プロジェクト: annggeel/tienda
 function createRequest()
 {
     $arrayXml['AccessRequest']['UserId'] = $this->username;
     $arrayXml['AccessRequest']['Password'] = $this->password;
     $arrayXml['TrackingNumber'] = $this->track;
     $xml = trim(TiendaArrayToXML::toXml($arrayXml, 'DocumentRequest'));
     $this->request = $xml;
 }