Get Orders from External Ressource

Hi!
I would like to create a simple plugin-connector with OTTO marketplace. 

The Idea is to post the products from a stream with the special name in to OTTO Markeplace via API and then get orders from OTTO into Shopware.

Actually, I am getting the orders data from OTTO sandbox (Demo orders) via API with Curl.

The response with one order looks like this:

{
	{
	   "salesOrderId":"e439b68e-0e27-4475-8f6f-b2ffaf5529f8",
	   "orderNumber":"bk22dvtvdm",
	   "orderDate":"2020-07-23T08:29:54.711+0000",
	   "lastModifiedDate":"2020-07-23T10:29:55.557+0000",
	   "positionItems":{
		  0:{
			 "positionItemId":"ccfd90cd-cf9d-4991-b758-bff29afc1992",
			 "fulfillmentStatus":"ANNOUNCED",
			 "itemValueGrossPrice":{
				"amount":"499.99",
				"currency":"EUR"
			 },
			 "product":{
				"sku":"SmartCM1000-schwarz-1",
				"productTitle":"Smartphone »CallMe 1000«",
				"articleNumber":"S0A000SP28AP2",
				"ean":"4851278936452",
				"vatRate":"19.0"
			 },
			 "trackingInfo":"",
			 "sentDate":""
		  },
		  1:{
			 "positionItemId":"38109946-15ca-4c9e-828d-9c8de1c091ed",
			 "fulfillmentStatus":"ANNOUNCED",
			 "itemValueGrossPrice":{
				"amount":"499.99",
				"currency":"EUR"
			 },
			 "product":{
				"sku":"SmartCM1000-schwarz-1",
				"productTitle":"Smartphone »CallMe 1000«",
				"articleNumber":"S0A000SP28AP2",
				"ean":"4851278936452",
				"vatRate":"19.0"
			 },
			 "trackingInfo":"",
			 "sentDate":""
		  },
		  2:{
			 "positionItemId":"808053a1-89e1-4775-84bb-8f608fad2912",
			 "fulfillmentStatus":"ANNOUNCED",
			 "itemValueGrossPrice":{
				"amount":"250",
				"currency":"EUR"
			 },
			 "product":{
				"sku":"0440-Rasen-T-V1",
				"productTitle":"Rasenmaeher »Turbo V1«",
				"articleNumber":"S0C456SP44CP2",
				"ean":"9821393948573",
				"vatRate":"19.0"
			 },
			 "trackingInfo":"",
			 "sentDate":""
		  },
		  3:{
			 "positionItemId":"492de58d-7c09-4daf-89d6-a7fc1fffeb3c",
			 "fulfillmentStatus":"ANNOUNCED",
			 "itemValueGrossPrice":{
				"amount":"250",
				"currency":"EUR"
			 },
			 "product":{
				"sku":"0440-Rasen-T-V1",
				"productTitle":"Rasenmaeher »Turbo V1«",
				"articleNumber":"S0C456SP44CP2",
				"ean":"9821393948573",
				"vatRate":"19.0"
			 },
			 "trackingInfo":"",
			 "sentDate":""
		  }
	   },
	   "orderLifecycleInformation":{
		  "lifecycleChangeDate":"2020-07-23T10:29:55.555+0000"
	   },
	   "initialServiceFees":{
		  0:{
			 "name":"DELIVERY_FEE_STANDARD",
			 "amount":"5.95",
			 "currency":"EUR",
			 "positionItemIds":{
				0:"ccfd90cd-cf9d-4991-b758-bff29afc1992",
				1:"38109946-15ca-4c9e-828d-9c8de1c091ed",
				2:"808053a1-89e1-4775-84bb-8f608fad2912",
				3:"492de58d-7c09-4daf-89d6-a7fc1fffeb3c"
			 },
			 "vatRate":"19"
		  }
	   },
	   "deliveryAddress":{
		  "salutation":"MS",
		  "title":"",
		  "lastName":"Sanbox",
		  "firstName":"Kundin",
		  "street":"Werner-Otto-Straße",
		  "addition":"3. Stock",
		  "houseNumber":"7",
		  "city":"Hamburg",
		  "zipCode":"22179",
		  "countryCode":"DEU"
	   },
	   "invoiceAddress":{
		  "salutation":"MR",
		  "title":"Dr.",
		  "lastName":"Sandbox",
		  "firstName":"Kunde",
		  "street":"Werner-Otto-Straße",
		  "addition":"Testkunde",
		  "houseNumber":"1",
		  "city":"Hamburg",
		  "zipCode":"22179",
		  "countryCode":"DEU"
	   },
	   "links":{
		  0:{
			 "rel":"self",
			 "href":"/v3/orders/e439b68e-0e27-4475-8f6f-b2ffaf5529f8"
		  }
	   }
	},

}

My Idea was to insert orders from OTTO in s_orders table on Shopware. Then after status change to update the order data in OTTO… 

When the order is created in Shopware, first is created a new user and the order is attached to this user.

How should I do with OTTO orders? Should I first extract from API response the new user data and insert in SW s_user then insert order data connected to this user? And what to do with data which are requested in SW for an order but are missing in OTTO response? The SW table does not accept empty values.

So, I tried today to insert orders to Shopware via API using file client.php, how is explained in the book “SW Das handbuch fur Entwicller” page 293. It works but I inserted hard coded data:

require 'client.php';

$client = new ApiClient(
  'http://shopware567.loc/api',
  'admin',
  'nUeRFUr998dE8lD2xXF0QzPbJbOLFuAroingElhJ'
);

$result = $client->call(
  'orders',
  'POST',
  [
    'changed' => '2020-07-28T10:25:45+0200',
    'number' => '20003',
    'customerId' => '1',
    'paymentId' => '5',
    'dispatchId' => '9',
    'partnerId' => '',
    'shopId' => '1',
    'invoiceAmount' => '350',
    'invoiceAmountNet' => '340',
    'invoiceShipping' => '6',
    'invoiceShippingNet' => '8',
    'invoiceShippingTaxRate' => '5',
    'orderTime' => '2020-07-23T10:00:05+0200',
    'transactionId' => '',
    'comment' => '',
    'customerComment' => '',
    'internalComment' => '',
    'net' => '0',
    'taxFree' => '0',
    'temporaryId' => '',
    'referer' => '',
    'clearedDate' => '2020-07-23T10:00:05+0200',
    'trackingCode' => '',
    'languageIso' => '1',
    'currency' => 'EUR',
    'currencyFactor' => '1',
    'remoteAddress' => '',
    'deviceType' => '',
    'isProportionalCalculation' => '',
    'attribute' => [
      'id' => '2',
      'orderId' => '2',
      'attribute1' => '',
      'attribute2' => '',
      'attribute3' => '',
      'attribute4' => '',
      'attribute5' => '',
      'attribute6' => ''
    ],
    'customer' => [
      'id' => '1',
      'email' => 'my-email@mail.com'
    ],
    'paymentStatusId' => '13',
    'orderStatusId' => '1',
    'billing' => [
      'countryId' => '2'
    ],
    'shipping' => [
      'countryId' => '2'
    ],
  ],

);

I copied the GET response and created the POST request with the same data structure but could not post because some parameters like billing, shippint where missing. I added them and succeeded to post. 
Now, how to fill the data structure for POST request with real data from OTTO response? Some necessary dada is possilbe to extract but some are not present or have different format. For example in OTTO the order number is like this “bk22dvtvdm”, in Shopware looks like this “20003”?

Some Marketplaces have their marketplace-ordernumber and you can sometimes have your own ordernumber (which is often called “own ordernumber” surprisingly) in parallel.

1 „Gefällt mir“

@brettvormkopp schrieb:

Some Marketplaces have their marketplace-ordernumber and you can sometimes have your own ordernumber (which is often called „own ordernumber“ surprisingly) in parallel.

Thanks! If such field exists in OTTO order table, then I think it should be visible in the get order response? I don’t see such a parameter in the reponse. 

@anatol06 schrieb:

@brettvormkopp schrieb:

Some Marketplaces have their marketplace-ordernumber and you can sometimes have your own ordernumber (which is often called „own ordernumber“ surprisingly) in parallel.

Thanks! If such field exists in OTTO order table, then I think it should be visible in the get order response? I don’t see such a parameter in the reponse. 

And the orders should come firstly FROM OTTO Marketplace in Shopware. So,  somehow it should be saved into SW database with SW order number and if is possilbe, to save the OTTO order number in SW as own ordernumber…

Sorry, it was an issue to insert such an order number ‘bk22dvtvdm’ with MySQL query but via SW API is possible to store the order with such a number and even without number. 
I am not sure that it is a solution but it works for now :slight_smile:
Now I have to find solutions for all other data.

As I understood, in order to register an order from external ressource in Shopware is necessary first to register a new customer and then attach the order to this customer. The field  “customerId”  in the POST order query is mandatory. 

In Orders response from OTTO there is no cutomer data but could be used the date from ‘invoiceAddress’.  The problme is that there is missing the email address which is mandatory for customer registration in Shopware. 

I am thinking now of creating a single customer for OTTO in Shopware, so that for all OTTO orders will be used just one " cusomerId".  But there will be different data ffor billing and delivery for each order.
Is this a good solution?