Skip to content

Instantly share code, notes, and snippets.

@Mozu-CS
Created January 14, 2016 19:50
Show Gist options
  • Save Mozu-CS/3e951dcbfdca9787d5cb to your computer and use it in GitHub Desktop.
Save Mozu-CS/3e951dcbfdca9787d5cb to your computer and use it in GitHub Desktop.
Basic Products Request using the Mozu PHP SDK
<?php
var_dump(file_exists("Contracts/AppDev/AppAuthInfo.php"));
require_once('../vendor/autoload.php');
use Mozu\Api\Contracts\AppDev\AppAuthInfo;
use Mozu\Api\MozuConfig;
use Mozu\Api\ApiContext;
use Mozu\Api\DataViewMode;
use Mozu\Api\Security\AppAuthenticator;
use Mozu\Api\Resources\Platform\TenantResource;
use Mozu\Api\Resources\Commerce\Catalog\Storefront\ProductResource;
$tenantId = intval("");
$siteId = intval("");
$appAuthInfo = new AppAuthInfo();
$appAuthInfo->sharedSecret = "";
$appAuthInfo->applicationId = "";
AppAuthenticator::initialize($appAuthInfo);
$appAuthenticator = AppAuthenticator::getInstance();
printf("Access Token : " .$appAuthenticator->getAccessToken());
$apiContext = new ApiContext($tenantId,$siteId,1,1);
$productResource = new ProductResource($apiContext, DataViewMode::LIVE);
$promise = $productResource->getProductsAsync(0, 200, null, null, null, null, null);
$promise->then(function($mozuResult) {
$result = $mozuResult->json();
var_dump($result);
}, function($apiException) {
printf("Exception : code - " . $apiException->getCode() . ", <br/><br/>message - " . $apiException->getMessage(). ", <br/><br/>correlationid - " . $apiException->getCorrelationId() );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment