reseller to customer

This commit is contained in:
Almira Krdzic
2018-10-16 06:45:28 +02:00
parent b7ac53d195
commit afab22a30b
37 changed files with 852 additions and 152 deletions

View File

@@ -15,3 +15,7 @@
#createuser .acf-taxonomy-field, #your-profile .acf-taxonomy-field {
width: 25em;
}
.wc-order-preview footer {
display: none;
}

View File

@@ -0,0 +1,67 @@
<?php
class Wiaas_Admin_CL_Shop {
public static function init() {
add_action( 'admin_menu', array( __CLASS__, 'add_customers_page' ), 9 );
}
public static function add_customers_page() {
add_menu_page(
__( 'Customers', 'wiaas' ),
__( 'Customers', 'wiaas' ),
'manage_wiaas_cl_customers',
'wiaas-cl-customers',
array(__CLASS__, 'output_customers'),
'dashicons-groups',
'66.0' );
}
public static function output_orders() {
}
public static function output_customers() {
$organization_id = wiaas_get_current_user_organization_id();
// handle default order type update if needed
if (! empty($_POST['wiaas_update_cl_default_order_type_nonce']) &&
! empty($_POST['default_order_type']) &&
wp_verify_nonce(
$_POST['wiaas_update_cl_default_order_type_nonce'],
'wiaas_update_cl_default_order_type')
) {
$default_order_type = sanitize_key($_POST['default_order_type']);
error_log($default_order_type);
Wiaas_Shop::update_default_order_type($organization_id, $default_order_type);
}
// handle customer order type update if needed
if (! empty($_POST['wiaas_update_cl_customer_order_type_nonce']) &&
! empty($_POST['customer_order_type']) &&
wp_verify_nonce(
$_POST['wiaas_update_cl_customer_order_type_nonce'],
'wiaas_update_cl_customer_order_type')
) {
$customer_id = absint($_POST['customer_order_type']['customer_id']);
$order_type = sanitize_key($_POST['customer_order_type']['order_type']);
Wiaas_Shop_Data_Store::update_shop_customer_order_type(
$organization_id,
$customer_id,
$order_type);
}
$customers = Wiaas_Shop_Data_Store::get_shop_customers($organization_id);
require 'views/html-admin-cl-customers-page.php';
}
}
Wiaas_Admin_CL_Shop::init();

View File

@@ -0,0 +1,75 @@
<?php
class Wiaas_Admin_CL_Orders {
public static function init() {
add_filter( 'bulk_actions-edit-shop_order', array( __CLASS__, 'remove_bulk_actions_for_list_table_orders' ), 999 );
add_filter('woocommerce_admin_order_preview_actions', array(__CLASS__, 'remove_actions_from_order_preview'));
add_filter('woocommerce_admin_order_preview_line_items', array(__CLASS__, 'filter_order_items_for_order_preview'), 10, 2);
add_filter('manage_shop_order_posts_columns', array(__CLASS__, 'columns_for_list_table_orders'), 999);
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);
}
public static function remove_bulk_actions_for_list_table_orders() {
return array();
}
public static function remove_actions_from_order_preview() {
return array();
}
public static function filter_order_items_for_order_preview($order_items, $order) {
$items = array();
foreach ($order_items as $order_item) {
if (isset($order_item['wiaas_standard_package'])) {
$items[] = $order_item;
}
}
return $items;
}
public static function columns_for_list_table_orders($columns) {
$show_columns = array();
$show_columns['cb'] = $columns['cb'];
$show_columns['_wiaas_order_number'] = __( 'Order', 'woocommerce' );
$show_columns['order_date'] = __( 'Date', 'woocommerce' );
$show_columns['order_status'] = __( 'Status', 'woocommerce' );
$show_columns['order_total'] = __( 'Total', 'woocommerce' );
return $show_columns;
}
public static function define_sortable_columns_for_list_table_orders($sortable_columns) {
$sortable_columns['_wiaas_order_number'] = 'ID';
return $sortable_columns;
}
public static function render_columns_for_list_table_orders($column, $order_id) {
if ($column === '_wiaas_order_number') {
$order = wc_get_order($order_id);
echo '<strong>#' . esc_attr( $order->get_order_number() ) . '</strong>';
if ( $order->get_status() !== 'trash' ) {
echo '<a href="#" class="order-preview" data-order-id="' . absint( $order->get_id() ) . '" title="' . esc_attr( __( 'Preview', 'wiaas' ) ) . '">' . esc_html( __( 'Preview', 'wiaas' ) ) . '</a>';
}
}
}
}
Wiaas_Admin_CL_Orders::init();

View File

@@ -0,0 +1,126 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<style>
select {
width: 300px;
max-width: 100%;
}
</style>
<div class="wrap">
<h1><?php esc_html_e( 'Customers', 'wiaas' ); ?> </h1>
<br class="clear" />
<div id="col-container">
<div id="col-right">
<div class="col-wrap">
<table class="widefat wp-list-table striped" style="width:100%">
<thead>
<tr>
<th scope="col"><?php esc_html_e( 'Name', 'wiaas' ); ?></th>
<th scope="col"><?php esc_html_e( 'Order type', 'wiaas' ); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($customers as $customer) {
$name = wiaas_get_organization_name($customer['customer_id']);
?>
<tr>
<td>
<h2><?php esc_html_e($name, 'wiaas') ?></h2>
</td>
<td>
<?php
esc_html_e(
$customer['order_type']=== 'commercial_lead' ? 'Commercial Lead' : 'Reseller',
'wiaas'
)
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div id="col-left">
<div class="col-wrap">
<div class="inside">
<div class="form-wrap">
<h2><?php esc_html_e('Default order type:', 'wiaas') ?></h2>
<form class="form" action="" method="post">
<input type="hidden" name="page" value="wiaas-cl-customers"/>
<div class="form-field">
<select class="form-control" name="default_order_type">
<option
value="commercial_lead"
<?php selected('commercial_lead', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
>
<?php esc_html_e('Commercial Lead', 'wiaas') ?>
</option>
<option
value="reseller"
<?php selected('reseller', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
>
<?php esc_html_e('Reseller', 'wiaas') ?>
</option>
</select>
</div>
<input class="button button-primary button-large" type="submit" value="Change"/>
<?php wp_nonce_field( 'wiaas_update_cl_default_order_type', 'wiaas_update_cl_default_order_type_nonce' ); ?>
</form>
</div>
<hr style="margin: 30px 0;" />
<div class="form-wrap">
<h2><?php esc_html_e('Update order type for customer', 'wiaas') ?></h2>
<form class="form" action="" method="post">
<div class="form-field">
<label><?php esc_html_e('Customer:', 'wiaas') ?> </label>
<select class="form-control" name="customer_order_type[customer_id]">
<?php
foreach ($customers as $customer) {
$name = wiaas_get_organization_name($customer['customer_id']);
?>
<option
value="<?php esc_html_e($customer['customer_id'], 'wiaas') ?>"
>
<?php esc_html_e($name, 'wiaas') ?>
</option>
<?php
}
?>
</select>
</div>
<div class="form-field">
<label><?php esc_html_e('Order type:', 'wiaas') ?> </label>
<select class="form-control" name="customer_order_type[order_type]">
<option value="commercial_lead">
<?php esc_html_e('Commercial Lead', 'wiaas') ?>
</option>
<option value="reseller">
<?php esc_html_e('Reseller', 'wiaas') ?>
</option>
</select>
</div>
<input class="button button-large" type="submit" value="Update"/>
<?php wp_nonce_field( 'wiaas_update_cl_customer_order_type', 'wiaas_update_cl_customer_order_type_nonce' ); ?>
</form>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -9,6 +9,10 @@ class Wiaas_Admin_CL {
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';
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';

View File

@@ -14,8 +14,14 @@ class Wiaas_Admin_Organization {
add_filter('get_role_list', array(__CLASS__, 'get_role_list_for_user'), 10, 2);
// hide woocommerce meta fields form customer user profile
add_filter('woocommerce_customer_meta_fields', array(__CLASS__, 'hide_woocommerce_customer_fields'));
// save related customers when organization form data has been saved by acf
add_action('acf/save_post', array(__CLASS__, 'maybe_save_related_customers'), 1);
// load related customers for organization form
add_filter('acf/load_value/name=_wiaas_organization_customers', array(__CLASS__, 'load_related_customer_organizations'), 10, 3);
}
public static function hide_woocommerce_customer_fields() {
@@ -26,6 +32,49 @@ class Wiaas_Admin_Organization {
return array();
}
/**
* Saves related customers if organization new/edit form has been submited
* Customer ids are collected from posted data of linked customers acf field and saved
*
* @param string $id in format `term_{$organization_id}`
*/
public static function maybe_save_related_customers($id) {
if ($_POST['taxonomy'] === Wiaas_User_Organization::TAXONOMY_NAME && ! empty($_POST['acf'])) {
$field = get_field_object('_wiaas_organization_customers', $id);
//get organization id
$id = absint(str_replace('term_', '', $id));
$customer_organization_ids = $_POST['acf'][$field['key']];
$customer_organization_ids = is_array($customer_organization_ids) ?
wp_parse_id_list($customer_organization_ids) :
array();
Wiaas_Shop::set_shop_customers($id, $customer_organization_ids);
}
}
/**
* Loads related customers for linked customers acf field on organization edit form
*
* @param array $value
* @param string $id in format `term_{$organization_id}`
* @param array $field acf field details
*
* @return array
*/
public static function load_related_customer_organizations($value, $id, $field) {
//get organization id
$id = absint(str_replace('term_', '', $id));
$customers = wp_list_pluck(
Wiaas_Shop_Data_Store::get_shop_customers($id),
'customer_id');
return $customers;
}
/**
* Render user organization roles as available user roles on user list
* @param $role_list

View File

@@ -31,12 +31,20 @@ class Wiaas_Cart_API {
'package_id' => array(
'description' => __( 'Wiaas package ID.', 'wiaas' ),
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
),
'cl_id' => array(
'description' => __( 'Commercial lead ID.', 'wiaas' ),
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
),
'price_id' => array(
'description' => __( 'Selected price ID for Wiaas package.', 'wiaas' ),
'type' => 'string',
'enum' => array_keys(Wiaas_Package_Pricing::get_available_pay_types()),
'required' => true,
'sanitize_callback' => 'sanitize_key',
),
'options_ids' => array(
@@ -225,6 +233,7 @@ class Wiaas_Cart_API {
$success = Wiaas_Cart::add_package_to_cart(
$request['package_id'],
$request['price_id'],
$request['cl_id'],
$request['addons_ids'],
$request['options_ids']
);

View File

@@ -2,34 +2,32 @@
class Wiaas_Package_API {
private static $namespace = 'wiaas';
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() {
// TODO: Handle this when assigment of customer to commercial lead is done
register_rest_route( self::$namespace, '/commercial-leads', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(__CLASS__, 'get_customer_commercial_leads'),
'permission_callback' => 'is_user_logged_in'
) );
// do nothing
}
// TODO: Handle this when assigment of customer to commercial lead is done
public static function get_customer_commercial_leads() {
$commercial_leads = array();
public static function validate_package_search_request($null, $request, $route, $handler) {
foreach (wiaas_get_commercial_leads() as $id => $name) {
$commercial_leads[] = array(
'id' => $id,
'name' => $name
);
}
if (strpos($route, '/wc/v2/products') !== false) {
return rest_ensure_response($commercial_leads);
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;
}
/**

View File

@@ -1,5 +1,12 @@
<?php
/**
* TODO: Refactor this class so it reflects the fact that customer is an organization
* TODO: Format should be `customer/(?P<organization_id>\d+)/user/(?P<id>\d+)
*
* Class Wiaas_REST_Customer_API
*/
class Wiaas_REST_Customer_API {
/**
* Endpoint namespace.
@@ -9,13 +16,19 @@ class Wiaas_REST_Customer_API {
private static $namespace = 'wiaas';
public function __construct() {
include_once dirname( __FILE__ ) . '/../user/class-wiaas-customer.php';
include_once dirname( __FILE__ ) . '/helper/class-rest-helper-functions.php';
}
public static function register_routes() {
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/shops', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_customer_shops'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses', array(
'methods' => 'PUT',
'callback' => array(__CLASS__, 'update_customer_profile_addresses'),
@@ -54,6 +67,23 @@ class Wiaas_REST_Customer_API {
}
public static function get_customer_shops() {
$customer_id = wiaas_get_current_user_organization_id();
$customer_shops = Wiaas_Shop_Data_Store::get_customer_shops($customer_id);
$customer_shops = array_map(function($customer_shop) {
return array(
'id' => $customer_shop['owner_id'],
'type' => $customer_shop['order_type'],
'name' => wiaas_get_organization_name($customer_shop['owner_id'])
);
}, $customer_shops);
return rest_ensure_response($customer_shops);
}
public static function update_customer_profile_addresses(WP_REST_Request $request){

View File

@@ -114,12 +114,13 @@ class Wiaas_Cart {
*
* @param int $package_id Package ID of selected package
* @param string $price_id Price ID of selected package payment
* @param int $commercial_lead_id Shop owner commercial lead ID
* @param array $addons_ids Array of selected additional 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
*/
public static function add_package_to_cart($package_id, $price_id, $addons_ids, $options_ids) {
public static function add_package_to_cart($package_id, $price_id, $commercial_lead_id, $addons_ids, $options_ids) {
// try adding package to cart
try {
// Check if package is in cart
@@ -144,12 +145,11 @@ class Wiaas_Cart {
// Retrieve package country
$country = Wiaas_Countries::get_package_country($package);
// TODO: Change this so commercial lead is sent via request
$customer_id = wiaas_get_current_user_organization_id();
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
// Retrieve package price
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
// Initialize additional cart item data for wiaas packages
@@ -159,6 +159,7 @@ class Wiaas_Cart {
'_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_commercial_lead_id' => $commercial_lead_id,
'_wiaas_documents' => array()
);
@@ -170,7 +171,7 @@ class Wiaas_Cart {
}
// Add selected additional packages and options
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $addons_ids, $options_ids);
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $commercial_lead_id, $addons_ids, $options_ids);
// Trigger calculation of total prices after additional packages are added
WC()->cart->calculate_totals();
@@ -302,6 +303,9 @@ class Wiaas_Cart {
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
if (isset($cart_item['_wiaas_option_items'])) {
@@ -380,7 +384,8 @@ class Wiaas_Cart {
'_wiaas_option_group_name',
'_wiaas_standard_package',
'_wiaas_currency',
'_wiaas_documents'
'_wiaas_documents',
'_wiaas_commercial_lead_id'
) );
}
@@ -636,21 +641,20 @@ class Wiaas_Cart {
*
* @param string $package_cart_item_key
* @param int $price_id
* @param int $commercial_lead_id
* @param array $addons_ids
* @param array $options_ids
*
* @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, $addons_ids, $options_ids) {
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $commercial_lead_id, $addons_ids, $options_ids) {
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
$addon_items_keys = array();
$option_items_keys = array();
// TODO: Change this so commercial lead is sent via request
$customer_id = wiaas_get_current_user_organization_id();
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
// Try adding package addons to cart
foreach ($addons_ids as $addon_id) {

View File

@@ -85,12 +85,15 @@ class Wiaas_Checkout {
private static function _add_wiaas_checkout_data($order, $data) {
// save 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;
}
}
$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
Wiaas_Order::set_order_vat($order->get_id(), $data['vat']);
@@ -102,6 +105,7 @@ class Wiaas_Checkout {
if (isset($data['project_id'])) {
Wiaas_Order_Project::set_project_for_order($order->get_id(), $data['project_id']);
}
}
}

View File

@@ -0,0 +1,11 @@
<?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();

View File

@@ -17,7 +17,8 @@ class Wiaas_DB_Update {
'201810101644700' => 'wiaas_db_import_aam_role_settings',
'201810111644700' => 'wiaas_db_update_add_organization_info_ui_fields',
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
'201810161644700' => 'wiaas_db_update_update_commercial_lead_capabilities'
'201810171644700' => 'wiaas_db_setup_create_customer_commercial_lead_table',
'201810171744702' => 'wiaas_db_update_update_commercial_lead_capabilities',
);
public static function execute() {

View File

@@ -45,8 +45,11 @@ class Wiaas_Order {
* @param $order_id
*/
public static function assign_order_to_organization($order_id) {
$user = wp_get_current_user();
Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID);
$customer_id = wiaas_get_current_user_organization_id();
$commercial_lead_id =
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
}
/**

View File

@@ -93,9 +93,8 @@ class Wiaas_Package {
* @return array
*/
private static function _append_additional_packages($data, $package, $request) {
// TODO: Change this so commercial lead is sent via request
$customer_id = wiaas_get_current_user_organization_id();
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
$commercial_lead_id = absint($request['cl_id']);
$data['additional_packages'] = array();
$addons = Wiaas_Package_Addon::get_package_addons($package);
@@ -142,9 +141,8 @@ class Wiaas_Package {
* @return array
*/
private static function _append_package_prices($data, $package, $request) {
// TODO: Change this so commercial lead is sent via request
$customer_id = wiaas_get_current_user_organization_id();
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
$commercial_lead_id = absint($request['cl_id']);
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);

View File

@@ -10,6 +10,75 @@ class Wiaas_Shop {
// 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);
// create new shop if organization was assigned commercial lead role
// or remove shop if commercial lead role was removed for organization
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'maybe_manage_shop_for_commercial_lead'), 10, 2);
}
/**
* Link customers to shop (this will enable them to search and order packages from this shop)
*
* @param int $owner_id
* @param array $customer_ids
*/
public static function set_shop_customers($owner_id, $customer_ids) {
$current_customer_ids = wp_list_pluck(
Wiaas_Shop_Data_Store::get_shop_customers($owner_id),
'customer_id');
// delete removed customers
$removed_customer_ids = array_diff($current_customer_ids, $customer_ids);
Wiaas_Shop_Data_Store::remove_shop_customers($owner_id, $removed_customer_ids);
// save added customers
$added_customer_ids = array_diff($customer_ids, $current_customer_ids);
Wiaas_Shop_Data_Store::add_shop_customers($owner_id, $added_customer_ids);
}
/**
* Retrieve default order type for shop
*
* @param int $owner_id
*
* @return string
*/
public static function get_default_order_type($owner_id) {
$order_type = get_term_meta(
$owner_id,
'_wiaas_shop_default_order_type',
true);
return empty($order_type) ? 'commercial_lead' : $order_type;
}
/**
* Update default order type for shop
*
* @param int $owner_id
* @param string $order_type
*/
public static function update_default_order_type($owner_id, $order_type) {
if (in_array($order_type, array('commercial_lead', 'reseller'))) {
update_term_meta($owner_id, '_wiaas_shop_default_order_type', $order_type);
}
}
/**
* Creates shop for new shop owner (organization with commercial lead role) or
* deletes existing shop if that role has been removed
*
* @param int $owner_id
* @param array $roles
*/
public static function maybe_manage_shop_for_commercial_lead($owner_id, $roles) {
$is_commercial_lead = in_array('commercial_lead', $roles);
$is_commercial_lead ?
self::_maybe_create_shop($owner_id) :
self::_maybe_remove_shop($owner_id);
}
/**
@@ -21,12 +90,12 @@ class Wiaas_Shop {
'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',
),
// '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 );
@@ -68,7 +137,37 @@ class Wiaas_Shop {
$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');
wp_add_object_terms($package_id, $new_terms_names, '_wiaas_shop_prices');
}
// PRIVATE
private static function _maybe_create_shop($owner_id) {
$shop_name = 'wiaas_shop_' . $owner_id;
$attribute_id = wc_attribute_taxonomy_id_by_name($shop_name);
if ($attribute_id === 0) {
// create shop attribute
wc_create_attribute(array( 'slug' => $shop_name, 'name' => 'Catalogue' ));
$taxonomy_name = wc_attribute_taxonomy_name($shop_name);
register_taxonomy($taxonomy_name, array('product'));
// add default catalogue option to shop attribute
wp_insert_term( 'Default', $taxonomy_name);
}
}
private static function _maybe_remove_shop($owner_id) {
// get corresponding attribute for shop
$attribute_id = wc_attribute_taxonomy_id_by_name('wiaas_shop_' . $owner_id);
// if shop attribute exists then remove it
if ($attribute_id > 0) {
wc_delete_attribute($attribute_id);
}
}
}

View File

@@ -0,0 +1,157 @@
<?php
class Wiaas_Shop_Data_Store {
/**
* Inserts new customer for shop
*
* @param int $owner_id
* @param array $customer_ids
*/
public static function add_shop_customers($owner_id, $customer_ids) {
global $wpdb;
foreach ($customer_ids as $customer_id) {
$wpdb->insert( $wpdb->prefix . 'wiaas_shop_customer_relationships',
array(
'customer_id' => $customer_id,
'shop_owner_id' => $owner_id,
'order_type' => Wiaas_Shop::get_default_order_type($owner_id)
),
array( '%d', '%d', '%s')
);
}
}
/**
* Updates order type for customer in shop
*
* @param int $owner_id
* @param int $customer_id
* @param string $order_type
*
* @return bool|WP_Error
*/
public static function update_shop_customer_order_type($owner_id, $customer_id, $order_type) {
global $wpdb;
$results = $wpdb->update(
$wpdb->prefix . 'wiaas_shop_customer_relationships',
array( 'order_type' => $order_type ),
array(
'customer_id' => $customer_id,
'shop_owner_id' => $owner_id,
),
array( '%s' ),
array( '%d', '%d' )
);
if (false === $results) {
return new WP_Error('cannot_update_order_type', __( 'Could not update order type.', 'wiaas' ), array( 'status' => 400 ));
}
return true;
}
/**
* Removes customer from shop
*
* @param int $owner_id
* @param array $customer_ids
*/
public static function remove_shop_customers($owner_id, $customer_ids) {
if (empty($customer_ids)) {
return;
}
global $wpdb;
$customer_ids = array_map('absint', $customer_ids);
$customer_ids = implode(',', $customer_ids);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->prefix}wiaas_shop_customer_relationships
WHERE shop_owner_id = %d AND customer_id IN (%s)",
$owner_id,
$customer_ids )
);
}
/**
* Retrieves array of customers assigned to shop
*
* @param int $owner_id
*
* @return array {
* @type int customer_id
* @type string order_typr
* }
*/
public static function get_shop_customers($owner_id) {
if ($owner_id === 0) {
return array();
}
global $wpdb;
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT customer_id, order_type
FROM {$wpdb->prefix}wiaas_shop_customer_relationships
WHERE shop_owner_id = %d",
$owner_id )
);
if ( empty( $results ) ) {
return array();
}
$customers = array_map(function($result_row) {
return array(
'customer_id' => $result_row->customer_id,
'order_type' => $result_row->order_type
);
}, $results);
return $customers;
}
/**
* Retrieves array of shops that are assigned to customer
*
* @param int $customer_id
*
* @return array {
* @type int owner_id
* @type string order_type
* }
*/
public static function get_customer_shops($customer_id) {
global $wpdb;
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT customer_id, shop_owner_id, order_type
FROM {$wpdb->prefix}wiaas_shop_customer_relationships
WHERE customer_id = %d",
$customer_id )
);
if (empty($results)) {
return array();
}
$shops = array_map(function($result_row) {
return array(
'owner_id' => $result_row->shop_owner_id,
'order_type' => $result_row->order_type
);
}, $results);
return $shops;
}
}

View File

@@ -125,4 +125,24 @@ function wiaas_db_setup_customer_capabilities() {
$customer_role->add_cap('list_users');
$customer_role->add_cap('edit_users');
}
function wiaas_db_setup_create_customer_commercial_lead_table() {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$sql = "
CREATE TABLE {$wpdb->prefix}wiaas_shop_customer_relationships (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`customer_id` bigint(20) unsigned NOT NULL,
`shop_owner_id` bigint(20) unsigned NOT NULL,
`order_type` varchar(44) NOT NULL default '',
PRIMARY KEY (`ID`),
KEY `relationship` (`customer_id`, `shop_owner_id`),
KEY `order_type` (`order_type`)
) COLLATE {$wpdb->collate};
";
dbDelta( $sql );
}

View File

@@ -141,4 +141,6 @@ 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
wp_roles()->add_cap( 'commercial_lead', 'view_admin_dashboard' ); // cl products screen
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_customers' ); // cl products screen
}

View File

@@ -13,14 +13,17 @@ class Wiaas_Customer {
public static function get_customer_info($customer_id){
$user = get_userdata($customer_id);
$organization_id = wiaas_get_user_organization_id($customer_id);
$result = array(
'id' => $customer_id,
'company_id' => self::get_customer_company_id($customer_id),
'company_id' => $organization_id,
'is_company_admin' => self::get_customer_company_admin_status($customer_id),
'mail' => $user->user_email,
'name' => $user->first_name . ' ' . $user->last_name,
'phone' => self::get_customer_phone_number($customer_id),
'company_name' => self::get_customer_company_name($customer_id),
'company_name' => wiaas_get_organization_name($organization_id),
'vat_code' => self::get_customer_vat_code($customer_id),
'billing_addresses' => self::get_customer_billing_addresses($customer_id),
'profile_addresses' => self::get_customer_profile_addresses($customer_id),
@@ -80,10 +83,6 @@ class Wiaas_Customer {
return get_user_meta($customer_id, 'company_name', true) ?: '';
}
public static function get_customer_company_id($customer_id){
return 0; //TODO: don't hardocde this
}
public static function get_customer_company_admin_status($customer_id){
return 1; //TODO: don't hardcode this
}

View File

@@ -36,6 +36,10 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
add_action( 'created_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_added' ));
add_action( 'pre_delete_term', array( __CLASS__, 'on_taxonomy_term_will_be_deleted' ), 10, 2);
add_action( 'delete_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_deleted' ));
add_action('acf/save_post', array(__CLASS__, 'on_organization_roles_maybe_updated'));
add_action('set_object_terms', array( __CLASS__, 'on_taxonomy_term_assigned' ), 10, 4);
add_action('deleted_term_relationships', array( __CLASS__, 'on_taxonomy_term_unassigned' ), 10, 3);
@@ -61,6 +65,8 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
*/
public static function on_organization_added($organization_id) {
self::_create_organization_access_group($organization_id);
do_action('wiaas_organization_created', $organization_id);
}
/**
@@ -73,9 +79,37 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
if ($taxonomy === self::TAXONOMY_NAME) {
$organization_id = $term_id;
self::_remove_organization_access_group($organization_id);
do_action('wiaas_organization_will_be_deleted', $organization_id);
}
}
/**
* Removes corresponding acces group when organization term is deleted
*
* @param $organization_id id of the organization term
*/
public static function on_organization_deleted($organization_id) {
do_action('wiaas_organization_deleted', $organization_id);
}
/**
* @param string $id acf object id for which data has been updated,
* for organization it will be in format `term_{$organization_id}`
*/
public static function on_organization_roles_maybe_updated($id) {
if ($_POST['taxonomy'] === self::TAXONOMY_NAME) {
$roles = get_field('_wiaas_organization_roles', $id);
//get organization id
$id = absint(str_replace('term_', '', $id));
do_action('wiaas_organization_roles_updated', $id, $roles);
}
}
/**
* Adds user to corresponding access groups when he is assigned to organization.
* User will also be added to child organizations access groups.
@@ -132,10 +166,9 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
* to access order.
*
* @param $post_id - custom post id (product, order, ...)
* @param $user_id
* @param $organization_id
*/
public static function assign_post_to_user_organization($post_id, $user_id) {
$organization_id = self::get_user_organization_id($user_id);
public static function assign_post_to_organization($post_id, $organization_id) {
self::_assign_post_to_organization($post_id, $organization_id);
}

View File

@@ -28,6 +28,7 @@ if (is_admin()) {
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-delivery-process.php';

View File

@@ -42,7 +42,7 @@ export const fetchPackageDetails = (params) => {
return dispatch => {
dispatch(requestPackageDetails());
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/products/${params.idPackage}`,
url: `${API_SERVER}/wp-json/wc/v2/products/${params.idPackage}?cl_id=${params.shopId}`,
method: 'get'
})
.then(response => {
@@ -127,7 +127,8 @@ export const addToCart = (addParams) => {
'package_id': addParams.selectedPackage.id,
'price_id': addParams.selectedAgreement.idPrice,
'addons_ids': result.additionalPackages,
'options_ids': result.optionPackages
'options_ids': result.optionPackages,
'cl_id': addParams.shopId,
},
})
.then(response => {

View File

@@ -5,9 +5,9 @@ import HtmlClient from '../../helpers/HtmlClient';
import {
REQUEST_SHOP_PACKAGES,
RECIEVE_SHOP_PACKAGES,
REQUEST_SHOP_COMMERCIAL_LEADS,
RECIEVE_SHOP_COMMERCIAL_LEADS,
SELECT_SHOP_COMMERCIAL_LEAD
REQUEST_SHOPS,
RECEIVE_SHOPS,
SELECT_SHOP
} from '../../constants/coMarketConstants';
import { fromWCPackage } from '../../helpers/PackageHelper';
@@ -23,13 +23,13 @@ const recieveShopPackages = (json) => ({
shopPackages: json
});
export const fetchShopPackages = (cl, search) => {
export const fetchShopPackages = (shop, search) => {
return dispatch => {
dispatch(requestShopPackages());
let searchParam = search ? '?search=' +search : ''
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${cl.idCommercialLead}` + searchParam,
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${shop.id}` + searchParam,
})
.then(response => {
if (response.data) {
@@ -42,41 +42,38 @@ export const fetchShopPackages = (cl, search) => {
}
}
const requestShopCommercialLeads = () => ({
type: REQUEST_SHOP_COMMERCIAL_LEADS
const requestShops = () => ({
type: REQUEST_SHOPS
});
const recieveShopCommercialLeads = (json) => ({
type: RECIEVE_SHOP_COMMERCIAL_LEADS,
commercialLeads: json
const receiveShops = (json) => ({
type: RECEIVE_SHOPS,
shops: json
});
const generateClOptions = (commercialLeads) => {
commercialLeads.forEach((cl) => {
cl.value = cl.idCommercialLead;
cl.label = cl.commercialLeadName;
const generateShopOptions = (shops) => {
shops.forEach((shop) => {
shop.value = shop.id;
shop.label = shop.name;
});
return commercialLeads;
return shops;
}
export const fetchShopCommercialLeads = () => {
export const fetchShops = () => {
return dispatch => {
dispatch(requestShopCommercialLeads());
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/commercial-leads` })
dispatch(requestShops());
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/customer/0/shops` })
.then(response => {
if(response.data){
const clOptions = generateClOptions(response.data.map(cl => ({
idCommercialLead: cl.id,
commercialLeadName: cl.name
})));
const shopOptions = generateShopOptions(response.data);
dispatch(recieveShopCommercialLeads(clOptions));
dispatch(receiveShops(shopOptions));
if (clOptions.length) {
dispatch(selectCommercialLead(clOptions[0]));
dispatch(fetchShopPackages(clOptions[0]));
if (shopOptions.length) {
dispatch(selectShop(shopOptions[0]));
dispatch(fetchShopPackages(shopOptions[0]));
}
}
})
@@ -86,7 +83,7 @@ export const fetchShopCommercialLeads = () => {
}
}
export const selectCommercialLead = (cl) => ({
type: SELECT_SHOP_COMMERCIAL_LEAD,
selectedCommercialLead: cl
export const selectShop = (shopInfo) => ({
type: SELECT_SHOP,
selectedShop: shopInfo
});

View File

@@ -16,7 +16,7 @@ export const MainContainers = {
},
CoMarket: {
container: CoMarketContainer,
params: ['idCommercialLead', 'idPackage']
params: ['shopId', 'idPackage']
},
Cart: {
container: CartContainer,

View File

@@ -2,9 +2,9 @@ const MODULE = 'CO_MARKET_';
export const REQUEST_SHOP_PACKAGES = MODULE + 'REQUEST_SHOP_PACKAGES';
export const RECIEVE_SHOP_PACKAGES = MODULE + 'RECIEVE_SHOP_PACKAGES';
export const REQUEST_SHOP_COMMERCIAL_LEADS = MODULE + 'REQUEST_SHOP_COMMERCIAL_LEADS';
export const RECIEVE_SHOP_COMMERCIAL_LEADS = MODULE + 'RECIEVE_SHOP_COMMERCIAL_LEADS';
export const SELECT_SHOP_COMMERCIAL_LEAD = MODULE + 'SELECT_SHOP_COMMERCIAL_LEAD';
export const REQUEST_SHOPS = MODULE + 'REQUEST_SHOPS';
export const RECEIVE_SHOPS = MODULE + 'RECEIVE_SHOPS';
export const SELECT_SHOP = MODULE + 'SELECT_SHOP';
export const REQUEST_PACKAGE_DETAILS = MODULE + 'REQUEST_PACKAGE_DETAILS';
export const RECIEVE_PACKAGE_DETAILS = MODULE + 'RECIEVE_PACKAGE_DETAILS';

View File

@@ -1,5 +1,4 @@
import React, {Component} from 'react';
import {cartTexts} from '../../../constants/cartConstants';
class CartIcon extends Component {
render() {

View File

@@ -1,10 +1,9 @@
@import '../../../styleConstants.scss';
#cart-count {
vertical-align: middle;
vertical-align: sub;
color: $accentColor;
font-size: 1.5rem;
border-radius: 1rem;
font-size: 1.6rem;
font-family: arial,sans-serif;
}

View File

@@ -17,7 +17,7 @@ class CoMarketContainer extends Component {
return (<Container fluid={true} id="co-market-container">
{
urlParams.idPackage ?
<CoMarketPackageDetailsContainer idPackage={urlParams.idPackage} idCommercialLead={urlParams.idCommercialLead}/> :
<CoMarketPackageDetailsContainer idPackage={urlParams.idPackage} shopId={urlParams.shopId}/> :
<CoMarketPackagesContainer/>
}
</Container>);

View File

@@ -16,8 +16,8 @@ class CoMarketNavContainer extends Component {
handleSearchChange(event) {
this.setState({searchValue: event.target.value});
if (this.props.selectedCommercialLead) {
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
if (this.props.selectedShop) {
this.props.dispatch(fetchShopPackages(this.props.selectedShop, event.target.value));
}
}
@@ -42,7 +42,7 @@ class CoMarketNavContainer extends Component {
}
const mapStateToProps = (state) => ({
selectedCommercialLead: state.coMarketPackagesReducer.selectedCommercialLead
selectedShop: state.coMarketPackagesReducer.selectedShop
});
export default connect(mapStateToProps)(CoMarketNavContainer);

View File

@@ -26,14 +26,15 @@ class CoMarketPackageDetailsContainer extends Component {
selectedPackage: this.props.selectedPackage,
selectedAgreement: this.props.selectedAgreement,
selectedOptions: this.props.selectedOptions,
selectedAdditionals: this.props.selectedAdditionals
selectedAdditionals: this.props.selectedAdditionals,
shopId: this.props.shopId,
};
this.props.dispatch(addToCart(addParams));
}
componentDidMount() {
const {idPackage, idCommercialLead} = this.props;
this.props.dispatch(fetchPackageDetails({idPackage, idCommercialLead}));
const {idPackage, shopId} = this.props;
this.props.dispatch(fetchPackageDetails({idPackage, shopId}));
}
render() {

View File

@@ -1,6 +1,10 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {Row, Col} from 'reactstrap';
import {
Navbar,
Row,
Col
} from 'reactstrap';
import ShopItem from './components/ShopItem.jsx';
import WiaasBox from '../../mainComponents/box/WiaasBox.jsx';
import CoMarketNavContainer from './CoMarketNavContainer.jsx';
@@ -8,16 +12,19 @@ import {fetchShopPackages} from '../../actions/coMarket/coMarketPackagesActions'
class CoMarketPackagesContainer extends Component {
componentDidMount() {
if (this.props.selectedCommercialLead) {
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead));
if (this.props.selectedShop) {
this.props.dispatch(fetchShopPackages(this.props.selectedShop));
}
}
render() {
const {shopPackages, selectedCommercialLead, isLoading} = this.props;
const {shopPackages, selectedShop, isLoading} = this.props;
return (
<div id="co-market-shop">
<Col>
<Navbar></Navbar>
</Col>
<Row>
<Col xl="8" lg="8" md="8" sm="12" xs="12">
<WiaasBox id="co-market-big-commercial">
@@ -43,7 +50,7 @@ class CoMarketPackagesContainer extends Component {
{
(shopPackages && !isLoading) &&
shopPackages.map((shopPackage, mapKey) => <ShopItem key={shopPackage.id}
idCommercialLead={selectedCommercialLead.value}
shopId={selectedShop.id}
shopPackage={shopPackage}/>)
}
</Row>
@@ -57,7 +64,7 @@ class CoMarketPackagesContainer extends Component {
const mapStateToProps = (state) => ({
shopPackages: state.coMarketPackagesReducer.shopPackages,
selectedCommercialLead: state.coMarketPackagesReducer.selectedCommercialLead,
selectedShop: state.coMarketPackagesReducer.selectedShop,
isLoading: state.coMarketPackagesReducer.isLoading
});

View File

@@ -1,14 +1,14 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import Select from 'react-select';
import {fetchShopPackages, fetchShopCommercialLeads, selectCommercialLead} from '../../../actions/coMarket/coMarketPackagesActions';
import {fetchShopPackages, fetchShops, selectShop} from '../../../actions/coMarket/coMarketPackagesActions';
import {coMarketTexts} from '../../../constants/coMarketConstants';
class CoMarketCatalogSelect extends Component {
constructor(props) {
super(props);
this.handleClChange = this.handleClChange.bind(this);
this.handleShopChange = this.handleShopChange.bind(this);
this.handleSearchChange = this.handleSearchChange.bind(this);
this.state = {
searchValue : ''
@@ -16,56 +16,57 @@ class CoMarketCatalogSelect extends Component {
}
componentDidMount() {
this.props.dispatch(fetchShopCommercialLeads());
this.props.dispatch(fetchShops());
if(this.props.commercialLeads && this.props.cartItems && this.props.activeModule==='cart'){
const cl = this.props.commercialLeads.find((cl) => {return cl.idCommercialLead===this.props.cartItems[0].idCommercialLead});
this.props.dispatch(selectCommercialLead(cl));
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 });
this.props.dispatch(selectShop(cartShop));
}
}
componentWillReceiveProps(nextProps){
if(nextProps.activeModule==='cart' && nextProps.commercialLeads && nextProps.cartItems && nextProps.cartItems.length > 0){
const cl = nextProps.commercialLeads.find((cl) => {return cl.idCommercialLead===nextProps.cartItems[0].idCommercialLead});
nextProps.dispatch(selectCommercialLead(cl));
}
// if(nextProps.activeModule==='cart' && nextProps.shops && nextProps.cartItems && nextProps.cartItems.length > 0){
// const cartShop = this.props.shops.find( shop => { return shop.id === this.props.cartItems[0].idCommercialLead });
// nextProps.dispatch(selectShop(cartShop));
// }
if(nextProps.commercialLeads && nextProps.idCommercialLead && nextProps.activeModule === 'co-market'){
const cl = nextProps.commercialLeads.find((cl) => {return cl.idCommercialLead===nextProps.idCommercialLead});
nextProps.dispatch(selectCommercialLead(cl));
if(nextProps.shops && nextProps.idCommercialLead && nextProps.activeModule === 'co-market'){
const shop = nextProps.shops.find( shop => {return shop.id === nextProps.idCommercialLead });
nextProps.dispatch(selectShop(shop));
}
}
handleClChange(cl) {
this.props.dispatch(selectCommercialLead(cl));
this.props.dispatch(fetchShopPackages(cl));
handleShopChange(shop) {
this.props.dispatch(selectShop(shop));
this.props.dispatch(fetchShopPackages(shop));
}
handleSearchChange(event) {
this.setState({searchValue: event.target.value});
if (this.props.selectedCommercialLead) {
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
if (this.props.selectedShop) {
this.props.dispatch(fetchShopPackages(this.props.selectedShop, event.target.value));
}
}
render() {
const {commercialLeads, selectedCommercialLead, idPackage, activeSubmodule} = this.props;
const {shops, selectedShop, idPackage, activeSubmodule} = this.props;
const isDisabled = (idPackage || this.props.activeModule === 'cart') ? true : false;
return (
<div id="co-market-catalog">
{
commercialLeads && activeSubmodule !== 'orders' &&
shops && activeSubmodule !== 'orders' &&
<div className="filters co-market-nav-div">
<div className="filter-name">{coMarketTexts.labels.CATALOGUE}:</div>
<Select value={selectedCommercialLead}
<Select value={selectedShop}
name="commercialLead"
className="filter-select"
placeholder={coMarketTexts.labels.SELECT_CL}
options={commercialLeads}
options={shops}
disabled={isDisabled}
clearable={false}
onChange={(cl) => {this.handleClChange(cl)}}
onChange={shop => {this.handleShopChange(shop)}}
/>
</div>
}
@@ -75,8 +76,8 @@ class CoMarketCatalogSelect extends Component {
}
const mapStateToProps = (state) => ({
commercialLeads: state.coMarketPackagesReducer.commercialLeads,
selectedCommercialLead: state.coMarketPackagesReducer.selectedCommercialLead,
shops: state.coMarketPackagesReducer.shops,
selectedShop: state.coMarketPackagesReducer.selectedShop,
idPackage: state.coMarketReducer.idPackage,
cartItems: state.cartReducer.cartItems,
activeSubmodule: state.pageReducer.activeSubmodule

View File

@@ -9,7 +9,7 @@ class ShopItem extends Component {
}
render() {
const {shopPackage, idCommercialLead} = this.props;
const {shopPackage, shopId} = this.props;
return (
@@ -21,7 +21,7 @@ class ShopItem extends Component {
alt="Card image cap"/>
<CardBody>
<CardTitle className="shop-package-title">
<Link to={`/co-market/${idCommercialLead}/${shopPackage.id}`}>
<Link to={`/co-market/${shopId}/${shopPackage.id}`}>
{this.getShopItemPackageTitle(shopPackage.name)}
</Link>
</CardTitle>
@@ -34,7 +34,7 @@ class ShopItem extends Component {
<span className={'flag-icon flag-icon-' + shopPackage.countryCode}></span>
</div>
<div className="shop-package-details-btn-layer">
<Link id={'shop-package-details-' + shopPackage.id} to={`/co-market/${idCommercialLead}/${shopPackage.id}`}>
<Link id={'shop-package-details-' + shopPackage.id} to={`/co-market/${shopId}/${shopPackage.id}`}>
<Button className="shop-package-details-btn">{coMarketTexts.buttons.DETAILS}</Button>
</Link>
</div>

View File

@@ -84,9 +84,8 @@ class Menu extends Component {
)
}
</Nav>
<div className="wiaas-divider nav-btn-cart-divider"></div>
<Nav className="nav-btn-cart navbar-right" navbar>
<NavItem id="nav-button-cart">
<NavItem id="nav-button-cart" className="navbar-button">
<NavLink tag={Link} to="/cart">
<CartIcon cartCount={this.props.cartCount} />
<span className="fa fa-shopping-cart cart-icon"></span>

View File

@@ -64,25 +64,21 @@
}
.cart-icon {
font-size: 1.6rem;
font-size: 1.2rem;
vertical-align: middle;
}
.cart-label {
margin-left: 0.5rem;
margin-left: 0.2rem;
font-size: 0.8rem;
vertical-align: sub;
}
.items-cart-count {
margin-right: 0.5rem;
margin-right: 0.2rem;
padding-left: 0.5rem;
}
.nav-btn-cart-divider {
height: 2.4rem !important;
}
.navbar-collapse {
min-width: 100%;
}
@@ -104,6 +100,12 @@
cursor: pointer;
}
#nav-profile {
.dropdown-menu .nav-link {
color: #7e7e7e !important;
}
}
@media all and (max-width: 768px) {
.navigation-bar {
min-height: 3.6rem;

View File

@@ -1,7 +1,7 @@
import {
RECIEVE_SHOP_PACKAGES,
RECIEVE_SHOP_COMMERCIAL_LEADS,
SELECT_SHOP_COMMERCIAL_LEAD,
RECEIVE_SHOPS,
SELECT_SHOP,
REQUEST_SHOP_PACKAGES
} from '../../constants/coMarketConstants';
@@ -20,15 +20,15 @@ moduleReducers[RECIEVE_SHOP_PACKAGES] = (state, action) => {
});
};
moduleReducers[RECIEVE_SHOP_COMMERCIAL_LEADS] = (state, action) => {
moduleReducers[RECEIVE_SHOPS] = (state, action) => {
return Object.assign({}, state, {
commercialLeads: action.commercialLeads
shops: action.shops
});
};
moduleReducers[SELECT_SHOP_COMMERCIAL_LEAD] = (state, action) => {
moduleReducers[SELECT_SHOP] = (state, action) => {
return Object.assign({}, state, {
selectedCommercialLead: action.selectedCommercialLead
selectedShop: action.selectedShop
});
};