update package status on package update
This commit is contained in:
@@ -29,20 +29,24 @@ class Wiaas_Product_Hooks {
|
||||
|
||||
foreach($packages_containing_updated_product as $index => $package_id){
|
||||
$package = new WC_Product_Bundle($package_id);
|
||||
$package_total_cost = Wiaas_Pricing::get_package_total_cost($package);
|
||||
$package_max_cost_margin = Wiaas_Package_Pricing::get_package_max_cost_margin($package);
|
||||
|
||||
if (($package_max_cost_margin !== 0) && ($package_total_cost > $package_max_cost_margin)){
|
||||
Wiaas_Package_Status::set_package_status($package_id, Wiaas_Package_Status::INVALID_MARGIN);
|
||||
}else{
|
||||
//TODO: Check if template is valid
|
||||
Wiaas_Package_Status::set_package_status($package_id, Wiaas_Package_Status::AVAILABLE);
|
||||
}
|
||||
self::validate_package($package);
|
||||
}
|
||||
}else if ($product->get_type() === WC_Product_Bundle::get_type()){
|
||||
self::validate_package($product);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function validate_package($package){
|
||||
$package_total_cost = Wiaas_Pricing::get_package_total_cost($package);
|
||||
$package_max_cost_margin = Wiaas_Package_Pricing::get_package_max_cost_margin($package);
|
||||
file_put_contents('/home/bilal/wiaas.log', 'Paket ID : ' . $package->get_id() . ' Total cost = ' . $package_total_cost . ' Max margin = ' . $package_max_cost_margin . ' ||| ', FILE_APPEND);
|
||||
if (($package_max_cost_margin != 0) && ($package_total_cost > $package_max_cost_margin)){
|
||||
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::INVALID_MARGIN);
|
||||
}else{
|
||||
//TODO: Check if template is valid
|
||||
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::AVAILABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Product_Hooks::init();
|
||||
Reference in New Issue
Block a user