|
1 | | -php-mozu-api |
2 | | -============ |
| 1 | +# Mozu PHP SDK |
3 | 2 |
|
4 | 3 | PHP SDK for the full v1 Mozu Api |
5 | 4 |
|
6 | 5 | PackageGist: https://packagist.org/packages/mozu/api |
7 | 6 |
|
8 | | -Usage: |
| 7 | +## Usage: |
9 | 8 |
|
10 | | -<B>Authenticating an Application with server provided refresh interval tokens</B><br> |
| 9 | +### Authenticating an Application with server provided refresh interval tokens |
| 10 | +``` |
11 | 11 | $appAuthInfo = new AppAuthInfo();<br> |
12 | | -$appAuthInfo->sharedSecret = [sharedSecret];<br> |
13 | | -$appAuthInfo->applicationId = [applicationId];<br> |
14 | | -AppAuthenticator::initialize($appAuthInfo,null);<br> |
15 | | -<br> |
16 | | -<B>Get Tenant Information using Async operation</B><br> |
17 | | -$tenantResource = new TenantResource();<br> |
18 | | -$promise = $tenantResource->getTenantAsync([tenantId]);<br> |
| 12 | +$appAuthInfo->sharedSecret = [sharedSecret]; |
| 13 | +$appAuthInfo->applicationId = [applicationId]; |
| 14 | +AppAuthenticator::initialize($appAuthInfo,null); |
| 15 | +``` |
| 16 | + |
| 17 | +###Get Tenant Information using Async operation |
| 18 | +``` |
| 19 | +$tenantResource = new TenantResource(); |
| 20 | +$promise = $tenantResource->getTenantAsync([tenantId]); |
19 | 21 | $tenant = $promise->wait()->json(); |
20 | | -<br> |
21 | | -<B>Get Products</B><br> |
22 | | -$apiContext = new ApiContext($tenant);<br> |
23 | | -<B>Note:</B> You might need to create an API Context with a specific Mastercatalog or catalogId if you own a multi-catalog tenant<br> |
24 | | -$productResource = new ProductResource($apiContext, DataViewMode::LIVE);<br> |
25 | | -$promise = $productResource->getProductsAsync(0, 200, null, null, null, null, null);<br> |
26 | | -$promise->then(function($mozuResult) {<br> |
27 | | - printf($mozuResult->json()->pageCount);<br> |
28 | | - printf($mozuResult->json()->items);<br> |
29 | | - <br> |
30 | | - printf($mozuResult->correlationId);<br> |
31 | | -}, function($apiException) {<br> |
| 22 | +``` |
| 23 | + |
| 24 | +###Get Products |
| 25 | + |
| 26 | +``` |
| 27 | +$apiContext = new ApiContext($tenant); |
| 28 | +#You might need to create an API Context with a specific Mastercatalog or catalogId if you own a multi-catalog tenant<br> |
| 29 | +$productResource = new ProductResource($apiContext, DataViewMode::LIVE); |
| 30 | +$promise = $productResource->getProductsAsync(0, 200, null, null, null, null, null); |
| 31 | +$promise->then(function($mozuResult) { |
| 32 | + printf($mozuResult->json()->pageCount); |
| 33 | + printf($mozuResult->json()->items); |
| 34 | + |
| 35 | + printf($mozuResult->correlationId); |
| 36 | +}, function($apiException) { |
32 | 37 | printf("Exception : code - " . $apiException->getCode() . ", message - " . $apiException->getMessage(). ", correlationid - " . $apiException->getCorrelationId() ); |
33 | 38 | }); |
34 | | -<br> |
35 | | -<B>Get Orders - Filter by date</B><br> |
36 | | -$orderResource = new OrderResource($apiContext);<br> |
37 | | -$filters = urlencode("submittedDate gt 2013-12-15T12:21:24z");<br> |
38 | | -$promise = $orderResource->getOrdersAsync('0',100, null,$filters, null, null);<br> |
| 39 | +``` |
| 40 | + |
| 41 | +###Get Orders - Filter by date |
| 42 | +``` |
| 43 | +$orderResource = new OrderResource($apiContext); |
| 44 | +$filters = urlencode("submittedDate gt 2013-12-15T12:21:24z"); |
| 45 | +$promise = $orderResource->getOrdersAsync('0',100, null,$filters, null, null); |
39 | 46 | $mozuResult = $promise->wait(); |
40 | 47 | $correlation = $mozuResult->correlationId; |
41 | 48 | $orders = $mozuResult->json()->items; |
| 49 | +``` |
42 | 50 |
|
43 | | -<br> |
44 | | -<B>Get Products - Pool multiple requests</B><br> |
45 | | -$productResource = new ProductResource($apiContext, DataViewMode::LIVE);<br> |
46 | | -$promises = [<br> |
| 51 | +###Get Products - Pool multiple requests |
| 52 | +``` |
| 53 | +$productResource = new ProductResource($apiContext, DataViewMode::LIVE); |
| 54 | +$promises = [ |
47 | 55 | "product1" => $this->object->getProductAsync("product1"),<br> |
48 | 56 | "product2" => $this->object->getProductAsync("product2"),<br> |
49 | 57 | "product3" => $this->object->getProductAsync("product3")<br> |
50 | | -];<br> |
51 | | -$results = Promise\unwrap($promises);<br> |
52 | | -printf($results["product1"]->json()->productCode);<br> |
53 | | -printf($results["product2"]->json()->productCode);<br> |
54 | | -printf($results["product3"]->json()->productCode);<br> |
| 58 | +]; |
| 59 | +$results = Promise\unwrap($promises); |
| 60 | +printf($results["product1"]->json()->productCode); |
| 61 | +printf($results["product2"]->json()->productCode); |
| 62 | +printf($results["product3"]->json()->productCode); |
| 63 | +``` |
0 commit comments