Fix tests

This commit is contained in:
Almira Krdzic
2018-10-15 05:06:46 +02:00
parent e810dd086a
commit f14d35b1aa
17 changed files with 245 additions and 77 deletions

View File

@@ -6,7 +6,7 @@ class Wiaas_Package_API {
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() {
@@ -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();
foreach (wiaas_get_commercial_leads() as $id => $name) {
@@ -31,15 +32,43 @@ class Wiaas_Package_API {
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(
'key' => '_wiaas_catalogue_'.$catalogue_id,
'value' => 'yes',
$commercial_lead_id = absint($request['cl_id']);
$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;