浏览代码

Sync default invoice & shipping addresses in PS customer

Mathieu Moulin 10 月之前
父节点
当前提交
866b60f9c5
共有 2 个文件被更改,包括 38 次插入0 次删除
  1. 14 0
      src/sync/customer/common.inc.php
  2. 24 0
      src/sync/customer/dp.inc.php

+ 14 - 0
src/sync/customer/common.inc.php

@@ -19,6 +19,15 @@ const D_REF_LENGTH = 6;
 const D_REF_DATE = true;
 protected static $nb;
 
+public static function __init()
+{
+	parent::__init();
+
+	if (P_CUSTOMER_DEFAULT_ADDRESSES) {
+		static::_d_type_contact_load();
+	}
+}
+
 function d_data($otype, $oid)
 {
 	$data = [];
@@ -28,6 +37,11 @@ function d_data($otype, $oid)
 	// address
 	$data['socpeople'] = DB::d_get_rows('socpeople', ['fk_soc'=>$oid]);
 
+	// Default addresses
+	if (P_CUSTOMER_DEFAULT_ADDRESSES) {
+		$data['societe_contacts'] = DB::d_get_rows('societe_contacts', ['fk_soc'=>$oid]);
+	}
+
 	return $data;
 }
 

+ 24 - 0
src/sync/customer/dp.inc.php

@@ -98,6 +98,30 @@ public function dp_update_more(&$o, &$p_data_map, &$p_data_map_create, &$p_data,
 			sync::_action('address', 'dp', 'osync', 'socpeople', $rowid);
 		}
 	}
+	
+	if (P_CUSTOMER_DEFAULT_ADDRESSES) {
+		$p_data_map_more['customer'] = [];
+		$shipping_contact_type_id = static::$_d_type_contact_code['commande']['external']['SHIPPING'];
+		$invoice_contact_type_id = static::$_d_type_contact_code['commande']['external']['BILLING'];
+		//var_dump($shipping_contact_type_id);
+		if (!empty($d_data['societe_contacts'])) {
+			foreach ($d_data['societe_contacts'] as $row) {
+				//var_dump($row);
+				if ($row['fk_c_type_contact'] == $shipping_contact_type_id) {
+					//var_dump('yoooo');
+					$p_data_map_more['customer']['default_shipping_address_id'] = static::_dp_map_fk('address', 'socpeople', $row['fk_socpeople']);
+					//var_dump('yoooo');
+				}
+				if ($row['fk_c_type_contact']==$invoice_contact_type_id) {
+					$p_data_map_more['customer']['default_invoice_address_id'] = static::_dp_map_fk('address', 'socpeople', $row['fk_socpeople']);
+				}
+			}
+		}
+		if (!empty($p_data_map_more['customer'])) {
+			var_dump($p_data_map_more['customer']);
+			DB::p_update_row('customer', $p_data_map_more['customer'], ['id_customer'=>$p_id]);
+		}
+	}
 }
 
 // -- MAPPING --