// Replace tho following variables with your own key management
// $APPLICATION_ID
// $APPLICATION_KEY
// $USER_ID
// $TOKEN
try {
$appId = $APPLICATION_ID;
$appKey = $APPLICATION_KEY;
$userId = $USER_ID;
$token = $TOKEN;
$restrictedServiceUrl = 'https://api.tradera.com/v3/RestrictedService.asmx';
$restrictedServiceUrlWithAuth = $restrictedServiceUrl
. '?appId=' . $appId
. '&appKey=' . $appKey
. '&userId=' . $userId
. '&token=' . $token;
$restrictedClient = new SoapClient(
$restrictedServiceUrl . '?WSDL',
array('location' => $restrictedServiceUrlWithAuth)
);
// Create shop item data
$title = 'Test item - Do not buy';
$description = 'Test item - Do not buy';
$quantity = 5;
$price = 4321;
$vat = 25;
$shippingOptionPosten = new StdClass();
$shippingOptionPosten -> ShippingOptionId = 1;
$shippingOptionPosten -> Cost = 130;
$shippingOptionPickup = new StdClass();
$shippingOptionPickup -> ShippingOptionId = 8;
$shippingOptionPickup -> Cost = 0;
$myShippingOptions = array($shippingOptionPosten, $shippingOptionPickup);
$paymentOptionCashOnPickup = 32;
$paymentOptionSwish = 4096;
$myPaymentOptions = array($paymentOptionCashOnPickup, $paymentOptionSwish);
$myShippingConditions = 'Shipping conditions';
$myPaymentConditions = 'Payment conditions';
$itemImageNames = array('image123.jpeg');
$itemImages = array();
foreach ($itemImageNames as $key => $itemImageName) {
$itemImageData = new StdClass();
$itemImageData -> Format = 'Jpeg';
$itemImageData -> Data = file_get_contents('images/' . $itemImageName);
$itemImageData -> Name = explode('.', $itemImageName)[0];
$itemImageData -> HasMega = true;
array_push($itemImages, $itemImageData);
}
$shopItem = new StdClass();
$shopItem -> Title = $title;
$shopItem -> Description = $description;
$shopItem -> CategoryId = 344481;
$shopItem -> AcceptedBuyerId = 3; //international
$shopItem -> ShippingOptions = $myShippingOptions;
$shopItem -> PaymentOptionIds = $myPaymentOptions;
$shopItem -> ItemAttributes = 1; // 1=New, 2= Used
$shopItem -> ShippingCondition = $myShippingConditions;
$shopItem -> PaymentConditions = $myPaymentConditions;
$shopItem -> OwnReferences = array(); // Array of strings
$shopItem -> VAT = $vat; //
$shopItem -> ItemImages = $itemImages;
$shopItem -> ActivateDate = mktime(6, 0, 0, 8, 1, 2015);
$shopItem -> DeactivateDate = mktime(6, 15, 0, 8, 1, 2016);
$shopItem -> Quantity = $quantity;
$shopItem -> ExternalId = array(); // Array of strings
$shopItem -> Price = $price;
$addShopItemParams = new StdClass();
$addShopItemParams -> shopItemData = $shopItem;
// Make Soap call
$addShopItemResult = $restrictedClient->AddShopItem($addShopItemParams);
// Use the requestId to verify the request has been succesful
$requestId = $addShopItemResult -> AddShopItemResult -> RequestId;
// Use the itemId when referencing the item in the future
$itemId = $addShopItemResult -> AddShopItemResult -> ItemId;
sleep(5);
$getReqResultsParams = new StdClass();
$getReqResultsParams -> requestIds -> int = array($requestId);
$requestResult = $restrictedClient -> GetRequestResults($getReqResultsParams);
$result = $requestResult -> GetRequestResultsResult -> RequestResult;
if($result -> ResultCode == 'Ok'){
echo 'SUCCES:' . PHP_EOL . $result -> Message . PHP_EOL;
}
else {
echo 'REQUEST NOT FINISHED:' . $result -> ResultCode . PHP_EOL;
echo $result -> Message;
}
}
catch(SoapFault $soapFault) {
echo 'Error: ' . $soapFault->faultstring;
}
|