From cf4d65cea42aef6a046c9b990c2d7d896ee3de67 Mon Sep 17 00:00:00 2001 From: Tanner Moushey Date: Sun, 25 Mar 2018 17:21:15 -0700 Subject: [PATCH 1/3] Reformat default relationships file. fixes #7. fixes #10 --- data/default_relationships.json | 150 ++++++++++++++++---------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/data/default_relationships.json b/data/default_relationships.json index d6c70c2..fe8b851 100644 --- a/data/default_relationships.json +++ b/data/default_relationships.json @@ -4,116 +4,116 @@ "from_object_label":"Order", "to_object":"Contact", "to_object_label":"Contact", - "relationships":"[ - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_last_name\",\"to\":\"LastName\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_first_name\",\"to\":\"FirstName\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_city\",\"to\":\"OtherCity\"}, - {\"source\":\"woocommerce\",\"type\":\"phone\",\"from\":\"billing_phone\",\"to\":\"Phone\"}, - {\"source\":\"woocommerce\",\"type\":\"email\",\"from\":\"billing_email\",\"to\":\"Email\"}, - {\"source\":\"sf-picklist\",\"type\":\"picklist\",\"from\":\"salesforce\",\"to\":\"LeadSource\",\"value\":\"Web\"} - ]", - "required_sf_objects":"[{\"name\":\"Account\",\"label\":\"Account\",\"id\":\"AccountId\"}]", - "unique_sf_fields":"[\"Email\"]" + "relationships":[ + {"source":"woocommerce","type":"string","from":"billing_last_name","to":"LastName"}, + {"source":"woocommerce","type":"string","from":"billing_first_name","to":"FirstName"}, + {"source":"woocommerce","type":"string","from":"billing_city","to":"OtherCity"}, + {"source":"woocommerce","type":"phone","from":"billing_phone","to":"Phone"}, + {"source":"woocommerce","type":"email","from":"billing_email","to":"Email"}, + {"source":"sf-picklist","type":"picklist","from":"salesforce","to":"LeadSource","value":"Web"} + ], + "required_sf_objects":[{"name":"Account","label":"Account","id":"AccountId"}], + "unique_sf_fields":["Email"] }, { "from_object":"Order", "from_object_label":"Order", "to_object":"Account", "to_object_label":"Account", - "relationships":"[ - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_company\",\"to\":\"Name\"}, - {\"source\":\"sf-picklist\",\"type\":\"picklist\",\"from\":\"salesforce\",\"to\":\"Type\",\"value\":\"Customer - Channel\"}, - {\"source\":\"woocommerce\",\"type\":\"textarea\",\"from\":\"billing_address_1\",\"to\":\"BillingStreet\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_city\",\"to\":\"BillingCity\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_state\",\"to\":\"BillingState\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_postcode\",\"to\":\"BillingPostalCode\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_country\",\"to\":\"BillingCountry\"}, - {\"source\":\"woocommerce\",\"type\":\"textarea\",\"from\":\"shipping_address_1\",\"to\":\"ShippingStreet\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"shipping_city\",\"to\":\"ShippingCity\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"shipping_state\",\"to\":\"ShippingState\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"shipping_postcode\",\"to\":\"ShippingPostalCode\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"shipping_country\",\"to\":\"ShippingCountry\"}, - {\"source\":\"woocommerce\",\"type\":\"phone\",\"from\":\"billing_phone\",\"to\":\"Phone\"}, - {\"source\":\"sf-picklist\",\"type\":\"picklist\",\"from\":\"salesforce\",\"to\":\"Industry\",\"value\":\"Other\"}, - {\"source\":\"sf-picklist\",\"type\":\"picklist\",\"from\":\"salesforce\",\"to\":\"Rating\",\"value\":\"Warm\"}, - {\"source\":\"sf-picklist\",\"type\":\"picklist\",\"from\":\"salesforce\",\"to\":\"AccountSource\",\"value\":\"Web\"} - ]", - "required_sf_objects":"[]", - "unique_sf_fields":"[\"Name\"]" + "relationships":[ + {"source":"woocommerce","type":"string","from":"billing_company","to":"Name"}, + {"source":"sf-picklist","type":"picklist","from":"salesforce","to":"Type","value":"Customer - Channel"}, + {"source":"woocommerce","type":"textarea","from":"billing_address_1","to":"BillingStreet"}, + {"source":"woocommerce","type":"string","from":"billing_city","to":"BillingCity"}, + {"source":"woocommerce","type":"string","from":"billing_state","to":"BillingState"}, + {"source":"woocommerce","type":"string","from":"billing_postcode","to":"BillingPostalCode"}, + {"source":"woocommerce","type":"string","from":"billing_country","to":"BillingCountry"}, + {"source":"woocommerce","type":"textarea","from":"shipping_address_1","to":"ShippingStreet"}, + {"source":"woocommerce","type":"string","from":"shipping_city","to":"ShippingCity"}, + {"source":"woocommerce","type":"string","from":"shipping_state","to":"ShippingState"}, + {"source":"woocommerce","type":"string","from":"shipping_postcode","to":"ShippingPostalCode"}, + {"source":"woocommerce","type":"string","from":"shipping_country","to":"ShippingCountry"}, + {"source":"woocommerce","type":"phone","from":"billing_phone","to":"Phone"}, + {"source":"sf-picklist","type":"picklist","from":"salesforce","to":"Industry","value":"Other"}, + {"source":"sf-picklist","type":"picklist","from":"salesforce","to":"Rating","value":"Warm"}, + {"source":"sf-picklist","type":"picklist","from":"salesforce","to":"AccountSource","value":"Web"} + ], + "required_sf_objects":[], + "unique_sf_fields":["Name"] }, { "from_object":"Order", "from_object_label":"Order", "to_object":"Order", "to_object_label":"Order", - "relationships":"[ - {\"source\":\"woocommerce\",\"type\":\"date\",\"from\":\"order_date\",\"to\":\"EffectiveDate\"}, - {\"source\":\"sf-picklist\",\"type\":\"picklist\",\"from\":\"salesforce\",\"to\":\"Status\",\"value\":\"Draft\"}, - {\"source\":\"woocommerce\",\"type\":\"textarea\",\"from\":\"custom\",\"to\":\"Description\",\"value\":null}, - {\"source\":\"woocommerce\",\"type\":\"textarea\",\"from\":\"billing_address_1\",\"to\":\"BillingStreet\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_city\",\"to\":\"BillingCity\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_state\",\"to\":\"BillingState\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_postcode\",\"to\":\"BillingPostalCode\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"billing_country\",\"to\":\"BillingCountry\"}, - {\"source\":\"woocommerce\",\"type\":\"textarea\",\"from\":\"shipping_address_1\",\"to\":\"ShippingStreet\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"shipping_city\",\"to\":\"ShippingCity\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"shipping_state\",\"to\":\"ShippingState\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"shipping_country\",\"to\":\"ShippingCountry\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"order_key\",\"to\":\"Name\"} - ]", - "required_sf_objects":"[{\"name\":\"Account\",\"label\":\"Account\",\"id\":\"AccountId\"},{\"name\":\"Pricebook2\",\"label\":\"Price Book\",\"id\":\"Pricebook2Id\"}]", - "unique_sf_fields":"[\"\"]" + "relationships":[ + {"source":"woocommerce","type":"date","from":"order_date","to":"EffectiveDate"}, + {"source":"sf-picklist","type":"picklist","from":"salesforce","to":"Status","value":"Draft"}, + {"source":"woocommerce","type":"textarea","from":"custom","to":"Description","value":null}, + {"source":"woocommerce","type":"textarea","from":"billing_address_1","to":"BillingStreet"}, + {"source":"woocommerce","type":"string","from":"billing_city","to":"BillingCity"}, + {"source":"woocommerce","type":"string","from":"billing_state","to":"BillingState"}, + {"source":"woocommerce","type":"string","from":"billing_postcode","to":"BillingPostalCode"}, + {"source":"woocommerce","type":"string","from":"billing_country","to":"BillingCountry"}, + {"source":"woocommerce","type":"textarea","from":"shipping_address_1","to":"ShippingStreet"}, + {"source":"woocommerce","type":"string","from":"shipping_city","to":"ShippingCity"}, + {"source":"woocommerce","type":"string","from":"shipping_state","to":"ShippingState"}, + {"source":"woocommerce","type":"string","from":"shipping_country","to":"ShippingCountry"}, + {"source":"woocommerce","type":"string","from":"order_key","to":"Name"} + ], + "required_sf_objects":[{"name":"Account","label":"Account","id":"AccountId"},{"name":"Pricebook2","label":"Price Book","id":"Pricebook2Id"}], + "unique_sf_fields":[""] }, { "from_object":"Order Product", "from_object_label":"Order Product", "to_object":"Product2", "to_object_label":"Product", - "relationships":"[ - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"name\",\"to\":\"Name\"}, - {\"source\":\"woocommerce\",\"type\":\"string\",\"from\":\"sku\",\"to\":\"ProductCode\"}, - {\"source\":\"woocommerce\",\"type\":\"textarea\",\"from\":\"description\",\"to\":\"Description\"}, - {\"source\":\"custom\",\"type\":\"boolean\",\"from\":\"custom\",\"to\":\"IsActive\",\"value\":\"true\"} - ]", - "required_sf_objects":"[]", - "unique_sf_fields":"[\"Name\",\"ProductCode\"]" + "relationships":[ + {"source":"woocommerce","type":"string","from":"name","to":"Name"}, + {"source":"woocommerce","type":"string","from":"sku","to":"ProductCode"}, + {"source":"woocommerce","type":"textarea","from":"description","to":"Description"}, + {"source":"custom","type":"boolean","from":"custom","to":"IsActive","value":"true"} + ], + "required_sf_objects":[], + "unique_sf_fields":["Name","ProductCode"] }, { "from_object":"Order Product", "from_object_label":"Order Product", "to_object":"PricebookEntry", "to_object_label":"Pricebook Entry", - "relationships":"[ - {\"source\":\"woocommerce\",\"type\":\"currency\",\"from\":\"regular_price\",\"to\":\"UnitPrice\"}, - {\"source\":\"custom\",\"type\":\"boolean\",\"from\":\"custom\",\"to\":\"IsActive\",\"value\":\"true\"} - ]", - "required_sf_objects":"[{\"name\":\"Pricebook2\",\"label\":\"Pricebook2\",\"id\":\"Pricebook2Id\"},{\"name\":\"Product2\",\"label\":\"Product2\",\"id\":\"Product2Id\"}]", - "unique_sf_fields":"[\"\"]" + "relationships":[ + {"source":"woocommerce","type":"currency","from":"regular_price","to":"UnitPrice"}, + {"source":"custom","type":"boolean","from":"custom","to":"IsActive","value":"true"} + ], + "required_sf_objects":[{"name":"Pricebook2","label":"Pricebook2","id":"Pricebook2Id"},{"name":"Product2","label":"Product2","id":"Product2Id"}], + "unique_sf_fields":[""] }, { "from_object":"Order Product", "from_object_label":"Order Product", "to_object":"OrderItem", "to_object_label":"Order Item", - "relationships":"[ - {\"source\":\"woocommerce\",\"type\":\"double\",\"from\":\"qty\",\"to\":\"Quantity\"}, - {\"source\":\"woocommerce\",\"type\":\"currency\",\"from\":\"sale_price\",\"to\":\"UnitPrice\"}, - {\"source\":\"custom\",\"type\":\"date\",\"from\":\"custom\",\"to\":\"ServiceDate\",\"value\":\"current\"}, - {\"source\":\"custom\",\"type\":\"string\",\"from\":\"custom\",\"to\":\"Description\",\"value\":\"From testing site\"} - ]", - "required_sf_objects":"[{\"name\":\"PricebookEntry\",\"label\":\"PricebookEntry\",\"id\":\"PricebookEntryId\"},{\"name\":\"Order\",\"label\":\"Order\",\"id\":\"OrderId\"}]", - "unique_sf_fields":"[\"\"]" + "relationships":[ + {"source":"woocommerce","type":"double","from":"qty","to":"Quantity"}, + {"source":"woocommerce","type":"currency","from":"sale_price","to":"UnitPrice"}, + {"source":"custom","type":"date","from":"custom","to":"ServiceDate","value":"current"}, + {"source":"custom","type":"string","from":"custom","to":"Description","value":"From testing site"} + ], + "required_sf_objects":[{"name":"PricebookEntry","label":"PricebookEntry","id":"PricebookEntryId"},{"name":"Order","label":"Order","id":"OrderId"}], + "unique_sf_fields":[""] }, { "from_object":"Order", "from_object_label":"Order", "to_object":"Pricebook2", "to_object_label":"Price Book", - "relationships":"[ - {\"source\":\"custom\",\"type\":\"string\",\"from\":\"custom\",\"to\":\"Name\",\"value\":\"WooCommerce price book\"}, - {\"source\":\"custom\",\"type\":\"boolean\",\"from\":\"custom\",\"to\":\"IsActive\",\"value\":\"true\"} - ]", - "required_sf_objects":"[]", - "unique_sf_fields":"[\"Name\"]" + "relationships":[ + {"source":"custom","type":"string","from":"custom","to":"Name","value":"WooCommerce price book"}, + {"source":"custom","type":"boolean","from":"custom","to":"IsActive","value":"true"} + ], + "required_sf_objects":[], + "unique_sf_fields":["Name"] } ] From d4b2e35ca5954c3eed33794f4e619ec45efc1ff7 Mon Sep 17 00:00:00 2001 From: Tanner Moushey Date: Sun, 25 Mar 2018 17:42:56 -0700 Subject: [PATCH 2/3] json_encode default relationships to avoide processing them --- neuralab-woocommerce-salesforce-integration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuralab-woocommerce-salesforce-integration.php b/neuralab-woocommerce-salesforce-integration.php index 1cf0cca..566e2d0 100644 --- a/neuralab-woocommerce-salesforce-integration.php +++ b/neuralab-woocommerce-salesforce-integration.php @@ -114,7 +114,7 @@ public static function install() { if ( !empty( $relationships ) ) { foreach( $relationships as $relationship ) { $db->save_new_relationship( $relationship->from_object, $relationship->from_object_label, - $relationship->to_object, $relationship->to_object_label, $relationship->relationships, + $relationship->to_object, $relationship->to_object_label, json_encode( $relationship->relationships ), $relationship->required_sf_objects, $relationship->unique_sf_fields ); } } From 2ae1a5566d597ab5a36687caf0b6a575ea91f016 Mon Sep 17 00:00:00 2001 From: Tanner Moushey Date: Sun, 25 Mar 2018 17:48:23 -0700 Subject: [PATCH 3/3] json encode required_sf_objects and unique_sf_fields as well --- neuralab-woocommerce-salesforce-integration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neuralab-woocommerce-salesforce-integration.php b/neuralab-woocommerce-salesforce-integration.php index 566e2d0..67cbdb1 100644 --- a/neuralab-woocommerce-salesforce-integration.php +++ b/neuralab-woocommerce-salesforce-integration.php @@ -115,7 +115,7 @@ public static function install() { foreach( $relationships as $relationship ) { $db->save_new_relationship( $relationship->from_object, $relationship->from_object_label, $relationship->to_object, $relationship->to_object_label, json_encode( $relationship->relationships ), - $relationship->required_sf_objects, $relationship->unique_sf_fields ); + json_encode( $relationship->required_sf_objects ), json_encode( $relationship->unique_sf_fields ) ); } } }