refactor
This commit is contained in:
@@ -121,8 +121,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
if ($cat === 'product') {
|
||||
|
||||
$products_total_cost = wiaas_get_package_hardware_procurement_cost($package) +
|
||||
wiaas_get_package_software_procurement_cost($package);
|
||||
$products_total_cost = wiaas_get_package_product_procurement_cost($package);
|
||||
|
||||
esc_html_e('Total: ' . $products_total_cost, 'wiaas');
|
||||
}
|
||||
|
||||
@@ -50,29 +50,14 @@ function wiaas_get_price_margin($fixed_price, $principal_amount, $total_cost) {
|
||||
return $total_gain - $total_cost;
|
||||
}
|
||||
|
||||
function wiaas_get_package_hardware_procurement_cost($package) {
|
||||
function wiaas_get_package_product_procurement_cost($package){
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$total_cost = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
|
||||
if (Wiaas_Product_Category::get_category($product) === 'hardware') {
|
||||
$total_cost += Wiaas_Pricing::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
|
||||
return $total_cost;
|
||||
}
|
||||
|
||||
function wiaas_get_package_software_procurement_cost($package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$total_cost = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
|
||||
if (Wiaas_Product_Category::get_category($product) === 'software') {
|
||||
if (Wiaas_Product_Category::is_product($product)) {
|
||||
$total_cost += Wiaas_Pricing::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,26 +86,15 @@ class Wiaas_Product_Category {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if provided product is hardware
|
||||
* Determines if provided product type is product (hardware or software)
|
||||
* @param $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_hardware($product) {
|
||||
return self::_get_product_category_type($product) === 'hardware';
|
||||
public static function is_product($product) {
|
||||
return self::_get_product_category_type($product) === 'product';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if provided product is software
|
||||
* @param $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_software($product) {
|
||||
return self::_get_product_category_type($product) === 'software';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PRIVATE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user