product details
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#wiaas_package_price {
|
||||
padding: 20px;
|
||||
#wiaas_package_price .wc-metaboxes-wrapper {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#wiaas_package_price label {
|
||||
@@ -12,7 +12,7 @@
|
||||
}
|
||||
|
||||
#wiaas_package_price_controls {
|
||||
float: right;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#wiaas_package_price_controls > select {
|
||||
@@ -92,6 +92,32 @@
|
||||
}
|
||||
|
||||
|
||||
#wiaas_package_option_groups div.expand-close {
|
||||
#wiaas_linked_packages div.wc-metaboxes-wrapper {
|
||||
float: none;
|
||||
width: 100%;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
#wiaas_linked_packages .toolbar {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#wiaas_linked_packages .expand-close {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#wiaas_package_option_groups_list {
|
||||
margin: 9px 12px;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#wiaas_package_option_groups_list label {
|
||||
float: none;
|
||||
margin: 0;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#wiaas_package_option_groups_list .wiaas_option_group h3 {
|
||||
background-color:#F9F9F9;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Wiaas_Admin_Package {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-linked-packages.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-package-types.php';
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package::init();
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_Pricing
|
||||
*/
|
||||
|
||||
class Wiaas_Admin_Pricing {
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-admin-product-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-admin-package-pricing.php';
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Pricing::init();
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_Linked_Packages
|
||||
*/
|
||||
|
||||
class Wiaas_Admin_Linked_Packages {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'wp_ajax_wiaas_json_search_addons', array(__CLASS__, 'json_search_addons') );
|
||||
add_action( 'wp_ajax_wiaas_json_search_options', array(__CLASS__, 'json_search_options') );
|
||||
|
||||
add_action( 'wp_ajax_wiaas_create_empty_option_group', array(__CLASS__, 'create_empty_option_group') );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects default woocommerce linked packages tab to wiaas linked packages tab
|
||||
* @param $tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'linked_product' ]['label'] = __( 'Linked Packages', 'wiaas' );
|
||||
$tabs[ 'linked_product' ]['target'] = 'wiaas_linked_packages';
|
||||
$tabs[ 'linked_product' ]['class'] = array('show_if_bundle', 'hide_if_simple');
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders wiaas linked packages tab
|
||||
*/
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
|
||||
$package = wc_get_product( $post->ID );
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
$option_groups = Wiaas_Package_Option_Groups::get_package_option_groups($package);
|
||||
|
||||
include 'views/html-linked-packages.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements ajax search for package addons
|
||||
*/
|
||||
public static function json_search_addons() {
|
||||
self::_json_search_packages('add_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements ajax searc for package options
|
||||
*/
|
||||
public static function json_search_options() {
|
||||
|
||||
self::_json_search_packages('option');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and renders new optional packages group
|
||||
*/
|
||||
public static function create_empty_option_group() {
|
||||
$group = array(
|
||||
'name' => 'Untitled',
|
||||
'id' => uniqid('option_'),
|
||||
'default' => false,
|
||||
'options' => array()
|
||||
);
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
||||
</script>
|
||||
<?php
|
||||
$group_options = isset($group['options']) ? $group['options'] : array();
|
||||
$id = $group['id'];
|
||||
|
||||
include 'views/html-package-options-group.php';
|
||||
?>
|
||||
<?php
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves posted linked packages data
|
||||
*
|
||||
* @param $package_id
|
||||
*/
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
// Handle linked addons
|
||||
|
||||
$addons_ids = isset( $_POST['wiaas_addon_packages'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $_POST['wiaas_addon_packages'] ) ) :
|
||||
array();
|
||||
|
||||
Wiaas_Package_Addon::set_package_addons(
|
||||
$package,
|
||||
$addons_ids);
|
||||
|
||||
// Handle linked options
|
||||
|
||||
$posted_option_groups = isset( $_POST['wiaas_option_groups'] ) ? $_POST['wiaas_option_groups'] : array();
|
||||
|
||||
$option_groups = array();
|
||||
|
||||
foreach ($posted_option_groups as $id => $posted_option_group) {
|
||||
$option_group = array(
|
||||
'id' => $posted_option_group['id'],
|
||||
'name' => $posted_option_group['name'],
|
||||
'default' => $posted_option_group['default'],
|
||||
'options' => array()
|
||||
);
|
||||
$option_group['options'] = isset( $posted_option_group['options'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $posted_option_group['options'] ) ) :
|
||||
array();
|
||||
|
||||
$option_groups[] = $option_group;
|
||||
}
|
||||
|
||||
Wiaas_Package_Option_Groups::set_package_option_groups(
|
||||
$package,
|
||||
$posted_option_groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements search for packages of provided type
|
||||
* @param $package_type
|
||||
*/
|
||||
private static function _json_search_packages($package_type) {
|
||||
check_ajax_referer( 'search-products', 'security' );
|
||||
|
||||
$term = wc_clean( empty( $term ) ? wp_unslash( $_GET['term'] ) : $term );
|
||||
|
||||
if ( empty( $term ) ) {
|
||||
wp_die();
|
||||
}
|
||||
|
||||
$data_store = WC_Data_Store::load( 'product' );
|
||||
$ids = $data_store->search_products( $term );
|
||||
|
||||
$packages= array_filter( array_map( 'wc_get_product', $ids ), 'wc_products_array_filter_readable' );
|
||||
$result = array();
|
||||
|
||||
foreach ( $packages as $package ) {
|
||||
|
||||
if (Wiaas_Package_Type::get_package_type($package->get_id()) === $package_type) {
|
||||
$result[ $package->get_id() ] = rawurldecode( $package->get_formatted_name() );
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json( $result );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Linked_Packages::init();
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Package_Addon {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_addons' ] = array(
|
||||
'label' => __( 'Add-ons', 'wiaas' ),
|
||||
'target' => 'wiaas_package_addons',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_addons" class="panel woocommerce_options_panel wc_gte_30">
|
||||
<div class="options_group">
|
||||
<p class="form-field">
|
||||
<label for="wiaas_addon_packages"><?php esc_html_e( 'Additional packages:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
id="wiaas_addon_packages"
|
||||
name="wiaas_addon_packages[]"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for a product…', 'wiaas' ); ?>"
|
||||
data-action="woocommerce_json_search_products"
|
||||
data-exclude="<?php echo intval( $package->get_id() ); ?>">
|
||||
<?php
|
||||
foreach ( $addons as $addon ) {
|
||||
echo '<option value="' . esc_attr( $addon->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $addon->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php echo wc_help_tip( __( 'This lets you choose which packages will be available as addons.', 'wiaas' ) );?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function meta_box_javascript() {
|
||||
|
||||
}
|
||||
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$addons_ids = isset( $_POST['wiaas_addon_packages'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $_POST['wiaas_addon_packages'] ) ) :
|
||||
array();
|
||||
|
||||
Wiaas_Package_Addon::set_package_addons(
|
||||
$package,
|
||||
$addons_ids);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Addon::init();
|
||||
@@ -1,242 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Package_Option_Groups {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'wp_ajax_wiaas_create_empty_option_group', array(__CLASS__, 'create_empty_option_group') );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
public static function create_empty_option_group() {
|
||||
$option_group = array(
|
||||
'name' => 'Untitled',
|
||||
'id' => uniqid('option_'),
|
||||
'default' => false,
|
||||
'options' => array()
|
||||
);
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
||||
</script>
|
||||
<?php
|
||||
self::_render_option_group($option_group);
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_options_groups' ] = array(
|
||||
'label' => __( 'Option groups', 'wiaas' ),
|
||||
'target' => 'wiaas_package_option_groups',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
|
||||
$option_groups = Wiaas_Package_Option_Groups::get_package_option_groups($package);
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_option_groups" class="panel wc-metaboxes-wrapper hidden">
|
||||
<?php self::meta_box_javascript(); ?>
|
||||
<div class="toolbar toolbar-top">
|
||||
<button type="button" class="button button-primary" id="wiaas_add_option_group">
|
||||
<?php esc_html_e( 'Add new option group', 'wiaas' ); ?>
|
||||
</button>
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all"><?php esc_html_e( 'Expand', 'wiaas' ); ?></a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
<div id="wiaas_package_option_groups_list" class="wc-metaboxes">
|
||||
<?php
|
||||
foreach ($option_groups as $option_group) {
|
||||
self::_render_option_group($option_group);
|
||||
}
|
||||
// render empty option group
|
||||
?>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all">
|
||||
<?php esc_html_e( 'Expand', 'wiaas' ); ?>
|
||||
</a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_option_group($group) {
|
||||
$group_options = isset($group['options']) ? $group['options'] : array();
|
||||
$id = $group['id'];
|
||||
|
||||
?>
|
||||
<div id="wiaas_option_group_<?php echo esc_attr( $id ); ?>" class="wc-metabox closed">
|
||||
<h3>
|
||||
<a
|
||||
href="#"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="delete delete_wiaas_option_group">
|
||||
<?php esc_html_e( 'Remove', 'wiaas' ); ?>
|
||||
</a>
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'wiaas' ); ?>"></div>
|
||||
<strong id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_title">
|
||||
<?php echo $group['name']; ?>
|
||||
</strong>
|
||||
</h3>
|
||||
<div class="wc-metabox-content">
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<label><?php esc_html_e( 'Name', 'wiaas' ); ?>:</label>
|
||||
<input
|
||||
type="text"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="wiaas_option_group_name"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][name]"
|
||||
value="<?php echo esc_attr( $group['name'] ); ?>" />
|
||||
<input
|
||||
type="hidden"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][id]"
|
||||
value="<?php echo esc_attr( $id ); ?>" />
|
||||
</td>
|
||||
<td rowspan="3">
|
||||
<label><?php esc_html_e( 'Options:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][options][]"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for a product…', 'wiaas' ); ?>"
|
||||
data-action="woocommerce_json_search_products"
|
||||
data-exclude="">
|
||||
<?php
|
||||
foreach ( $group_options as $group_option ) {
|
||||
echo '<option value="' . esc_attr( $group_option->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $group_option->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="checkbox wiaas_option_group_default"
|
||||
<?php checked( $group['default'], true ); ?>
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][default]"
|
||||
value="1" />
|
||||
<?php esc_html_e( 'Set as default', 'wiaas' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function meta_box_javascript() {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas_add_option_group").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var data = {
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'wiaas_create_empty_option_group'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_option_groups_list').append(response);
|
||||
});
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.delete_wiaas_option_group', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this option group?', 'wiaas' ); ?>")) {
|
||||
var id = $(this).data('id');
|
||||
$('#wiaas_option_group_' + id).slideUp().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_name', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var name = $(this).val();
|
||||
var id = $(this).data('id');
|
||||
|
||||
$(`#wiaas_option_group_${id}_title`).text(name);
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_default', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var id = $(this).data('id');
|
||||
|
||||
$(`:input.wiaas_option_group_default`).each(function() {
|
||||
var group_id = $(this).data('id');
|
||||
if (group_id !== id) {
|
||||
$(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$posted_option_groups = isset( $_POST['wiaas_option_groups'] ) ? $_POST['wiaas_option_groups'] : array();
|
||||
|
||||
error_log(print_r($posted_option_groups, true));
|
||||
|
||||
$option_groups = array();
|
||||
|
||||
foreach ($posted_option_groups as $id => $posted_option_group) {
|
||||
$option_group = array(
|
||||
'id' => $posted_option_group['id'],
|
||||
'name' => $posted_option_group['name'],
|
||||
'default' => $posted_option_group['default'],
|
||||
'options' => array()
|
||||
);
|
||||
$option_group['options'] = isset( $posted_option_group['options'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $posted_option_group['options'] ) ) :
|
||||
array();
|
||||
|
||||
$option_groups[] = $option_group;
|
||||
}
|
||||
|
||||
Wiaas_Package_Option_Groups::set_package_option_groups(
|
||||
$package,
|
||||
$posted_option_groups);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Option_Groups::init();
|
||||
@@ -1,356 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Package_Pricing
|
||||
*/
|
||||
class Wiaas_Admin_Package_Pricing {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
add_action( 'wp_ajax_create_empty_pricing_rule', array(__CLASS__, 'create_empty_pricing_rule') );
|
||||
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ), 1, 2 );
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
||||
}
|
||||
|
||||
public static function create_empty_pricing_rule() {
|
||||
$pay_type = $_POST['pay_type'];
|
||||
$pricing_rule_sets = array();
|
||||
$pricing_rule_sets[ $pay_type ] = Wiaas_Package_Pricing::get_empty_pricing_rule();
|
||||
self::_render_pricing_rules( $pricing_rule_sets );
|
||||
}
|
||||
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_price' ] = array(
|
||||
'label' => __( 'Pricing', 'wiaas' ),
|
||||
'target' => 'wiaas_package_price',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_price" class="panel woocommerce_options_panel wc_gte_30">
|
||||
<div id="wiaas_package_pricing_rules" data-setindex="<?php echo count( $pricing_rules ); ?>">
|
||||
<?php self::meta_box_javascript(); ?>
|
||||
<?php self::_render_pricing_rules( $pricing_rules ); ?>
|
||||
</div>
|
||||
<?php self::_render_pricing_controls( $pricing_rules ); ?>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_pricing_rules( $pricing_rule_sets ) {
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ( $pricing_rule_sets as $name => $pricing_rule_set ) {
|
||||
$pay_type = $available_pay_types[$name];
|
||||
?>
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule">
|
||||
<div class="section">
|
||||
<h4 class="first"><?php echo $pay_type['title']; ?>
|
||||
<a href="#" data-name="<?php echo $name; ?>"
|
||||
class="delete_wiaas_pricing_rule">
|
||||
REMOVE
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( 'Minimal fixed price:', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="wiaas_minimal_fixed_price_<?php echo $name; ?>"
|
||||
data-name="<?php echo $name; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][minimal_fixed_price]"
|
||||
value="<?php echo $pricing_rule_set['minimal_fixed_price'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php self::_render_pricing_rule_recurrent_price($name, $pay_type, $pricing_rule_set) ?>
|
||||
<?php self::_render_pricing_rule_principal_amount($name, $pay_type, $pricing_rule_set) ?>
|
||||
<?php self::_render_pricing_rule_services_price($name, $pay_type, $pricing_rule_set) ?>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( 'Max contract period:', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span id="wiaas_max_contract_period_<?php echo $name; ?>">
|
||||
<?php echo $pay_type['max_contract_period'] . ' ' . $pay_type['period_unit'] ?>
|
||||
</span>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private static function _render_pricing_rule_services_price($name, $pay_type, $pricing_rule) {
|
||||
$label = 'Minimal services and support price ';
|
||||
if ($pay_type['services_contract_period'] > 0) {
|
||||
$label .= '(' . $pay_type['services_contract_period'] . ' ' . $pay_type['period_unit'] . ')';
|
||||
} else {
|
||||
$label .= '(Unbound)';
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( $label . ':', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td class="wiaas_input_container">
|
||||
<input
|
||||
id="wiaas_minimal_services_price_<?php echo $name; ?>"
|
||||
class="wiaas_minimal_services_price"
|
||||
data-name="<?php echo $name; ?>"
|
||||
data-period="<?php echo $pay_type['services_contract_period']; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][minimal_services_price]"
|
||||
value="<?php echo $pricing_rule['minimal_services_price'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td>
|
||||
<span style="line-height: 28px; margin-left: 10px;">
|
||||
<?php echo ' / ' . $pay_type['period_unit'] ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
if ($pay_type['services_contract_period'] > 0) {
|
||||
?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>Final total:</td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_services_price_<?php echo $name; ?>_final">
|
||||
<?php echo round(
|
||||
$pricing_rule['minimal_services_price'] * $pay_type['services_contract_period'],
|
||||
2) ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private static function _render_pricing_rule_principal_amount($name, $pay_type, $pricing_rule) {
|
||||
if ($pay_type['package_pay_period'] === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value_per_month = round($pricing_rule['principal_amount'] / $pay_type['package_pay_period'], 2);
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php _e( 'Principal amount:', 'wiaas' ); ?></td>
|
||||
<td class="wiaas_input_container">
|
||||
<input
|
||||
id="wiaas_principal_amount_<?php echo $name; ?>"
|
||||
class="wiaas_principal_amount"
|
||||
data-name="<?php echo $name; ?>"
|
||||
data-period="<?php echo $pay_type['package_pay_period']; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][principal_amount]"
|
||||
value="<?php echo $pricing_rule['principal_amount'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<?php _e( 'Minimal recurrent package price ( ' .
|
||||
$pay_type['services_contract_period'] .
|
||||
' ' . $pay_type['period_unit'] .
|
||||
'): ', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_recurrent_package_price_<?php echo $name; ?>">
|
||||
<?php echo $value_per_month ?>
|
||||
</span>
|
||||
<?php echo ' / ' . $pay_type['period_unit'] ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_pricing_rule_recurrent_price($name, $pay_type, $pricing_rule) {
|
||||
$value = $pricing_rule['minimal_services_price'];
|
||||
if ($pricing_rule['principal_amount'] > 0 && $pay_type['package_pay_period'] > 0) {
|
||||
$value += $pricing_rule['principal_amount'] / $pay_type['package_pay_period'];
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php _e( 'Minimal recurrent price:', 'wiaas' ); ?></td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_recurrent_price_<?php echo $name; ?>">
|
||||
<?php echo round($value, 2) ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_pricing_controls($pricing_rule_sets) {
|
||||
$has_available_pay_types = false;
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
if (!isset($pricing_rule_sets[$name])) {
|
||||
$has_available_pay_types = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$class = $has_available_pay_types ? '' : 'wiaas_hidden';
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_price_controls" class="section <?php echo $class ?>">
|
||||
<select id="wiaas_pay_type" name="wiaas-pay-type" class="pricing_rule_mode">
|
||||
<?php
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
?>
|
||||
<option
|
||||
value="<?php echo $name ?>"
|
||||
id="wiaas_pay_type_<?php echo $name ?>"
|
||||
class="<?php echo $class ?>"
|
||||
>
|
||||
<?php _e( $pay_type['title'], 'wiaas' ); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button
|
||||
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
|
||||
id="wiaas-add-pricing"
|
||||
type="button"
|
||||
class="button button-primary">
|
||||
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function meta_box_javascript() {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas-add-pricing").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
|
||||
$("#wiaas_package_pricing_rules").data('setindex', set_index);
|
||||
|
||||
var pay_type = $('#wiaas_pay_type').val();
|
||||
|
||||
var data = {
|
||||
'pay_type': pay_type,
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'create_empty_pricing_rule'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_pricing_rules').append(response);
|
||||
|
||||
$(`#wiaas_pay_type_${pay_type}`).addClass('wiaas_hidden');
|
||||
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 0) {
|
||||
$('#wiaas_package_price_controls').addClass('wiaas_hidden');
|
||||
} else {
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//Remove Pricing Type
|
||||
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this pay type?', 'wiaas' ); ?>")) {
|
||||
var name = $(this).data('name');
|
||||
$('#wiaas-pricing-rule-' + name).slideUp().remove();
|
||||
|
||||
// append new option to controls
|
||||
$(`#wiaas_pay_type_${name}`).removeClass('wiaas_hidden');
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 1) {
|
||||
$('#wiaas_package_price_controls').removeClass('wiaas_hidden');
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var minimal_services_price = parseFloat($(this).val()) || 0;
|
||||
var principal_amount = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
|
||||
if (principal_amount_input) {
|
||||
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
|
||||
}
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
|
||||
var services_contract_period = $(this).data('period');
|
||||
if (services_contract_period > 0) {
|
||||
var final_services_price = minimal_services_price * services_contract_period;
|
||||
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var principal_amount = parseFloat($(this).val() / $(this).data('period')) || 0;
|
||||
var minimal_services_price = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
|
||||
if (minimal_services_price_input) {
|
||||
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
|
||||
}
|
||||
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(2));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function process_meta_box( $post_id, $post ) {
|
||||
Wiaas_Package_Pricing::set_package_prices(
|
||||
wc_get_product( $post_id ),
|
||||
$_POST['wiaas_pricing_rules']);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Pricing::init();
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_Package_Types
|
||||
*/
|
||||
class Wiaas_Admin_Package_Types {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'woocommerce_product_options_general_product_data', array( __CLASS__, 'package_types_data' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders wiaas package types options
|
||||
*/
|
||||
public static function package_types_data() {
|
||||
|
||||
global $post;
|
||||
|
||||
$package = wc_get_product( $post->ID );
|
||||
|
||||
include 'views/html-package-types.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves posted wiaas package type data
|
||||
* @param $package_id
|
||||
*/
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
if ($package->get_type() === 'bundle') {
|
||||
// Save wiaas package type
|
||||
Wiaas_Package_Type::set_package_type($package_id, $_POST['wiaas_package_type']);
|
||||
} else {
|
||||
Wiaas_Package_Type::set_package_type($package_id, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Types::init();
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas Linked Packages Editor
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_linked_packages" class="panel woocommerce_options_panel">
|
||||
|
||||
<div class="options_group">
|
||||
<p class="form-field">
|
||||
<label style="font-weight: bold;" for="wiaas_addon_packages"><?php esc_html_e( 'Add-ons:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
id="wiaas_addon_packages"
|
||||
name="wiaas_addon_packages[]"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for addons ...', 'wiaas' ); ?>"
|
||||
data-action="wiaas_json_search_addons"
|
||||
data-exclude="<?php echo intval( $package->get_id() ); ?>">
|
||||
<?php
|
||||
foreach ( $addons as $addon ) {
|
||||
echo '<option value="' . esc_attr( $addon->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $addon->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php echo wc_help_tip( __( 'This lets you choose which packages will be available as addons.', 'wiaas' ) );?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas_add_option_group").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var data = {
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'wiaas_create_empty_option_group'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_option_groups_list').append(response);
|
||||
});
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.delete_wiaas_option_group', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this option group?', 'wiaas' ); ?>")) {
|
||||
var id = $(this).data('id');
|
||||
$('#wiaas_option_group_' + id).slideUp().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_name', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var name = $(this).val();
|
||||
var id = $(this).data('id');
|
||||
|
||||
$(`#wiaas_option_group_${id}_title`).text(name);
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_options', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var id = $(this).data('id');
|
||||
var selected_options_ids = $(this).val() ? $(this).val().toString().split(',') : [];
|
||||
var previous_options_ids = $(this).data('selected') ? $(this).data('selected').toString().split(',') : [];
|
||||
|
||||
var added_option_id = selected_options_ids.find(id => previous_options_ids.indexOf(id) === -1);
|
||||
var removed_option_id = previous_options_ids.find(id => selected_options_ids.indexOf(id) === -1);
|
||||
|
||||
if (added_option_id) {
|
||||
$(this).children().filter(function() {
|
||||
var option_id = $(this).val();
|
||||
return option_id === added_option_id;
|
||||
}).clone().appendTo(`#wiaas_option_group_${id}_default`);
|
||||
}
|
||||
|
||||
if (removed_option_id) {
|
||||
$(`#wiaas_option_group_${id}_default`).children().
|
||||
filter(function() {
|
||||
var option_id = $(this).val();
|
||||
return option_id === removed_option_id;
|
||||
}).
|
||||
remove();
|
||||
}
|
||||
|
||||
$(this).data('selected', selected_options_ids.join(','));
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="wiaas_package_option_groups" class="wc-metaboxes-wrapper">
|
||||
<div class="toolbar toolbar-top">
|
||||
<button type="button" class="button button-primary" id="wiaas_add_option_group">
|
||||
<?php esc_html_e( 'Add new option group', 'wiaas' ); ?>
|
||||
</button>
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all"><?php esc_html_e( 'Expand', 'wiaas' ); ?></a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
<div id="wiaas_package_option_groups_list" class="wc-metaboxes">
|
||||
<?php
|
||||
foreach ($option_groups as $group) {
|
||||
$group_options = isset($group['options']) ? $group['options'] : array();
|
||||
$id = $group['id'];
|
||||
|
||||
include 'html-package-options-group.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all">
|
||||
<?php esc_html_e( 'Expand', 'wiaas' ); ?>
|
||||
</a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas Package Option Group Editor
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_option_group_<?php echo esc_attr( $id ); ?>" class="wiaas_option_group wc-metabox closed">
|
||||
<h3>
|
||||
<a
|
||||
href="#"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="delete delete_wiaas_option_group">
|
||||
<?php esc_html_e( 'Remove', 'wiaas' ); ?>
|
||||
</a>
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'wiaas' ); ?>"></div>
|
||||
<strong id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_title">
|
||||
<?php echo $group['name']; ?>
|
||||
</strong>
|
||||
</h3>
|
||||
<div class="wc-metabox-content">
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<label><?php esc_html_e( 'Name', 'wiaas' ); ?>:</label>
|
||||
<input
|
||||
type="text"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="wiaas_option_group_name"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][name]"
|
||||
value="<?php echo esc_attr( $group['name'] ); ?>" />
|
||||
<input
|
||||
type="hidden"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][id]"
|
||||
value="<?php echo esc_attr( $id ); ?>" />
|
||||
</td>
|
||||
<td rowspan="3">
|
||||
<label><?php esc_html_e( 'Options:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search wiaas_option_group_options"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][options][]"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for options ...', 'wiaas' ); ?>"
|
||||
data-action="wiaas_json_search_options"
|
||||
data-selected="<?php echo implode( ',', array_map(function($option) { return $option->get_id(); }, $group_options)) ?>"
|
||||
data-exclude="">
|
||||
<?php
|
||||
foreach ( $group_options as $option ) {
|
||||
echo '<option value="' . esc_attr( $option->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $option->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<?php esc_html_e( 'Default option:', 'wiaas' ); ?>
|
||||
</label>
|
||||
<select
|
||||
id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_default"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][default]"
|
||||
>
|
||||
<?php
|
||||
foreach ( $group_options as $option ) {
|
||||
echo '<option value="' . esc_attr( $option->get_id() ) . '"' .
|
||||
selected( $option->get_id(), $group['default'], false ) .
|
||||
'>' .
|
||||
wp_kses_post( $option->get_formatted_name() ) .
|
||||
'</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas Package Types Editor
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_package_type_editor" class="options_group show_if_bundle hidden">
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas_package_type").change(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
handlePackageTypeToolsVisiblity();
|
||||
});
|
||||
|
||||
function handlePackageTypeToolsVisiblity() {
|
||||
var currentPackageType = $('#wiaas_package_type').val();
|
||||
var productType = $('#product-type').val();
|
||||
|
||||
if (currentPackageType === 'standard' && productType === 'bundle') {
|
||||
$('#woocommerce-product-data').find('.linked_product_tab').show();
|
||||
} else {
|
||||
$('#woocommerce-product-data').find('.linked_product_tab').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function showDownloadableFiles() {
|
||||
$('#general_product_data').find('.show_if_downloadable').each(function() {
|
||||
$(this).show();
|
||||
$(this).removeClass('hidden');
|
||||
$(this).removeClass('show_if_downloadable');
|
||||
|
||||
$(this).find('._download_limit_field, ._download_expiry_field').hide();
|
||||
});
|
||||
}
|
||||
|
||||
showDownloadableFiles();
|
||||
|
||||
handlePackageTypeToolsVisiblity();
|
||||
});
|
||||
</script>
|
||||
|
||||
<p class="form-field">
|
||||
<label for="wiaas_package_type"><?php esc_html_e( 'Package type:', 'wiaas' ); ?></label>
|
||||
<select id="wiaas_package_type" name="wiaas_package_type">
|
||||
<?php
|
||||
// Array of available package types
|
||||
$package_types = Wiaas_Package_Type::get_available_package_types();
|
||||
|
||||
$current_package_type = Wiaas_Package_Type::get_package_type($package->get_id());
|
||||
$current_package_type = isset($current_package_type) ? $current_package_type : 'standard';
|
||||
|
||||
if ( ! empty( $package_types ) ) {
|
||||
foreach ( $package_types as $package_type ) {
|
||||
$label = '';
|
||||
switch($package_type) {
|
||||
case 'standard':
|
||||
$label = 'Standard';
|
||||
break;
|
||||
case 'option':
|
||||
$label = 'Option';
|
||||
break;
|
||||
case 'add_on':
|
||||
$label = 'Add-on';
|
||||
break;
|
||||
}
|
||||
|
||||
echo '<option ' .
|
||||
'value="' . esc_attr( $package_type ) . '" ' .
|
||||
selected( $package_type, $current_package_type, false ) .
|
||||
' >' .
|
||||
esc_html( $label ) .
|
||||
'</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php echo wc_help_tip( __( 'Choose Wiaas package type.', 'wiaas' ) );?>
|
||||
</p>
|
||||
</div>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Package_Pricing
|
||||
*/
|
||||
class Wiaas_Admin_Package_Pricing {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'wp_ajax_create_empty_pricing_rule', array(__CLASS__, 'create_empty_pricing_rule') );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ), 1, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and renders new empty package pricing rule
|
||||
*/
|
||||
public static function create_empty_pricing_rule() {
|
||||
$pay_type = $_POST['pay_type'];
|
||||
$pricing_rules = array();
|
||||
$pricing_rules[ $pay_type ] = Wiaas_Package_Pricing::get_empty_pricing_rule();
|
||||
|
||||
require 'views/html-package-pricing-rules-list.php';
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers wiaas pricing tab for package data
|
||||
* @param $tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_price' ] = array(
|
||||
'label' => __( 'Pricing', 'wiaas' ),
|
||||
'target' => 'wiaas_package_price',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderes wiaas pricing tab content for package
|
||||
*/
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
$commission = Wiaas_Package_Pricing::get_package_pricing_commission($package);
|
||||
|
||||
include 'views/html-package-pricing.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves posted package pricing rules
|
||||
* @param $post_id
|
||||
* @param $post
|
||||
*/
|
||||
public function process_meta_box( $post_id, $post ) {
|
||||
Wiaas_Package_Pricing::set_package_prices(
|
||||
wc_get_product( $post_id ),
|
||||
$_POST['wiaas_pricing_rules'],
|
||||
$_POST['wiaas_pricing_rules_commision']);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Pricing::init();
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_Product_Pricing
|
||||
*/
|
||||
class Wiaas_Admin_Product_Pricing {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_options_pricing', array( __CLASS__, 'product_pricing' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ), 1, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders wiaas pricing options for product
|
||||
*/
|
||||
public static function product_pricing() {
|
||||
|
||||
global $post;
|
||||
|
||||
$product = wc_get_product( $post->ID );
|
||||
|
||||
$product_pricing = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
include 'views/html-product-pricing.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves posted product pricing settings
|
||||
* @param $post_id
|
||||
* @param $post
|
||||
*/
|
||||
public function process_meta_box( $post_id, $post ) {
|
||||
|
||||
$product = wc_get_product( $post_id );
|
||||
if ($product->get_type() === 'simple') {
|
||||
$is_recurring = $_POST['_wiaas_recurring_price'] === 'yes';
|
||||
$pay_period = isset($_POST['_wiaas_recurring_pay_period']) ? $_POST['_wiaas_recurring_pay_period'] : 0;
|
||||
|
||||
Wiaas_Product_Pricing::set_product_price($product, $product->get_price(), $is_recurring, $pay_period);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product_Pricing::init();
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
if ($pay_type['package_pay_period'] === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value_per_month = round( wiaas_PMT(
|
||||
Wiaas_Pricing::INTEREST_RATE,
|
||||
$pay_type['package_pay_period'],
|
||||
$pricing_rule['principal_amount']), 0);
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php _e( 'Principal amount:', 'wiaas' ); ?></td>
|
||||
<td class="wiaas_input_container">
|
||||
<input
|
||||
id="wiaas_principal_amount_<?php echo $name; ?>"
|
||||
class="wiaas_principal_amount"
|
||||
data-name="<?php echo $name; ?>"
|
||||
data-period="<?php echo $pay_type['package_pay_period']; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][principal_amount]"
|
||||
value="<?php echo $pricing_rule['principal_amount'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<?php _e( 'Minimal recurrent package price ( ' .
|
||||
$pay_type['services_contract_period'] .
|
||||
' ' . $pay_type['period_unit'] .
|
||||
'): ', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_recurrent_package_price_<?php echo $name; ?>">
|
||||
<?php echo $value_per_month ?>
|
||||
</span>
|
||||
<?php echo ' / ' . $pay_type['period_unit'] ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
$value = $pricing_rule['minimal_services_price'];
|
||||
if ($pricing_rule['principal_amount'] > 0 && $pay_type['package_pay_period'] > 0) {
|
||||
$value += wiaas_PMT(
|
||||
Wiaas_Pricing::INTEREST_RATE,
|
||||
$pay_type['package_pay_period'],
|
||||
$pricing_rule['principal_amount']);
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php _e( 'Minimal recurrent price:', 'wiaas' ); ?></td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_recurrent_price_<?php echo $name; ?>">
|
||||
<?php echo round($value, 0) ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
$label = 'Minimal services and support price ';
|
||||
if ($pay_type['services_contract_period'] > 0) {
|
||||
$label .= '(' . $pay_type['services_contract_period'] . ' ' . $pay_type['period_unit'] . ')';
|
||||
} else {
|
||||
$label .= '(Unbound)';
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( $label . ':', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td class="wiaas_input_container">
|
||||
<input
|
||||
id="wiaas_minimal_services_price_<?php echo $name; ?>"
|
||||
class="wiaas_minimal_services_price"
|
||||
data-name="<?php echo $name; ?>"
|
||||
data-period="<?php echo $pay_type['services_contract_period']; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][minimal_services_price]"
|
||||
value="<?php echo $pricing_rule['minimal_services_price'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td>
|
||||
<span style="line-height: 28px; margin-left: 10px;">
|
||||
<?php echo ' / ' . $pay_type['period_unit'] ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
if ($pay_type['services_contract_period'] > 0) {
|
||||
?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>Final total:</td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_services_price_<?php echo $name; ?>_final">
|
||||
<?php echo round(
|
||||
$pricing_rule['minimal_services_price'] * $pay_type['services_contract_period'],
|
||||
2) ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
|
||||
foreach ( $pricing_rules as $name => $pricing_rule ) {
|
||||
$pay_type = $available_pay_types[$name];
|
||||
?>
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule">
|
||||
<div class="section">
|
||||
<h4 class="first"><?php echo $pay_type['title']; ?>
|
||||
<a href="#" data-name="<?php echo $name; ?>"
|
||||
class="delete_wiaas_pricing_rule">
|
||||
REMOVE
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( 'Minimal fixed price:', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="wiaas_minimal_fixed_price_<?php echo $name; ?>"
|
||||
data-name="<?php echo $name; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][minimal_fixed_price]"
|
||||
value="<?php echo $pricing_rule['minimal_fixed_price'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php require 'html-package-pricing-rule-recurrent-price.php'; ?>
|
||||
<?php require 'html-package-pricing-rule-principal-amount.php'; ?>
|
||||
<?php require 'html-package-pricing-rule-services-price.php'; ?>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( 'Max contract period:', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span id="wiaas_max_contract_period_<?php echo $name; ?>">
|
||||
<?php echo $pay_type['max_contract_period'] . ' ' . $pay_type['period_unit'] ?>
|
||||
</span>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_package_price" class="panel woocommerce_options_panel">
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas-add-pricing").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
|
||||
$("#wiaas_package_pricing_rules").data('setindex', set_index);
|
||||
|
||||
var pay_type = $('#wiaas_pay_type').val();
|
||||
|
||||
var data = {
|
||||
'pay_type': pay_type,
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'create_empty_pricing_rule'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_pricing_rules').append(response);
|
||||
|
||||
$(`#wiaas_pay_type_${pay_type}`).addClass('wiaas_hidden');
|
||||
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 0) {
|
||||
$('#wiaas_package_price_controls').addClass('wiaas_hidden');
|
||||
} else {
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//Remove Pricing Type
|
||||
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this pay type?', 'wiaas' ); ?>")) {
|
||||
var name = $(this).data('name');
|
||||
$('#wiaas-pricing-rule-' + name).slideUp().remove();
|
||||
|
||||
// append new option to controls
|
||||
$(`#wiaas_pay_type_${name}`).removeClass('wiaas_hidden');
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 1) {
|
||||
$('#wiaas_package_price_controls').removeClass('wiaas_hidden');
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var minimal_services_price = parseFloat($(this).val()) || 0;
|
||||
var principal_amount = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
|
||||
if (principal_amount_input) {
|
||||
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
|
||||
}
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
|
||||
var services_contract_period = $(this).data('period');
|
||||
if (services_contract_period > 0) {
|
||||
var final_services_price = minimal_services_price * services_contract_period;
|
||||
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var value = parseFloat($(this).val());
|
||||
var period = parseFloat($(this).data('period'));
|
||||
var interestRate = 0.58;
|
||||
|
||||
|
||||
var principal_amount = calculateFinancing(interestRate, period, value);
|
||||
var minimal_services_price = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
|
||||
if (minimal_services_price_input) {
|
||||
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
|
||||
}
|
||||
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(0));
|
||||
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(0));
|
||||
});
|
||||
|
||||
/**
|
||||
* Copy of Excel's PMT function.
|
||||
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
|
||||
*
|
||||
* @param ratePerPeriod The interest rate for the loan.
|
||||
* @param numberOfPayments The total number of payments for the loan in months.
|
||||
* @param presentValue The present value, or the total amount that a series of future payments is worth now;
|
||||
* Also known as the principal.
|
||||
* @param futureValue The future value, or a cash balance you want to attain after the last payment is made.
|
||||
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
|
||||
* @param type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
|
||||
* 0 = At the end of period
|
||||
* 1 = At the beginning of the period
|
||||
* @returns {number}
|
||||
*/
|
||||
function calculateFinancing(ratePerPeriod, numberOfPayments, presentValue, futureValue = 0, type = 0) {
|
||||
/*var q = 0;
|
||||
var c = 0;
|
||||
const monthlyRatePerPeriod = ratePerPeriod / 12;
|
||||
|
||||
if (monthlyRatePerPeriod !== 0.0) {
|
||||
// Interest rate exists
|
||||
q = Math.pow(1 + monthlyRatePerPeriod, numberOfPayments);
|
||||
c = (monthlyRatePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + monthlyRatePerPeriod * (type)));
|
||||
return c.toFixed(2);
|
||||
|
||||
} else if (numberOfPayments !== 0.0) {
|
||||
// No interest rate, but number of payments exists
|
||||
return -(futureValue + presentValue) / numberOfPayments;
|
||||
}
|
||||
|
||||
return 0;*/
|
||||
const rates = {
|
||||
24 : 4.282,
|
||||
30 : 3.451,
|
||||
36 : 2.896,
|
||||
42 : 2.500,
|
||||
48 : 2.223,
|
||||
54 : 2.025,
|
||||
60 : 1.834
|
||||
};
|
||||
|
||||
const interest = rates[numberOfPayments] || 10;
|
||||
|
||||
return presentValue * (interest / 100);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_wiaas_price_commision',
|
||||
'name' => 'wiaas_pricing_rules_commision',
|
||||
'value' => $commission,
|
||||
'label' => __( 'Commision (Percent):', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<div class="wc-metaboxes-wrapper">
|
||||
<?php
|
||||
$has_available_pay_types = false;
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
if (!isset($pricing_rule_sets[$name])) {
|
||||
$has_available_pay_types = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$class = $has_available_pay_types ? '' : 'wiaas_hidden';
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_price_controls" class="toolbar toolbar-top <?php echo $class ?>">
|
||||
<select id="wiaas_pay_type" name="wiaas-pay-type" class="pricing_rule_mode">
|
||||
<?php
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
?>
|
||||
<option
|
||||
value="<?php echo $name ?>"
|
||||
id="wiaas_pay_type_<?php echo $name ?>"
|
||||
class="<?php echo $class ?>"
|
||||
>
|
||||
<?php _e( $pay_type['title'], 'wiaas' ); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button
|
||||
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
|
||||
id="wiaas-add-pricing"
|
||||
type="button"
|
||||
class="button button-primary">
|
||||
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="wiaas_package_pricing_rules" class="wc-metaboxes">
|
||||
<?php
|
||||
require 'html-package-pricing-rules-list.php';
|
||||
?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
$("#general_product_data").find('.pricing').addClass('hide_if_bundle');
|
||||
$("#general_product_data").find('.pricing').removeClass('show_if_bundle');
|
||||
|
||||
if ($('#product-type').val() === 'bundle') {
|
||||
$("#general_product_data .pricing").hide();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_checkbox(
|
||||
array(
|
||||
'id' => '_wiaas_recurring_price',
|
||||
'value' => $product_pricing['is_recurring'] ? 'yes' : 'no',
|
||||
'data_type' => 'price',
|
||||
'label' => __( $product->get_category_ids()[0], 'wiaas' ),
|
||||
)
|
||||
);
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_wiaas_recurring_pay_period',
|
||||
'value' => $product_pricing['pay_period'],
|
||||
'label' => __( 'Pay period (Months)', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
@@ -100,7 +100,7 @@ class Wiaas_Cart_API {
|
||||
$package = wc_get_product($item['product_id']);
|
||||
|
||||
// Retrieve package addons
|
||||
$addon_cart_items = Wiaas_Package_Addon::get_cart_item_addons($item);
|
||||
$addon_cart_items = wiaas_get_cart_item_addons($item);
|
||||
$additional_packages = array();
|
||||
|
||||
foreach ($addon_cart_items as $addon_cart_item) {
|
||||
@@ -109,30 +109,34 @@ class Wiaas_Cart_API {
|
||||
'idAdditionalPackage' => $additional_package->get_id(),
|
||||
'packageName' => $additional_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixedExtra' => $addon_cart_item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentExtra' => $addon_cart_item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesExtra' => $addon_cart_item['_wiaas_payment']['minimal_services_price'],
|
||||
'fixedExtra' => $addon_cart_item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrentExtra' => $addon_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||
'servicesExtra' => $addon_cart_item['_wiaas_payment']['services_extra'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Retrieve package options
|
||||
$option_cart_items = Wiaas_Package_Option_Groups::get_cart_item_options($item);
|
||||
$option_cart_items = wiaas_get_cart_item_options($item);
|
||||
$package_options = array();
|
||||
foreach ($option_cart_items as $option_cart_item) {
|
||||
$option_package = wc_get_product($option_cart_item['product_id']);
|
||||
$package_options[] = array(
|
||||
'idOptionPackage' => $option_package->get_id(),
|
||||
'groupName' => $option_package->get_title(),
|
||||
'groupName' => $option_cart_item['_wiaas_option_group_name'],
|
||||
'packageName' => $option_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixedExtra' => $item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentExtra' => $item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesExtra' => $item['_wiaas_payment']['minimal_services_price'],
|
||||
'fixedExtra' => $option_cart_item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrentExtra' => $option_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||
'servicesExtra' => $option_cart_item['_wiaas_payment']['services_extra'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$totalPrices = Wiaas_Cart::get_cart_item_total($item);
|
||||
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
|
||||
|
||||
$result[] = array(
|
||||
'idPackage' => $item['product_id'],
|
||||
@@ -144,7 +148,7 @@ class Wiaas_Cart_API {
|
||||
'bids' => array(),
|
||||
'commercialLead' => 'Coor Service Management',
|
||||
'country' => array(
|
||||
'currency' => 'SEK'
|
||||
'currency' => $country['currency']
|
||||
),
|
||||
'options' => $package_options,
|
||||
'quantity' => $item['quantity'],
|
||||
@@ -153,14 +157,14 @@ class Wiaas_Cart_API {
|
||||
'payType' => $item['_wiaas_payment']['payment_type'],
|
||||
'periodUnit' => $item['_wiaas_payment']['period_unit'],
|
||||
'idPrice' => $item['_wiaas_payment']['id'],
|
||||
'fixedPrice' => $item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentPrice' => $item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesPrice' => $item['_wiaas_payment']['minimal_services_price'],
|
||||
'fixedPrice' => $item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrentPrice' => $item['_wiaas_payment']['recurrent_extra'],
|
||||
'servicesPrice' => $item['_wiaas_payment']['services_extra'],
|
||||
|
||||
'totalPrices' => array(
|
||||
'fixedPrice' => $item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentPrice' => $item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesPrice' => $item['_wiaas_payment']['minimal_services_price'],
|
||||
'fixedPrice' => $totalPrices['fixed_extra'],
|
||||
'recurrentPrice' => $totalPrices['recurrent_extra'],
|
||||
'servicesPrice' => $totalPrices['services_extra'],
|
||||
),
|
||||
|
||||
'status' => 'available',
|
||||
@@ -302,6 +306,15 @@ class Wiaas_Cart_API {
|
||||
$order_id = WC()->checkout()->create_order(array());
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
// set order currency
|
||||
$line_items = $order->get_items();
|
||||
foreach ($line_items as $line_item) {
|
||||
if (isset($line_item['wiaas_currency'])) {
|
||||
$order->set_currency($line_item['wiaas_currency']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$order->set_shipping_city($delivery_address['city']);
|
||||
$order->set_shipping_country($delivery_address['countryName']);
|
||||
$order->set_shipping_address_1($delivery_address['detailedAddress']);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: This is temporary implemetation and will probably be changed during work on pending wiaas cart task
|
||||
* Class Wiaas_Document_API
|
||||
*/
|
||||
class Wiaas_Document_API {
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public static function register_routes() {
|
||||
register_rest_route( self::$namespace, 'download-package-file', array(
|
||||
'methods' => 'GET',
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'callback' => array(__CLASS__, 'download_package_file'),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Download package document
|
||||
*/
|
||||
public static function download_package_file() {
|
||||
$document_id = $_GET['document_id'];
|
||||
$package_id = $_GET['package_id'];
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$file = $package->get_file($document_id);
|
||||
|
||||
if ($file) {
|
||||
WC_Download_Handler::download_file_force($package->get_file_download_path($document_id), $file->get_name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
class Wiaas_Admin {
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/admin/package/class-wiaas-admin-package-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/package/class-wiaas-admin-package-addon.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/package/class-wiaas-admin-package-option-groups.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/class-wiaas-admin-package.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/class-wiaas-admin-pricing.php';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,14 @@ class Wiaas_API {
|
||||
#Delivery process controller
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-delivery-process-api.php';
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-cart-api.php';
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-document-api.php';
|
||||
}
|
||||
|
||||
public static function register_rest_routes() {
|
||||
$controllers = array(
|
||||
'Wiass_REST_Delivery_Process_API',
|
||||
'Wiaas_Cart_API'
|
||||
'Wiaas_Cart_API',
|
||||
'Wiaas_Document_API'
|
||||
);
|
||||
|
||||
foreach ( $controllers as $controller ) {
|
||||
|
||||
340
backend/app/plugins/wiaas/includes/class-wiaas-cart.php
Normal file
340
backend/app/plugins/wiaas/includes/class-wiaas-cart.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: This implementation is temporary and will probably be changed during implementation of currently pending cart task
|
||||
*
|
||||
* Class Wiaas_Cart
|
||||
*/
|
||||
class Wiaas_Cart {
|
||||
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||
|
||||
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
||||
|
||||
add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ), 10, 2 );
|
||||
|
||||
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
|
||||
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
|
||||
// Add options and addons to cart.
|
||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extend cart item data with wiaas package payment info and addons and options
|
||||
*
|
||||
* Every package cart item will be extended with its payment info but only standard package type
|
||||
* will be extended with addons and options arrays
|
||||
*
|
||||
* @param $cart_item_data
|
||||
* @param $package_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function add_cart_item_data($cart_item_data, $package_id) {
|
||||
|
||||
$is_valid = isset( $_POST[ 'price_id' ]) &&
|
||||
WC_Product_Factory::get_product_type( $package_id ) === 'bundle';
|
||||
|
||||
if (!$is_valid) {
|
||||
return $cart_item_data;
|
||||
}
|
||||
|
||||
$package_type = Wiaas_Package_Type::get_package_type($package_id);
|
||||
|
||||
$package = wc_get_product( $package_id );
|
||||
|
||||
switch ($package_type) {
|
||||
case 'standard':
|
||||
|
||||
error_log('I am standard ');
|
||||
|
||||
$cart_item['_wiaas_standard_package'] = true;
|
||||
|
||||
// Prepare addons additional data for later use.
|
||||
if ( ! isset( $cart_item_data['_wiaas_addon_items'] ) ) {
|
||||
$cart_item_data['_wiaas_addon_items' ] = array();
|
||||
}
|
||||
// Prepare options additional data for later use.
|
||||
if ( ! isset( $cart_item_data['_wiaas_option_items'] ) ) {
|
||||
$cart_item_data['_wiaas_option_items' ] = array();
|
||||
}
|
||||
|
||||
error_log('I am standard again');
|
||||
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
if (isset($country)) {
|
||||
$cart_item_data['_wiaas_currency'] = $country['currency'];
|
||||
}
|
||||
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
break;
|
||||
case 'add_on':
|
||||
$parent_key = $cart_item_data['_wiaas_addon_for'];
|
||||
$parent_item = WC()->cart->get_cart_item($parent_key);
|
||||
|
||||
$package_prices = Wiaas_Pricing::get_addon_package_customer_price($package, $parent_item['data']);
|
||||
break;
|
||||
case 'option':
|
||||
$parent_key = $cart_item_data['_wiaas_option_for'];
|
||||
$parent_item = WC()->cart->get_cart_item($parent_key);
|
||||
|
||||
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($parent_item['data'], $package);
|
||||
$cart_item_data['_wiaas_option_group_name' ] = $option_group_name;
|
||||
|
||||
$package_prices = Wiaas_Pricing::get_option_package_customer_price($package, $parent_item['data']);
|
||||
break;
|
||||
}
|
||||
|
||||
$selected_price_index = array_search($_POST['price_id'], array_column($package_prices, 'id'));
|
||||
|
||||
if (is_numeric($selected_price_index) && isset($package_prices[$selected_price_index])) {
|
||||
$cart_item_data['_wiaas_payment'] = $package_prices[$selected_price_index];
|
||||
}
|
||||
|
||||
return $cart_item_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add selected package options and addons after parent standard package is added to cart
|
||||
*
|
||||
* @param $cart_item_key
|
||||
* @param $package_id
|
||||
* @param $quantity
|
||||
* @param $variation_id
|
||||
* @param $variation
|
||||
* @param $cart_item_data
|
||||
*/
|
||||
public static function add_additional_packages_to_cart($cart_item_key, $package_id, $quantity, $variation_id, $variation, $cart_item_data) {
|
||||
|
||||
remove_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ));
|
||||
|
||||
self::_add_options_to_cart($cart_item_key, $package_id, $cart_item_data);
|
||||
|
||||
self::_add_addons_to_cart($cart_item_key, $package_id, $cart_item_data);
|
||||
|
||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update package cart item with `minimal_fixed_price` as its price
|
||||
* so resulting totals would be sum of these prices
|
||||
* @param $cart
|
||||
*/
|
||||
public static function on_calculate_totals($cart) {
|
||||
|
||||
foreach ($cart->cart_contents as $key => $cart_item) {
|
||||
if (isset($cart_item['_wiaas_standard_package'])) {
|
||||
|
||||
$total = self::get_cart_item_total($cart_item);
|
||||
|
||||
WC()->cart->cart_contents[ $key ]['data']->set_price( $total['fixed_extra'] );
|
||||
|
||||
} else {
|
||||
WC()->cart->cart_contents[ $key ]['data']->set_price( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist used payment type information for package in corresponding order line item.
|
||||
* Also for standard package type list of addons and options will be saved.
|
||||
*
|
||||
* @param $order_item
|
||||
* @param $cart_item_key
|
||||
* @param $cart_item
|
||||
* @param $order
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
|
||||
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
|
||||
|
||||
$payment = $cart_item['_wiaas_payment'];
|
||||
|
||||
$total = self::get_cart_item_total($cart_item);
|
||||
|
||||
$order_item->add_meta_data( '_wiaas_payment_type', $payment['payment_type'], true );
|
||||
$order_item->add_meta_data( '_wiaas_services_extra', $total['services_extra'], true );
|
||||
$order_item->add_meta_data( '_wiaas_service_contract_period', $payment['services_contract_period'], true );
|
||||
$order_item->add_meta_data( '_wiaas_max_contract_period', $payment['max_contract_period'], true );
|
||||
$order_item->add_meta_data( '_wiaas_period_unit', $payment['period_unit'], true );
|
||||
$order_item->add_meta_data( '_wiaas_recurrent_extra', $total['recurrent_extra'], true );
|
||||
$order_item->add_meta_data( '_wiaas_pay_period', $payment['package_pay_period'], true );
|
||||
}
|
||||
|
||||
if (isset($cart_item['_wiaas_standard_package'])) {
|
||||
$order_item->add_meta_data( '_wiaas_standard_package', $cart_item['_wiaas_standard_package'], true );
|
||||
}
|
||||
if (isset($cart_item['_wiaas_currency'])) {
|
||||
$order_item->add_meta_data( '_wiaas_currency', $cart_item['_wiaas_currency'], true );
|
||||
}
|
||||
|
||||
// add options metadata
|
||||
if (isset($cart_item['_wiaas_option_items'])) {
|
||||
$order_item->add_meta_data( '_wiaas_option_items', $cart_item['_wiaas_option_items'] );
|
||||
}
|
||||
if (isset($cart_item['_wiaas_option_for'])) {
|
||||
$order_item->add_meta_data( '_wiaas_option_for', $cart_item['_wiaas_option_for'], true );
|
||||
}
|
||||
if (isset($cart_item['_wiaas_option_group_name'])) {
|
||||
$order_item->add_meta_data( '_wiaas_option_group_name', $cart_item['_wiaas_option_group_name'], true );
|
||||
}
|
||||
|
||||
// add addons metadata
|
||||
if (isset($cart_item['_wiaas_addon_items'])) {
|
||||
$order_item->add_meta_data( '_wiaas_addon_items', $cart_item['_wiaas_addon_items'] );
|
||||
}
|
||||
if (isset($cart_item['_wiaas_addon_for'])) {
|
||||
$order_item->add_meta_data( '_wiaas_addon_for', $cart_item['_wiaas_addon_for'], true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark extended properties for order as hidden
|
||||
* @param $hidden
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function hidden_order_item_meta( $hidden ) {
|
||||
|
||||
return array_merge( $hidden, array(
|
||||
'_wiaas_payment_type',
|
||||
'_wiaas_services_extra',
|
||||
'_wiaas_service_contract_period',
|
||||
'_wiaas_max_contract_period',
|
||||
'_wiaas_period_unit',
|
||||
'_wiaas_recurrent_extra',
|
||||
'_wiaas_pay_period',
|
||||
'_wiaas_addon_items',
|
||||
'_wiaas_addon_for',
|
||||
'_wiaas_option_items',
|
||||
'_wiaas_option_for',
|
||||
'_wiaas_option_group_name',
|
||||
'_wiaas_standard_package',
|
||||
'_wiaas_currency',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate total cost for cart item
|
||||
*
|
||||
* @param $cart_item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
public static function get_cart_item_total($cart_item) {
|
||||
|
||||
$package_price = isset($cart_item['_wiaas_payment']) ? $cart_item['_wiaas_payment'] : array(
|
||||
'fixed_extra' => 0,
|
||||
'services_extra' => 0,
|
||||
'recurrent_extra' => 0
|
||||
);
|
||||
|
||||
$total_fixed_extra = $package_price['fixed_extra'];
|
||||
$total_services_extra = $package_price['services_extra'];
|
||||
$total_recurrent_extra = $package_price['recurrent_extra'];
|
||||
|
||||
$cart_item_addons = wiaas_get_cart_item_addons($cart_item);
|
||||
foreach ($cart_item_addons as $cart_item_addon) {
|
||||
$addon_price = $cart_item_addon['_wiaas_payment'];
|
||||
$total_fixed_extra += $addon_price['fixed_extra'];
|
||||
$total_services_extra += $addon_price['services_extra'];
|
||||
$total_recurrent_extra += $addon_price['recurrent_extra'];
|
||||
}
|
||||
|
||||
$cart_item_options = wiaas_get_cart_item_options($cart_item);
|
||||
foreach ($cart_item_options as $cart_item_option) {
|
||||
$option_price = $cart_item_option['_wiaas_payment'];
|
||||
$total_fixed_extra += $option_price['fixed_extra'];
|
||||
$total_services_extra += $option_price['services_extra'];
|
||||
$total_recurrent_extra += $option_price['recurrent_extra'];
|
||||
}
|
||||
|
||||
return array(
|
||||
'fixed_extra' => $total_fixed_extra,
|
||||
'services_extra' => $total_services_extra,
|
||||
'recurrent_extra' => $total_recurrent_extra
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//PRIVATE
|
||||
|
||||
/**
|
||||
* Add selected package options to cart
|
||||
* @param $cart_item_key
|
||||
* @param $package_id
|
||||
* @param $cart_item_data
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function _add_options_to_cart($cart_item_key, $package_id, $cart_item_data) {
|
||||
$is_option_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_option_items']);
|
||||
$has_selected_options = isset($_POST['options']) && is_array($_POST['options']);
|
||||
|
||||
if ($is_option_parent && $has_selected_options) {
|
||||
|
||||
$options_ids = $_POST['options'];
|
||||
|
||||
foreach ($options_ids as $option_id) {
|
||||
$option_package = wc_get_product($option_id);
|
||||
if (is_object($option_package)) {
|
||||
|
||||
$option_cart_item_key = WC()->cart->add_to_cart($option_id, 1, 0, array(), array(
|
||||
'_wiaas_option_for' => $cart_item_key
|
||||
));
|
||||
|
||||
if ($option_cart_item_key) {
|
||||
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_option_items'][] = $option_cart_item_key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add selected package addons to cart
|
||||
*
|
||||
* @param $cart_item_key
|
||||
* @param $package_id
|
||||
* @param $cart_item_data
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function _add_addons_to_cart($cart_item_key, $package_id, $cart_item_data) {
|
||||
|
||||
$is_addon_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_addon_items']);
|
||||
$has_selected_addons = isset($_POST['addons']) && is_array($_POST['addons']);
|
||||
|
||||
if ($is_addon_parent && $has_selected_addons) {
|
||||
$addons_ids = $_POST['addons'];
|
||||
|
||||
foreach ($addons_ids as $addon_id) {
|
||||
$addon_package = wc_get_product($addon_id);
|
||||
if (is_object($addon_package)) {
|
||||
|
||||
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id, 1, 0, array(), array(
|
||||
'_wiaas_addon_for' => $cart_item_key
|
||||
));
|
||||
|
||||
if ($addon_cart_item_key) {
|
||||
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_addon_items'][] = $addon_cart_item_key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Cart::init();
|
||||
104
backend/app/plugins/wiaas/includes/class-wiaas-countries.php
Normal file
104
backend/app/plugins/wiaas/includes/class-wiaas-countries.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements available wiaas countries
|
||||
*
|
||||
* Class Wiaas_Countries
|
||||
*/
|
||||
class Wiaas_Countries {
|
||||
|
||||
/**
|
||||
* Available countries for wiaas
|
||||
* @var array
|
||||
*/
|
||||
private static $available_countries = array(
|
||||
'Sweden' => array(
|
||||
'name' => 'Sweden',
|
||||
'code' => 'se',
|
||||
'vat' => 9 ,
|
||||
'currency' => 'SEK'
|
||||
),
|
||||
'Denmark' => array(
|
||||
'name' => 'Denmark',
|
||||
'code' => 'dk',
|
||||
'vat' => 9 ,
|
||||
'currency' => 'DKK'
|
||||
),
|
||||
'Finland' => array(
|
||||
'name' => 'Finland',
|
||||
'code' => 'fi',
|
||||
'vat' => 9 ,
|
||||
'currency' => 'EUR'
|
||||
),
|
||||
);
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers product taxonomy for avaiable countries
|
||||
*/
|
||||
public static function register_product_countries_taxonomy() {
|
||||
|
||||
$labels = array(
|
||||
'name' => _x( 'Country', 'taxonomy general name', 'wiaas' ),
|
||||
'singular_name' => _x( 'Country', 'taxonomy singular name', 'wiaas' ),
|
||||
'menu_name' => _x( 'Country', 'Admin menu name', 'wiaas' ),
|
||||
'search_items' => __( 'Search Countries', 'wiaas' ),
|
||||
'all_items' => __( 'All Countries', 'wiaas' ),
|
||||
'parent_item' => __( 'Parent Country', 'wiaas' ),
|
||||
'parent_item_colon' => __( 'Parent Country:', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit Country', 'wiaas' ),
|
||||
'update_item' => __( 'Update Country', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add New Country', 'wiaas' ),
|
||||
'new_item_name' => __( 'New Country Name', 'wiaas' ),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'label' => __( 'Countries', 'wiaas' ),
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'product_country' ),
|
||||
);
|
||||
|
||||
register_taxonomy( 'product_country', array( 'product' ), $args );
|
||||
|
||||
foreach (self::$available_countries as $available_country) {
|
||||
wp_insert_term($available_country['name'], 'product_country');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves country for provided package
|
||||
* @param $package
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_package_country($package) {
|
||||
return self::get_product_country($package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves country for provided product
|
||||
* @param $product
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_product_country($product) {
|
||||
$product_country = get_the_terms($product->get_id(), 'product_country');
|
||||
return is_array($product_country) && isset($product_country[0]) ?
|
||||
self::$available_countries[$product_country[0]->name] :
|
||||
null;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Countries::init();
|
||||
@@ -11,7 +11,9 @@ class Wiaas_DB_Update {
|
||||
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities',
|
||||
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
|
||||
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
|
||||
'20180826153509' => 'wiaas_create_broker_access_group'
|
||||
'20180826153509' => 'wiaas_create_broker_access_group',
|
||||
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
|
||||
'20180912101010' => 'wiaas_db_setup_default_cl'
|
||||
);
|
||||
|
||||
public static function execute() {
|
||||
|
||||
103
backend/app/plugins/wiaas/includes/class-wiaas-documents.php
Normal file
103
backend/app/plugins/wiaas/includes/class-wiaas-documents.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Wiaas Document types
|
||||
*
|
||||
* Class Wiaas_Documents
|
||||
*/
|
||||
class Wiaas_Documents {
|
||||
|
||||
/**
|
||||
* Default available document types for wiaas
|
||||
* @var array
|
||||
*/
|
||||
private static $available_doc_types = array(
|
||||
'template_questionaire' => array(
|
||||
'name' => 'Template Questionaire',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'order_questionaire' => array(
|
||||
'name' => 'Order Questionaire',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'configuration' => array(
|
||||
'name' => 'Configuration',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'install_guide' => array(
|
||||
'name' => 'Install guide',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'customer_acceptance' => array(
|
||||
'name' => 'Customer acceptance',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'template_agreement' => array(
|
||||
'name' => 'Template Agreement',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'order_agreement' => array(
|
||||
'name' => 'Order Agreement',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'installation_protocol' => array(
|
||||
'name' => 'Installation protocol',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'statements' => array(
|
||||
'name' => 'Statements',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'customer_acceptance_template' => array(
|
||||
'name' => 'Customer acceptance template',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
);
|
||||
|
||||
public static function init() {
|
||||
add_action( 'init', array( __CLASS__, 'register_wiaas_document_types' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers taxonomy and default values for wiaas document types
|
||||
*/
|
||||
public static function register_wiaas_document_types() {
|
||||
$labels = array(
|
||||
'name' => _x( 'Document type', 'taxonomy general name', 'wiaas' ),
|
||||
'singular_name' => _x( 'Document type', 'taxonomy singular name', 'wiaas' ),
|
||||
'menu_name' => _x( 'Document types', 'Admin menu name', 'wiaas' ),
|
||||
'search_items' => __( 'Search Document types', 'wiaas' ),
|
||||
'all_items' => __( 'All Document types', 'wiaas' ),
|
||||
'parent_item' => __( 'Parent Document type', 'wiaas' ),
|
||||
'parent_item_colon' => __( 'Parent Document type:', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit Document type', 'wiaas' ),
|
||||
'update_item' => __( 'Update Document type', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add New Document type', 'wiaas' ),
|
||||
'new_item_name' => __( 'New Document type Name', 'wiaas' ),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'label' => __( 'Document types', 'wiaas' ),
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'wiaas_document_types' ),
|
||||
);
|
||||
|
||||
register_taxonomy( 'wiaas_document_types', array( 'attachment' ), $args );
|
||||
|
||||
foreach (self::$available_doc_types as $key => $available_doc_type) {
|
||||
wp_insert_term($available_doc_type['name'], 'wiaas_document_types', array(
|
||||
'slug' => $key
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Documents::init();
|
||||
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class Wiaas_Order
|
||||
*
|
||||
@@ -96,17 +101,21 @@ class Wiaas_Order {
|
||||
$data = $response->get_data();
|
||||
|
||||
# apply overrides
|
||||
$data = self::_append_packages($data, $order, $request);
|
||||
|
||||
$data = self::_append_order_process($data, $order, $request);
|
||||
|
||||
$data = self::_append_customer_info($data, $order, $request);
|
||||
|
||||
$data = self::_append_commercial_lead_info($data, $order, $request);
|
||||
|
||||
$data = self::_append_wiaas_order_details($data, $order, $request);
|
||||
|
||||
$data = self::_append_order_comments($data, $order, $request);
|
||||
|
||||
$data = self::_append_packages($data, $order, $request);
|
||||
|
||||
if (isset($request['id'])) {
|
||||
|
||||
$data = self::_append_order_process($data, $order, $request);
|
||||
|
||||
$data = self::_append_order_comments($data, $order, $request);
|
||||
}
|
||||
|
||||
$response->set_data($data);
|
||||
|
||||
@@ -196,11 +205,11 @@ class Wiaas_Order {
|
||||
|
||||
# get payment type info
|
||||
$product_line['payment_type'] = $item['wiaas_payment_type'];
|
||||
$product_line['service_price'] = floatval($item['wiaas_service_price']);
|
||||
$product_line['service_price'] = floatval($item['wiaas_services_extra']);
|
||||
$product_line['service_contract_period'] = floatval($item['wiaas_service_contract_period']);
|
||||
$product_line['max_contract_period'] = floatval($item['wiaas_max_contract_period']);
|
||||
$product_line['period_unit'] = $item['wiaas_period_unit'];
|
||||
$product_line['recurring_price'] = floatval($item['wiaas_recurring_price']);
|
||||
$product_line['recurring_price'] = floatval($item['wiaas_recurrent_extra']);
|
||||
$product_line['pay_period'] = floatval($item['wiaas_pay_period']);
|
||||
|
||||
# collect status from order
|
||||
@@ -217,24 +226,27 @@ class Wiaas_Order {
|
||||
# collect completion data from order
|
||||
$product_line['date_completed'] = $data['date_completed'];
|
||||
|
||||
// collect package addons
|
||||
$product_line['additional_packages'] = array();
|
||||
$addon_items = Wiaas_Package_Addon::get_order_item_addons($order_items, $item);
|
||||
foreach ($addon_items as $addon_item) {
|
||||
$product_line['additional_packages'][] = array(
|
||||
'id' => $addon_item->get_id(),
|
||||
'name' => $addon_item->get_name(),
|
||||
);
|
||||
}
|
||||
if (isset($request['id'])) {
|
||||
// collect package addons
|
||||
$product_line['additional_packages'] = array();
|
||||
$addon_items = wiaas_get_order_item_addons($order_items, $item);
|
||||
foreach ($addon_items as $addon_item) {
|
||||
$product_line['additional_packages'][] = array(
|
||||
'id' => $addon_item->get_id(),
|
||||
'name' => $addon_item->get_name(),
|
||||
);
|
||||
}
|
||||
|
||||
// collect package options
|
||||
$product_line['options'] = array();
|
||||
$option_items = Wiaas_Package_Option_Groups::get_order_item_options($order_items, $item);
|
||||
foreach ($option_items as $option_item) {
|
||||
$product_line['options'][] = array(
|
||||
'id' => $option_item->get_id(),
|
||||
'name' => $option_item->get_name(),
|
||||
);
|
||||
// collect package options
|
||||
$product_line['options'] = array();
|
||||
$option_items = wiaas_get_order_item_options($order_items, $item);
|
||||
foreach ($option_items as $option_item) {
|
||||
$product_line['options'][] = array(
|
||||
'id' => $option_item->get_id(),
|
||||
'name' => $option_item->get_name(),
|
||||
'group_name' => $option_item['wiaas_option_group_name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$line_items[] = $product_line;
|
||||
@@ -242,6 +254,17 @@ class Wiaas_Order {
|
||||
}
|
||||
$data['line_items'] = $line_items;
|
||||
|
||||
$total_recurring_price = 0;
|
||||
|
||||
foreach ($order_items as $order_item) {
|
||||
if (isset($order_item['wiaas_standard_package'])) {
|
||||
$total_recurring_price += floatval($order_item['quantity']) * floatval($order_item['wiaas_services_extra']) +
|
||||
floatval($order_item['quantity']) * floatval($order_item['wiaas_recurrent_extra']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['recurring_price'] = $total_recurring_price;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
|
||||
class Wiaas_Package {
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-addon.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-option-groups.php';
|
||||
|
||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-type.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/wiaas-package-functions.php';
|
||||
|
||||
add_filter('woocommerce_rest_prepare_product_object', array(__CLASS__, 'transform_rest_package'), 999, 3);
|
||||
|
||||
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
||||
}
|
||||
|
||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ){
|
||||
if (isset($cart_item['_wiaas_standard_package'])) {
|
||||
$order_item->add_meta_data( '_wiaas_standard_package', $cart_item['_wiaas_standard_package'], true );
|
||||
}
|
||||
}
|
||||
|
||||
public static function hidden_order_item_meta( $hidden ) {
|
||||
|
||||
return array_merge( $hidden, array(
|
||||
'_wiaas_standard_package',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,21 +24,78 @@ class Wiaas_Package {
|
||||
* @param $package
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
* @return array
|
||||
*/
|
||||
public static function transform_rest_package($response, $package, $request) {
|
||||
$data = $response->get_data();
|
||||
|
||||
$data = self::_append_package_prices($data, $package, $request);
|
||||
$data = self::_append_country_info($data, $package, $request);
|
||||
|
||||
$data = self::_append_grouped_products($data, $package, $request);
|
||||
if (isset($request['id'])) {
|
||||
$data = self::_append_package_prices($data, $package, $request);
|
||||
|
||||
$data = self::_append_documents_info($data, $package, $request);
|
||||
|
||||
$data = self::_append_additional_packages($data, $package, $request);
|
||||
}
|
||||
|
||||
$response->set_data($data);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private static function _append_grouped_products($data, $package, $request) {
|
||||
/**
|
||||
* Append package documents
|
||||
* @param $data
|
||||
* @param $package
|
||||
* @param $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_documents_info($data, $package, $request) {
|
||||
|
||||
unset($data['downloads']);
|
||||
|
||||
$data['documents'] = array_map(function($download) {
|
||||
return array(
|
||||
'id' => $download->get_id(),
|
||||
'name' => $download->get_name(),
|
||||
'extension' => $download->get_file_extension(),
|
||||
);
|
||||
}, array_values($package->get_downloads()));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append package country and currency info
|
||||
* @param $data
|
||||
* @param $package
|
||||
* @param $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_country_info($data, $package, $request) {
|
||||
$package_country = Wiaas_Countries::get_package_country($package);
|
||||
|
||||
if (isset($package_country)) {
|
||||
$data['country'] = $package_country['name'];
|
||||
$data['country_code'] = $package_country['code'];
|
||||
$data['currency'] = $package_country['currency'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append package addons and options
|
||||
* @param $data
|
||||
* @param $package
|
||||
* @param $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_additional_packages($data, $package, $request) {
|
||||
|
||||
$data['additional_packages'] = array();
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
@@ -56,7 +104,7 @@ class Wiaas_Package {
|
||||
'id' => $addon->get_id(),
|
||||
'name' => $addon->get_name(),
|
||||
'description' => $addon->get_description(),
|
||||
'prices' => array_values(Wiaas_Package_Pricing::get_package_prices($addon))
|
||||
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,15 +114,18 @@ class Wiaas_Package {
|
||||
$data['groups'][$option_group['id']] = array(
|
||||
'id' => $option_group['id'],
|
||||
'name' => $option_group['name'],
|
||||
'default' => $option_group['default'],
|
||||
'options' => array()
|
||||
);
|
||||
$default_option_id = (int) $option_group['default'];
|
||||
|
||||
foreach ($option_group['options'] as $option_package) {
|
||||
$data['groups'][$option_group['id']]['options'][] = array(
|
||||
'id' => $option_package->get_id(),
|
||||
'name' => $option_package->get_name(),
|
||||
'description' => $option_package->get_description(),
|
||||
'default' => 0,
|
||||
'prices' => array_values(Wiaas_Package_Pricing::get_package_prices($option_package))
|
||||
'default' => $default_option_id === $option_package->get_id(),
|
||||
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -88,12 +139,10 @@ class Wiaas_Package {
|
||||
* @param $package
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_package_prices($data, $package, $request) {
|
||||
$package_prices = array_values(Wiaas_Package_Pricing::get_package_prices($package));
|
||||
|
||||
$data['prices'] = $package_prices;
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
241
backend/app/plugins/wiaas/includes/class-wiaas-pricing.php
Normal file
241
backend/app/plugins/wiaas/includes/class-wiaas-pricing.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Pricing
|
||||
*/
|
||||
class Wiaas_Pricing {
|
||||
|
||||
/**
|
||||
* Wiaas interest rate
|
||||
*/
|
||||
const INTEREST_RATE = 0.58;
|
||||
|
||||
const COMMERCIAL_LEAD_NAME = 'Coor Service Management';
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-product-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/wiaas-pricing-functions.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates total cost for product
|
||||
* @param $product
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_product_total_cost($product) {
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
return $product_price['is_recurring'] ?
|
||||
$product_price['price'] * $product_price['pay_period'] :
|
||||
$product_price['price'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates total cost for package
|
||||
* @param $package
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_package_total_cost($package) {
|
||||
|
||||
$total_cost_per_category = array();
|
||||
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
|
||||
if (!isset($total_cost_per_category[$product_cat])) {
|
||||
$total_cost_per_category[$product_cat] = 0;
|
||||
}
|
||||
|
||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
|
||||
if (Wiaas_Product_Category::is_installation($product)) {
|
||||
$total_cost_per_category[$product_cat] += $total_cost_per_category[$product_cat] < $total_item_cost ?
|
||||
$total_item_cost :
|
||||
$total_cost_per_category[$product_cat];
|
||||
} else {
|
||||
$total_cost_per_category[$product_cat] += $total_item_cost;
|
||||
}
|
||||
}
|
||||
|
||||
return array_sum(array_values($total_cost_per_category));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas standard package
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_standard_package_customer_prices($package) {
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
$cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($package)) / 100;
|
||||
$total_cost = self::get_package_total_cost($package);
|
||||
|
||||
$customer_package_prices = array();
|
||||
|
||||
foreach ($package_prices as $type => $package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$package_price,
|
||||
$cl_commision,
|
||||
$total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
|
||||
return $customer_package_prices;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas addon package
|
||||
* @param $addon_package
|
||||
* @param $parent_package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_addon_package_customer_price($addon_package, $parent_package) {
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
$addon_package_prices = Wiaas_Package_Pricing::get_package_prices($addon_package);
|
||||
|
||||
$customer_package_prices = array();
|
||||
|
||||
foreach ($addon_package_prices as $type => $addon_package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$addon_package_price,
|
||||
$parent_cl_commision,
|
||||
$parent_total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
|
||||
return $customer_package_prices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas option package
|
||||
* @param $option_package
|
||||
* @param $parent_package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_option_package_customer_price($option_package, $parent_package) {
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
$option_package_prices = Wiaas_Package_Pricing::get_package_prices($option_package);
|
||||
|
||||
$customer_package_prices = array();
|
||||
|
||||
foreach ($option_package_prices as $type => $option_package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$option_package_price,
|
||||
$parent_cl_commision,
|
||||
$parent_total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
|
||||
return $customer_package_prices;
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
||||
/**
|
||||
* Determines if customer and commercial lead are in the same company
|
||||
* For now this is hardcoded and we have only one CL
|
||||
*
|
||||
* TODO: This should be changed after customer leads are handled
|
||||
* @return bool
|
||||
*/
|
||||
private static function _is_customer_same_company_as_cl() {
|
||||
$current_user = wp_get_current_user();
|
||||
$user_organization = Wiaas_User_Organization::get_user_organization($current_user->ID);
|
||||
$is_same_company_as_cl = $user_organization->name === self::COMMERCIAL_LEAD_NAME;
|
||||
|
||||
return $is_same_company_as_cl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas package
|
||||
* @param $package_price
|
||||
* @param $cl_commision
|
||||
* @param $total_cost
|
||||
* @param $is_same_company_as_cl
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_package_customer_price($package_price, $cl_commision, $total_cost, $is_same_company_as_cl) {
|
||||
|
||||
$package_total_margin = wiaas_get_price_margin(
|
||||
$package_price['minimal_fixed_price'],
|
||||
$package_price['principal_amount'],
|
||||
$total_cost);
|
||||
$cl_margin = $package_total_margin > 0 ? $package_total_margin * $cl_commision : 0;
|
||||
|
||||
$cl_package_prices = array(
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
|
||||
$interest_rate = self::INTEREST_RATE;
|
||||
|
||||
$customer_price = array(
|
||||
'id' => $package_price['id'],
|
||||
'payment_type' => $package_price['payment_type'],
|
||||
'max_contract_period' => $package_price['max_contract_period'],
|
||||
'package_pay_period' => $package_price['package_pay_period'],
|
||||
'period_unit' => $package_price['period_unit'],
|
||||
'services_contract_period' => $package_price['services_contract_period'],
|
||||
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
|
||||
if ($is_same_company_as_cl) {
|
||||
|
||||
if ($package_price['package_pay_period'] > 0) {
|
||||
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'];
|
||||
$customer_price['recurrent_extra'] = wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
$cl_margin,
|
||||
$interest_rate);
|
||||
} else {
|
||||
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'] - $cl_margin;
|
||||
$customer_price['recurrent_extra'] = 0;
|
||||
}
|
||||
$customer_price['services_extra'] = $package_price['minimal_services_price'];
|
||||
|
||||
} else {
|
||||
|
||||
$customer_price['fixed_extra'] = $cl_package_prices['fixed_extra'] + $package_price['minimal_fixed_price'];
|
||||
$customer_price['recurrent_extra'] = $package_price['package_pay_period'] > 0 ?
|
||||
$cl_package_prices['recurrent_extra'] + wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
0,
|
||||
$interest_rate)
|
||||
: 0;
|
||||
$customer_price['services_extra'] = $cl_package_prices['services_extra'] + $package_price['minimal_services_price'];
|
||||
}
|
||||
|
||||
return $customer_price;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Pricing::init();
|
||||
10
backend/app/plugins/wiaas/includes/class-wiaas-product.php
Normal file
10
backend/app/plugins/wiaas/includes/class-wiaas-product.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Product {
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Product::init();
|
||||
@@ -110,4 +110,19 @@ function wiaas_create_broker_access_group() {
|
||||
Groups_Group::create(array(
|
||||
'name' => 'Broker',
|
||||
));
|
||||
}
|
||||
|
||||
function wiaas_db_setup_exclusive_taxonomies() {
|
||||
update_option('radio_button_for_taxonomies_options', array(
|
||||
'taxonomies' => array(
|
||||
'product_cat',
|
||||
'product_country',
|
||||
'wiaas_document_types',
|
||||
),
|
||||
'delete' => 0,
|
||||
));
|
||||
}
|
||||
|
||||
function wiaas_db_setup_default_cl() {
|
||||
wp_insert_term(Wiaas_Pricing::COMMERCIAL_LEAD_NAME, Wiaas_User_Organization::TAXONOMY_NAME);
|
||||
}
|
||||
@@ -1,134 +1,41 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements addons for standard wiaas package types
|
||||
*
|
||||
* Class Wiaas_Package_Addon
|
||||
*/
|
||||
class Wiaas_Package_Addon {
|
||||
|
||||
private static $package_addons_meta_key = '_wiaas_package_addons';
|
||||
|
||||
private static $cart_item_addon_items_key = '_wiaas_addon_items';
|
||||
|
||||
private static $cart_item_addon_parent_key = '_wiaas_addon_for';
|
||||
|
||||
public static function init() {
|
||||
|
||||
self::_add_addons_hooks();
|
||||
|
||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||
|
||||
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
||||
add_filter('wiaas_package_types', array( __CLASS__, 'register_addon_package_type' ) );
|
||||
}
|
||||
|
||||
private static function _add_addons_hooks() {
|
||||
// Add bundle-specific cart item data based on posted vars.
|
||||
add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ), 10, 2 );
|
||||
/**
|
||||
* Registers addon as available wiaas package type
|
||||
* @param $package_types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function register_addon_package_type($package_types) {
|
||||
$package_types[] = 'add_on';
|
||||
|
||||
// Add addon items to the cart.
|
||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_addons_to_cart' ), 10, 6 );
|
||||
}
|
||||
|
||||
private static function _remove_addons_hooks() {
|
||||
|
||||
remove_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ));
|
||||
|
||||
remove_action('woocommerce_add_to_cart', array( __CLASS__, 'add_addons_to_cart' ));
|
||||
}
|
||||
|
||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ){
|
||||
if (isset($cart_item[self::$cart_item_addon_items_key])) {
|
||||
$order_item->add_meta_data( self::$cart_item_addon_items_key, $cart_item[self::$cart_item_addon_items_key] );
|
||||
}
|
||||
if (isset($cart_item[self::$cart_item_addon_parent_key])) {
|
||||
$order_item->add_meta_data( self::$cart_item_addon_parent_key, $cart_item[self::$cart_item_addon_parent_key], true );
|
||||
}
|
||||
}
|
||||
|
||||
public static function hidden_order_item_meta( $hidden ) {
|
||||
|
||||
return array_merge( $hidden, array(
|
||||
self::$cart_item_addon_items_key,
|
||||
self::$cart_item_addon_parent_key,
|
||||
) );
|
||||
}
|
||||
|
||||
public static function add_cart_item_data($cart_item_data, $package_id) {
|
||||
|
||||
// If cart item that will be added is actually requested package
|
||||
if ($_POST['package_id'] = $package_id) {
|
||||
// Prepare additional data for later use.
|
||||
if ( ! isset( $cart_item_data[self::$cart_item_addon_items_key] ) ) {
|
||||
$cart_item_data[self::$cart_item_addon_items_key ] = array();
|
||||
}
|
||||
}
|
||||
|
||||
return $cart_item_data;
|
||||
}
|
||||
|
||||
public static function add_addons_to_cart($cart_item_key, $package_id, $quantity, $variation_id, $variation, $cart_item_data) {
|
||||
|
||||
$is_addon_parent = $_POST['package_id'] = $package_id && isset($cart_item_data[self::$cart_item_addon_items_key]);
|
||||
$has_selected_addons = isset($_POST['addons']) && is_array($_POST['addons']);
|
||||
|
||||
self::_remove_addons_hooks();
|
||||
|
||||
if ($is_addon_parent && $has_selected_addons) {
|
||||
$addons_ids = $_POST['addons'];
|
||||
|
||||
foreach ($addons_ids as $addon_id) {
|
||||
$addon_package = wc_get_product($addon_id);
|
||||
if (is_object($addon_package)) {
|
||||
|
||||
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id);
|
||||
|
||||
if ($addon_cart_item_key) {
|
||||
WC()->cart->cart_contents[$addon_cart_item_key][self::$cart_item_addon_parent_key] = $cart_item_key;
|
||||
|
||||
WC()->cart->cart_contents[ $cart_item_key ][self::$cart_item_addon_items_key][] = $addon_cart_item_key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::_add_addons_hooks();
|
||||
}
|
||||
|
||||
public static function get_cart_item_addons($cart_item) {
|
||||
$addon_cart_items = array();
|
||||
|
||||
if (isset($cart_item[self::$cart_item_addon_items_key])) {
|
||||
$addon_cart_items_ids = $cart_item[self::$cart_item_addon_items_key];
|
||||
|
||||
foreach ($addon_cart_items_ids as $addon_cart_item_id) {
|
||||
$addon_cart_item = WC()->cart->get_cart_item($addon_cart_item_id);
|
||||
|
||||
if (isset($addon_cart_item)) {
|
||||
$addon_cart_items[] = $addon_cart_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $addon_cart_items;
|
||||
}
|
||||
|
||||
public static function get_order_item_addons($order_items, $parent_order_item) {
|
||||
$addon_order_items = array();
|
||||
|
||||
if (isset($parent_order_item['wiaas_addon_items']) && isset($parent_order_item['bundle_cart_key'])) {
|
||||
foreach ($order_items as $order_item) {
|
||||
if (isset($order_item['bundle_cart_key']) && $order_item['wiaas_addon_for'] === $parent_order_item['bundle_cart_key']) {
|
||||
$addon_order_items[] = $order_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $addon_order_items;
|
||||
}
|
||||
|
||||
public static function set_package_addons($package, $children_ids) {
|
||||
$package->update_meta_data( self::$package_addons_meta_key, $children_ids );
|
||||
$package->save_meta_data();
|
||||
return $package_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves addons configured for provided wiaas standard package type
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_package_addons($package) {
|
||||
$addon_ids = $package->get_meta( self::$package_addons_meta_key );
|
||||
$addon_ids = $package->get_meta( '__wiaas_package_addons' );
|
||||
|
||||
$addons = array();
|
||||
|
||||
@@ -141,6 +48,16 @@ class Wiaas_Package_Addon {
|
||||
|
||||
return $addons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets addons for provided wiaas standard package type
|
||||
* @param $package
|
||||
* @param $children_ids
|
||||
*/
|
||||
public static function set_package_addons($package, $children_ids) {
|
||||
$package->update_meta_data( '__wiaas_package_addons', $children_ids );
|
||||
$package->save_meta_data();
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_Addon::init();
|
||||
@@ -1,136 +1,63 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementas groups of optional packages available for wiaas standard package type
|
||||
*
|
||||
* Class Wiaas_Package_Option_Groups
|
||||
*/
|
||||
class Wiaas_Package_Option_Groups {
|
||||
|
||||
private static $package_option_groups_meta_key = '_wiaas_package_option_groups';
|
||||
|
||||
private static $cart_item_option_items_key = '_wiaas_option_items';
|
||||
|
||||
private static $cart_item_option_parent_key = '_wiaas_option_for';
|
||||
|
||||
public static function init() {
|
||||
|
||||
self::_add_options_hooks();
|
||||
|
||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||
|
||||
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
||||
add_filter('wiaas_package_types', array( __CLASS__, 'register_option_package_type' ) );
|
||||
}
|
||||
|
||||
private static function _add_options_hooks() {
|
||||
// Add bundle-specific cart item data based on posted vars.
|
||||
add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ), 10, 2 );
|
||||
/**
|
||||
* Register option as ne of available wiaas package types
|
||||
* @param $package_types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function register_option_package_type($package_types) {
|
||||
$package_types[] = 'option';
|
||||
|
||||
// Add option items to the cart.
|
||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_options_to_cart' ), 10, 6 );
|
||||
return $package_types;
|
||||
}
|
||||
|
||||
private static function _remove_options_hooks() {
|
||||
/**
|
||||
* Retrives options group name for package option
|
||||
* @param $package
|
||||
* @param $option_package
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function get_group_name_for_package_option($package, $option_package) {
|
||||
$option_groups = $package->get_meta( '_wiaas_package_option_groups' );
|
||||
|
||||
remove_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ));
|
||||
|
||||
remove_action('woocommerce_add_to_cart', array( __CLASS__, 'add_options_to_cart' ));
|
||||
}
|
||||
|
||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ){
|
||||
if (isset($cart_item[self::$cart_item_option_items_key])) {
|
||||
$order_item->add_meta_data( self::$cart_item_option_items_key, $cart_item[self::$cart_item_option_items_key] );
|
||||
}
|
||||
if (isset($cart_item[self::$cart_item_option_parent_key])) {
|
||||
$order_item->add_meta_data( self::$cart_item_option_parent_key, $cart_item[self::$cart_item_option_parent_key], true );
|
||||
}
|
||||
}
|
||||
|
||||
public static function hidden_order_item_meta( $hidden ) {
|
||||
|
||||
return array_merge( $hidden, array(
|
||||
self::$cart_item_option_items_key,
|
||||
self::$cart_item_option_parent_key,
|
||||
) );
|
||||
}
|
||||
|
||||
public static function set_package_option_groups($package, $groups_data) {
|
||||
$package->update_meta_data( self::$package_option_groups_meta_key, $groups_data );
|
||||
$package->save_meta_data();
|
||||
}
|
||||
|
||||
public static function add_cart_item_data($cart_item_data, $package_id) {
|
||||
|
||||
// If cart item that will be added is actually requested package
|
||||
if ($_POST['package_id'] = $package_id) {
|
||||
// Prepare additional data for later use.
|
||||
if ( ! isset( $cart_item_data[self::$cart_item_option_items_key] ) ) {
|
||||
$cart_item_data[self::$cart_item_option_items_key ] = array();
|
||||
}
|
||||
}
|
||||
|
||||
return $cart_item_data;
|
||||
}
|
||||
|
||||
public static function add_options_to_cart($cart_item_key, $package_id, $quantity, $variation_id, $variation, $cart_item_data) {
|
||||
|
||||
$is_option_parent = $_POST['package_id'] = $package_id && isset($cart_item_data[self::$cart_item_option_items_key]);
|
||||
$has_selected_options = isset($_POST['options']) && is_array($_POST['options']);
|
||||
|
||||
if ($is_option_parent && $has_selected_options) {
|
||||
|
||||
self::_remove_options_hooks();
|
||||
|
||||
$options_ids = $_POST['options'];
|
||||
|
||||
foreach ($options_ids as $option_id) {
|
||||
$option_package = wc_get_product($option_id);
|
||||
if (is_object($option_package)) {
|
||||
|
||||
$option_cart_item_key = WC()->cart->add_to_cart($option_id);
|
||||
|
||||
if ($option_cart_item_key) {
|
||||
WC()->cart->cart_contents[$option_cart_item_key][self::$cart_item_option_parent_key] = $cart_item_key;
|
||||
|
||||
WC()->cart->cart_contents[ $cart_item_key ][self::$cart_item_option_items_key][] = $option_cart_item_key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::_add_options_hooks();
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_cart_item_options($cart_item) {
|
||||
$option_cart_items = array();
|
||||
|
||||
if (isset($cart_item[self::$cart_item_option_items_key])) {
|
||||
$option_cart_items_ids = $cart_item[self::$cart_item_option_items_key];
|
||||
|
||||
foreach ($option_cart_items_ids as $option_cart_item_id) {
|
||||
$option_cart_item = WC()->cart->get_cart_item($option_cart_item_id);
|
||||
|
||||
if (isset($option_cart_item)) {
|
||||
$option_cart_items[] = $option_cart_item;
|
||||
foreach ($option_groups as $option_group) {
|
||||
foreach ($option_group['options'] as $group_option_id) {
|
||||
if ((int) $group_option_id === $option_package->get_id()) {
|
||||
return $option_group['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $option_cart_items;
|
||||
}
|
||||
|
||||
public static function get_order_item_options($order_items, $parent_order_item) {
|
||||
$option_order_items = array();
|
||||
|
||||
if (isset($parent_order_item['wiaas_option_items']) && isset($parent_order_item['bundle_cart_key'])) {
|
||||
foreach ($order_items as $order_item) {
|
||||
if (isset($order_item['bundle_cart_key']) && $order_item['wiaas_option_for'] === $parent_order_item['bundle_cart_key']) {
|
||||
$option_order_items[] = $order_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $option_order_items;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve groups of optional packages configured for provided package
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_package_option_groups($package) {
|
||||
|
||||
$groups_data = $package->get_meta( self::$package_option_groups_meta_key );
|
||||
$groups_data = $package->get_meta( '_wiaas_package_option_groups' );
|
||||
|
||||
$option_groups = array();
|
||||
|
||||
@@ -153,6 +80,16 @@ class Wiaas_Package_Option_Groups {
|
||||
|
||||
return $option_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set groups of optional packages for provided package
|
||||
* @param $package
|
||||
* @param $groups_data
|
||||
*/
|
||||
public static function set_package_option_groups($package, $groups_data) {
|
||||
$package->update_meta_data( '_wiaas_package_option_groups', $groups_data );
|
||||
$package->save_meta_data();
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_Option_Groups::init();
|
||||
@@ -1,204 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Package_Pricing
|
||||
*/
|
||||
class Wiaas_Package_Pricing {
|
||||
|
||||
/**
|
||||
* Available pay types for wiaas packages
|
||||
* @var array
|
||||
*/
|
||||
private static $pay_types = array(
|
||||
'purchase' => array(
|
||||
'title' => 'Purchase',
|
||||
'package_pay_period' => 0,
|
||||
'services_contract_period' => 0,
|
||||
'max_contract_period' => 36,
|
||||
'period_unit' => 'month',
|
||||
'labe'
|
||||
),
|
||||
'purchase_24' => array(
|
||||
'title' => 'Purchase with 24M commitment',
|
||||
'package_pay_period' => 0,
|
||||
'services_contract_period' => 24,
|
||||
'max_contract_period' => 36,
|
||||
'period_unit' => 'month'
|
||||
),
|
||||
'managed_36' => array(
|
||||
'title' => 'Managed service 36M rent',
|
||||
'package_pay_period' => 36,
|
||||
'services_contract_period'=> 36,
|
||||
'max_contract_period' => 36,
|
||||
'period_unit' => 'month'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Payment fields for pricing rules
|
||||
* @var array
|
||||
*/
|
||||
private static $payment_fields = array(
|
||||
'minimal_fixed_price' => 0,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 0
|
||||
);
|
||||
|
||||
/**
|
||||
* Meta key for pricing rules
|
||||
* @var string
|
||||
*/
|
||||
private static $package_prices_meta_key = '_wiaas_pricing_rules';
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||
|
||||
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
||||
|
||||
add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ), 10, 2 );
|
||||
|
||||
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
|
||||
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
}
|
||||
|
||||
public static function add_cart_item_data($cart_item_data, $package_id) {
|
||||
|
||||
if ( isset( $_POST[ 'price_id' ]) &&
|
||||
WC_Product_Factory::get_product_type( $package_id ) === 'bundle') {
|
||||
$selected_price_id = $_POST['price_id'];
|
||||
$package = wc_get_product( $package_id );
|
||||
|
||||
$configured_package_prices = self::get_package_prices($package);
|
||||
|
||||
$selected_price = $configured_package_prices[$selected_price_id];
|
||||
|
||||
if (isset($selected_price)) {
|
||||
$cart_item_data['_wiaas_payment'] = $selected_price;
|
||||
}
|
||||
}
|
||||
return $cart_item_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for available payment types
|
||||
* @return array
|
||||
*/
|
||||
public static function get_available_pay_types() {
|
||||
return self::$pay_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get empty payment rule with initialized fields to default values
|
||||
* @return array
|
||||
*/
|
||||
public static function get_empty_pricing_rule() {
|
||||
return self::$payment_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update package cart item with `minimal_fixed_price` as its price
|
||||
* so resulting totals would be sum of these prices
|
||||
* @param $cart
|
||||
*/
|
||||
public static function on_calculate_totals($cart) {
|
||||
|
||||
foreach ($cart->cart_contents as $key => $cart_item) {
|
||||
if (isset($cart_item['_wiaas_payment'])) {
|
||||
|
||||
$price = $cart_item['_wiaas_payment'];
|
||||
|
||||
WC()->cart->cart_contents[ $key ]['data']->set_price( $price['minimal_fixed_price'] );
|
||||
}
|
||||
|
||||
if (isset($cart_item['bundled_by'])) {
|
||||
WC()->cart->cart_contents[ $key ]['data']->set_price( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist used payment type informations for package in corresponding order line item
|
||||
* @param $order_item
|
||||
* @param $cart_item_key
|
||||
* @param $cart_item
|
||||
* @param $order
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
|
||||
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
|
||||
|
||||
$payment = $cart_item['_wiaas_payment'];
|
||||
|
||||
$order_item->add_meta_data( '_wiaas_payment_type', $payment['payment_type'], true );
|
||||
$order_item->add_meta_data( '_wiaas_service_price', $payment['minimal_services_price'], true );
|
||||
$order_item->add_meta_data( '_wiaas_service_contract_period', $payment['services_contract_period'], true );
|
||||
$order_item->add_meta_data( '_wiaas_max_contract_period', $payment['max_contract_period'], true );
|
||||
$order_item->add_meta_data( '_wiaas_period_unit', $payment['period_unit'], true );
|
||||
$order_item->add_meta_data( '_wiaas_recurring_price', $payment['recurrent_price'], true );
|
||||
$order_item->add_meta_data( '_wiaas_pay_period', $payment['package_pay_period'], true );
|
||||
}
|
||||
}
|
||||
|
||||
public static function hidden_order_item_meta( $hidden ) {
|
||||
|
||||
return array_merge( $hidden, array(
|
||||
'_wiaas_payment_type',
|
||||
'_wiaas_service_price',
|
||||
'_wiaas_service_contract_period',
|
||||
'_wiaas_max_contract_period',
|
||||
'_wiaas_period_unit',
|
||||
'_wiaas_recurring_price',
|
||||
'_wiaas_pay_period'
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve configured payment prices for package
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_package_prices($package) {
|
||||
$pricing_rules = $package->get_meta( self::$package_prices_meta_key );
|
||||
|
||||
$prices = array();
|
||||
foreach ($pricing_rules as $type => $pricing_rule) {
|
||||
|
||||
$pay_type = self::$pay_types[$type];
|
||||
|
||||
$prices[$type] = array(
|
||||
'id' => $type,
|
||||
'payment_type' => $pay_type['title'],
|
||||
'max_contract_period' => $pay_type['max_contract_period'],
|
||||
'package_pay_period' => floatval($pay_type['package_pay_period']),
|
||||
'period_unit' => $pay_type['period_unit'],
|
||||
'services_contract_period' => $pay_type['services_contract_period'],
|
||||
|
||||
'minimal_fixed_price' => floatval($pricing_rule['minimal_fixed_price']),
|
||||
'principal_amount' => floatval($pricing_rule['principal_amount']),
|
||||
'recurrent_price' => 0,
|
||||
'minimal_services_price' => floatval($pricing_rule['minimal_services_price']),
|
||||
);
|
||||
}
|
||||
|
||||
return $prices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist payment prices configuration for package
|
||||
* @param $package
|
||||
* @param $pricing_rules
|
||||
*/
|
||||
public static function set_package_prices($package, $pricing_rules) {
|
||||
if ( isset( $pricing_rules ) ) {
|
||||
$package->update_meta_data( self::$package_prices_meta_key, $pricing_rules );
|
||||
} else {
|
||||
$package->delete_meta_data( self::$package_prices_meta_key );
|
||||
}
|
||||
$package->save_meta_data();
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_Pricing::init();
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class Wiaas_Package_Type
|
||||
*/
|
||||
|
||||
|
||||
class Wiaas_Package_Type {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('init', array( __CLASS__, 'register_package_type_taxonomy' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register wiaas package type taxonomy
|
||||
*/
|
||||
public static function register_package_type_taxonomy() {
|
||||
|
||||
$labels = array(
|
||||
'name' => _x( 'Package type', 'taxonomy general name', 'wiaas' ),
|
||||
'singular_name' => _x( 'Package type', 'taxonomy singular name', 'wiaas' ),
|
||||
'search_items' => __( 'Search Package types', 'wiaas' ),
|
||||
'all_items' => __( 'All Package types', 'wiaas' ),
|
||||
'parent_item' => __( 'Parent Package type', 'wiaas' ),
|
||||
'parent_item_colon' => __( 'Parent Package type:', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit Package type', 'wiaas' ),
|
||||
'update_item' => __( 'Update Package type', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add New Package type', 'wiaas' ),
|
||||
'new_item_name' => __( 'New Package type Name', 'wiaas' ),
|
||||
'menu_name' => __( 'Package type', 'wiaas' ),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'labels' => $labels,
|
||||
'show_ui' => false,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'package_type' ),
|
||||
);
|
||||
|
||||
register_taxonomy( 'package_type', array( 'product' ), $args );
|
||||
|
||||
|
||||
// Register available package types
|
||||
// standard package type is default package type for wiaas packages
|
||||
|
||||
$types = apply_filters('wiaas_package_types', array('standard'));
|
||||
|
||||
foreach ($types as $type) {
|
||||
wp_insert_term($type, 'package_type');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve available wiaas package types
|
||||
* @return array
|
||||
*/
|
||||
public static function get_available_package_types() {
|
||||
$types = get_terms( array(
|
||||
'taxonomy' => 'package_type',
|
||||
'hide_empty' => false,
|
||||
) );
|
||||
|
||||
return array_map(function($type) {
|
||||
return $type->name;
|
||||
}, $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve package type for provided package id
|
||||
* @param $package_id
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function get_package_type($package_id) {
|
||||
$terms = wp_get_object_terms($package_id, 'package_type');
|
||||
$package_type = isset($terms[0]) ? $terms[0]->name : null;
|
||||
return $package_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set package type for provided package id
|
||||
* @param $package_id
|
||||
* @param $type
|
||||
*/
|
||||
public static function set_package_type($package_id, $type) {
|
||||
|
||||
wp_delete_object_term_relationships( $package_id, 'package_type' );
|
||||
|
||||
if (isset($type)) {
|
||||
wp_set_object_terms($package_id, $type, 'package_type', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_Type::init();
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Collect optional packages for provided order item package
|
||||
* @param $order_items
|
||||
* @param $parent_order_item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_order_item_options($order_items, $parent_order_item) {
|
||||
$option_order_items = array();
|
||||
|
||||
if (isset($parent_order_item['wiaas_option_items']) && isset($parent_order_item['bundle_cart_key'])) {
|
||||
foreach ($order_items as $order_item) {
|
||||
if (isset($order_item['bundle_cart_key']) && $order_item['wiaas_option_for'] === $parent_order_item['bundle_cart_key']) {
|
||||
$option_order_items[] = $order_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $option_order_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect optional packages cart items for provided cart item
|
||||
* @param $cart_item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_cart_item_options($cart_item) {
|
||||
$option_cart_items = array();
|
||||
|
||||
if (isset($cart_item['_wiaas_option_items'])) {
|
||||
$option_cart_items_ids = $cart_item['_wiaas_option_items'];
|
||||
|
||||
foreach ($option_cart_items_ids as $option_cart_item_id) {
|
||||
$option_cart_item = WC()->cart->get_cart_item($option_cart_item_id);
|
||||
|
||||
if (isset($option_cart_item)) {
|
||||
$option_cart_items[] = $option_cart_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $option_cart_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect addon packages for provided order item package
|
||||
* @param $order_items
|
||||
* @param $parent_order_item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_order_item_addons($order_items, $parent_order_item) {
|
||||
$addon_order_items = array();
|
||||
|
||||
if (isset($parent_order_item['wiaas_addon_items']) && isset($parent_order_item['bundle_cart_key'])) {
|
||||
foreach ($order_items as $order_item) {
|
||||
if (isset($order_item['bundle_cart_key']) && $order_item['wiaas_addon_for'] === $parent_order_item['bundle_cart_key']) {
|
||||
$addon_order_items[] = $order_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $addon_order_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect addon packages cart items for provided cart item
|
||||
* @param $cart_item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_cart_item_addons($cart_item) {
|
||||
$addon_cart_items = array();
|
||||
|
||||
if (isset($cart_item['_wiaas_addon_items'])) {
|
||||
$addon_cart_items_ids = $cart_item['_wiaas_addon_items'];
|
||||
|
||||
foreach ($addon_cart_items_ids as $addon_cart_item_id) {
|
||||
$addon_cart_item = WC()->cart->get_cart_item($addon_cart_item_id);
|
||||
|
||||
if (isset($addon_cart_item)) {
|
||||
$addon_cart_items[] = $addon_cart_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $addon_cart_items;
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Package_Pricing
|
||||
*/
|
||||
class Wiaas_Package_Pricing {
|
||||
|
||||
/**
|
||||
* Available pay types for wiaas packages
|
||||
* @var array
|
||||
*/
|
||||
private static $pay_types = array(
|
||||
'purchase' => array(
|
||||
'title' => 'Purchase',
|
||||
'package_pay_period' => 0,
|
||||
'services_contract_period' => 0,
|
||||
'max_contract_period' => 36,
|
||||
'period_unit' => 'month',
|
||||
'labe'
|
||||
),
|
||||
'purchase_24' => array(
|
||||
'title' => 'Purchase with 24M commitment',
|
||||
'package_pay_period' => 0,
|
||||
'services_contract_period' => 24,
|
||||
'max_contract_period' => 36,
|
||||
'period_unit' => 'month'
|
||||
),
|
||||
'managed_36' => array(
|
||||
'title' => 'Managed service 36M rent',
|
||||
'package_pay_period' => 36,
|
||||
'services_contract_period'=> 36,
|
||||
'max_contract_period' => 36,
|
||||
'period_unit' => 'month'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Payment fields for pricing rules
|
||||
* @var array
|
||||
*/
|
||||
private static $payment_fields = array(
|
||||
'minimal_fixed_price' => 0,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 0
|
||||
);
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('woocommerce_bundle_price_html', array( __CLASS__, 'get_package_price_html' ), 10, 2);
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
public static function get_available_pay_types() {
|
||||
return self::$pay_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get empty payment rule with initialized fields to default values
|
||||
* @return array
|
||||
*/
|
||||
public static function get_empty_pricing_rule() {
|
||||
return self::$payment_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve configured payment prices for package
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_package_prices($package) {
|
||||
return self::_get_package_prices($package);
|
||||
}
|
||||
|
||||
public static function get_package_pricing_commission($package) {
|
||||
return self::_get_package_pricing_commision($package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist payment prices configuration for package
|
||||
* @param $package
|
||||
* @param $pricing_rules
|
||||
*/
|
||||
public static function set_package_prices($package, $pricing_rules, $commision) {
|
||||
if ( isset( $pricing_rules ) ) {
|
||||
$package->update_meta_data( '_wiaas_pricing_rules', $pricing_rules );
|
||||
$package->update_meta_data('_package_pricing_commision', $commision, true);
|
||||
} else {
|
||||
$package->delete_meta_data( '_wiaas_pricing_rules' );
|
||||
}
|
||||
$package->save_meta_data();
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
||||
private static function _get_package_prices($package) {
|
||||
$pricing_rules = $package->get_meta( '_wiaas_pricing_rules' );
|
||||
$commision = self::_get_package_pricing_commision($package);
|
||||
|
||||
$prices = array();
|
||||
foreach ($pricing_rules as $type => $pricing_rule) {
|
||||
|
||||
$pay_type = self::$pay_types[$type];
|
||||
|
||||
$prices[$type] = array(
|
||||
'id' => $type,
|
||||
'payment_type' => $pay_type['title'],
|
||||
'max_contract_period' => $pay_type['max_contract_period'],
|
||||
'package_pay_period' => floatval($pay_type['package_pay_period']),
|
||||
'period_unit' => $pay_type['period_unit'],
|
||||
'services_contract_period' => $pay_type['services_contract_period'],
|
||||
'commision_split' => $commision / 100.00,
|
||||
|
||||
'minimal_fixed_price' => floatval($pricing_rule['minimal_fixed_price']),
|
||||
'principal_amount' => floatval($pricing_rule['principal_amount']),
|
||||
'minimal_services_price' => floatval($pricing_rule['minimal_services_price']),
|
||||
);
|
||||
}
|
||||
|
||||
return $prices;
|
||||
}
|
||||
|
||||
private static function _get_package_pricing_commision($package) {
|
||||
$commision = $package->get_meta( '_package_pricing_commision', true);
|
||||
|
||||
if (!isset($commision) || $commision === '') {
|
||||
return 50.00;
|
||||
}
|
||||
|
||||
return (float) $commision;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_Pricing::init();
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Wiaas_Product_Pricing
|
||||
*/
|
||||
class Wiaas_Product_Pricing {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('woocommerce_get_price_html', array(__CLASS__, 'get_product_price_html'), 10, 2);
|
||||
|
||||
add_filter('woocommerce_bundled_item_price', array(__CLASS__, 'get_bundled_product_fixed_price'), 10, 4);
|
||||
|
||||
add_filter('woocommerce_bundled_item_is_priced_individually', array(__CLASS__, 'is_bundled_product_price_fixed'), 10, 2);
|
||||
|
||||
add_filter('woocommerce_bundles_process_bundled_item_admin_data', array(__CLASS__, 'handle_bundled_product_pricing'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures each bundled product to be priced individually as default setting
|
||||
* @param $bundled_item_data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function handle_bundled_product_pricing($bundled_item_data) {
|
||||
|
||||
$bundled_item_data[ 'priced_individually' ] = 'yes';
|
||||
|
||||
return $bundled_item_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bunded product has fixed price
|
||||
* @param $is_priced_individually
|
||||
* @param $bundled_item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_bundled_product_price_fixed($is_priced_individually, $bundled_item) {
|
||||
|
||||
$bundled_product = $bundled_item->product;
|
||||
|
||||
return isset($bundled_product) ?
|
||||
!self::_get_is_product_price_recurring($bundled_product) :
|
||||
false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrives fixed price for bundled product
|
||||
* @param $price
|
||||
* @param $product
|
||||
* @param $discount
|
||||
* @param $bundled_item
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_bundled_product_fixed_price($price, $product, $discount, $bundled_item) {
|
||||
if (self::_get_is_product_price_recurring($product)) {
|
||||
return 0;
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds html for product
|
||||
* @param $price
|
||||
* @param $object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_product_price_html($price, $object) {
|
||||
|
||||
if ($object instanceof WC_Product_Simple) {
|
||||
$is_recurring = self::_get_is_product_price_recurring($object);
|
||||
if ($is_recurring) {
|
||||
$price .= ' / month';
|
||||
}
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves product configured price
|
||||
* @param $product
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_product_price($product) {
|
||||
$is_recurring = self::_get_is_product_price_recurring($product);
|
||||
$pay_period = self::_get_product_price_pay_period($product);
|
||||
|
||||
return array(
|
||||
'price' => $product->get_price(),
|
||||
'is_recurring' => $is_recurring,
|
||||
'pay_period' => $pay_period
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets configured product price
|
||||
* @param $product
|
||||
* @param $price
|
||||
* @param bool $is_recurring
|
||||
* @param int $pay_period
|
||||
*/
|
||||
public static function set_product_price($product, $price, $is_recurring = false, $pay_period = 0) {
|
||||
$product->set_price($price);
|
||||
self::_set_is_product_price_recurring($product, $is_recurring);
|
||||
self::_set_product_price_pay_period($product, $pay_period);
|
||||
|
||||
$product->save_meta_data();
|
||||
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
||||
private static function _get_is_product_price_recurring($product) {
|
||||
return $product->get_meta( '_wiaas_is_product_price_recurring', true) === 'yes';
|
||||
}
|
||||
|
||||
private static function _get_product_price_pay_period($product) {
|
||||
return (int) $product->get_meta( '_wiaas_product_pay_period', true);
|
||||
}
|
||||
|
||||
private static function _set_is_product_price_recurring($product, $is_recurring) {
|
||||
$product->update_meta_data('_wiaas_is_product_price_recurring', $is_recurring ? 'yes' : 'no');
|
||||
}
|
||||
|
||||
|
||||
private static function _set_product_price_pay_period($product, $pay_period) {
|
||||
$product->update_meta_data('_wiaas_product_pay_period', (int) $pay_period);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Product_Pricing::init();
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copy of Excel's PMT function.
|
||||
* Credit: http://thoughts-of-laszlo.blogspot.nl/2012/08/complete-formula-behind-excels-pmt.html
|
||||
*
|
||||
* @param double $interest The interest rate for the loan.
|
||||
* @param int $num_of_payments The total number of payments for the loan in months.
|
||||
* @param double $PV The present value, or the total amount that a series of future payments is worth now;
|
||||
* Also known as the principal.
|
||||
* @param double $FV The future value, or a cash balance you want to attain after the last payment is made.
|
||||
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
|
||||
* @param int $Type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
|
||||
* 0 = At the end of period
|
||||
* 1 = At the beginning of the period
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function wiaas_PMT($interest, $num_of_payments, $PV, $FV = 0.00, $Type = 0){
|
||||
/*$interest = $interest / 12;
|
||||
$xp=pow((1+$interest),$num_of_payments);
|
||||
return
|
||||
($PV* $interest*$xp/($xp-1)+$interest/($xp-1)*$FV)*
|
||||
($Type==0 ? 1 : 1/($interest+1));*/
|
||||
$rates = [
|
||||
24 => 4.282,
|
||||
30 => 3.451,
|
||||
36 => 2.896,
|
||||
42 => 2.500,
|
||||
48 => 2.223,
|
||||
54 => 2.025,
|
||||
60 => 1.834
|
||||
];
|
||||
|
||||
$interest = isset($rates[$num_of_payments]) ? $rates[$num_of_payments] : 10;
|
||||
|
||||
return round($PV * ($interest / 100));
|
||||
}
|
||||
|
||||
function wiaas_get_recurrent_price_mortage($principal_amount, $pay_period, $margin, $interest_rate) {
|
||||
$new_principal_amount = $principal_amount - $margin;
|
||||
$interest_rate = $interest_rate / 100;
|
||||
$fixed_mortage = wiaas_PMT($interest_rate, $pay_period, $new_principal_amount);
|
||||
|
||||
return round($fixed_mortage, 2);
|
||||
}
|
||||
|
||||
function wiaas_get_price_margin($fixed_price, $principal_amount, $total_cost) {
|
||||
$total_gain = $fixed_price + $principal_amount;
|
||||
return $total_gain - $total_cost;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers available wiaas product categories
|
||||
*
|
||||
* Class Wiaas_Product_Category
|
||||
*/
|
||||
class Wiaas_Product_Category {
|
||||
|
||||
/**
|
||||
* Available wiaas product categories
|
||||
* @var array
|
||||
*/
|
||||
private static $available_product_categories = array(
|
||||
'hardware' => array(
|
||||
'name' => 'Hardware',
|
||||
'type' => 'product',
|
||||
),
|
||||
'software' => array(
|
||||
'name' => 'Software',
|
||||
'type' => 'product',
|
||||
),
|
||||
'service' => array(
|
||||
'name' => 'Service',
|
||||
'type' => 'service',
|
||||
),
|
||||
'installation' => array(
|
||||
'name' => 'Installation',
|
||||
'type' => 'installation',
|
||||
),
|
||||
);
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers available wiaas product categories
|
||||
*/
|
||||
public static function register_product_categories() {
|
||||
|
||||
foreach (self::$available_product_categories as $key => $available_product_category) {
|
||||
wp_insert_term($key, 'product_cat');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves category for provided product
|
||||
* @param $product
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function get_category($product) {
|
||||
$product_categories = get_the_terms($product->get_id(), 'product_cat');
|
||||
return is_array($product_categories) && isset($product_categories[0]) ?
|
||||
$product_categories[0]->name :
|
||||
null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if provided product is installation
|
||||
* @param $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_installation($product) {
|
||||
return self::_get_product_category_type($product) === 'installation';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if provided product is service
|
||||
* @param $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_service($product) {
|
||||
return self::_get_product_category_type($product) === 'service';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PRIVATE
|
||||
|
||||
|
||||
/**
|
||||
* Retrives product type based on its category for provided product
|
||||
* @param $product
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private static function _get_product_category_type($product) {
|
||||
$product_categories = get_the_terms($product->get_id(), 'product_cat');
|
||||
|
||||
return is_array($product_categories) &&
|
||||
isset($product_categories[0]) &&
|
||||
isset(self::$available_product_categories[$product_categories[0]->name]) ?
|
||||
self::$available_product_categories[$product_categories[0]->name]['type'] : null;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Product_Category::init();
|
||||
@@ -26,10 +26,20 @@ include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-order.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-product.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-package.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-user.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-pricing.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-countries.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-documents.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-cart.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
"wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4",
|
||||
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
|
||||
"wpackagist-plugin/wp-user-groups": "2.2.0",
|
||||
"wpackagist-plugin/radio-buttons-for-taxonomies": "1.8.3",
|
||||
|
||||
"3rdparty/gravityforms": "*",
|
||||
"3rdparty/gravityflow": "*",
|
||||
@@ -94,6 +95,7 @@
|
||||
"wp plugin activate capability-manager-enhanced",
|
||||
"wp plugin activate groups",
|
||||
"wp plugin activate wp-user-groups",
|
||||
"wp plugin activate radio-buttons-for-taxonomies",
|
||||
"wp plugin activate wiaas"
|
||||
],
|
||||
"update-db": [
|
||||
|
||||
24
backend/composer.lock
generated
24
backend/composer.lock
generated
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "302f569929ecdaf4d349b0bf764de74c",
|
||||
"content-hash": "d979d3435513dd818189e2f68cc023fe",
|
||||
"packages": [
|
||||
{
|
||||
"name": "3rdparty/gravityflow",
|
||||
@@ -568,6 +568,26 @@
|
||||
"type": "wordpress-plugin",
|
||||
"homepage": "https://wordpress.org/plugins/mailchimp-for-woocommerce/"
|
||||
},
|
||||
{
|
||||
"name": "wpackagist-plugin/radio-buttons-for-taxonomies",
|
||||
"version": "1.8.3",
|
||||
"source": {
|
||||
"type": "svn",
|
||||
"url": "https://plugins.svn.wordpress.org/radio-buttons-for-taxonomies/",
|
||||
"reference": "tags/1.8.3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://downloads.wordpress.org/plugin/radio-buttons-for-taxonomies.1.8.3.zip",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"composer/installers": "~1.0"
|
||||
},
|
||||
"type": "wordpress-plugin",
|
||||
"homepage": "https://wordpress.org/plugins/radio-buttons-for-taxonomies/"
|
||||
},
|
||||
{
|
||||
"name": "wpackagist-plugin/woocommerce-gateway-paypal-express-checkout",
|
||||
"version": "1.5.6",
|
||||
|
||||
5
frontend/package-lock.json
generated
5
frontend/package-lock.json
generated
@@ -4336,11 +4336,6 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
|
||||
},
|
||||
"lodash.cond": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.cond/-/lodash.cond-4.5.2.tgz",
|
||||
"integrity": "sha1-9HGh2khr5g9quVXRcRVSPdHSVdU="
|
||||
},
|
||||
"lodash.defaults": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz",
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"@tinymce/tinymce-react": "^2.0.3",
|
||||
"axios": "^0.17.0",
|
||||
"bootstrap": "^4.0.0-beta.2",
|
||||
"classnames": "^2.2.5",
|
||||
"flag-icon-css": "^2.8.0",
|
||||
"font-awesome": "^4.7.0",
|
||||
"glamor": "^2.20.40",
|
||||
|
||||
@@ -55,7 +55,7 @@ export const fetchPackageDetails = (params) => {
|
||||
|
||||
if(packageData.groups){
|
||||
Object.keys(packageData.groups).forEach((idGroup) => {
|
||||
const defaultOption = packageData.groups[idGroup].options.find((option) => {return parseInt(option.isDefault, 10) === 1});
|
||||
const defaultOption = packageData.groups[idGroup].options.find((option) => option.isDefault);
|
||||
if(defaultOption){
|
||||
dispatch(selectOption(idGroup, defaultOption));
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ export const cartTexts = {
|
||||
REMOVE_ITEM_HEADER: 'Remove item confirmation',
|
||||
REMOVE_ITEM_TEXT: 'Are you sure you want to remove ',
|
||||
REMOVE_FROM_CART: 'Remove from cart',
|
||||
ADDITIOONAL_PACKAGE: 'Additional package',
|
||||
ADDITIOONAL_PACKAGE: 'Addons',
|
||||
DOC_NOT_REQUIRED: 'Document not required',
|
||||
FILE_UPLOADED_TEXT: 'File uploaded! Select or drop to replace ',
|
||||
FILE: 'file',
|
||||
|
||||
@@ -84,7 +84,7 @@ export const coMarketTexts = {
|
||||
ON_DELIVERY: 'On delivery',
|
||||
MONTHLY: 'Monthly',
|
||||
NOT_AVAILABLE: 'Not available',
|
||||
SELECTION_NOT_AVAILABLE: 'This selection is not available for the selected price type!',
|
||||
SELECTION_NOT_AVAILABLE: 'Not available for price type',
|
||||
RECURRENT_PRICE: 'Package recurent price',
|
||||
SERVICE_PRICE: 'Services and support',
|
||||
EXTEND: 'with possibility to extend each',
|
||||
|
||||
@@ -32,36 +32,39 @@ class CartItemsContainer extends Component {
|
||||
isFormDisabled={isCartItemsDisabled}/>)}
|
||||
|
||||
<div id="total-price-in-cart-container" className="cart-show-items">
|
||||
<Row className="cart-total-price">
|
||||
<Col lg="5" xs="5" className="item-name">
|
||||
{cartTexts.labels.TOTAL_PRICE}:
|
||||
<Row id={"cart-total-price"} className="cart-total-price">
|
||||
<Col lg="3" xs="3" className="item-name d-flex align-items-center">
|
||||
<span>
|
||||
{cartTexts.labels.TOTAL_PRICE}:
|
||||
</span>
|
||||
</Col>
|
||||
{
|
||||
orderTotalPrice &&
|
||||
<Col id={"cart-total-price"}
|
||||
lg="7" xs="7"
|
||||
className="item-name">
|
||||
<table className="price-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{cartTexts.labels.ON_DELIVERY}</th>
|
||||
<th>{cartTexts.labels.MONTHLY}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<Col className="d-flex">
|
||||
<div className="d-flex flex-column flex-grow-1">
|
||||
<div className="d-flex flex-grow-1 no-wrap cart-total-price-header">
|
||||
<Col>
|
||||
<span>{cartTexts.labels.ON_DELIVERY}:</span>
|
||||
</Col>
|
||||
<Col>
|
||||
<span>{cartTexts.labels.MONTHLY}:</span>
|
||||
</Col>
|
||||
</div>
|
||||
<div className="d-flex flex-grow-1 no-wrap item-price-value">
|
||||
<Col>
|
||||
<h5>
|
||||
{orderTotalPrice.fixedPrice.toLocaleString()} {orderTotalPrice.currency} {' '}
|
||||
</td>
|
||||
<td>
|
||||
</h5>
|
||||
</Col>
|
||||
<Col>
|
||||
<h5>
|
||||
{
|
||||
orderTotalPrice.recurrentPrice && orderTotalPrice.recurrentPrice.toLocaleString() + ' ' + orderTotalPrice.currency
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</h5>
|
||||
</Col>
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
|
||||
@@ -93,7 +93,7 @@ class CartReviewOrderContainer extends Component {
|
||||
<Col md="4" id="review-tender">{customerDetails.details.idProject ? this.getProjectName(customerDetails.details.idProject) : '-'}</Col>
|
||||
</Row>
|
||||
<div>
|
||||
<h4>{cartTexts.labels.DELIVERY_ADDRESS}</h4>
|
||||
<h6>{cartTexts.labels.DELIVERY_ADDRESS}</h6>
|
||||
<Row className="cart-customer-main-info-row">
|
||||
<Col md="4">{cartTexts.labels.ADDRESS}</Col>
|
||||
<Col md="4"id="review-delivery-address">{customerDetails.delivery.detailedAddress}</Col>
|
||||
@@ -113,7 +113,7 @@ class CartReviewOrderContainer extends Component {
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h4>{cartTexts.labels.BILLING_ADDRESS}</h4>
|
||||
<h6>{cartTexts.labels.BILLING_ADDRESS}</h6>
|
||||
<Row className="cart-customer-main-info-row">
|
||||
<Col md="4">{cartTexts.labels.COMPANY}</Col>
|
||||
<Col md="4" id="review-billing-company">{customerDetails.companyName}</Col>
|
||||
|
||||
@@ -7,6 +7,7 @@ import {updateQuantity, removeCartItem} from '../../../actions/cart/cartActions'
|
||||
import {setDialogContent, setDialogOpenFlag} from '../../../actions/dialog/dialogActions';
|
||||
import {cartMessages, cartTexts} from '../../../constants/cartConstants';
|
||||
import PackageBids from './PackageBids.jsx';
|
||||
import {coMarketTexts} from "../../../constants/coMarketConstants";
|
||||
|
||||
class CartItem extends Component {
|
||||
constructor(props) {
|
||||
@@ -88,17 +89,17 @@ class CartItem extends Component {
|
||||
totalRecurrent += selectedBid.servicesPrice + selectedBid.recurrentPrice;
|
||||
|
||||
oldTotal = cartItem.fixedPrice;
|
||||
oldTotalRecurrent = cartItem.servicesPrice + cartItem.recurentPrice;
|
||||
oldTotalRecurrent = cartItem.servicesPrice + cartItem.recurrentPrice;
|
||||
}else{
|
||||
total += cartItem.fixedPrice;
|
||||
totalRecurrent += cartItem.servicesPrice + cartItem.recurentPrice;
|
||||
totalRecurrent += cartItem.servicesPrice + cartItem.recurrentPrice;
|
||||
}
|
||||
|
||||
if(cartItem.options.length) {
|
||||
cartItem.options.forEach((packageOption) => {
|
||||
if(Object.keys(packageOption.prices).length) {
|
||||
total += parseFloat(packageOption.prices.fixedExtra);
|
||||
totalRecurrent += parseFloat(packageOption.prices.recurentExtra) + parseFloat(packageOption.prices.servicesExtra);
|
||||
totalRecurrent += parseFloat(packageOption.prices.recurrentExtra) + parseFloat(packageOption.prices.servicesExtra);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -106,7 +107,7 @@ class CartItem extends Component {
|
||||
cartItem.additionalPackages.forEach((additionalPackage) => {
|
||||
if(Object.keys(additionalPackage).length) {
|
||||
total += parseFloat(additionalPackage.prices.fixedExtra);
|
||||
totalRecurrent += parseFloat(additionalPackage.prices.recurentExtra) + parseFloat(additionalPackage.prices.servicesExtra);
|
||||
totalRecurrent += parseFloat(additionalPackage.prices.recurrentExtra) + parseFloat(additionalPackage.prices.servicesExtra);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -201,43 +202,52 @@ class CartItem extends Component {
|
||||
}
|
||||
{cartItem.options.length > 0 &&
|
||||
cartItem.options.map((packageOption) =>
|
||||
<Row className="cart-item-small-details" key={"package-option-" + cartItem.key + "-" + packageOption.idOptionPackage}>
|
||||
<Col lg={{offset: 1, size: 4}} xs={{offset: 1, size: 4}}>
|
||||
<Row
|
||||
className="cart-item-small-details flex-column"
|
||||
key={"package-option-" + cartItem.key + "-" + packageOption.idOptionPackage}
|
||||
>
|
||||
<span className="cart-item-additional-title">
|
||||
{packageOption.groupName}:
|
||||
</Col>
|
||||
<Col lg="7" xs="7" id={"item-option-" + cartItem.key + "-" + packageOption.idOptionPackage}>
|
||||
</span>
|
||||
<span id={"item-option-" + cartItem.key + "-" + packageOption.idOptionPackage}>
|
||||
{packageOption.packageName}
|
||||
</Col>
|
||||
</span>
|
||||
</Row>
|
||||
)
|
||||
}
|
||||
{cartItem.additionalPackages.length > 0 &&
|
||||
cartItem.additionalPackages.map((additionalPackage) =>
|
||||
<Row className="cart-item-small-details" key={"additional-package-" + cartItem.key + "-" + additionalPackage.idAdditionalPackage}>
|
||||
<Col lg={{offset: 1, size: 4}} xs={{offset:1, size: 4}}>
|
||||
{
|
||||
cartItem.additionalPackages.length > 0 && <Row className="cart-item-small-details flex-column">
|
||||
<span className="cart-item-additional-title">
|
||||
{cartTexts.labels.ADDITIOONAL_PACKAGE}:
|
||||
</Col>
|
||||
<Col lg="7" xs="7" id={"item-additional-" + cartItem.key + "-" + additionalPackage.idAdditionalPackage}>
|
||||
{additionalPackage.packageName}
|
||||
</Col>
|
||||
</span>
|
||||
{
|
||||
cartItem.additionalPackages.map((additionalPackage) =>
|
||||
<span
|
||||
key={"item-additional-" + cartItem.key + "-" + additionalPackage.idAdditionalPackage}
|
||||
id={"item-additional-" + cartItem.key + "-" + additionalPackage.idAdditionalPackage}
|
||||
>
|
||||
{additionalPackage.packageName}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
}
|
||||
<Row className="cart-item-small-details justify-content-between item-price">
|
||||
<Col className="d-flex align-items-center">
|
||||
<span className="item-payment-type">{cartItem.payType}:</span>
|
||||
<Row className="cart-item-small-details item-price">
|
||||
<Col className="d-flex align-items-center col-3 item-price-type">
|
||||
<span className="item-price-type">{cartItem.payType}:</span>
|
||||
</Col>
|
||||
<Col className="d-flex col-auto">
|
||||
<table className="price-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{cartTexts.labels.ON_DELIVERY}</th>
|
||||
<th>{cartTexts.labels.MONTHLY}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<Col className="d-flex">
|
||||
<div className="d-flex flex-column flex-grow-1">
|
||||
<div className="d-flex flex-grow-1 no-wrap item-price-header">
|
||||
<Col>
|
||||
<span>{cartTexts.labels.ON_DELIVERY}:</span>
|
||||
</Col>
|
||||
<Col>
|
||||
<span>{cartTexts.labels.MONTHLY}:</span>
|
||||
</Col>
|
||||
</div>
|
||||
<div className="d-flex flex-grow-1 no-wrap item-price-value">
|
||||
<Col>
|
||||
{
|
||||
this.state.fixedPrice &&
|
||||
<div>
|
||||
@@ -251,8 +261,8 @@ class CartItem extends Component {
|
||||
</div>
|
||||
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
</Col>
|
||||
<Col>
|
||||
{
|
||||
this.state.recurrentPrice &&
|
||||
<div>
|
||||
@@ -265,10 +275,9 @@ class CartItem extends Component {
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</Col>
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</Col>
|
||||
|
||||
@@ -46,6 +46,11 @@
|
||||
font-weight: $font-weight;
|
||||
}
|
||||
|
||||
.cart-item-additional-title {
|
||||
font-weight: 600;
|
||||
color: $font-light-color;
|
||||
}
|
||||
|
||||
.cart-item-details {
|
||||
.item-name {
|
||||
}
|
||||
@@ -65,14 +70,34 @@
|
||||
}
|
||||
|
||||
.item-price {
|
||||
background-color: $hoverColor;
|
||||
background-color: #fbfbfb;
|
||||
margin-top: 1rem;
|
||||
border-radius: $box-radius;
|
||||
|
||||
.item-price-type {
|
||||
padding: 0.4rem;
|
||||
color: $font-light-color;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.item-price-header {
|
||||
font-weight: 600;
|
||||
color: $font-light-color;
|
||||
padding: 0.4rem;
|
||||
}
|
||||
|
||||
.item-price-value {
|
||||
padding: 0.4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.cart-total-price {
|
||||
padding: 1rem 0;
|
||||
font-size: $font-size-big;
|
||||
|
||||
.cart-total-price-header {
|
||||
color: $font-light-color;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.price-table th{
|
||||
@@ -105,17 +130,27 @@
|
||||
#cart-review-order-container {
|
||||
border-radius: $box-radius;
|
||||
|
||||
|
||||
|
||||
.cart-customer-main-info-row {
|
||||
padding: 0.5rem;
|
||||
text-align: left;
|
||||
> div:first-child {
|
||||
color: $font-light-color;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.place-order-btn {
|
||||
cursor: pointer;
|
||||
background-color: $done-status-color;
|
||||
background-color: $accentColor;
|
||||
border: none;
|
||||
width: 100%;
|
||||
float: right;
|
||||
font-weight: $font-weight;
|
||||
&:focus, &:hover {
|
||||
box-shadow: 0 0 0 0.1rem lighten($accentColor, 0.9) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.button-cart {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
import {Label, Popover, PopoverBody, Input, Col, Row} from 'reactstrap';
|
||||
import classnames from 'classnames';
|
||||
import {Label, Input, Col} from 'reactstrap';
|
||||
import {selectAdditional, removetAdditional} from '../../../actions/coMarket/coMarketPackageDetailsActions';
|
||||
import PriceHelper from '../../../helpers/coMarket/PriceHelper';
|
||||
import {coMarketTexts} from '../../../constants/coMarketConstants';
|
||||
@@ -11,18 +12,9 @@ class AdditionalPackageItem extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.toggle = this.toggle.bind(this);
|
||||
this.handleOptionChange = this.handleOptionChange.bind(this);
|
||||
this.isChecked = this.isChecked.bind(this);
|
||||
this.state = {
|
||||
popoverOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.setState({
|
||||
popoverOpen: !this.state.popoverOpen
|
||||
});
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
handleOptionChange() {
|
||||
@@ -60,10 +52,16 @@ class AdditionalPackageItem extends Component {
|
||||
const selectedPrice = priceHelper.getSelectedPrice(additionalPackage, this.props.selectedAgreement);
|
||||
const isChecked = this.isChecked();
|
||||
|
||||
const classes = classnames('shop-package-option d-flex',
|
||||
{
|
||||
'shop-package-option-selected': isChecked,
|
||||
'shop-package-option-disabled': !isAvailable,
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
id={'info-additonal-' + additionalPackage.idAdditionalPackage}
|
||||
className={`shop-package-option d-flex ${this.getClass()}`}
|
||||
className={classes}
|
||||
>
|
||||
<Label check className="d-flex flex-grow-1 flex-column">
|
||||
<div className="d-flex">
|
||||
@@ -73,24 +71,39 @@ class AdditionalPackageItem extends Component {
|
||||
onChange={this.handleOptionChange}
|
||||
name={'package-option-'+ additionalPackage.idAdditionalPackage}
|
||||
className="package-option-input"
|
||||
disabled={!isAvailable}
|
||||
/>
|
||||
<span className="option-name">
|
||||
{this.formatName(additionalPackage.packageName)}
|
||||
</span>
|
||||
{
|
||||
!isAvailable &&
|
||||
<span className="not-available">
|
||||
({coMarketTexts.labels.SELECTION_NOT_AVAILABLE})
|
||||
</span>
|
||||
}
|
||||
</Col>
|
||||
<Col className="col-3 d-flex align-items-center">
|
||||
{
|
||||
priceHelper.hasFixedPrice(selectedPrice) && (<span>
|
||||
{selectedPrice.fixedExtra && selectedPrice.fixedExtra.toLocaleString() + ' ' + currency}
|
||||
</span>)
|
||||
}
|
||||
<span>
|
||||
{
|
||||
isAvailable ?
|
||||
(selectedPrice.fixedExtra ?
|
||||
`${selectedPrice.fixedExtra} ${currency}` :
|
||||
'0') :
|
||||
'-'
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
<Col className="col-3 d-flex align-items-center">
|
||||
{
|
||||
priceHelper.hasFixedPrice(selectedPrice) && priceHelper.hasRecurrentPrice(selectedPrice) ?
|
||||
(<span>{priceHelper.sumPrices([selectedPrice.recurentExtra, selectedPrice.servicesExtra]).toLocaleString()} {currency}</span>) :
|
||||
<span>0</span>
|
||||
}
|
||||
<span>
|
||||
{
|
||||
isAvailable ?
|
||||
(priceHelper.hasRecurrentPrice(selectedPrice) ?
|
||||
`${priceHelper.sumPrices([selectedPrice.recurrentExtra, selectedPrice.servicesExtra])} ${currency}` :
|
||||
'0') :
|
||||
'-'
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
</div>
|
||||
<div
|
||||
@@ -98,24 +111,6 @@ class AdditionalPackageItem extends Component {
|
||||
dangerouslySetInnerHTML={{__html: additionalPackage.shortDescription}}
|
||||
></div>
|
||||
</Label>
|
||||
{
|
||||
!isAvailable &&
|
||||
<span className="not-available">
|
||||
({coMarketTexts.labels.NOT_AVAILABLE})
|
||||
<i className="price-info-btn fa fa-info-circle"
|
||||
aria-hidden="true"
|
||||
id={'info-additonal-' + additionalPackage.idAdditionalPackage}
|
||||
onClick={this.toggle}></i>
|
||||
</span>
|
||||
}
|
||||
<Popover placement="bottom"
|
||||
isOpen={this.state.popoverOpen}
|
||||
target={'info-additonal-' + additionalPackage.idAdditionalPackage}
|
||||
toggle={this.toggle}>
|
||||
<PopoverBody>
|
||||
{coMarketTexts.labels.SELECTION_NOT_AVAILABLE}
|
||||
</PopoverBody>
|
||||
</Popover>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
import {Label, Popover, PopoverBody, Input, Col} from 'reactstrap';
|
||||
import {Label, Input, Col} from 'reactstrap';
|
||||
import {selectAgreement} from '../../../actions/coMarket/coMarketPackageDetailsActions';
|
||||
import PriceHelper from '../../../helpers/coMarket/PriceHelper';
|
||||
import {coMarketTexts} from '../../../constants/coMarketConstants';
|
||||
@@ -39,72 +39,59 @@ class AgreementOptionItem extends Component {
|
||||
|
||||
return (
|
||||
<div className={`shop-package-option d-flex ${this.getClass(selectedAgreement, price)}`}>
|
||||
<Label check className="d-flex flex-grow-1 no-wrap">
|
||||
<Col className="d-flex align-items-center col-6">
|
||||
<Input type="radio"
|
||||
name="price-type"
|
||||
onChange={this.handleOptionChange}
|
||||
checked={selectedAgreement.idPaymentType === price.idPaymentType}
|
||||
value={price.idPaymentType}
|
||||
className="price-type-option"/>
|
||||
<span className="option-name">{price.payType}</span>
|
||||
</Col>
|
||||
<Col className="d-flex align-items-center col-3">
|
||||
<span>{price.fixedExtra.toLocaleString()} {currency}</span>
|
||||
</Col>
|
||||
<Col className="d-flex align-items-center col-3">
|
||||
<span className="option-value-text monthly-price">
|
||||
<Label check className="d-flex flex-grow-1 flex-column">
|
||||
<div className="d-flex">
|
||||
<Col className="d-flex align-items-center col-6">
|
||||
<Input type="radio"
|
||||
name="price-type"
|
||||
onChange={this.handleOptionChange}
|
||||
checked={selectedAgreement.idPaymentType === price.idPaymentType}
|
||||
value={price.idPaymentType}
|
||||
className="price-type-option"/>
|
||||
<span className="option-name">{price.payType}</span>
|
||||
</Col>
|
||||
<Col className="d-flex align-items-center col-3">
|
||||
<span>{price.fixedExtra.toLocaleString()} {currency}</span>
|
||||
</Col>
|
||||
<Col className="d-flex align-items-center col-3">
|
||||
<span className="option-value-text monthly-price">
|
||||
{
|
||||
priceHelper.hasRecurrentPrice(price)
|
||||
? `${priceHelper.sumPrices([price.recurrentExtra, price.servicesExtra]).toLocaleString()} ${currency}`
|
||||
: '0'
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
</div>
|
||||
<div className="shop-package-option-description">
|
||||
{
|
||||
priceHelper.hasRecurrentPrice(price)
|
||||
? `${priceHelper.sumPrices([price.recurentExtra, price.servicesExtra]).toLocaleString()} ${currency}`
|
||||
: '0'
|
||||
price.recurrentExtra > 0 &&
|
||||
<span>
|
||||
{
|
||||
`${coMarketTexts.labels.RECURRENT_PRICE}: ${price.recurrentExtra} ${currency} / ${price.periodUnit}} ${price.packagePayPeriod > 0 ? ` for ${price.packagePayPeriod} ${price.periodUnit}` : ''}`
|
||||
}
|
||||
</span>
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
{
|
||||
price.servicesExtra > 0 &&
|
||||
<div className="d-flex flex-column">
|
||||
<span>
|
||||
{
|
||||
`${coMarketTexts.labels.SERVICE_PRICE}: ${(price.servicesExtra)} ${currency} / ${price.periodUnit} ${price.servicesContractPeriod > 0 ? `for ${price.servicesContractPeriod} ${price.periodUnit}` : ''}`
|
||||
}
|
||||
</span>
|
||||
{
|
||||
price.servicesContractPeriod > 0 &&
|
||||
<span>
|
||||
{
|
||||
`${coMarketTexts.labels.EXTEND} ${price.periodUnit} (Max ${price.maxContractPeriod} ${price.periodUnit})`
|
||||
}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</Label>
|
||||
<i
|
||||
className="price-info-btn fa fa-info-circle d-flex align-items-center"
|
||||
aria-hidden="true"
|
||||
id={'info-additonal-' + price.idPaymentType}
|
||||
onClick={this.toggle}
|
||||
></i>
|
||||
<Popover placement="bottom"
|
||||
isOpen={this.state.popoverOpen}
|
||||
target={'info-additonal-' + price.idPaymentType}
|
||||
className="price-info-popover"
|
||||
container="shop-package-buy-info"
|
||||
toggle={this.toggle}>
|
||||
<PopoverBody>
|
||||
<div>
|
||||
{
|
||||
price.recurentExtra > 0 &&
|
||||
<div className="package-price-recurrent">
|
||||
<span className="price-info-title">{coMarketTexts.labels.RECURRENT_PRICE}: </span>
|
||||
{(price.recurentExtra).toLocaleString()} {currency} / {price.periodUnit}
|
||||
{
|
||||
price.packagePayPeriod > 0 &&
|
||||
<span>
|
||||
{' '} for {price.packagePayPeriod} {price.periodUnit}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
{
|
||||
price.servicesExtra > 0 &&
|
||||
<div className="services-price-recurrent">
|
||||
<span className="price-info-title">{coMarketTexts.labels.SERVICE_PRICE}: </span>
|
||||
{(price.servicesExtra).toLocaleString()} {currency} / {price.periodUnit}
|
||||
{
|
||||
price.servicesContractPeriod > 0 &&
|
||||
<span>
|
||||
{' '} for {price.servicesContractPeriod} {price.periodUnit} {coMarketTexts.labels.EXTEND} {price.periodUnit} (Max {price.maxContractPeriod} {price.periodUnit})
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</PopoverBody>
|
||||
</Popover>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ const fileHandler = new FileDownloader();
|
||||
|
||||
class PackageInfo extends Component {
|
||||
downloadDocument(document){
|
||||
const fileUrl = `${API_SERVER}/utils/api/downloadFile?idDocument=${document.idDocument}&fileName=${document.documentName}.${document.extension}`
|
||||
const fileUrl = `${API_SERVER}/wp-json/wiaas/download-package-file?document_id=${document.idDocument}&package_id=${document.idPackage}`
|
||||
const fileName = document.documentName + '.' + document.extension;
|
||||
fileHandler.download(fileUrl, fileName);
|
||||
}
|
||||
@@ -37,16 +37,14 @@ class PackageInfo extends Component {
|
||||
{
|
||||
documents && documents.length > 0 &&
|
||||
<Col lg="12"
|
||||
className="shop-package-details-documents">
|
||||
className="shop-package-details-documents d-flex flex-column">
|
||||
<div className="shop-package-label">{coMarketTexts.labels.DOCUMENTS}:</div>
|
||||
{
|
||||
documents.map((document) =>
|
||||
<div key={document.idDocument}>
|
||||
<span className="document-link"
|
||||
onClick={() => {this.downloadDocument(document)}}>
|
||||
<i className="fa fa-file" aria-hidden="true"></i> {document.documentName} ({document.extension})
|
||||
</span>
|
||||
</div>
|
||||
<span key={document.idDocument} className="document-link"
|
||||
onClick={() => {this.downloadDocument(document)}}>
|
||||
<i className="fa fa-file" aria-hidden="true"></i> {document.documentName} ({document.extension})
|
||||
</span>
|
||||
)
|
||||
}
|
||||
</Col>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
import {Label, Popover, PopoverBody, Input, Row, Col} from 'reactstrap';
|
||||
import {Label, Input, Col} from 'reactstrap';
|
||||
import {selectOption} from '../../../actions/coMarket/coMarketPackageDetailsActions';
|
||||
import PriceHelper from '../../../helpers/coMarket/PriceHelper';
|
||||
import {coMarketTexts} from '../../../constants/coMarketConstants';
|
||||
@@ -11,18 +11,9 @@ class PackageOptionItem extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.toggle = this.toggle.bind(this);
|
||||
this.handleOptionChange = this.handleOptionChange.bind(this);
|
||||
|
||||
this.state = {
|
||||
popoverOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.setState({
|
||||
popoverOpen: !this.state.popoverOpen
|
||||
});
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
handleOptionChange() {
|
||||
@@ -48,6 +39,7 @@ class PackageOptionItem extends Component {
|
||||
render() {
|
||||
const {idGroup, option, currency, simplified} = this.props;
|
||||
const selectedPrice = this.props.selectedAgreement ? priceHelper.getSelectedPrice(option, this.props.selectedAgreement) : null;
|
||||
const isAvailable = selectedPrice !== undefined;
|
||||
const isChecked = this.isChecked();
|
||||
|
||||
if (simplified) {
|
||||
@@ -56,20 +48,34 @@ class PackageOptionItem extends Component {
|
||||
<span className="option-name">
|
||||
{this.formatName(option.optionName)}
|
||||
</span>
|
||||
{
|
||||
!isAvailable &&
|
||||
<span className="not-available">
|
||||
({coMarketTexts.labels.SELECTION_NOT_AVAILABLE})
|
||||
</span>
|
||||
}
|
||||
</Col>
|
||||
<Col className="d-flex align-items-center col-3">
|
||||
{
|
||||
priceHelper.hasFixedPrice(selectedPrice) && (<span>
|
||||
{selectedPrice.fixedExtra && selectedPrice.fixedExtra.toLocaleString() + ' ' + currency}
|
||||
</span>)
|
||||
}
|
||||
<span>
|
||||
{
|
||||
isAvailable ?
|
||||
(selectedPrice.fixedExtra ?
|
||||
`${selectedPrice.fixedExtra} ${currency}` :
|
||||
'0') :
|
||||
'-'
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
<Col className="d-flex align-items-center col-3">
|
||||
{
|
||||
priceHelper.hasFixedPrice(selectedPrice) && priceHelper.hasRecurrentPrice(selectedPrice) ?
|
||||
(<span>{priceHelper.sumPrices([selectedPrice.recurentExtra, selectedPrice.servicesExtra]).toLocaleString()} {currency}</span>) :
|
||||
<span>0</span>
|
||||
}
|
||||
<span>
|
||||
{
|
||||
isAvailable ?
|
||||
(priceHelper.hasRecurrentPrice(selectedPrice) ?
|
||||
`${priceHelper.sumPrices([selectedPrice.recurrentExtra, selectedPrice.servicesExtra])} ${currency}` :
|
||||
'0') :
|
||||
'-'
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
</div>)
|
||||
}
|
||||
@@ -91,46 +97,40 @@ class PackageOptionItem extends Component {
|
||||
<div className="option-name">
|
||||
{this.formatName(option.optionName)}
|
||||
</div>
|
||||
{
|
||||
!isAvailable &&
|
||||
<span className="not-available">
|
||||
({coMarketTexts.labels.SELECTION_NOT_AVAILABLE})
|
||||
</span>
|
||||
}
|
||||
</Col>
|
||||
<Col className="col-3 d-flex align-items-center">
|
||||
{
|
||||
priceHelper.hasFixedPrice(selectedPrice) && (<span>
|
||||
{selectedPrice.fixedExtra && selectedPrice.fixedExtra.toLocaleString() + ' ' + currency}
|
||||
</span>)
|
||||
}
|
||||
<span>
|
||||
{
|
||||
isAvailable ?
|
||||
(selectedPrice.fixedExtra ?
|
||||
`${selectedPrice.fixedExtra} ${currency}` :
|
||||
'0') :
|
||||
'-'
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
<Col className="col-3 d-flex align-items-center">
|
||||
{
|
||||
priceHelper.hasFixedPrice(selectedPrice) && priceHelper.hasRecurrentPrice(selectedPrice) ?
|
||||
(<span>{priceHelper.sumPrices([selectedPrice.recurentExtra, selectedPrice.servicesExtra]).toLocaleString()} {currency}</span>) :
|
||||
<span>0</span>
|
||||
}
|
||||
<span>
|
||||
{
|
||||
isAvailable ?
|
||||
(priceHelper.hasRecurrentPrice(selectedPrice) ?
|
||||
`${priceHelper.sumPrices([selectedPrice.recurrentExtra, selectedPrice.servicesExtra])} ${currency}` :
|
||||
'0') :
|
||||
'-'
|
||||
}
|
||||
</span>
|
||||
</Col>
|
||||
</div>
|
||||
<div
|
||||
className="shop-package-option-description"
|
||||
dangerouslySetInnerHTML={{__html: option.shortDescription}}></div>
|
||||
</Label>
|
||||
{
|
||||
!selectedPrice &&
|
||||
<Label>
|
||||
<div className="not-available">
|
||||
({coMarketTexts.labels.NOT_AVAILABLE})
|
||||
<i className="price-info-btn fa fa-info-circle"
|
||||
aria-hidden="true"
|
||||
id={'info-option-' + idGroup + '-' + option.idOptionPackage}
|
||||
onClick={this.toggle}></i>
|
||||
</div>
|
||||
</Label>
|
||||
}
|
||||
<Popover placement="bottom"
|
||||
isOpen={this.state.popoverOpen}
|
||||
target={'info-option-' + idGroup + '-' + option.idOptionPackage}
|
||||
toggle={this.toggle}>
|
||||
<PopoverBody>
|
||||
{coMarketTexts.labels.SELECTION_NOT_AVAILABLE}
|
||||
</PopoverBody>
|
||||
</Popover>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class PackagePrice extends Component {
|
||||
return '-';
|
||||
}
|
||||
|
||||
const recurrentExtra = this.getFinalPrice(selectedAgreement, selectedOptions, selectedAdditionals, 'recurentExtra');
|
||||
const recurrentExtra = this.getFinalPrice(selectedAgreement, selectedOptions, selectedAdditionals, 'recurrentExtra');
|
||||
const servicesExtra = this.getFinalPrice(selectedAgreement, selectedOptions, selectedAdditionals, 'servicesExtra');
|
||||
|
||||
return `${(recurrentExtra + servicesExtra).toLocaleString()} ${this.props.currency}`
|
||||
|
||||
@@ -1,59 +1,68 @@
|
||||
@import '../../../styleConstants.scss';
|
||||
|
||||
#co-market-shop {
|
||||
.shop-package-title {
|
||||
font-size: 1rem;
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.shop-package-title a {
|
||||
font-size: $font-size-msmall;
|
||||
font-weight: $font-weight;
|
||||
text-align: left;
|
||||
color: $header-background;
|
||||
}
|
||||
|
||||
.shop-package-reference {
|
||||
font-size: $font-size-xsmal;
|
||||
font-weight: $font-weight;
|
||||
text-align: left;
|
||||
color: $warmGreyColor;
|
||||
}
|
||||
|
||||
.shop-package-country {
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
font-size: $font-size-xsmal;
|
||||
text-align: left;
|
||||
color: $warmGreyColor;
|
||||
}
|
||||
|
||||
.shop-package-details-btn-layer{
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.shop-package-details-btn{
|
||||
border-radius: 50px;
|
||||
background-color: $whiteColor;
|
||||
border: solid 0.7px $borderColor;
|
||||
color: $darkBlue;
|
||||
font-weight: $font-weight;
|
||||
font-size: $font-size-xsmal;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.shop-package-item{
|
||||
margin-top: 1rem;
|
||||
border-radius: 4px;
|
||||
border-radius: 0;
|
||||
background-color: $whiteColor;
|
||||
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
// box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
|
||||
|
||||
.card-body {
|
||||
background: rgb(251, 251, 251);
|
||||
}
|
||||
|
||||
.shop-package-details-btn{
|
||||
border-radius: 50px;
|
||||
background-color: $accentColor;
|
||||
border: none;
|
||||
color: $whiteColor;
|
||||
font-weight: $font-weight;
|
||||
font-size: $font-size-xsmal;
|
||||
cursor: pointer;
|
||||
&:focus, &:hover {
|
||||
box-shadow: 0 0 0 0.1rem lighten($accentColor, 0.9) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.shop-package-title {
|
||||
font-size: 1rem;
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.shop-package-title a {
|
||||
font-size: $font-size-msmall;
|
||||
font-weight: $font-weight;
|
||||
text-align: left;
|
||||
color: $header-background;
|
||||
}
|
||||
|
||||
.shop-package-reference {
|
||||
font-size: $font-size-xsmal;
|
||||
font-weight: $font-weight;
|
||||
text-align: left;
|
||||
color: $warmGreyColor;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.shop-package-country {
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
font-size: $font-size-xsmal;
|
||||
text-align: left;
|
||||
color: $warmGreyColor;
|
||||
}
|
||||
|
||||
.shop-package-details-btn-layer{
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.flag-icon{
|
||||
border-radius: 2px;
|
||||
margin-left: 0.2rem;
|
||||
}
|
||||
|
||||
.flag-icon{
|
||||
border-radius: 2px;
|
||||
margin-left: 0.2rem;
|
||||
}
|
||||
|
||||
.wiaas-box-header {
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
.shop-package-label{
|
||||
display: inline-block;
|
||||
color: $font-light-color;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.shop-package-text {
|
||||
@@ -48,6 +50,7 @@
|
||||
|
||||
.document-link{
|
||||
color: #33425b;
|
||||
padding: 6px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
@@ -61,6 +64,9 @@
|
||||
position: relative;
|
||||
margin: 0 10px 0 0;
|
||||
}
|
||||
.option-name {
|
||||
color: $font-dark-color;
|
||||
}
|
||||
.dropdown-toggle {
|
||||
border: 1px solid $hoverColor;
|
||||
border-radius: $box-radius;
|
||||
@@ -68,12 +74,28 @@
|
||||
cursor: pointer;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.shop-package-option {
|
||||
.shop-package-option {
|
||||
&-selected {
|
||||
background: $lightHoverColor;
|
||||
}
|
||||
}
|
||||
&-disabled {
|
||||
.option-name {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
&:not(.shop-package-option-disabled) {
|
||||
&:hover {
|
||||
background: $hoverColor;
|
||||
}
|
||||
label {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
&-header {
|
||||
color: $font-light-color;
|
||||
font-weight: 600;
|
||||
}
|
||||
&-description {
|
||||
padding-top: 0.5rem;
|
||||
@@ -82,7 +104,6 @@
|
||||
color: $font-light-color;
|
||||
}
|
||||
label {
|
||||
cursor: pointer;
|
||||
padding: 0.375rem 0.75rem;
|
||||
margin-right: 0.855rem;
|
||||
}
|
||||
@@ -96,13 +117,9 @@
|
||||
padding-right: 0 !important;
|
||||
}
|
||||
}
|
||||
.shop-package-option:hover, label:hover, .dropdown:hover {
|
||||
background: $hoverColor;
|
||||
}
|
||||
}
|
||||
|
||||
.not-available {
|
||||
margin-top: 1rem;
|
||||
margin-left: 0.2rem;
|
||||
color: $not-available-status-color;
|
||||
font-weight: $font-weight;
|
||||
@@ -120,13 +137,12 @@
|
||||
color: #fff;
|
||||
background-color: $accentColor;
|
||||
border: none;
|
||||
&:focus, &:hover {
|
||||
box-shadow: 0 0 0 0.1rem lighten($accentColor, 0.9) !important;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.price-info-popover {
|
||||
max-width: 50rem;
|
||||
}
|
||||
|
||||
.recurent-total-price{
|
||||
font-size: $font-size-msmall;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export const fromWCOrder = (WCOrder) => {
|
||||
reference: WCOrder['reference'],
|
||||
assignedTo: 'assigned to',
|
||||
fixedPrice: WCOrder.total,
|
||||
recurringPrice: 0,
|
||||
recurringPrice: WCOrder['recurring_price'],
|
||||
status: WCOrder.status,
|
||||
currency: WCOrder.currency,
|
||||
billing:{
|
||||
@@ -49,14 +49,15 @@ export const fromWCOrder = (WCOrder) => {
|
||||
payPeriod: packageLine['pay_period'],
|
||||
shortDesc: packageLine['short_desc'],
|
||||
dateCompleted: formatDate(packageLine['date_completed']),
|
||||
additionalPackages: packageLine['additional_packages'].map(additionalPackage => ({
|
||||
additionalPackages: packageLine['additional_packages'] ? packageLine['additional_packages'].map(additionalPackage => ({
|
||||
idPackage: additionalPackage.id,
|
||||
packageName: additionalPackage.name,
|
||||
})),
|
||||
options: packageLine['options'].map(packageOption => ({
|
||||
})) : [],
|
||||
options: packageLine['options'] ? packageLine['options'].map(packageOption => ({
|
||||
idPackage: packageOption.id,
|
||||
packageName: packageOption.name,
|
||||
})),
|
||||
groupName: packageOption['group_name'] || '',
|
||||
})) : [],
|
||||
};
|
||||
}),
|
||||
process: processInfo,
|
||||
|
||||
@@ -12,9 +12,9 @@ function extractPrices(wcPackageId, prices) {
|
||||
maxContractPeriod: price['max_contract_period'],
|
||||
packagePayPeriod: price['package_pay_period'],
|
||||
servicesContractPeriod: price['services_contract_period'],
|
||||
fixedExtra: price['minimal_fixed_price'],
|
||||
servicesExtra: price['minimal_services_price'],
|
||||
recurentExtra: price['recurrent_price']
|
||||
fixedExtra: price['fixed_extra'],
|
||||
servicesExtra: price['services_extra'],
|
||||
recurrentExtra: price['recurrent_extra']
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -46,29 +46,23 @@ export const fromWCPackage = wcPackage => {
|
||||
image: wcPackage.images[0].src || DEFAULT_PACKAGE_IMG,
|
||||
hasImage: !!wcPackage.images.length,
|
||||
name: wcPackage.name,
|
||||
country: 'Sweden',
|
||||
countryCode: 'se',
|
||||
currency: 'SEK',
|
||||
documents: [
|
||||
{
|
||||
idDocument: 1,
|
||||
documentName: 'test1',
|
||||
extension: '.php'
|
||||
},
|
||||
{
|
||||
idDocument: 2,
|
||||
documentName: 'test2',
|
||||
extension: '.php'
|
||||
}
|
||||
],
|
||||
country: wcPackage.country,
|
||||
countryCode: wcPackage['country_code'],
|
||||
currency: wcPackage.currency,
|
||||
documents: wcPackage.documents ? wcPackage.documents.map(document => ({
|
||||
idDocument: document.id,
|
||||
documentName: document.name,
|
||||
extension: document.extension,
|
||||
idPackage: wcPackage.id,
|
||||
})) : [],
|
||||
shortDescription: wcPackage.description,
|
||||
prices: extractPrices(wcPackage.id, wcPackage.prices) || [],
|
||||
groups: extractGroups(wcPackage.groups),
|
||||
additionalPackages: wcPackage['additional_packages'].map(additionalPackage =>({
|
||||
prices: extractPrices(wcPackage.id, wcPackage.prices || []),
|
||||
groups: extractGroups(wcPackage.groups || {}),
|
||||
additionalPackages: wcPackage['additional_packages'] ? wcPackage['additional_packages'].map(additionalPackage =>({
|
||||
idAdditionalPackage: additionalPackage.id,
|
||||
packageName: additionalPackage.name,
|
||||
shortDescription: additionalPackage.description,
|
||||
prices: extractPrices(additionalPackage.id, additionalPackage.prices)
|
||||
})),
|
||||
})) : [],
|
||||
}
|
||||
};
|
||||
@@ -19,7 +19,11 @@ class PriceHellper {
|
||||
}
|
||||
|
||||
hasRecurrentPrice(selectedPrice){
|
||||
return selectedPrice && (selectedPrice.recurentExtra > 0 || selectedPrice.servicesExtra > 0);
|
||||
return selectedPrice && (selectedPrice.recurrentExtra > 0 || selectedPrice.servicesExtra > 0);
|
||||
}
|
||||
|
||||
calculateCartItemTotal(cartItem) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,10 +95,13 @@
|
||||
.generic-dialog-box {
|
||||
min-width: 30%;
|
||||
|
||||
.btn-success {
|
||||
background-color: $greenColor;
|
||||
border-color: $borderColor;
|
||||
.btn-success, .btn-success:active, .btn-success:hover, .btn-success:focus {
|
||||
background-color: $accentColor !important;
|
||||
border: none !important;
|
||||
cursor: pointer;
|
||||
&:focus, &:hover {
|
||||
box-shadow: 0 0 0 0.1rem lighten($accentColor, 0.9) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
|
||||
@@ -15,7 +15,7 @@ $blueColor: #2b6279;
|
||||
$hoverColor: #ebebeb;
|
||||
$lightHoverColor: #f2f2f2;
|
||||
|
||||
$accentColor: #f16078;
|
||||
$accentColor: #e25c56;
|
||||
|
||||
$boxShadow: rgba(0, 0, 0, 0.1);
|
||||
|
||||
@@ -40,7 +40,7 @@ $font-size-big: 1.125rem; //18px
|
||||
$font-size-xbig: 1.5rem;
|
||||
|
||||
$font-light-color: rgba(33, 33, 33, 0.54);
|
||||
$font-strong-color: rgba(33, 33, 33, 0.87);
|
||||
$font-dark-color: rgba(33, 33, 33, 0.87);
|
||||
|
||||
$open-status-color: #045FB4;
|
||||
$in-progress-status-color: #FD8049;
|
||||
|
||||
Reference in New Issue
Block a user