Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 3.46 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Extending Zend_Service for Amazon BrowseNodes, Ancestors are not processed
  2. <BrowseNodes>
  3.     <BrowseNode>
  4.         <BrowseNodeId>10605</BrowseNodeId>
  5.         <Name>Education</Name>
  6.         <Children>...</Children>
  7.         <Ancestors>
  8.             <BrowseNode>
  9.                 <BrowseNodeId>21</BrowseNodeId>
  10.                 <Name>Education & Reference</Name>
  11.                 <Ancestors>
  12.                     <BrowseNode>
  13.                         <BrowseNodeId>1000</BrowseNodeId>
  14.                         <Name>Subjects</Name>
  15.                         <IsCategoryRoot>1</IsCategoryRoot>
  16.                         <Ancestors>
  17.                             <BrowseNode>
  18.                                 <BrowseNodeId>283155</BrowseNodeId>
  19.                                 <Name>Books</Name>
  20.                             </BrowseNode>
  21.                         </Ancestors>
  22.                     </BrowseNode>
  23.                 </Ancestors>
  24.             </BrowseNode>
  25.         </Ancestors>
  26.     </BrowseNode>
  27. </BrowseNodes>
  28.        
  29. class Zend_Service_Amazon_Item
  30. {
  31.  
  32.     /**
  33.      * @var array
  34.      */
  35.     public $BrowseNodes = array();
  36.  
  37.     public function __construct($dom) {
  38.  
  39.         // .... the code for the other items
  40.  
  41.         // .... for browsenode
  42.         $result = $xpath->query('./az:BrowseNodes/*', $dom);
  43.         if ($result->length > 1) {
  44.             /**
  45.              * @see Zend_Service_Amazon_BrowseNode
  46.              */
  47.             require_once 'Zend/Service/Amazon/BrowseNode.php';
  48.             foreach ($result as $r) {
  49.                 $this->BrowseNodes[] = new Zend_Service_Amazon_BrowseNode($r);
  50.             }
  51.         }
  52.     }
  53. }
  54.        
  55. class Zend_Service_Amazon_BrowseNode
  56. {
  57.     /**
  58.      * @var integer
  59.      */
  60.     public $BrowseNodeId;
  61.  
  62.     /**
  63.      * @var string
  64.      */
  65.     public $Name;
  66.  
  67.     /**
  68.      * @var boolean
  69.      */
  70.     public $IsCategoryRoot;
  71.  
  72.  
  73.     /**
  74.      * @var array BrwoserNodes
  75.      */
  76.     public $Ancestors = array();
  77.  
  78.     /**
  79.      * @var string
  80.      */
  81.     public $Children = array();
  82.  
  83.     /**
  84.      * Assigns values to properties relevant to BrowseNode
  85.      *
  86.      * @param  DOMElement $dom
  87.      * @return void
  88.      */
  89.     public function __construct(DOMElement $dom)
  90.     {
  91.  
  92.         $xpath = new DOMXPath($dom->ownerDocument);
  93.         $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01');
  94.         foreach (array('BrowseNodeId', 'Name') as $el) {
  95.             $result = $xpath->query("./az:$el/text()", $dom);
  96.             if ($result->length == 1) {
  97.                 $this->$el = (string) $result->item(0)->data;
  98.             }
  99.         }
  100.  
  101.         $result = $xpath->query('./az:IsCategoryRoot/text()', $dom);
  102.         if ($result->length == 1) {
  103.             $this->IsCategoryRoot = (bool) $result->item(0)->data ;
  104.         }
  105.  
  106.         foreach (array('Children','Ancestors') as $el) {
  107.             $result = $xpath->query("./$el/*", $dom);
  108.             if ($result->length > 1) {
  109.                 foreach ($result as $r) {
  110.                     array_push($this->$el, new Zend_Service_Amazon_BrowseNode($r));
  111.                 }
  112.             }
  113.         }
  114.     }
  115. }
  116.        
  117. $result = $xpath->query("./$el/*", $dom);
  118.        
  119. $result = $xpath->query("./az:$el/*", $dom);
  120.        
  121. if ($result->length > 1) {
  122.        
  123. if ($result->length > 0) {
  124.        
  125. foreach (array('Children','Ancestors') as $el) {
  126.         $result = $xpath->query("./az:$el/*", $dom);
  127.         if ($result->length > 0) {
  128.             foreach ($result as $r) {
  129.                 array_push($this->$el, new Zend_Service_Amazon_BrowseNode($r));
  130.             }
  131.         }
  132.     }