Fix tests
This commit is contained in:
@@ -32,7 +32,7 @@ class Wiaas_Admin_CL_Packages {
|
|||||||
add_menu_page(
|
add_menu_page(
|
||||||
__( 'Products', 'wiaas' ),
|
__( 'Products', 'wiaas' ),
|
||||||
__( 'Products', 'wiaas' ),
|
__( 'Products', 'wiaas' ),
|
||||||
'wiaas_manage_cl_products',
|
'manage_wiaas_cl_products',
|
||||||
'wiaas-cl-packages',
|
'wiaas-cl-packages',
|
||||||
array(__CLASS__, 'output_list'),
|
array(__CLASS__, 'output_list'),
|
||||||
null,
|
null,
|
||||||
@@ -42,7 +42,7 @@ class Wiaas_Admin_CL_Packages {
|
|||||||
null,
|
null,
|
||||||
__( 'Products', 'wiaas' ),
|
__( 'Products', 'wiaas' ),
|
||||||
null,
|
null,
|
||||||
'wiaas_manage_cl_products',
|
'manage_wiaas_cl_products',
|
||||||
'wiaas-cl-product',
|
'wiaas-cl-product',
|
||||||
array(__CLASS__, 'output_package')
|
array(__CLASS__, 'output_package')
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -218,25 +218,25 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<div>
|
<div>
|
||||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||||
<strong><?php esc_html_e('EPR') ?></strong>
|
<strong><?php esc_html_e('EPR', 'wiaas') ?></strong>
|
||||||
<span><?php esc_html_e('= Extra package recurrent commission') ?></span>
|
<span><?php esc_html_e('= Extra package recurrent commission', 'wiaas') ?></span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||||
<strong><?php esc_html_e('ESR') ?></strong>
|
<strong><?php esc_html_e('ESR') ?></strong>
|
||||||
<span><?php esc_html_e('= Extra services and support recurrent commission') ?></span>
|
<span><?php esc_html_e('= Extra services and support recurrent commission', 'wiaas') ?></span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||||
<strong><?php esc_html_e('Extra commission') ?></strong>
|
<strong><?php esc_html_e('Extra commission', 'wiaas') ?></strong>
|
||||||
<span><?php esc_html_e('= EPR + ESR') ?></span>
|
<span><?php esc_html_e('= EPR + ESR', 'wiaas') ?></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="tabs">
|
<div id="tabs">
|
||||||
<ul id="tabs-navigation">
|
<ul id="tabs-navigation">
|
||||||
<li><a href="#tabs-1">Default prices</a> | </li>
|
<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
|
||||||
<li><a href="#tabs-2">Customer specific prices</a></li>
|
<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<form id="wiaas_package_extras" action="" method="post">
|
<form id="wiaas_package_extras" action="" method="post">
|
||||||
@@ -256,6 +256,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
<?php
|
<?php
|
||||||
$customers = wiaas_get_customers();
|
$customers = wiaas_get_customers();
|
||||||
foreach ($customers as $id => $name) {
|
foreach ($customers as $id => $name) {
|
||||||
|
// shik current organization if it has role of customer
|
||||||
|
if ($id === $cl_id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<option
|
<option
|
||||||
<?php disabled(in_array($id, $customer_ids_with_extras), true, true) ?>
|
<?php disabled(in_array($id, $customer_ids_with_extras), true, true) ?>
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ $id = isset($customer_id) ? 'extras_customer_'.$customer_id : 'extras_default';
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
<td>Minimal sell price</td>
|
<td><?php esc_html_e('Minimal sell price', 'wiaas') ?></td>
|
||||||
<td>Extra commision</td>
|
<td><?php esc_html_e('Extra commision', 'wiaas') ?></td>
|
||||||
<td>Default price</td>
|
<td><?php esc_html_e('Default price', 'wiaas') ?></td>
|
||||||
<td>Visible?
|
<td><?php esc_html_e('Visible?', 'wiaas') ?>
|
||||||
<?php
|
<?php
|
||||||
if (isset($customer_id)) {
|
if (isset($customer_id)) {
|
||||||
?>
|
?>
|
||||||
@@ -106,7 +106,7 @@ $id = isset($customer_id) ? 'extras_customer_'.$customer_id : 'extras_default';
|
|||||||
value="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
value="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
||||||
type="text"
|
type="text"
|
||||||
>
|
>
|
||||||
<label>(EPR)</label>
|
<label><?php esc_html_e('(EPR)', 'wiaas') ?></label>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ $id = isset($customer_id) ? 'extras_customer_'.$customer_id : 'extras_default';
|
|||||||
value="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
value="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
||||||
type="text"
|
type="text"
|
||||||
>
|
>
|
||||||
<label>(ESR)</label>
|
<label><?php esc_html_e('(ESR)', 'wiaas') ?></label>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ class Wiaas_Admin_Organization {
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render user organization roles as available user roles on user list
|
||||||
|
* @param $role_list
|
||||||
|
* @param $user
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public static function get_role_list_for_user($role_list, $user) {
|
public static function get_role_list_for_user($role_list, $user) {
|
||||||
$organization_id = wiaas_get_user_organization_id($user->ID);
|
$organization_id = wiaas_get_user_organization_id($user->ID);
|
||||||
|
|
||||||
@@ -44,6 +51,13 @@ class Wiaas_Admin_Organization {
|
|||||||
return $role_list;
|
return $role_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customize columns for users table list view
|
||||||
|
*
|
||||||
|
* @param array $defaults
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public static function manage_users_table_columns( $defaults = array() ) {
|
public static function manage_users_table_columns( $defaults = array() ) {
|
||||||
|
|
||||||
$defaults['role'] = __('Roles', 'wiaas');
|
$defaults['role'] = __('Roles', 'wiaas');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class Wiaas_Package_API {
|
|||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_by_commercial_lead'), 10, 2);
|
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
@@ -18,7 +18,8 @@ class Wiaas_Package_API {
|
|||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_customer_commercial_leads() {
|
// TODO: Handle this when assigment of customer to commercial lead is done
|
||||||
|
public static function get_customer_commercial_leads() {
|
||||||
$commercial_leads = array();
|
$commercial_leads = array();
|
||||||
|
|
||||||
foreach (wiaas_get_commercial_leads() as $id => $name) {
|
foreach (wiaas_get_commercial_leads() as $id => $name) {
|
||||||
@@ -31,15 +32,43 @@ class Wiaas_Package_API {
|
|||||||
return rest_ensure_response($commercial_leads);
|
return rest_ensure_response($commercial_leads);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function filter_by_commercial_lead($args, $request) {
|
/**
|
||||||
|
* Filter woocommerce REST API query so only valid wiaas packages are returned to the customer
|
||||||
|
*
|
||||||
|
* @param $args
|
||||||
|
* @param $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function filter_packages($args, $request) {
|
||||||
|
|
||||||
$catalogue_id = absint($request['cl_id']);
|
if ( empty($query['tax_query']) ){
|
||||||
|
$query['tax_query'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
$args['meta_query'] ?: array();
|
// Moved package status handling here
|
||||||
|
$query['tax_query'][] = array(
|
||||||
|
'taxonomy' => 'package_status',
|
||||||
|
'field' => 'name',
|
||||||
|
'terms' => Wiaas_Package_Status::AVAILABLE
|
||||||
|
);
|
||||||
|
|
||||||
$args['meta_query'][] = array(
|
$commercial_lead_id = absint($request['cl_id']);
|
||||||
'key' => '_wiaas_catalogue_'.$catalogue_id,
|
|
||||||
'value' => 'yes',
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
|
|
||||||
|
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||||
|
|
||||||
|
$price_serch_terms = array();
|
||||||
|
foreach ($pay_types as $pay_type) {
|
||||||
|
$price_serch_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_default';
|
||||||
|
$price_serch_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_customer_' . $customer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$args['tax_query'][] = array(
|
||||||
|
'taxonomy' => '_wiaas_shop_prices',
|
||||||
|
'terms' => $price_serch_terms,
|
||||||
|
'field' => 'slug'
|
||||||
);
|
);
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ class Wiaas_DB_Update {
|
|||||||
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
|
'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',
|
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
|
||||||
'20180912101010' => 'wiaas_db_setup_default_cl',
|
|
||||||
'20181003164100' => 'wiaas_db_setup_customer_capabilities',
|
'20181003164100' => 'wiaas_db_setup_customer_capabilities',
|
||||||
'201810031644700' => 'wiaas_db_update_create_default_roles',
|
'201810031644700' => 'wiaas_db_update_create_default_roles',
|
||||||
'201810101644700' => 'wiaas_db_import_aam_role_settings',
|
'201810101644700' => 'wiaas_db_import_aam_role_settings',
|
||||||
'201810111644700' => 'wiaas_db_update_add_organization_info_ui_fields',
|
'201810111644700' => 'wiaas_db_update_add_organization_info_ui_fields',
|
||||||
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields'
|
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
|
||||||
|
'201810161644700' => 'wiaas_db_update_update_commercial_lead_capabilities'
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function execute() {
|
public static function execute() {
|
||||||
|
|||||||
@@ -17,33 +17,6 @@ class Wiaas_Package {
|
|||||||
require_once dirname( __FILE__ ) . '/package/wiaas-package-functions.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_rest_prepare_product_object', array(__CLASS__, 'transform_rest_package'), 999, 3);
|
||||||
|
|
||||||
add_filter('woocommerce_rest_product_object_query', array( __CLASS__, 'edit_product_query'), 10, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change product query to fetch only available packages (available status)
|
|
||||||
* @param $query
|
|
||||||
* @param $instance
|
|
||||||
*/
|
|
||||||
public static function edit_product_query($query, $request){
|
|
||||||
if (isset($request['id'])){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($query['tax_query'])){
|
|
||||||
$query['tax_query'] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$query['tax_query'][] =
|
|
||||||
array(
|
|
||||||
'taxonomy' => 'package_status',
|
|
||||||
'field' => 'name',
|
|
||||||
'terms' => Wiaas_Package_Status::AVAILABLE
|
|
||||||
);
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
75
backend/app/plugins/wiaas/includes/class-wiaas-shop.php
Normal file
75
backend/app/plugins/wiaas/includes/class-wiaas-shop.php
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Shop {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
|
||||||
|
// registers special prices taxonomy that will enable package search based on
|
||||||
|
// set and visible price types (default and customer specific ones)
|
||||||
|
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_prices_taxonomy'));
|
||||||
|
|
||||||
|
// update prices search terms for package after prices extras have been updated
|
||||||
|
add_action('wiaas_package_prices_extras_set', array(__CLASS__, 'update_package_prices_search_terms'), 10, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register special prices taxonomy to enable search of packages by prices inside every shop
|
||||||
|
*/
|
||||||
|
public static function register_prices_taxonomy() {
|
||||||
|
$args = array(
|
||||||
|
'hierarchical' => false,
|
||||||
|
'query_var' => true,
|
||||||
|
'rewrite' => false,
|
||||||
|
'public' => true,
|
||||||
|
'capabilities' => array(
|
||||||
|
'manage_terms' => 'manage_wiaas_package_price_terms',
|
||||||
|
'edit_terms' => 'edit_wiaas_package_price_terms',
|
||||||
|
'delete_terms' => 'delete_wiaas_package_price_terms',
|
||||||
|
'assign_terms' => 'assign_wiaas_package_price_terms',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
register_taxonomy( '_wiaas_shop_prices', array( 'product' ), $args );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relate pricing search terms to package so customer can retrieve packages with default or
|
||||||
|
* their own specific prices.
|
||||||
|
* (ex: Package which will be hidden fro Customer 1 because default price
|
||||||
|
* is hidden can be visible for Customer 2 because specific prices are set for that customer)
|
||||||
|
*
|
||||||
|
* @param int $owner_id
|
||||||
|
* @param int $package_id
|
||||||
|
* @param array $cl_extras {
|
||||||
|
* $extra_price_payment_type => {
|
||||||
|
* @type bool visible Indicates if payment type is visible to customer
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* @param array $old_cl_extras {
|
||||||
|
* $extra_price_payment_type => {
|
||||||
|
* @type bool visible Indicates if payment type is visible to customer
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public static function update_package_prices_search_terms($owner_id, $package_id, $cl_extras, $old_cl_extras) {
|
||||||
|
// remove pricing terms for previous prices
|
||||||
|
if (! empty($old_cl_extras)) {
|
||||||
|
|
||||||
|
$old_visible_price_types = array_keys(wp_list_filter($old_cl_extras, array( 'visible' => true )));
|
||||||
|
|
||||||
|
$old_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $old_visible_price_types);
|
||||||
|
|
||||||
|
wp_remove_object_terms($package_id, $old_terms_names, '_wiaas_shop_prices');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get visible price types set by shop owner (commercial lead)
|
||||||
|
$visible_price_types = array_keys(wp_list_filter($cl_extras, array('visible' => true)));
|
||||||
|
|
||||||
|
$new_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $visible_price_types);
|
||||||
|
|
||||||
|
// create term for every visible pricing type and link them to package so package can be queried
|
||||||
|
wp_set_object_terms($package_id, $new_terms_names, '_wiaas_shop_prices');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Shop::init();
|
||||||
@@ -113,10 +113,6 @@ function wiaas_db_setup_exclusive_taxonomies() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function wiaas_db_setup_default_cl() {
|
|
||||||
wp_insert_term(Wiaas_Pricing::COMMERCIAL_LEAD_NAME, Wiaas_User_Organization::TAXONOMY_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
function wiaas_db_setup_customer_capabilities() {
|
function wiaas_db_setup_customer_capabilities() {
|
||||||
$customer_role = get_role('customer');
|
$customer_role = get_role('customer');
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ function wiaas_db_update_create_default_roles() {
|
|||||||
array(
|
array(
|
||||||
'read',
|
'read',
|
||||||
'view_admin_dashboard',
|
'view_admin_dashboard',
|
||||||
'wiaas_manage_cl_products'
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -138,3 +137,8 @@ function wiaas_db_import_aam_role_settings() {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wiaas_db_update_update_commercial_lead_capabilities() {
|
||||||
|
// add commercial lead specific roles
|
||||||
|
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_products' ); // cl products screen
|
||||||
|
}
|
||||||
@@ -15,29 +15,23 @@ class Wiaas_Package_CL_Pricing {
|
|||||||
* @param array $cl_extras
|
* @param array $cl_extras
|
||||||
*/
|
*/
|
||||||
public static function set_extras($organization_id, $package_id, $cl_extras) {
|
public static function set_extras($organization_id, $package_id, $cl_extras) {
|
||||||
//self::_assign_catalogue_attribute_options($organization_id, $package_id, $cl_extras);
|
|
||||||
|
|
||||||
$has_extras = false;
|
|
||||||
|
|
||||||
foreach ($cl_extras as $extra_type => $cl_extra) {
|
foreach ($cl_extras as $extra_type => $cl_extra) {
|
||||||
unset($cl_extra['type']);
|
unset($cl_extra['type']);
|
||||||
unset($cl_extra['customer']);
|
unset($cl_extra['customer']);
|
||||||
|
|
||||||
$has_extras = $has_extras || $cl_extra['visible'];
|
|
||||||
|
|
||||||
$cl_extras[$extra_type] = $cl_extra;
|
$cl_extras[$extra_type] = $cl_extra;
|
||||||
}
|
}
|
||||||
|
|
||||||
$package = wc_get_product($package_id);
|
$old_extras = self::get_extras($organization_id, $package_id);
|
||||||
|
|
||||||
$package->add_meta_data('_wiaas_catalogue_'.$organization_id, $has_extras ? 'yes' : 'no', true);
|
// Persist package price extras
|
||||||
$package->save_meta_data();
|
|
||||||
|
|
||||||
// Persist package catalogue extras
|
|
||||||
update_term_meta(
|
update_term_meta(
|
||||||
$organization_id,
|
$organization_id,
|
||||||
'_wiaas_cm_extras_'.$package_id,
|
'_wiaas_cm_extras_'.$package_id,
|
||||||
$cl_extras);
|
$cl_extras);
|
||||||
|
|
||||||
|
do_action('wiaas_package_prices_extras_set', $organization_id, $package_id, $cl_extras, $old_extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -34,6 +34,19 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
$cost_margin = 0;
|
$cost_margin = 0;
|
||||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
||||||
|
|
||||||
|
$customer_id = wp_create_term(
|
||||||
|
'Customer',
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME
|
||||||
|
)['term_id'];
|
||||||
|
|
||||||
|
$commercial_lead_id = wp_create_term(
|
||||||
|
'Commercial Lead',
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME
|
||||||
|
)['term_id'];
|
||||||
|
|
||||||
|
|
||||||
|
self::_set_package_default_extras($commercial_lead_id, $package->get_id());
|
||||||
|
|
||||||
$expected_prices = array(
|
$expected_prices = array(
|
||||||
'purchase' => array(
|
'purchase' => array(
|
||||||
'fixed_extra' => 100,
|
'fixed_extra' => 100,
|
||||||
@@ -52,7 +65,32 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return array( $package, $expected_prices );
|
return array( $package, $expected_prices, $customer_id, $commercial_lead_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _set_package_default_extras($commercial_lead_id, $package_id) {
|
||||||
|
$cl_extras = array(
|
||||||
|
'purchase_default' => array(
|
||||||
|
'fixed' => 0,
|
||||||
|
'recurrent' => 0,
|
||||||
|
'services' => 0,
|
||||||
|
'visible' => true
|
||||||
|
),
|
||||||
|
'purchase_24_default' => array(
|
||||||
|
'fixed' => 0,
|
||||||
|
'recurrent' => 0,
|
||||||
|
'services' => 0,
|
||||||
|
'visible' => true
|
||||||
|
),
|
||||||
|
'managed_36_default' => array(
|
||||||
|
'fixed' => 0,
|
||||||
|
'recurrent' => 0,
|
||||||
|
'services' => 0,
|
||||||
|
'visible' => true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Wiaas_Package_CL_Pricing::set_extras($commercial_lead_id, $package_id, $cl_extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,9 +210,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
*/
|
*/
|
||||||
function test_get_standard_package_customer_price() {
|
function test_get_standard_package_customer_price() {
|
||||||
|
|
||||||
list( $package, $expected_prices ) = $this->_create_package_to_sell();
|
list( $package, $expected_prices, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
|
||||||
|
|
||||||
$customer_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
$customer_prices = Wiaas_Pricing::get_standard_package_customer_prices(
|
||||||
|
$package,
|
||||||
|
$customer_id,
|
||||||
|
$commercial_lead_id);
|
||||||
|
|
||||||
$this->assertCount(3, $customer_prices);
|
$this->assertCount(3, $customer_prices);
|
||||||
|
|
||||||
@@ -203,7 +244,7 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
* @covers Wiaas_Pricing::get_addon_package_customer_price()
|
* @covers Wiaas_Pricing::get_addon_package_customer_price()
|
||||||
*/
|
*/
|
||||||
function test_get_addon_package_customer_price() {
|
function test_get_addon_package_customer_price() {
|
||||||
list( $package ) = $this->_create_package_to_sell();
|
list( $package, $expected_prices, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
|
||||||
|
|
||||||
$addon_product = $this->create_new_product(20);
|
$addon_product = $this->create_new_product(20);
|
||||||
$this->add_product_category($addon_product, 'hardware');
|
$this->add_product_category($addon_product, 'hardware');
|
||||||
@@ -233,6 +274,8 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
$cost_margin = 0;
|
$cost_margin = 0;
|
||||||
Wiaas_Package_Pricing::set_package_prices($addon_package, $pricing_rules, $commision, $cost_margin);
|
Wiaas_Package_Pricing::set_package_prices($addon_package, $pricing_rules, $commision, $cost_margin);
|
||||||
|
|
||||||
|
self::_set_package_default_extras($commercial_lead_id, $addon_package->get_id());
|
||||||
|
|
||||||
Wiaas_Package_Addon::set_package_addons($package, array($addon_package->get_id()));
|
Wiaas_Package_Addon::set_package_addons($package, array($addon_package->get_id()));
|
||||||
|
|
||||||
$expected_prices = array(
|
$expected_prices = array(
|
||||||
@@ -253,7 +296,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$customer_prices = Wiaas_Pricing::get_addon_package_customer_price($addon_package, $package);
|
$customer_prices = Wiaas_Pricing::get_addon_package_customer_price(
|
||||||
|
$addon_package,
|
||||||
|
$package,
|
||||||
|
$customer_id,
|
||||||
|
$commercial_lead_id);
|
||||||
|
|
||||||
$this->assertCount(3, $customer_prices);
|
$this->assertCount(3, $customer_prices);
|
||||||
|
|
||||||
@@ -281,7 +328,7 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
* @covers Wiaas_Pricing::get_option_package_customer_price()
|
* @covers Wiaas_Pricing::get_option_package_customer_price()
|
||||||
*/
|
*/
|
||||||
function test_get_option_package_customer_price() {
|
function test_get_option_package_customer_price() {
|
||||||
list( $package ) = $this->_create_package_to_sell();
|
list( $package, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
|
||||||
|
|
||||||
$option_product = $this->create_new_product(20);
|
$option_product = $this->create_new_product(20);
|
||||||
$this->add_product_category($option_product, 'hardware');
|
$this->add_product_category($option_product, 'hardware');
|
||||||
@@ -311,6 +358,8 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
$cost_margin = 0;
|
$cost_margin = 0;
|
||||||
Wiaas_Package_Pricing::set_package_prices($option_package, $pricing_rules, $commision, $cost_margin);
|
Wiaas_Package_Pricing::set_package_prices($option_package, $pricing_rules, $commision, $cost_margin);
|
||||||
|
|
||||||
|
self::_set_package_default_extras($commercial_lead_id, $option_package->get_id());
|
||||||
|
|
||||||
Wiaas_Package_Option_Groups::set_package_option_groups($package, array(
|
Wiaas_Package_Option_Groups::set_package_option_groups($package, array(
|
||||||
'id' => 'option',
|
'id' => 'option',
|
||||||
'name' => 'Option',
|
'name' => 'Option',
|
||||||
@@ -336,7 +385,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$customer_prices = Wiaas_Pricing::get_option_package_customer_price($option_package, $package);
|
$customer_prices = Wiaas_Pricing::get_option_package_customer_price(
|
||||||
|
$option_package,
|
||||||
|
$package,
|
||||||
|
$customer_id,
|
||||||
|
$commercial_lead_id);
|
||||||
|
|
||||||
$this->assertCount(3, $customer_prices);
|
$this->assertCount(3, $customer_prices);
|
||||||
|
|
||||||
|
|||||||
17
backend/app/plugins/wiaas/tests/wiaas-unit-test-factory.php
Normal file
17
backend/app/plugins/wiaas/tests/wiaas-unit-test-factory.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Unit_Test_Factory {
|
||||||
|
|
||||||
|
//
|
||||||
|
public $product;
|
||||||
|
|
||||||
|
//
|
||||||
|
public $package;
|
||||||
|
|
||||||
|
//
|
||||||
|
public $organization;
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,8 @@ 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-package.php';
|
||||||
|
|
||||||
|
include_once WIAAS_DIR . '/includes/class-wiaas-shop.php';
|
||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-user.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-pricing.php';
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ class CoMarketNavContainer extends Component {
|
|||||||
|
|
||||||
handleSearchChange(event) {
|
handleSearchChange(event) {
|
||||||
this.setState({searchValue: event.target.value});
|
this.setState({searchValue: event.target.value});
|
||||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
if (this.props.selectedCommercialLead) {
|
||||||
|
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import {fetchShopPackages} from '../../actions/coMarket/coMarketPackagesActions'
|
|||||||
|
|
||||||
class CoMarketPackagesContainer extends Component {
|
class CoMarketPackagesContainer extends Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead));
|
if (this.props.selectedCommercialLead) {
|
||||||
|
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ class CoMarketCatalogSelect extends Component {
|
|||||||
|
|
||||||
handleSearchChange(event) {
|
handleSearchChange(event) {
|
||||||
this.setState({searchValue: event.target.value});
|
this.setState({searchValue: event.target.value});
|
||||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
if (this.props.selectedCommercialLead) {
|
||||||
|
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
Reference in New Issue
Block a user