handle bundle product prices editor and prices summary

This commit is contained in:
Almira Krdzic
2018-10-18 09:57:38 +02:00
parent b7ab761a25
commit 6d65a5f30c
18 changed files with 702 additions and 369 deletions

View File

@@ -49,30 +49,10 @@ class Wiaas_Package_Pricing {
);
public static function init() {
add_filter('woocommerce_bundle_price_html', array( __CLASS__, 'get_package_price_html' ), 10, 2);
add_action('woocommerce_update_product', array(__CLASS__, 'on_product_update' ), 10, 1 );
}
public static function get_package_price_html($price_html, $package) {
$bundled_items = $package->get_bundled_items();
$recurring_price = 0;
foreach ($bundled_items as $bundled_item) {
$product = $bundled_item->product;
$product_price = Wiaas_Product_Pricing::get_product_price($product);
if ($product_price['is_recurring']) {
$recurring_price += $product_price['price'] * $bundled_item->get_quantity();
}
}
$price_html = 'Fixed: ' . $price_html . ' and ' . $recurring_price . ' / month';
return $price_html;
}
/**
* Get configuration for available payment types
* @return array
@@ -121,6 +101,8 @@ class Wiaas_Package_Pricing {
$package->delete_meta_data( '_wiaas_pricing_rules' );
}
$package->save_meta_data();
self::_validate_package($package);
}
/**
@@ -147,6 +129,11 @@ class Wiaas_Package_Pricing {
private static function _get_package_prices($package) {
$pricing_rules = $package->get_meta( '_wiaas_pricing_rules' );
if (empty($pricing_rules)) {
return null;
}
$commision = self::_get_package_pricing_commision($package);
$prices = array();

View File

@@ -48,4 +48,80 @@ function wiaas_get_recurrent_price_mortage($principal_amount, $pay_period, $marg
function wiaas_get_price_margin($fixed_price, $principal_amount, $total_cost) {
$total_gain = $fixed_price + $principal_amount;
return $total_gain - $total_cost;
}
function wiaas_get_package_hardware_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) {
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) {
$bundled_items = $package->get_bundled_items();
$total_cost = 0;
foreach ($bundled_items as $bundled_item) {
if (Wiaas_Product_Category::is_installation($bundled_item->product)) {
$installation_cost = Wiaas_Pricing::get_product_total_cost($bundled_item->product);
$total_cost = $total_cost > $installation_cost ? $total_cost : $installation_cost;
}
}
return $total_cost;
}
function wiaas_get_package_one_time_services_procurement_cost($package) {
$bundled_items = $package->get_bundled_items();
$total_cost = 0;
foreach ($bundled_items as $bundled_item) {
if (Wiaas_Product_Category::is_service($bundled_item->product)) {
$price = Wiaas_Product_Pricing::get_product_price($bundled_item->product);
if (! $price['is_recurring']) {
$total_cost += Wiaas_Pricing::get_product_total_cost($bundled_item->product) * $bundled_item->get_quantity();
}
}
}
return $total_cost;
}
function wiaas_get_package_recurring_services_procurement_cost($package) {
$bundled_items = $package->get_bundled_items();
$total_cost = 0;
foreach ($bundled_items as $bundled_item) {
if (Wiaas_Product_Category::is_service($bundled_item->product)) {
$price = Wiaas_Product_Pricing::get_product_price($bundled_item->product);
if ( $price['is_recurring']) {
$total_cost += $price['price'] * $bundled_item->get_quantity();
}
}
}
return $total_cost;
}