Fixed finding orders in ivt import

This commit is contained in:
Frank Schubert
2024-07-08 12:18:43 +02:00
parent 14d3b65d50
commit 66d0a70481

View File

@@ -429,6 +429,7 @@ class Admin_IvtContractImport {
}
if(array_key_exists($owner->id, $this->ownerIdToBillingAddress)) {
//echo "1 produkt: '".$product->name."': Billingaddress id: ".$this->ownerIdToBillingAddress[$owner->id]."\n";
return ["billingaddress_id" => $this->ownerIdToBillingAddress[$owner->id]];
}
@@ -449,11 +450,13 @@ class Admin_IvtContractImport {
$billingaddress = new Address($order->billingaddress_id);
if (!$billingaddress->id) {
die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)");
die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)\n");
}
$compare_address = $billingaddress;
$compare_type = "billingaddress";
//echo "setting compare_type = billingaddress\n";
//var_dump($order);
}
@@ -467,6 +470,8 @@ class Admin_IvtContractImport {
$address_update = $this->compareBillingAddresses($ivt_customer, $compare_address);
if($address_update === true) {
//echo "addressupdate == true; compare type: $compare_type\n";
//var_dump($address_update);
$return["billingaddress_id"] = $compare_address->id;
} elseif(is_array($address_update) && count($address_update)) {
if($compare_type == "billingaddress") {
@@ -476,15 +481,17 @@ class Admin_IvtContractImport {
die("error updateing Billingaddress");
}
$this->ownerIdToBillingAddress[$owner->id] = $compare_address->id;
//echo "address_update has data\n";
$return["billingaddress_id"] = $compare_address->id;
} else {
// create billingaddress
$billingaddress = AddressModel::create($address_update);
try {
if(!$billingaddress->save()) {
var_dump($address_update);
//var_dump($address_update);
die("error creating Billingaddress");
}
//echo "create billingaddress\n";
$return["billingaddress_id"] = $billingaddress->id;
if(!array_key_exists($owner->id, $this->ownerIdToBillingAddress)) {
$this->ownerIdToBillingAddress[$owner->id] = $billingaddress->id;
@@ -505,7 +512,7 @@ class Admin_IvtContractImport {
} catch (Exception $e) {
echo "Exception: ".$e->getMessage()."\n";
var_dump($address_update);
//var_dump($address_update);
exit();
}
@@ -513,6 +520,7 @@ class Admin_IvtContractImport {
}
//echo "2 produkt: '".$product->name."': Billingaddress id: ".$return["billingaddress_id"]."\n";
return $return;
}
@@ -819,6 +827,7 @@ class Admin_IvtContractImport {
if(!$order->id) {
die("Manually specified order id ".$this->static_ivt_order_match[$ivt_contract->id]." not found for customer ".$ivt_customer->id);
}
//echo "order 1\n";
return $order;
} else {
$order_count = OrderModel::count(["owner_id" => $owner->id, "finish_date" => true]);
@@ -827,9 +836,10 @@ class Admin_IvtContractImport {
if ($order_count > 1) {
$found_product = 0;
foreach(OrderModel::search(["owner_id" => $owner->id, "finish_date" => true]) as $o) {
//var_dump($o);exit;
// find the one with the right product
foreach(OrderProductModel::search(["order_id" => $o->id, "product_id" => $product->id]) as $op) {
$order_id = $op->id;
$order_id = $op->order_id;
$found_product++;
}
if($found_product > 1) {
@@ -840,6 +850,7 @@ class Admin_IvtContractImport {
if(!$order) {
die("Order $order_id not found");
}
//echo "order 2 (owner_id $owner->id)\n";
return $order;
}