Jump to content

Create url from json object


reldridge

Recommended Posts

Ecwid API  - Updating Orders

 

I am going to be creating a script to update order tracking numbers and shipping info from our Fulfillment house.  Our fulfillment system will output an xml file of the order update.

 

I have created the below script to grab the xml file and convert it to json as needed for Ecwid API.

 

I am trying to figure out how to loop through the data and find all order numbers to create the url needed to update each order.

<?php
// The file data.xml contains an XML document with a root element
// and at least an element /[root]/title.

if (file_exists('data.xml')) {
    $xml = simplexml_load_file('data.xml');
 
    print_r($xml);
} else {
    exit('Failed to open data.xml.');
}

$data = json_encode($xml);


foreach ( $data->items as $item )
{
 	$url = "https://app.ecwid.com/api/v3/".urlencode($storeID)."/orders/".$item->orderNumber."?token=".$myToken;
	echo $url;
	}	
	

?>

I am getting no output for $url, and wondering what i may be doing wrong.

 

json output:

{"total":"3","count":"3","offset":"0","limit":"100","items":{"item0":{"vendorOrderNumber":"0137074","subtotal":"45","total":"53.75","email":"zeke1157@comcast.net","externalTransactionId":"5U025416EA256042V","paymentModule":"PayPalStandard","paymentMethod":"PayPal \/ Credit Card","tax":"0","ipAddress":"73.147.160.160","couponDiscount":"0","paymentStatus":"PAID","paymentMessage":"Your order has been approved","fulfillmentStatus":"AWAITING_PROCESSING","orderNumber":"7074","refererUrl":"http:\/\/fvhardmerchandise.com\/shop.php","volumeDiscount":"0","customerId":"24555144","membershipBasedDiscount":"0","totalAndMembershipBasedDiscount":"0","discount":"0","usdTotal":"53.75","globalReferer":"http:\/\/www.google.com\/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&sqi=2&ved=0ahUKEwiD1pjVz8PKAhWEKB4KHV-vAgAQFggiMAE&url=http%3A%2F%2Ffvhardmerchandise.com%2Fshop.php&usg=AFQjCNEhJcEyH-Ff8WNN64j9RvvptSX1tw&bvm=bv.112454388,d.dmo","createDate":"2016-01-24 23:45:55 +0000","updateDate":"2016-01-24 23:46:40 +0000","createTimestamp":"1453679155","updateTimestamp":"1453679200","items":{"item0":{"id":"70650077","productId":"57278799","categoryId":"2455976","price":"45","productPrice":"45","sku":"00135","quantity":"1","shortDescription":"Now Capt. Marciano and the team of the Hard Merchandise are showing their winter camo colors! Shades of black, greys a...","tax":"0","shipping":"8.75","quantityInStock":"3","name":"New! - Winter Black Camo Hard Merchandise Hoodie","isShippingRequired":"1","weight":"2","trackQuantity":"1","fixedShippingRateOnly":{},"imageUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/356535243.jpg","smallThumbnailUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/356535250.jpg","fixedShippingRate":"0","digital":{},"productAvailable":"1","couponApplied":{},"selectedOptions":{"item0":{"name":"Size","value":"2XL","valuesArray":{"item0":"2XL"},"type":"CHOICE"}}}},"billingPerson":{"name":"James Bennett","companyName":{},"street":"276 Teaberry St.","city":"Princeton","countryCode":"US","countryName":"United States","postalCode":"24739","stateOrProvinceCode":"WV","stateOrProvinceName":"West Virginia","phone":"3044250086"},"shippingPerson":{"name":"James Bennett","companyName":{},"street":"276 Teaberry St.","city":"Princeton","countryCode":"US","countryName":"United States","postalCode":"24739","stateOrProvinceCode":"WV","stateOrProvinceName":"West Virginia","phone":"3044250086"},"shippingOption":{"shippingCarrierName":"U.S.P.S.","shippingMethodName":"U.S.P.S. Priority Mail 3-Day\u2122","shippingRate":"8.75","estimatedTransitTime":"1-3"},"handlingFee":{"name":"Handling Fee","value":"0","description":{}},"additionalInfo":{},"paymentParams":{},"hidden":{}},"item1":{"vendorOrderNumber":"0137073","subtotal":"22","total":"38.5","email":"cjuttner04@hotmail.com","externalTransactionId":"4UA97564429585111","paymentModule":"PayPalStandard","paymentMethod":"PayPal \/ Credit Card","tax":"0","ipAddress":"198.53.126.146","couponDiscount":"0","paymentStatus":"PAID","paymentMessage":"Your order has been approved","fulfillmentStatus":"AWAITING_PROCESSING","orderNumber":"7073","refererUrl":"http:\/\/fvhardmerchandise.com\/shop.php","volumeDiscount":"0","customerId":"24526391","membershipBasedDiscount":"0","totalAndMembershipBasedDiscount":"0","discount":"0","usdTotal":"38.5","globalReferer":"https:\/\/www.google.ca\/","createDate":"2016-01-23 16:38:47 +0000","updateDate":"2016-01-23 16:45:34 +0000","createTimestamp":"1453567127","updateTimestamp":"1453567534","items":{"item0":{"id":"70561192","productId":"9673066","categoryId":"2455976","price":"22","productPrice":"22","sku":"00005","quantity":"1","shortDescription":"The original. Worn by Captain Marciano and his First Mate Jay from the very first season of Wicked Tuna , and from the ...","tax":"0","shipping":"16.5","quantityInStock":"184","name":"Black T-Shirt","isShippingRequired":"1","weight":"2","trackQuantity":"1","fixedShippingRateOnly":{},"imageUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/36454966.jpg","smallThumbnailUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/36454968.jpg","fixedShippingRate":"0","digital":{},"productAvailable":"1","couponApplied":{},"selectedOptions":{"item0":{"name":"Size","value":"X-Large","valuesArray":{"item0":"X-Large"},"type":"CHOICE"}}}},"billingPerson":{"name":"Christie J Juttner","companyName":{},"street":"704 - 12A ST NE","city":"Calgary","countryCode":"CA","countryName":"Canada","postalCode":"T2E 4R8","stateOrProvinceCode":"AB","stateOrProvinceName":"Alberta","phone":"4036677751"},"shippingPerson":{"name":"Christie J Juttner","companyName":{},"street":"704 - 12A ST NE","city":"Calgary","countryCode":"CA","countryName":"Canada","postalCode":"T2E 4R8","stateOrProvinceCode":"AB","stateOrProvinceName":"Alberta","phone":"4036677751"},"shippingOption":{"shippingCarrierName":"U.S.P.S.","shippingMethodName":"U.S.P.S. First-Class Package International Service\u2122","shippingRate":"16.5"},"handlingFee":{"name":"Handling Fee","value":"0","description":{}},"additionalInfo":{},"paymentParams":{},"hidden":{}},"item2":{"vendorOrderNumber":"0137072","subtotal":"46","total":"67.05","email":"kady_bug16@yahoo.com","externalTransactionId":"052953609D493691S","paymentModule":"PayPalStandard","paymentMethod":"PayPal \/ Credit Card","tax":"0","ipAddress":"24.156.66.75","couponDiscount":"0","paymentStatus":"PAID","paymentMessage":"Your order has been approved","fulfillmentStatus":"AWAITING_PROCESSING","orderNumber":"7072","refererUrl":"http:\/\/fvhardmerchandise.com\/shop.php","volumeDiscount":"0","customerId":"18235174","membershipBasedDiscount":"0","totalAndMembershipBasedDiscount":"0","discount":"0","usdTotal":"67.05","globalReferer":"https:\/\/www.google.com\/","createDate":"2016-01-23 04:48:59 +0000","updateDate":"2016-01-23 04:50:56 +0000","createTimestamp":"1453524539","updateTimestamp":"1453524656","items":{"item0":{"id":"70529558","productId":"35271535","categoryId":"2455976","price":"24","productPrice":"24","sku":"00352","quantity":"1","shortDescription":"This slightly redesigned shirt from Hard Merchandise now has the CUDA brand knife logo on the back in their awesome whi...","tax":"0","shipping":"7.89375","quantityInStock":"47","name":"Tech Fabric Friends of Hard Merchandise Shirt","isShippingRequired":"1","weight":"1.2","trackQuantity":"1","fixedShippingRateOnly":{},"imageUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/313266743.jpg","smallThumbnailUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/313266748.jpg","fixedShippingRate":"0","digital":{},"productAvailable":"1","couponApplied":{},"selectedOptions":{"item0":{"name":"Size","value":"XX- Large","valuesArray":{"item0":"XX- Large"},"type":"CHOICE"}}},"item1":{"id":"70529559","productId":"9673066","categoryId":"2455976","price":"22","productPrice":"22","sku":"00006","quantity":"1","shortDescription":"The original. Worn by Captain Marciano and his First Mate Jay from the very first season of Wicked Tuna , and from the ...","tax":"0","shipping":"13.15625","quantityInStock":"82","name":"Black T-Shirt","isShippingRequired":"1","weight":"2","trackQuantity":"1","fixedShippingRateOnly":{},"imageUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/36454966.jpg","smallThumbnailUrl":"https:\/\/dpbfm6h358sh7.cloudfront.net\/images\/1039296\/36454968.jpg","fixedShippingRate":"0","digital":{},"productAvailable":"1","couponApplied":{},"selectedOptions":{"item0":{"name":"Size","value":"2X-Large","valuesArray":{"item0":"2X-Large"},"type":"CHOICE"}}}},"billingPerson":{"name":"Katie Bardonne","companyName":{},"street":"Po Box 65","city":"Big Pine","countryCode":"US","countryName":"United States","postalCode":"93513","stateOrProvinceCode":"CA","stateOrProvinceName":"California","phone":"7609383141"},"shippingPerson":{"name":"Katie Bardonne","companyName":{},"street":"261 Hall St\nPo Box 65","city":"Big Pine","countryCode":"US","countryName":"United States","postalCode":"93513","stateOrProvinceCode":"CA","stateOrProvinceName":"California","phone":"7609383141"},"shippingOption":{"shippingCarrierName":"U.S.P.S.","shippingMethodName":"U.S.P.S. Priority Mail 3-Day\u2122","shippingRate":"21.05","estimatedTransitTime":"1-3"},"handlingFee":{"name":"Handling Fee","value":"0","description":{}},"additionalInfo":{},"paymentParams":{},"hidden":{}}}}
Link to comment
Share on other sites

$data is a string. You can't do ->items on it.

Ahh, Thanks requinix.

 

 I had to decode the json data to work within the foreach loop.

// Encode XML to JSON
$data = json_encode($xml);

// Decode json for below array to create 'PUT' URLs
$json_obj = json_decode($data, true);

foreach ($json_obj['items'] as $item) {
	$url = "https://app.ecwid.com/api/v3/".urlencode($storeID)."/orders/".$item['orderNumber']."?token=".$myToken;
	echo "<pre>";
	print_r($url);
} 
Edited by reldridge
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.