Browse Source

Sync presta module cdcombinationdimensions

Mathieu Moulin 2 months ago
parent
commit
71fe902a75

+ 3 - 0
config/config_defaults.inc.php

@@ -204,6 +204,9 @@ if (!defined("D_K_ECOTAX_PRODUCT"))
 	define('D_K_ECOTAX_PRODUCT', NULL);
 if (!defined("D_ECOTAX_PRODUCT_NAME"))
 	define('D_ECOTAX_PRODUCT_NAME', 'ECOTAX');
+// Gestion dimensions sur déclinaisons
+if (!defined('P_PRODUCT_CDC_DIMENSIONS'))
+	define('P_PRODUCT_CDC_DIMENSIONS', false);
 
 // Prix public
 if (!defined("PUBLIC_PRICE"))

+ 5 - 0
src/sync/product/common.inc.php

@@ -163,6 +163,11 @@ function p_data($otype, $oid)
 			$data['garantie'] = $row;
 	}
 
+	// Dimensions sur déclinaisons
+	if (P_PRODUCT_CDC_DIMENSIONS && $pa_id) {
+		$data['cdcd_product_combination_dimensions'] = DB::p_get_row('cdcd_product_combination_dimensions', ['id_product'=>$p_id, 'id_product_attribute'=>$pa_id]);
+	}
+
 	return $data;
 }
 

+ 14 - 3
src/sync/product/dp.inc.php

@@ -255,6 +255,11 @@ public function dp_update_combi_more(&$o, &$p_data_map, &$p_data_map_create, &$p
 	DB::p_update_row('product', $p_data_map['product'], ['id_product'=>$p_data['product']['id_product']], $p_data['product']);
 	// product_attribute_shop
 	DB::p_update_row('product_attribute_shop', $p_data_map['product_attribute_shop'], ['id_product_attribute'=>$p_data['product_attribute_shop']['id_product_attribute']], $p_data['product_attribute_shop']);
+	if (P_PRODUCT_CDC_DIMENSIONS) {
+		//var_dump($p_data_map['cdcd_product_combination_dimensions']); die();
+		// cdcd_product_combination_dimensions
+		static::p_update_row('cdcd_product_combination_dimensions', ['id_product'=>$p_data['product']['id_product'], 'id_product_attribute'=>$p_data['product_attribute_shop']['id_product_attribute']], $p_data_map, ['cdcd_product_combination_dimensions'=>['id_product'=>$p_data['product']['id_product'], 'id_product_attribute'=>$p_data['product_attribute_shop']['id_product_attribute']]], $p_data);
+	}
 
 	return $ret;
 }
@@ -612,9 +617,9 @@ public function map_update_combi(&$o, &$d_data, &$p_data=[])
 			//'reference' => '', //$d_data['product']['ref'], // on laisse tel quel, c'est la liste des différentes déclinaisons
 			//'supplier_reference' => '',
 			//'location' => '',
-			'width' => ($d_data['product']['width'] ?$d_data['product']['width'] :0),
-			'height' => ($d_data['product']['height'] ?$d_data['product']['height'] :0),
-			'depth' => ($d_data['product']['length'] ?$d_data['product']['length'] :0),
+			'width' => (!P_PRODUCT_CDC_DIMENSIONS && $d_data['product']['width'] ?$d_data['product']['width'] :0),
+			'height' => (!P_PRODUCT_CDC_DIMENSIONS && $d_data['product']['height'] ?$d_data['product']['height'] :0),
+			'depth' => (!P_PRODUCT_CDC_DIMENSIONS && $d_data['product']['length'] ?$d_data['product']['length'] :0),
 			'weight' => 0,
 			//'out_of_stock' => '0',
 			//'additional_delivery_times' => '0',
@@ -726,6 +731,12 @@ public function map_update_combi(&$o, &$d_data, &$p_data=[])
 		//$p_map_data['product']['supplier_direct_delivery_available'] = $d_data['product_extrafields']['supplier_direct_delivery'];
 	}
 
+	if (P_PRODUCT_CDC_DIMENSIONS) {
+		$p_data_map['cdcd_product_combination_dimensions']['width'] = ($d_data['product']['width'] ?$d_data['product']['width'] :0);
+		$p_data_map['cdcd_product_combination_dimensions']['height'] = ($d_data['product']['height'] ?$d_data['product']['height'] :0);
+		$p_data_map['cdcd_product_combination_dimensions']['depth'] = ($d_data['product']['length'] ?$d_data['product']['length'] :0);
+	}
+
 	return $p_data_map;
 }
 

+ 4 - 4
src/sync/product/pd.inc.php

@@ -436,11 +436,11 @@ public function pd_map_update_combi(&$o, &$p_data, &$d_data=[])
 			'tva_tx' => $tva_tx,
 			'weight' => PD_UNIT_UPDATE || empty($d_data['product']['weight']) ?round($p_data['product']['weight']+$p_data['product_attribute']['weight'], 5) :$d_data['product']['weight'],
 			'weight_units' => PD_UNIT_UPDATE || empty($d_data['product']['weight_units']) ?static::$_d_units_code['KG'] :$d_data['product']['weight_units'],
-			'length' => PD_UNIT_UPDATE || empty($d_data['product']['length']) ?$p_data['product']['depth'] :$d_data['product']['length'],
+			'length' => PD_UNIT_UPDATE || empty($d_data['product']['length']) ?(!empty($p_data['cdcd_product_combination_dimensions']['depth']) ?$p_data['cdcd_product_combination_dimensions']['depth'] :$p_data['product']['depth']) :$d_data['product']['length'],
 			'length_units' => PD_UNIT_UPDATE || empty($d_data['product']['length_units']) ?static::$_d_units_code['CM'] :$d_data['product']['length_units'],
-			'width' => PD_UNIT_UPDATE || empty($d_data['product']['width']) ?$p_data['product']['width'] :$d_data['product']['width'],
+			'width' => PD_UNIT_UPDATE || empty($d_data['product']['width']) ?(!empty($p_data['cdcd_product_combination_dimensions']['width']) ?$p_data['cdcd_product_combination_dimensions']['width'] :$p_data['product']['width']) :$d_data['product']['width'],
 			'width_units' => PD_UNIT_UPDATE || empty($d_data['product']['width_units']) ?static::$_d_units_code['CM'] :$d_data['product']['width_units'],
-			'height' => PD_UNIT_UPDATE || empty($d_data['product']['height']) ?$p_data['product']['height'] :$d_data['product']['height'],
+			'height' => PD_UNIT_UPDATE || empty($d_data['product']['height']) ?(!empty($p_data['cdcd_product_combination_dimensions']['height']) ?$p_data['cdcd_product_combination_dimensions']['height'] :$p_data['product']['height']) :$d_data['product']['height'],
 			'height_units' => PD_UNIT_UPDATE || empty($d_data['product']['height_units']) ?static::$_d_units_code['CM'] :$d_data['product']['height_units'],
 			'barcode' => static::_pd_map_barcode($p_data),
 			'fk_barcode_type' => static::_pd_map_barcode_type($p_data),
@@ -508,7 +508,7 @@ public function pd_map_update_combi(&$o, &$p_data, &$d_data=[])
 
 	if (PRODUCT_FIELD_DECLI_DISABLED)
 		$d_data_map['product_extrafields']['p_decli_disabled'] = !empty($p_data['tot_switch_attribute_disabled']) ?1 :NULL;
-	
+
 	return $d_data_map;
 }