OfferSet.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage Amazon
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @category Zend
  24. * @package Zend_Service
  25. * @subpackage Amazon
  26. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Service_Amazon_OfferSet
  30. {
  31. /**
  32. * @var string
  33. */
  34. public $LowestNewPrice;
  35. /**
  36. * @var string
  37. */
  38. public $LowestNewPriceCurrency;
  39. /**
  40. * @var string
  41. */
  42. public $LowestUsedPrice;
  43. /**
  44. * @var string
  45. */
  46. public $LowestUsedPriceCurrency;
  47. /**
  48. * @var int
  49. */
  50. public $TotalNew;
  51. /**
  52. * @var int
  53. */
  54. public $TotalUsed;
  55. /**
  56. * @var int
  57. */
  58. public $TotalCollectible;
  59. /**
  60. * @var int
  61. */
  62. public $TotalRefurbished;
  63. /**
  64. * @var Zend_Service_Amazon_Offer[]
  65. */
  66. public $Offers;
  67. /**
  68. * Parse the given Offer Set Element
  69. *
  70. * @param DOMElement $dom
  71. * @return void
  72. */
  73. public function __construct(DOMElement $dom)
  74. {
  75. $xpath = new DOMXPath($dom->ownerDocument);
  76. $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01');
  77. $offer = $xpath->query('./az:OfferSummary', $dom);
  78. if ($offer->length == 1) {
  79. $lowestNewPrice = $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:Amount', $dom);
  80. if ($lowestNewPrice->length == 1) {
  81. $this->LowestNewPrice = (int) $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:Amount/text()', $dom)->item(0)->data;
  82. $this->LowestNewPriceCurrency = (string) $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:CurrencyCode/text()', $dom)->item(0)->data;
  83. }
  84. $lowestUsedPrice = $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:Amount', $dom);
  85. if ($lowestUsedPrice->length == 1) {
  86. $this->LowestUsedPrice = (int) $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:Amount/text()', $dom)->item(0)->data;
  87. $this->LowestUsedPriceCurrency = (string) $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:CurrencyCode/text()', $dom)->item(0)->data;
  88. }
  89. $this->TotalNew = (int) $xpath->query('./az:OfferSummary/az:TotalNew/text()', $dom)->item(0)->data;
  90. $this->TotalUsed = (int) $xpath->query('./az:OfferSummary/az:TotalUsed/text()', $dom)->item(0)->data;
  91. $this->TotalCollectible = (int) $xpath->query('./az:OfferSummary/az:TotalCollectible/text()', $dom)->item(0)->data;
  92. $this->TotalRefurbished = (int) $xpath->query('./az:OfferSummary/az:TotalRefurbished/text()', $dom)->item(0)->data;
  93. }
  94. $offers = $xpath->query('./az:Offers/az:Offer', $dom);
  95. if ($offers->length >= 1) {
  96. /**
  97. * @see Zend_Service_Amazon_Offer
  98. */
  99. require_once 'Zend/Service/Amazon/Offer.php';
  100. foreach ($offers as $offer) {
  101. $this->Offers[] = new Zend_Service_Amazon_Offer($offer);
  102. }
  103. }
  104. }
  105. }