// limits for some types, if we don't respect the limitations, it will no work when sending request to envoimoinscher
//
if($sending_type == 'pli') {
$limitation = array(
'hauteur' => 2,
'poids' => 3
);
}
else if ($sending_type == 'colis')
{
$limitation = array(
'poids' => 70,
);
}
$j = 1;
$data[$j]['poids'] = 0;
$data[$j]['hauteur'] = 0;
$data[$j]['longueur'] = 0;
$data[$j]['largeur'] = 0;
foreach($order->products as $product){
if($product->product_parent_id == 0){
if(isset($product->variants)){
foreach($product->variants as $variant){
for($i=0;$i<$variant->cart_product_quantity;$i++){
$caracs["poids"] = $weightClass->convert($variant->product_weight_orig, $variant->product_weight_unit_orig, 'kg');
if($package == true)
$caracs["poids"] += $caracs["poids"]*(float)$weight_pack/100;
else
$caracs["poids"] += (float)0.1;
$caracs["longueur"] = $volumeClass->convert($variant->product_length, $variant->product_dimension_unit_orig, 'cm', 'dimension' );
$caracs["largeur"] = $volumeClass->convert($variant->product_width, $variant->product_dimension_unit_orig, 'cm', 'dimension' );
//if($sending_type != "pli")
$caracs["hauteur"] = $volumeClass->convert($variant->product_height, $variant->product_dimension_unit_orig, 'cm' , 'dimension');
$tmpHeight = $data[$j]['hauteur'] + round($caracs['hauteur'],2);
$tmpLength = $data[$j]['longueur'] + round($caracs['longueur'],2);
$tmpWidth = $data[$j]['largeur'] + round($caracs['largeur'],2);
$dim = $tmpLength+2*$tmpWidth+2*$tmpHeight;
$x = min($caracs['largeur'],$caracs['hauteur'],$caracs['longueur']);
if($x == $caracs['largeur']){
$y = min($caracs['hauteur'],$caracs['longueur']);
if($y == $caracs['hauteur']) $z = $caracs['longueur'];
else $z = $caracs['hauteur'];
}
if($x == $caracs['hauteur']){
$y = min($caracs['largeur'],$caracs['longueur']);
if($y == $caracs['largeur']) $z = $caracs['longueur'];
else $z = $caracs['largeur'];
}
if($x == $caracs['longueur']){
$y = min($caracs['hauteur'],$caracs['largeur']);
if($y == $caracs['hauteur']) $z = $caracs['largeur'];
else $z = $caracs['hauteur'];
}
if($sending_type == "pli"){
if(($data[$j]['poids'] + round($caracs['poids'],2) >= $limitation['poids'] || $data[$j]['hauteur'] > $limitation['hauteur']) && $data[$j]['longueur'] != 0){
//we create a new package if dimensions or weight exceed limitations
$j++;
$data[$j]['poids'] = round($caracs['poids'],2);
$data[$j]['largeur'] = $y;
$data[$j]['longueur'] = $z;
$data[$j]['hauteur'] = $x;
$price_total += $variant->prices[0]->unit_price->price_value_with_tax;
}
else{
$data[$j]['poids'] += round($caracs['poids'],2);
$data[$j]['largeur'] = max($data[$j]['largeur'],$y);
$data[$j]['longueur'] = max($data[$j]['longueur'],$z);
$data[$j]['hauteur'] += $x;
$price_total += $variant->prices[0]->unit_price->price_value_with_tax;
}
}
else if($sending_type == "colis"){
if(($data[$j]['poids'] + round($caracs['poids'],2) >= $limitation['poids']) && $data[$j]['longueur'] != 0){
$j++;
$data[$j]['poids'] = round($caracs['poids'],2);
$data[$j]['hauteur'] = $y;
$data[$j]['longueur'] = $z;
$data[$j]['largeur'] = $x;
$price_total += $variant->prices[0]->unit_price->price_value_with_tax;
}
else{
$data[$j]['poids'] += round($caracs['poids'],2);
$data[$j]['hauteur'] = max($data[$j]['hauteur'],$y);
$data[$j]['longueur'] = max($data[$j]['longueur'],$z);
$data[$j]['largeur'] += $x;
$price_total += $variant->prices[0]->unit_price->price_value_with_tax;
}
}
else{
$data[$j]['poids'] += round($caracs['poids'],2);
$data[$j]['hauteur'] = max($data[$j]['hauteur'],$y);
$data[$j]['longueur'] = max($data[$j]['longueur'],$z);
$data[$j]['largeur'] += $x;
$price_total += $variant->prices[0]->unit_price->price_value_with_tax;
}
}
}
}
//if product isn't a variant
else{
for($i=0;$i<$product->cart_product_quantity;$i++){
$caracs["poids"] = $weightClass->convert($product->product_weight_orig, $product->product_weight_unit_orig, 'kg');
if($package == true)
$caracs["poids"] += $caracs["poids"]*(float)$weight_pack/100;
else
$caracs["poids"] += (float)0.1;
$caracs["longueur"] = $volumeClass->convert($product->product_length, $product->product_dimension_unit_orig, 'cm', 'dimension' );
$caracs["largeur"] = $volumeClass->convert($product->product_width, $product->product_dimension_unit_orig, 'cm', 'dimension' );
//if($sending_type != "pli")
$caracs["hauteur"] = $volumeClass->convert($product->product_height, $product->product_dimension_unit_orig, 'cm' , 'dimension');
$x = min($caracs['largeur'],$caracs['hauteur'],$caracs['longueur']);
if($x == $caracs['largeur']){
$y = min($caracs['hauteur'],$caracs['longueur']);
if($y == $caracs['hauteur']) $z = $caracs['longueur'];
else $z = $caracs['hauteur'];
}
if($x == $caracs['hauteur']){
$y = min($caracs['largeur'],$caracs['longueur']);
if($y == $caracs['largeur']) $z = $caracs['longueur'];
else $z = $caracs['largeur'];
}
if($x == $caracs['longueur']){
$y = min($caracs['hauteur'],$caracs['largeur']);
if($y == $caracs['hauteur']) $z = $caracs['largeur'];
else $z = $caracs['hauteur'];
}
$tmpHeight = $data[$j]['hauteur'] + round($caracs['hauteur'],2);
$tmpLength = $data[$j]['longueur'] + round($caracs['longueur'],2);
$tmpWidth = $data[$j]['largeur'] + round($caracs['largeur'],2);
$dim = $tmpLength+2*$tmpWidth+2*$tmpHeight;
if($sending_type == "pli"){
if(($data[$j]['poids'] + round($caracs['poids'],2) >= $limitation['poids'] || $data[$j]['hauteur'] > $limitation['hauteur']) && $data[$j]['longueur'] != 0){
$j++;
$data[$j]['poids'] = round($caracs['poids'],2);
$data[$j]['largeur'] = $y;
$data[$j]['longueur'] = $z;
$data[$j]['hauteur'] = $x;
$price_total += $product->prices[0]->unit_price->price_value_with_tax;
}
else{
$data[$j]['poids'] += round($caracs['poids'],2);
$data[$j]['largeur'] = max($data[$j]['largeur'],$y);
$data[$j]['longueur'] = max($data[$j]['longueur'],$z);
$data[$j]['hauteur'] += $x;
$price_total += $product->prices[0]->unit_price->price_value_with_tax;
}
}
else if($sending_type == "colis"){
if(($data[$j]['poids'] + round($caracs['poids'],2) >= $limitation['poids']) && $data[$j]['longueur'] != 0){
$j++;
$data[$j]['poids'] = round($caracs['poids'],2);
$data[$j]['hauteur'] = $y;
$data[$j]['longueur'] = $z;
$data[$j]['largeur'] = $x;
$price_total += $product->prices[0]->unit_price->price_value_with_tax;
}
else{
$data[$j]['poids'] += round($caracs['poids'],2);
$data[$j]['hauteur'] = max($data[$j]['hauteur'],$y);
$data[$j]['longueur'] = max($data[$j]['longueur'],$z);
$data[$j]['largeur'] += $x;
$price_total += $product->prices[0]->unit_price->price_value_with_tax;
}
}
else{
$data[$j]['poids'] += round($caracs['poids'],2);
$data[$j]['hauteur'] = max($data[$j]['hauteur'],$y);
$data[$j]['longueur'] = max($data[$j]['longueur'],$z);
$data[$j]['largeur'] += $x;
$price_total += $product->prices[0]->unit_price->price_value_with_tax;
}
}
}
}
}
}
Etre capable de gérer plusieurs colis, ou améliorer la construction des paquets nécessiterait de revoir tout ce code. Donc ce n'est pas une mince affaire.
Mais rien d'impossible. Il suffit d'avoir un développeur pour vous faire cela.