Implement shop search and refactor
This commit is contained in:
@@ -7,6 +7,9 @@ class Wiaas_Admin_CL_Shop {
|
|||||||
add_action( 'admin_menu', array( __CLASS__, 'add_customers_page' ), 9 );
|
add_action( 'admin_menu', array( __CLASS__, 'add_customers_page' ), 9 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add customer menu page for commercial lead
|
||||||
|
*/
|
||||||
public static function add_customers_page() {
|
public static function add_customers_page() {
|
||||||
add_menu_page(
|
add_menu_page(
|
||||||
__( 'Customers', 'wiaas' ),
|
__( 'Customers', 'wiaas' ),
|
||||||
@@ -18,10 +21,9 @@ class Wiaas_Admin_CL_Shop {
|
|||||||
'66.0' );
|
'66.0' );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function output_orders() {
|
/**
|
||||||
|
* Render content for customer menu page
|
||||||
}
|
*/
|
||||||
|
|
||||||
public static function output_customers() {
|
public static function output_customers() {
|
||||||
$organization_id = wiaas_get_current_user_organization_id();
|
$organization_id = wiaas_get_current_user_organization_id();
|
||||||
|
|
||||||
@@ -52,13 +54,13 @@ class Wiaas_Admin_CL_Shop {
|
|||||||
$customer_id = absint($_POST['customer_order_type']['customer_id']);
|
$customer_id = absint($_POST['customer_order_type']['customer_id']);
|
||||||
$order_type = sanitize_key($_POST['customer_order_type']['order_type']);
|
$order_type = sanitize_key($_POST['customer_order_type']['order_type']);
|
||||||
|
|
||||||
Wiaas_Shop_Data_Store::update_shop_customer_order_type(
|
Wiaas_Shop::update_shop_customer_order_type(
|
||||||
$organization_id,
|
$organization_id,
|
||||||
$customer_id,
|
$customer_id,
|
||||||
$order_type);
|
$order_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
$customers = Wiaas_Shop_Data_Store::get_shop_customers($organization_id);
|
$customers = Wiaas_Shop::get_shop_customers($organization_id);
|
||||||
|
|
||||||
require 'views/html-admin-cl-customers-page.php';
|
require 'views/html-admin-cl-customers-page.php';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,17 @@ class Wiaas_Admin_CL_Orders {
|
|||||||
add_filter( 'manage_edit-shop_order_sortable_columns', array( __CLASS__, 'define_sortable_columns_for_list_table_orders' ) );
|
add_filter( 'manage_edit-shop_order_sortable_columns', array( __CLASS__, 'define_sortable_columns_for_list_table_orders' ) );
|
||||||
|
|
||||||
add_action('manage_shop_order_posts_custom_column', array(__CLASS__, 'render_columns_for_list_table_orders'), 999, 2);
|
add_action('manage_shop_order_posts_custom_column', array(__CLASS__, 'render_columns_for_list_table_orders'), 999, 2);
|
||||||
|
|
||||||
|
//add_filter('wc_order_types', array(__CLASS__, ''), 999, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function hide_order_customers_search( $order_types, $for ) {
|
||||||
|
|
||||||
|
if ($for === 'order-meta-boxes') {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $order_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function remove_bulk_actions_for_list_table_orders() {
|
public static function remove_bulk_actions_for_list_table_orders() {
|
||||||
|
|||||||
@@ -7,15 +7,29 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
class Wiaas_Admin_CL {
|
class Wiaas_Admin_CL {
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
|
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-customers.php';
|
add_action('init', array(__CLASS__, 'init_admin_cl'));
|
||||||
|
}
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-orders.php';
|
public static function init_admin_cl() {
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages-list.php';
|
$current_user = wp_get_current_user();
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/wiaas-admin-cl-packages-ajax.php';
|
$role = $current_user->roles[0];
|
||||||
|
|
||||||
|
$is_cl = $role === 'commercial_lead';
|
||||||
|
|
||||||
|
if ($is_cl) {
|
||||||
|
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-customers.php';
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-orders.php';
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages-list.php';
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/admin-cl/wiaas-admin-cl-packages-ajax.php';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ class Wiaas_Admin_Order_Projects {
|
|||||||
// Add admin page and subpage since woocommerce orders have custom menu page
|
// Add admin page and subpage since woocommerce orders have custom menu page
|
||||||
// so this will not be automatic
|
// so this will not be automatic
|
||||||
add_filter('admin_menu', array(__CLASS__, 'add_admin_page'));
|
add_filter('admin_menu', array(__CLASS__, 'add_admin_page'));
|
||||||
add_action( 'parent_file', array(__CLASS__, 'highlight_order_projects_parent_menu') );
|
|
||||||
|
|
||||||
// Add is available fields to create and edit forms
|
// Add is available fields to create and edit forms
|
||||||
add_action( 'shop_order_project_add_form_fields', array( __CLASS__, 'add_is_available_field' ) );
|
add_action( 'shop_order_project_add_form_fields', array( __CLASS__, 'add_is_available_field' ) );
|
||||||
@@ -33,19 +32,6 @@ class Wiaas_Admin_Order_Projects {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Correctly highlight parent menu page when order projects submenu is selected
|
|
||||||
* @param $parent_file
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function highlight_order_projects_parent_menu($parent_file) {
|
|
||||||
if ( get_current_screen()->taxonomy == 'shop_order_project' ) {
|
|
||||||
$parent_file = 'woocommerce';
|
|
||||||
}
|
|
||||||
return $parent_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add is available field to order project creation form
|
* Add is available field to order project creation form
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class Wiaas_Admin_Organization {
|
|||||||
$id = absint(str_replace('term_', '', $id));
|
$id = absint(str_replace('term_', '', $id));
|
||||||
|
|
||||||
$customers = wp_list_pluck(
|
$customers = wp_list_pluck(
|
||||||
Wiaas_Shop_Data_Store::get_shop_customers($id),
|
Wiaas_Shop::get_shop_customers($id),
|
||||||
'customer_id');
|
'customer_id');
|
||||||
|
|
||||||
return $customers;
|
return $customers;
|
||||||
|
|||||||
@@ -218,7 +218,6 @@ class Wiaas_Cart_API {
|
|||||||
public static function get_cart_items() {
|
public static function get_cart_items() {
|
||||||
return rest_ensure_response(array(
|
return rest_ensure_response(array(
|
||||||
'items' => Wiaas_Cart::get_cart_packages(),
|
'items' => Wiaas_Cart::get_cart_packages(),
|
||||||
'raw' => WC()->cart->get_cart_contents(),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class Wiaas_Package_API {
|
|
||||||
|
|
||||||
public static function init() {
|
|
||||||
|
|
||||||
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
|
|
||||||
|
|
||||||
add_filter('rest_dispatch_request', array(__CLASS__, 'validate_package_search_request'), 10, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function register_routes() {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function validate_package_search_request($null, $request, $route, $handler) {
|
|
||||||
|
|
||||||
if (strpos($route, '/wc/v2/products') !== false) {
|
|
||||||
|
|
||||||
if (empty($request['cl_id']) || ! absint($request['cl_id'])) {
|
|
||||||
|
|
||||||
return new WP_Error(
|
|
||||||
'missing_commercial_lead',
|
|
||||||
'Commercial lead is missing',
|
|
||||||
array ( 'status' => 400 )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
|
|
||||||
if ( empty($query['tax_query']) ){
|
|
||||||
$query['tax_query'] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve only packages with available package status
|
|
||||||
$query['tax_query'][] = array(
|
|
||||||
'taxonomy' => 'package_status',
|
|
||||||
'field' => 'name',
|
|
||||||
'terms' => Wiaas_Package_Status::AVAILABLE
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$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_search_terms = array();
|
|
||||||
foreach ($pay_types as $pay_type) {
|
|
||||||
$price_search_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_default';
|
|
||||||
$price_search_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_customer_' . $customer_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$args['tax_query'][] = array(
|
|
||||||
'taxonomy' => '_wiaas_shop_prices',
|
|
||||||
'terms' => $price_search_terms,
|
|
||||||
'field' => 'slug'
|
|
||||||
);
|
|
||||||
|
|
||||||
return $args;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Wiaas_Package_API::init();
|
|
||||||
@@ -69,9 +69,7 @@ class Wiaas_REST_Customer_API {
|
|||||||
|
|
||||||
public static function get_customer_shops() {
|
public static function get_customer_shops() {
|
||||||
|
|
||||||
$customer_id = wiaas_get_current_user_organization_id();
|
$customer_shops = Wiaas_Customer::get_customer_shops();
|
||||||
|
|
||||||
$customer_shops = Wiaas_Shop_Data_Store::get_customer_shops($customer_id);
|
|
||||||
|
|
||||||
$customer_shops = array_map(function($customer_shop) {
|
$customer_shops = array_map(function($customer_shop) {
|
||||||
return array(
|
return array(
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements wiaas shop based search on top of woocommerce product api
|
||||||
|
*
|
||||||
|
* Class Wiaas_WC_Package_API_Integration
|
||||||
|
*/
|
||||||
|
class Wiaas_WC_Package_API_Integration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rest base for woocommerce product search
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $wc_rest_base = '/wc/v2/products';
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
|
||||||
|
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
|
||||||
|
|
||||||
|
add_filter('rest_dispatch_request', array(__CLASS__, 'validate_package_search_request'), 10, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force wc api request to send shop id when searching packages
|
||||||
|
*
|
||||||
|
* @param $null
|
||||||
|
* @param $request
|
||||||
|
* @param $route
|
||||||
|
* @param $handler
|
||||||
|
*
|
||||||
|
* @return null|WP_Error
|
||||||
|
*/
|
||||||
|
public static function validate_package_search_request($null, $request, $route, $handler) {
|
||||||
|
|
||||||
|
if (strpos($route, self::$wc_rest_base) !== false) {
|
||||||
|
|
||||||
|
if (empty($request['shop_id']) || ! absint($request['shop_id'])) {
|
||||||
|
|
||||||
|
return new WP_Error(
|
||||||
|
'missing_shop',
|
||||||
|
'Shop parameter is missing',
|
||||||
|
array ( 'status' => 400 )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
|
||||||
|
if ( empty($args['tax_query']) ){
|
||||||
|
$args['tax_query'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve only packages with available package status
|
||||||
|
$args['tax_query'][] = array(
|
||||||
|
'taxonomy' => 'package_status',
|
||||||
|
'field' => 'name',
|
||||||
|
'terms' => Wiaas_Package_Status::AVAILABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve packages that satisfy one of two:
|
||||||
|
*
|
||||||
|
* 1) Package has at least one visible customer specific price set (for current customer)
|
||||||
|
* 2) Package has at least one visible default price set and not customer specific prices set (for current customer)
|
||||||
|
*
|
||||||
|
* This approach enables us that if package has specific prices set for current customer only those prices
|
||||||
|
* are taken into account and default ones are ignored.
|
||||||
|
* Only if package has no specific prices for current customer default prices are taken into account.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
$shop_id = absint($request['shop_id']);
|
||||||
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
|
|
||||||
|
$default_price_search_term = '_' . $shop_id . '_default';
|
||||||
|
$customer_visible_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_visible';
|
||||||
|
$customer_hidden_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_hidden';
|
||||||
|
|
||||||
|
$args['tax_query'][] = array(
|
||||||
|
'relation' => 'OR',
|
||||||
|
array(
|
||||||
|
'taxonomy' => '_wiaas_shop_prices',
|
||||||
|
'terms' => $customer_visible_price_search_term,
|
||||||
|
'field' => 'slug'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'taxonomy' => '_wiaas_shop_prices',
|
||||||
|
'terms' => $default_price_search_term,
|
||||||
|
'field' => 'slug'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'taxonomy' => '_wiaas_shop_prices',
|
||||||
|
'terms' => $customer_hidden_price_search_term,
|
||||||
|
'field' => 'slug',
|
||||||
|
'operator' => 'NOT IN'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_WC_Package_API_Integration::init();
|
||||||
@@ -43,7 +43,7 @@ class Wiaas_API {
|
|||||||
|
|
||||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
||||||
|
|
||||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-package-api.php';
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc- package-api-integration.php';
|
||||||
|
|
||||||
// API functions
|
// API functions
|
||||||
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
||||||
@@ -58,7 +58,6 @@ class Wiaas_API {
|
|||||||
'Wiass_REST_User_API',
|
'Wiass_REST_User_API',
|
||||||
'Wiaas_REST_Customer_API',
|
'Wiaas_REST_Customer_API',
|
||||||
'Wiaas_Order_Projects_API',
|
'Wiaas_Order_Projects_API',
|
||||||
'Wiaas_Package_API'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $controllers as $controller ) {
|
foreach ( $controllers as $controller ) {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ class Wiaas_Cart {
|
|||||||
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
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_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||||
|
|
||||||
|
add_action('woocommerce_checkout_create_order', array(__CLASS__, 'add_additional_order_data'), 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,13 +116,13 @@ class Wiaas_Cart {
|
|||||||
*
|
*
|
||||||
* @param int $package_id Package ID of selected package
|
* @param int $package_id Package ID of selected package
|
||||||
* @param string $price_id Price ID of selected package payment
|
* @param string $price_id Price ID of selected package payment
|
||||||
* @param int $commercial_lead_id Shop owner commercial lead ID
|
* @param int $shop_owner_id Shop owner commercial lead ID
|
||||||
* @param array $addons_ids Array of selected additional packages IDs
|
* @param array $addons_ids Array of selected additional packages IDs
|
||||||
* @param array $options_ids Array of selected option packages IDs
|
* @param array $options_ids Array of selected option packages IDs
|
||||||
*
|
*
|
||||||
* @return bool TRUE if all packages are succesfully added to cart, FALSE otherwise
|
* @return bool TRUE if all packages are succesfully added to cart, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
public static function add_package_to_cart($package_id, $price_id, $commercial_lead_id, $addons_ids, $options_ids) {
|
public static function add_package_to_cart($package_id, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
|
||||||
// try adding package to cart
|
// try adding package to cart
|
||||||
try {
|
try {
|
||||||
// Check if package is in cart
|
// Check if package is in cart
|
||||||
@@ -138,17 +140,28 @@ class Wiaas_Cart {
|
|||||||
|
|
||||||
//Check if package is available for adding to cart
|
//Check if package is available for adding to cart
|
||||||
if (Wiaas_Package_Status::get_package_status($package_id) !== Wiaas_Package_Status::AVAILABLE){
|
if (Wiaas_Package_Status::get_package_status($package_id) !== Wiaas_Package_Status::AVAILABLE){
|
||||||
wc_add_notice('Package cannot be purchased at the moment', 'error');
|
wc_add_notice('Package cannot be purchased at the moment!', 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve package country
|
// Retrieve package country
|
||||||
$country = Wiaas_Countries::get_package_country($package);
|
$country = Wiaas_Countries::get_package_country($package);
|
||||||
|
|
||||||
|
if (empty($country)) {
|
||||||
|
wc_add_notice('Package cannot be added do cart!', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add validation that only packages from the same country can be added to cart at the same time
|
||||||
|
update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
|
||||||
|
|
||||||
|
// TODO: Add validation that only packages from the same shop can be added to cart at the same time
|
||||||
|
update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
|
||||||
|
|
||||||
$customer_id = wiaas_get_current_user_organization_id();
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
|
|
||||||
// Retrieve package price
|
// Retrieve package price
|
||||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $shop_owner_id);
|
||||||
|
|
||||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||||
|
|
||||||
@@ -157,9 +170,7 @@ class Wiaas_Cart {
|
|||||||
'_wiaas_standard_package' => true,
|
'_wiaas_standard_package' => true,
|
||||||
'_wiaas_addon_items' => array(),
|
'_wiaas_addon_items' => array(),
|
||||||
'_wiaas_option_items' => array(),
|
'_wiaas_option_items' => array(),
|
||||||
'_wiaas_currency' => isset($country) ? $country['currency'] : get_woocommerce_currency(),
|
|
||||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
||||||
'_wiaas_commercial_lead_id' => $commercial_lead_id,
|
|
||||||
'_wiaas_documents' => array()
|
'_wiaas_documents' => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -171,7 +182,7 @@ class Wiaas_Cart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add selected additional packages and options
|
// Add selected additional packages and options
|
||||||
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $commercial_lead_id, $addons_ids, $options_ids);
|
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids);
|
||||||
|
|
||||||
// Trigger calculation of total prices after additional packages are added
|
// Trigger calculation of total prices after additional packages are added
|
||||||
WC()->cart->calculate_totals();
|
WC()->cart->calculate_totals();
|
||||||
@@ -300,12 +311,6 @@ class Wiaas_Cart {
|
|||||||
if (isset($cart_item['_wiaas_standard_package'])) {
|
if (isset($cart_item['_wiaas_standard_package'])) {
|
||||||
$order_item->add_meta_data( '_wiaas_standard_package', $cart_item['_wiaas_standard_package'], true );
|
$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 );
|
|
||||||
}
|
|
||||||
if (isset($cart_item['_wiaas_commercial_lead_id'])) {
|
|
||||||
$order_item->add_meta_data( '_wiaas_commercial_lead_id', $cart_item['_wiaas_commercial_lead_id'], true );
|
|
||||||
}
|
|
||||||
|
|
||||||
// add options metadata
|
// add options metadata
|
||||||
if (isset($cart_item['_wiaas_option_items'])) {
|
if (isset($cart_item['_wiaas_option_items'])) {
|
||||||
@@ -383,12 +388,33 @@ class Wiaas_Cart {
|
|||||||
'_wiaas_option_for',
|
'_wiaas_option_for',
|
||||||
'_wiaas_option_group_name',
|
'_wiaas_option_group_name',
|
||||||
'_wiaas_standard_package',
|
'_wiaas_standard_package',
|
||||||
'_wiaas_currency',
|
|
||||||
'_wiaas_documents',
|
'_wiaas_documents',
|
||||||
'_wiaas_commercial_lead_id'
|
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets additional order data form cart after order is successfully created
|
||||||
|
*
|
||||||
|
* @param WC_Order $order
|
||||||
|
*
|
||||||
|
* @throws WC_Data_Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function add_additional_order_data($order) {
|
||||||
|
|
||||||
|
// set order currency
|
||||||
|
$country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
|
||||||
|
$currency = empty($country) ? get_woocommerce_currency() : $country['currency'];
|
||||||
|
|
||||||
|
$order->set_currency($currency);
|
||||||
|
|
||||||
|
// set order commercial lead
|
||||||
|
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
|
||||||
|
$shop_owner_id = absint($shop_owner_id);
|
||||||
|
|
||||||
|
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate total cost for cart item
|
* Calculate total cost for cart item
|
||||||
*
|
*
|
||||||
@@ -456,6 +482,9 @@ class Wiaas_Cart {
|
|||||||
public static function get_cart_packages() {
|
public static function get_cart_packages() {
|
||||||
$items = WC()->cart->get_cart_contents();
|
$items = WC()->cart->get_cart_contents();
|
||||||
|
|
||||||
|
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
|
||||||
|
$shop_owner_id = absint($shop_owner_id);
|
||||||
|
|
||||||
$package_items = array();
|
$package_items = array();
|
||||||
|
|
||||||
foreach ($items as $key => $item) {
|
foreach ($items as $key => $item) {
|
||||||
@@ -505,8 +534,8 @@ class Wiaas_Cart {
|
|||||||
'package_name' => $package->get_title(),
|
'package_name' => $package->get_title(),
|
||||||
'quantity' => $item['quantity'],
|
'quantity' => $item['quantity'],
|
||||||
|
|
||||||
'commercial_lead_id' => 14,
|
'commercial_lead_id' => $shop_owner_id,
|
||||||
'commercial_lead' => 'Coor Service Management',
|
'commercial_lead' => wiaas_get_organization_name($shop_owner_id),
|
||||||
'country' => Wiaas_Countries::get_package_country($package),
|
'country' => Wiaas_Countries::get_package_country($package),
|
||||||
|
|
||||||
'are_additional_available' => true,
|
'are_additional_available' => true,
|
||||||
@@ -641,13 +670,13 @@ class Wiaas_Cart {
|
|||||||
*
|
*
|
||||||
* @param string $package_cart_item_key
|
* @param string $package_cart_item_key
|
||||||
* @param int $price_id
|
* @param int $price_id
|
||||||
* @param int $commercial_lead_id
|
* @param int $shop_owner_id
|
||||||
* @param array $addons_ids
|
* @param array $addons_ids
|
||||||
* @param array $options_ids
|
* @param array $options_ids
|
||||||
*
|
*
|
||||||
* @throws Exception if any of the addons or options cannot be added to cart
|
* @throws Exception if any of the addons or options cannot be added to cart
|
||||||
*/
|
*/
|
||||||
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $commercial_lead_id, $addons_ids, $options_ids) {
|
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
|
||||||
|
|
||||||
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
|
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||||
|
|
||||||
@@ -669,7 +698,7 @@ class Wiaas_Cart {
|
|||||||
$addon_package,
|
$addon_package,
|
||||||
$parent_item['data'],
|
$parent_item['data'],
|
||||||
$customer_id,
|
$customer_id,
|
||||||
$commercial_lead_id
|
$shop_owner_id
|
||||||
);
|
);
|
||||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||||
|
|
||||||
@@ -706,7 +735,7 @@ class Wiaas_Cart {
|
|||||||
$option_package,
|
$option_package,
|
||||||
$parent_item['data'],
|
$parent_item['data'],
|
||||||
$customer_id,
|
$customer_id,
|
||||||
$commercial_lead_id);
|
$shop_owner_id);
|
||||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||||
|
|
||||||
// Retrieve option package group name
|
// Retrieve option package group name
|
||||||
|
|||||||
@@ -83,17 +83,6 @@ class Wiaas_Checkout {
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
*/
|
*/
|
||||||
private static function _add_wiaas_checkout_data($order, $data) {
|
private static function _add_wiaas_checkout_data($order, $data) {
|
||||||
// save currency
|
|
||||||
$line_items = $order->get_items();
|
|
||||||
|
|
||||||
$currency = array_column($line_items, 'wiaas_currency')[0];
|
|
||||||
$currency = empty($currency) ? get_woocommerce_currency() : $currency;
|
|
||||||
$order->set_currency($currency);
|
|
||||||
|
|
||||||
// set order commercial lead
|
|
||||||
$commercial_lead_id = array_column($line_items, 'wiaas_commercial_lead_id')[0];
|
|
||||||
$order->add_meta_data('wiaas_commercial_lead_id', $commercial_lead_id, true);
|
|
||||||
$order->save_meta_data();
|
|
||||||
|
|
||||||
// save additional wiaas order info
|
// save additional wiaas order info
|
||||||
Wiaas_Order::set_order_vat($order->get_id(), $data['vat']);
|
Wiaas_Order::set_order_vat($order->get_id(), $data['vat']);
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class Wiaas_Data_Store {
|
|
||||||
|
|
||||||
public static function init() {
|
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/data-stores/class-wiaas-shop-data-store.php';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Wiaas_Data_Store::init();
|
|
||||||
11
backend/app/plugins/wiaas/includes/class-wiaas-db.php
Normal file
11
backend/app/plugins/wiaas/includes/class-wiaas-db.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_DB {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/db/class-wiaas-shop-db.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_DB::init();
|
||||||
@@ -19,6 +19,8 @@ class Wiaas_Order {
|
|||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
|
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
|
||||||
|
|
||||||
|
add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings'));
|
||||||
|
|
||||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||||
|
|
||||||
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
||||||
@@ -30,6 +32,35 @@ class Wiaas_Order {
|
|||||||
add_filter('woocommerce_new_order_note_data', array( __CLASS__, 'update_new_order_comment_date'), 10, 3);
|
add_filter('woocommerce_new_order_note_data', array( __CLASS__, 'update_new_order_comment_date'), 10, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update `shop_order` post type settings before creation to enable better order management for wiaas
|
||||||
|
*
|
||||||
|
* @param array $args
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function manage_order_settings($args) {
|
||||||
|
// show orders in backend menu
|
||||||
|
$args['show_in_menu'] = true;
|
||||||
|
|
||||||
|
//set icon
|
||||||
|
$args['menu_icon'] = 'dashicons-clipboard';
|
||||||
|
|
||||||
|
// set capabilities
|
||||||
|
$args['capabilities'] = array(
|
||||||
|
'edit_post' => 'edit_shop_order',
|
||||||
|
'read_post' => 'read_shop_order',
|
||||||
|
'delete_post' => 'delete_shop_order',
|
||||||
|
'edit_posts' => 'edit_shop_orders',
|
||||||
|
'edit_others_posts' => 'edit_others_shop_orders',
|
||||||
|
'publish_posts' => 'publish_shop_orders',
|
||||||
|
'read_private_posts' => 'read_private_shop_orders',
|
||||||
|
'create_posts' => 'create_shop_orders', // use `create_shop_orders` instead of `edit_shop_orders`
|
||||||
|
);
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
public static function update_new_order_comment_date($comment_data, $order_data) {
|
public static function update_new_order_comment_date($comment_data, $order_data) {
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
|
|
||||||
@@ -45,11 +76,17 @@ class Wiaas_Order {
|
|||||||
* @param $order_id
|
* @param $order_id
|
||||||
*/
|
*/
|
||||||
public static function assign_order_to_organization($order_id) {
|
public static function assign_order_to_organization($order_id) {
|
||||||
|
// assign order to customer organization
|
||||||
$customer_id = wiaas_get_current_user_organization_id();
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
|
|
||||||
$commercial_lead_id =
|
|
||||||
|
|
||||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
|
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
|
||||||
|
// assign order to commercial lead organization
|
||||||
|
$commercial_lead_id = absint($order->get_meta('_wiaas_commercial_lead_id', true));
|
||||||
|
if ($commercial_lead_id) {
|
||||||
|
Wiaas_User_Organization::assign_post_to_organization($order_id, $commercial_lead_id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class Wiaas_Package {
|
|||||||
*/
|
*/
|
||||||
private static function _append_additional_packages($data, $package, $request) {
|
private static function _append_additional_packages($data, $package, $request) {
|
||||||
$customer_id = wiaas_get_current_user_organization_id();
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
$commercial_lead_id = absint($request['cl_id']);
|
$commercial_lead_id = absint($request['shop_id']);
|
||||||
|
|
||||||
$data['additional_packages'] = array();
|
$data['additional_packages'] = array();
|
||||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||||
@@ -142,7 +142,7 @@ class Wiaas_Package {
|
|||||||
*/
|
*/
|
||||||
private static function _append_package_prices($data, $package, $request) {
|
private static function _append_package_prices($data, $package, $request) {
|
||||||
$customer_id = wiaas_get_current_user_organization_id();
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
$commercial_lead_id = absint($request['cl_id']);
|
$commercial_lead_id = absint($request['shop_id']);
|
||||||
|
|
||||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements logic for multiple shops existing in one marketplace
|
||||||
|
*
|
||||||
|
* Every shop has its owner (organization that is commercial lead) and multiple customers (organizations)
|
||||||
|
* assigned to it.
|
||||||
|
*
|
||||||
|
* Class Wiaas_Shop
|
||||||
|
*/
|
||||||
class Wiaas_Shop {
|
class Wiaas_Shop {
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
@@ -16,6 +24,10 @@ class Wiaas_Shop {
|
|||||||
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'maybe_manage_shop_for_commercial_lead'), 10, 2);
|
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'maybe_manage_shop_for_commercial_lead'), 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_shop_customers($owner_id) {
|
||||||
|
return Wiaas_Shop_DB::get_shop_customers($owner_id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link customers to shop (this will enable them to search and order packages from this shop)
|
* Link customers to shop (this will enable them to search and order packages from this shop)
|
||||||
*
|
*
|
||||||
@@ -25,16 +37,16 @@ class Wiaas_Shop {
|
|||||||
public static function set_shop_customers($owner_id, $customer_ids) {
|
public static function set_shop_customers($owner_id, $customer_ids) {
|
||||||
|
|
||||||
$current_customer_ids = wp_list_pluck(
|
$current_customer_ids = wp_list_pluck(
|
||||||
Wiaas_Shop_Data_Store::get_shop_customers($owner_id),
|
Wiaas_Shop_DB::get_shop_customers($owner_id),
|
||||||
'customer_id');
|
'customer_id');
|
||||||
|
|
||||||
// delete removed customers
|
// delete removed customers
|
||||||
$removed_customer_ids = array_diff($current_customer_ids, $customer_ids);
|
$removed_customer_ids = array_diff($current_customer_ids, $customer_ids);
|
||||||
Wiaas_Shop_Data_Store::remove_shop_customers($owner_id, $removed_customer_ids);
|
Wiaas_Shop_DB::remove_shop_customers($owner_id, $removed_customer_ids);
|
||||||
|
|
||||||
// save added customers
|
// save added customers
|
||||||
$added_customer_ids = array_diff($customer_ids, $current_customer_ids);
|
$added_customer_ids = array_diff($customer_ids, $current_customer_ids);
|
||||||
Wiaas_Shop_Data_Store::add_shop_customers($owner_id, $added_customer_ids);
|
Wiaas_Shop_DB::add_shop_customers($owner_id, $added_customer_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,6 +78,13 @@ class Wiaas_Shop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function update_shop_customer_order_type($owner_id, $customer_id, $order_type) {
|
||||||
|
Wiaas_Shop_DB::update_shop_customer_order_type(
|
||||||
|
$owner_id,
|
||||||
|
$customer_id,
|
||||||
|
$order_type);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates shop for new shop owner (organization with commercial lead role) or
|
* Creates shop for new shop owner (organization with commercial lead role) or
|
||||||
* deletes existing shop if that role has been removed
|
* deletes existing shop if that role has been removed
|
||||||
@@ -124,24 +143,27 @@ class Wiaas_Shop {
|
|||||||
// remove pricing terms for previous prices
|
// remove pricing terms for previous prices
|
||||||
if (! empty($old_cl_extras)) {
|
if (! empty($old_cl_extras)) {
|
||||||
|
|
||||||
$old_visible_price_types = array_keys(wp_list_filter($old_cl_extras, array( 'visible' => true )));
|
$old_terms = self::_get_search_terms_from_cl_extras($owner_id, $old_cl_extras);
|
||||||
|
|
||||||
$old_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $old_visible_price_types);
|
wp_remove_object_terms($package_id, $old_terms, '_wiaas_shop_prices');
|
||||||
|
|
||||||
wp_remove_object_terms($package_id, $old_terms_names, '_wiaas_shop_prices');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get visible price types set by shop owner (commercial lead)
|
$new_terms = self::_get_search_terms_from_cl_extras($owner_id, $cl_extras);
|
||||||
$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
|
// create term for every visible pricing type and link them to package so package can be queried
|
||||||
wp_add_object_terms($package_id, $new_terms_names, '_wiaas_shop_prices');
|
wp_add_object_terms($package_id, $new_terms, '_wiaas_shop_prices');
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRIVATE
|
// PRIVATE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each shop will be registered as product attribute.
|
||||||
|
* This will persist shops information into database.
|
||||||
|
* Also every attribute has taxonomy associated with it which will enable us to have multiple
|
||||||
|
* catalogues in one shop
|
||||||
|
*
|
||||||
|
* @param int $owner_id
|
||||||
|
*/
|
||||||
private static function _maybe_create_shop($owner_id) {
|
private static function _maybe_create_shop($owner_id) {
|
||||||
$shop_name = 'wiaas_shop_' . $owner_id;
|
$shop_name = 'wiaas_shop_' . $owner_id;
|
||||||
|
|
||||||
@@ -149,17 +171,24 @@ class Wiaas_Shop {
|
|||||||
|
|
||||||
if ($attribute_id === 0) {
|
if ($attribute_id === 0) {
|
||||||
// create shop attribute
|
// create shop attribute
|
||||||
wc_create_attribute(array( 'slug' => $shop_name, 'name' => 'Catalogue' ));
|
wc_create_attribute(array( 'slug' => $shop_name, 'name' => 'Shop' ));
|
||||||
|
|
||||||
$taxonomy_name = wc_attribute_taxonomy_name($shop_name);
|
$taxonomy_name = wc_attribute_taxonomy_name($shop_name);
|
||||||
|
|
||||||
|
// since attribute taxonomies are registered once on load
|
||||||
|
// we will register new attribute taxonomy here so default catalogue can be added
|
||||||
register_taxonomy($taxonomy_name, array('product'));
|
register_taxonomy($taxonomy_name, array('product'));
|
||||||
|
|
||||||
// add default catalogue option to shop attribute
|
// add default catalogue option to shop
|
||||||
wp_insert_term( 'Default', $taxonomy_name);
|
wp_insert_term( 'Default Catalogue', $taxonomy_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deleted associated attribute for shop. This will effectively remove shop and all of its potential catalogues
|
||||||
|
*
|
||||||
|
* @param int $owner_id
|
||||||
|
*/
|
||||||
private static function _maybe_remove_shop($owner_id) {
|
private static function _maybe_remove_shop($owner_id) {
|
||||||
// get corresponding attribute for shop
|
// get corresponding attribute for shop
|
||||||
$attribute_id = wc_attribute_taxonomy_id_by_name('wiaas_shop_' . $owner_id);
|
$attribute_id = wc_attribute_taxonomy_id_by_name('wiaas_shop_' . $owner_id);
|
||||||
@@ -169,6 +198,55 @@ class Wiaas_Shop {
|
|||||||
wc_delete_attribute($attribute_id);
|
wc_delete_attribute($attribute_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate search terms from cl extras
|
||||||
|
*
|
||||||
|
* For default prices search term
|
||||||
|
* `_{owner_id}_default` will be generated if all set prices are visible
|
||||||
|
*
|
||||||
|
* For every customer entry search term
|
||||||
|
* `_{owner_id}_customer_{customer_id}_visible` will be generated if any of the prices is visible or
|
||||||
|
* `_{owner_id}_customer_{customer_id}_hidden` if all prices are hidden`
|
||||||
|
*
|
||||||
|
* @param int $owner_id
|
||||||
|
* @param array $cl_extras
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function _get_search_terms_from_cl_extras($owner_id, $cl_extras) {
|
||||||
|
// determine if extras are visible grouped by customer and default settings
|
||||||
|
$cl_extras_per_customer = array();
|
||||||
|
$cl_extra_default = false;
|
||||||
|
|
||||||
|
foreach ($cl_extras as $cl_extra_type => $cl_extra) {
|
||||||
|
// is default
|
||||||
|
if (strpos($cl_extra_type, '_default') !== false) {
|
||||||
|
// determine if default cl extra is visible
|
||||||
|
$cl_extra_default = $cl_extra_default || $cl_extra['visible'];
|
||||||
|
}
|
||||||
|
// is customer specific
|
||||||
|
if (strpos($cl_extra_type, '_customer_') !== false) {
|
||||||
|
$customer_id = absint(explode('_customer_', $cl_extra_type)[1]);
|
||||||
|
// determine if customer cl extra is visible
|
||||||
|
$cl_extras_per_customer[$customer_id] = $cl_extras_per_customer[$customer_id] || $cl_extra['visible'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$terms = array();
|
||||||
|
|
||||||
|
if ($cl_extra_default) {
|
||||||
|
$terms[] = '_' . $owner_id . '_default';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($cl_extras_per_customer as $customer_id => $visible) {
|
||||||
|
|
||||||
|
$terms[] = '_' . $owner_id . '_customer_' . $customer_id . '_' .
|
||||||
|
($visible ? 'visible' : 'hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $terms;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiaas_Shop::init();
|
Wiaas_Shop::init();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Wiaas_Shop_Data_Store {
|
class Wiaas_Shop_DB {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts new customer for shop
|
* Inserts new customer for shop
|
||||||
@@ -33,6 +33,18 @@ class Wiaas_Customer {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve available shops for customer
|
||||||
|
*
|
||||||
|
* @return array of available shops for customer
|
||||||
|
*/
|
||||||
|
public static function get_customer_shops() {
|
||||||
|
|
||||||
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
|
|
||||||
|
return Wiaas_Shop_DB::get_customer_shops($customer_id);
|
||||||
|
}
|
||||||
|
|
||||||
public static function get_customer_profile_addresses($customer_id){
|
public static function get_customer_profile_addresses($customer_id){
|
||||||
return get_user_meta($customer_id, 'profile_addresses', true) ?: [];
|
return get_user_meta($customer_id, 'profile_addresses', true) ?: [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
|||||||
* @param $organization_id
|
* @param $organization_id
|
||||||
*/
|
*/
|
||||||
public static function assign_post_to_organization($post_id, $organization_id) {
|
public static function assign_post_to_organization($post_id, $organization_id) {
|
||||||
self::_assign_post_to_organization($post_id, $organization_id);
|
self::_assign_post_to_organization( $post_id, $organization_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
|||||||
private static function _assign_post_to_organization($post_id, $organization_id) {
|
private static function _assign_post_to_organization($post_id, $organization_id) {
|
||||||
if (class_exists('Groups_Post_Access')) {
|
if (class_exists('Groups_Post_Access')) {
|
||||||
$access_group_id = self::_get_organization_access_group_id($organization_id);
|
$access_group_id = self::_get_organization_access_group_id($organization_id);
|
||||||
Groups_Post_Access::update( array( 'post_id' => $post_id, 'groups_read' => [$access_group_id] ) );
|
Groups_Post_Access::create( array( 'post_id' => $post_id, 'group_id' => $access_group_id ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ if (is_admin()) {
|
|||||||
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-data-store.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-db.php';
|
||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export const fetchPackageDetails = (params) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestPackageDetails());
|
dispatch(requestPackageDetails());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/products/${params.idPackage}?cl_id=${params.shopId}`,
|
url: `${API_SERVER}/wp-json/wc/v2/products/${params.idPackage}?shop_id=${params.shopId}`,
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export const fetchShopPackages = (shop, search) => {
|
|||||||
let searchParam = search ? '?search=' +search : ''
|
let searchParam = search ? '?search=' +search : ''
|
||||||
|
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${shop.id}` + searchParam,
|
url: `${API_SERVER}/wp-json/wc/v2/products?shop_id=${shop.id}` + searchParam,
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
@@ -59,10 +59,11 @@ const generateShopOptions = (shops) => {
|
|||||||
return shops;
|
return shops;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchShops = () => {
|
export const fetchShops = (userId) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestShops());
|
dispatch(requestShops());
|
||||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/customer/0/shops` })
|
|
||||||
|
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/customer/${userId}/shops` })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
||||||
if(response.data){
|
if(response.data){
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class CoMarketCatalogSelect extends Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.dispatch(fetchShops());
|
this.props.dispatch(fetchShops(this.props.userInfo.wiaas_id_user));
|
||||||
|
|
||||||
if(this.props.shops && this.props.cartItems && this.props.activeModule==='cart'){
|
if(this.props.shops && this.props.cartItems && this.props.activeModule==='cart'){
|
||||||
const cartShop = this.props.shops.find( shop => { return shop.id===this.props.cartItems[0].idCommercialLead });
|
const cartShop = this.props.shops.find( shop => { return shop.id===this.props.cartItems[0].idCommercialLead });
|
||||||
@@ -80,7 +80,8 @@ const mapStateToProps = (state) => ({
|
|||||||
selectedShop: state.coMarketPackagesReducer.selectedShop,
|
selectedShop: state.coMarketPackagesReducer.selectedShop,
|
||||||
idPackage: state.coMarketReducer.idPackage,
|
idPackage: state.coMarketReducer.idPackage,
|
||||||
cartItems: state.cartReducer.cartItems,
|
cartItems: state.cartReducer.cartItems,
|
||||||
activeSubmodule: state.pageReducer.activeSubmodule
|
activeSubmodule: state.pageReducer.activeSubmodule,
|
||||||
|
userInfo: state.auth.userInfo
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(CoMarketCatalogSelect);
|
export default connect(mapStateToProps)(CoMarketCatalogSelect);
|
||||||
|
|||||||
Reference in New Issue
Block a user