preorder price now comes from preorder product's attributes

This commit is contained in:
Frank Schubert
2022-10-13 16:03:21 +02:00
parent f02791bdf8
commit 944784dc5c
6 changed files with 79 additions and 19 deletions
+26 -11
View File
@@ -250,23 +250,30 @@ class PreorderApicontroller extends mfBaseApicontroller {
if($type == "order") {
$product = $this->campaign->setup_products['activation'][0];
}
if($type == "reorder") {
$product = $this->campaign->setup_products['reorder'][0];
}
if($product) {
$preorder_data['setup_product_id'] = $product->id;
$preorder_data['price_setup'] = $product->price_setup;
if($connection_type == "multi-dwelling") {
if($preorder_data['connection_count'] == 2) {
$preorder_data['price_setup'] = round($product->price_setup * 2 - (($product->price_setup * 2) / 100) * TT_PREORDER_DISCOUNT_2);
//$preorder_data['price_setup'] = round($product->price_setup * 2 - (($product->price_setup * 2) / 100) * TT_PREORDER_DISCOUNT_2);
$preorder_data['price_setup'] = ($product->attributes["presales_setup_price2"]->value) ? $product->attributes["presales_setup_price2"]->value : $product->price_setup;
}
if($connection_type == "multi-dwelling" && $preorder_data['connection_count'] == 3) {
$preorder_data['price_setup'] = round($product->price_setup * 3 - (($product->price_setup * 3) / 100) * TT_PREORDER_DISCOUNT_3);
//$preorder_data['price_setup'] = round($product->price_setup * 3 - (($product->price_setup * 3) / 100) * TT_PREORDER_DISCOUNT_3);
$preorder_data['price_setup'] = ($product->attributes["presales_setup_price3"]->value) ? $product->attributes["presales_setup_price3"]->value : $product->price_setup;
}
}
if($connection_type == "apartment" && $type == "order") {
$preorder_data['price_setup'] = round($product->price_setup - (($product->price_setup) / 100) * TT_PREORDER_DISCOUNT_APART);
//$preorder_data['price_setup'] = round($product->price_setup - (($product->price_setup) / 100) * TT_PREORDER_DISCOUNT_APART);
$preorder_data['price_setup'] = ($product->attributes["presales_setup_price4"]->value) ? $product->attributes["presales_setup_price4"]->value : $product->price_setup;
}
if($connection_type == "business") {
$preorder_data['price_setup'] = round($product->price_setup - (($product->price_setup) / 100) * TT_PREORDER_DISCOUNT_BUSINESS);
//$preorder_data['price_setup'] = round($product->price_setup - (($product->price_setup) / 100) * TT_PREORDER_DISCOUNT_BUSINESS);
$preorder_data['price_setup'] = ($product->attributes["presales_setup_price_business"]->value) ? $product->attributes["presales_setup_price_business"]->value : $product->price_setup;
}
}
@@ -279,14 +286,22 @@ class PreorderApicontroller extends mfBaseApicontroller {
$preorder_data[$key] = $customer->$key;
}
}
/*
if($customer->type == "tenant") {
$preorder_data['contact_type'] = "tenant";
} elseif($customer->type == "owner") {
$preorder_data['contact_type'] = "owner";
} else {
return mfResponse::BadRequest(["message" => "customer type must be 'tenant' or 'owner'"]);
}*/
* check optional required fields
*/
if(is_array($this->campaign->required_fields) && count($this->campaign->required_fields)) {
if(in_array("contact_type", $this->campaign->required_fields)) {
if($customer->type == "tenant") {
$preorder_data['contact_type'] = "tenant";
} elseif($customer->type == "owner") {
$preorder_data['contact_type'] = "owner";
} else {
return mfResponse::BadRequest(["message" => "customer type must be 'tenant' or 'owner'"]);
}
}
}
/*
* create preorder record