public static function getUrl(array $prices)
 {
     global $tag, $marketplaceSingleCart;
     if (!$marketplaceSingleCart && count($prices) == 1) {
         return "http://www.amazon.com/gp/offer-listing/" . Isbn::to10(current($prices)->bookId) . "/condition=all&tag={$tag}";
     } else {
         return Amazon::getUrl($prices);
     }
 }
Пример #2
0
 public function testValidateAndConvertIsbn13Only()
 {
     $this->assertTrue(Isbn::validate($this->validIsbn13Only));
     $this->assertFalse(Isbn::to10($this->validIsbn13Only));
 }
Пример #3
0
 /**
  * Makes an Amazon cart.  Requires $tag global to be set.
  *
  * todo: fail gracefully if amazon cart api goes down (it did once).
  *
  * @return string   the url of an Amazon cart containing the items referred to in $ids
  */
 public static function getCartUrl(array $isbns, array $offerListingIds = array())
 {
     global $tag;
     $items = array();
     foreach ($isbns as $isbn) {
         $items[] = array('type' => 'ASIN', 'id' => Isbn::to10($isbn));
     }
     foreach ($offerListingIds as $id) {
         $items[] = array('type' => 'OfferListingId', 'id' => $id);
     }
     $amazon = new AmazonAPI();
     $data = array("AssociateTag" => $tag);
     $i = 1;
     $j = 1;
     $cartId = null;
     while ($j <= count($items)) {
         if ($cartId) {
             $data["CartId"] = $cartId;
             $data["HMAC"] = $hmac;
         }
         $data["Item.{$i}.{$items[$j - 1]['type']}"] = $items[$j - 1]['id'];
         $data["Item.{$i}.Quantity"] = "1";
         if ($i % 6 == 0 || $j == count($items)) {
             $operation = $cartId ? "CartAdd" : "CartCreate";
             $result = $amazon->request($operation, $data);
             $cartId = (string) $result->Cart->CartId;
             $hmac = (string) $result->Cart->HMAC;
             $i = 0;
             $data = array("AssociateTag" => $tag);
         }
         $i++;
         $j++;
     }
     return $result->Cart->PurchaseURL;
 }