示例#1
0
<?php

include "init.php";
/**
 * copy the config.yml.sample to config.yml and
 * provide you're cafepress developer appkey
 */
$products = CafePressApi::Products()->get('dogs');
/**
 * uncomment this code to show all available field names
 */
//var_export($products[0]);
?>
<!DOCTYPE html>
<html>
  <head>
    <title>CafePress PHP SDK Demo Page</title>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    <style type="text/css">
        table tr th, table tr td{
            padding: 5px 10px;
            text-align: left;
        }
    </style>
  </head>

  <body>
      <table>
示例#2
0
 public function testProductsGetByStoreIdMethod()
 {
     $search = 'kansasfest';
     $products = CafePressApi::Products()->get_by_storeid($search, array('pageNumber' => 2));
     /**
      * product id should exists
      */
     $this->assertTrue(isset($products['productId']));
     $this->assertTrue(isset($products['merchandiseId']));
     $this->assertTrue(isset($products['designId']));
     /**
      * :xml key is the product simple xml element object
      */
     $this->assertTrue($products[':xml'] instanceof SimpleXMLElement);
     /**
      * xmlresults contains all the simple xml element
      * object that was called from get method
      */
     foreach ($products->xmlresults as $k => $v) {
         $this->assertTrue($v instanceof SimpleXMLElement);
     }
     $this->assertTrue($products[':xml'] instanceof SimpleXMLElement);
     $total_loop = $products->resultLength;
     $loop = 0;
     foreach ($products as $k => $v) {
         $loop++;
         $this->assertTrue(isset($v['productId']));
         $this->assertTrue(isset($v['merchandiseId']));
         $this->assertTrue(isset($v['designId']));
         $this->assertTrue($v[':xml'] instanceof SimpleXMLElement);
     }
     // end foreach
     $this->assertEqual($loop, $total_loop);
     $this->assertTrue(isset($products->resultLength));
     $this->assertTrue(isset($products->startResult));
     $this->assertTrue(isset($products->totalProducts));
     $this->assertTrue(isset($products->totalDesigns));
     $this->assertTrue(isset($products->xml));
 }