Merge branch 'fix-total-cost' into 'master'

Fix total cost bug

See merge request saburly/wiaas/new-wiaas!47
This commit was merged in pull request #47.
This commit is contained in:
Almira
2018-10-31 10:24:37 +00:00
3 changed files with 6 additions and 31 deletions

View File

@@ -121,8 +121,7 @@ if ( ! defined( 'ABSPATH' ) ) {
if ($cat === 'product') { if ($cat === 'product') {
$products_total_cost = wiaas_get_package_hardware_procurement_cost($package) + $products_total_cost = wiaas_get_package_product_procurement_cost($package);
wiaas_get_package_software_procurement_cost($package);
esc_html_e('Total: ' . $products_total_cost, 'wiaas'); esc_html_e('Total: ' . $products_total_cost, 'wiaas');
} }

View File

@@ -50,14 +50,14 @@ function wiaas_get_price_margin($fixed_price, $principal_amount, $total_cost) {
return $total_gain - $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(); $bundled_items = $package->get_bundled_items();
$total_cost = 0; $total_cost = 0;
foreach ($bundled_items as $bundled_item) { foreach ($bundled_items as $bundled_item) {
$product = $bundled_item->product; $product = $bundled_item->product;
if (Wiaas_Product_Category::get_category($product) === 'hardware') { if (Wiaas_Product_Category::is_product($product)) {
$total_cost += Wiaas_Pricing::get_product_total_cost($product) * $bundled_item->get_quantity(); $total_cost += Wiaas_Pricing::get_product_total_cost($product) * $bundled_item->get_quantity();
} }
} }
@@ -65,19 +65,6 @@ function wiaas_get_package_hardware_procurement_cost($package) {
return $total_cost; 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) {
if (Wiaas_Product_Category::is_hardware($bundled_item->product)) {
$total_cost += Wiaas_Pricing::get_product_total_cost($bundled_item->product) * $bundled_item->get_quantity();
}
}
return $total_cost;
}
function wiaas_get_package_installation_procurement_cost($package) { function wiaas_get_package_installation_procurement_cost($package) {
$bundled_items = $package->get_bundled_items(); $bundled_items = $package->get_bundled_items();
$total_cost = 0; $total_cost = 0;

View File

@@ -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 * @param $product
* *
* @return bool * @return bool
*/ */
public static function is_hardware($product) { public static function is_product($product) {
return self::_get_product_category_type($product) === 'hardware'; 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 // PRIVATE