member type automaticly filled on checkout

This commit is contained in:
Bachir Soussi Chiadmi 2021-07-16 20:12:10 +02:00
parent 6cc3844230
commit e79bdeb5e6
8 changed files with 864 additions and 99 deletions

View File

@ -5,7 +5,12 @@ dependencies:
config:
- field.storage.user.field_memo
module:
- unique_content_field_validation
- user
third_party_settings:
unique_content_field_validation:
unique: false
unique_text: ''
id: user.user.field_memo
field_name: field_memo
entity_type: user

View File

@ -23,6 +23,9 @@ settings:
label: Showroom
-
value: 2
label: Multijoueurs
-
value: 3
label: AAF
allowed_values_function: ''
module: options

View File

@ -0,0 +1,20 @@
uuid: 1a7ee738-a8c1-4c68-ba4b-c5eb760e4e3c
langcode: fr
status: true
dependencies: { }
id: user
bundles:
user:
field_memo:
bundle: user
name: field_memo
entity_type_id: user
rtf: 'no'
rta: 'no'
enabled: false
anonymizer: email_anonymizer
notes: ''
relationship: 0
sars_filename: ''
filenames:
user: ''

View File

@ -78,6 +78,7 @@ process:
no_stub: true
source: field_showroom
field_memo: field_memo
field_member_type: member_type
destination:
plugin: 'entity:user'
migration_dependencies:

View File

@ -101,6 +101,7 @@ permissions:
- 'edit any thematique content'
- 'edit field_company'
- 'edit field_member_type'
- 'edit field_memo'
- 'edit field_showroom'
- 'edit own enregistrement content'
- 'edit own flag lists'
@ -203,6 +204,7 @@ permissions:
- 'view evenement revisions'
- 'view field_company'
- 'view field_member_type'
- 'view field_memo'
- 'view field_showroom'
- 'view frontpage revisions'
- 'view materiau revisions'

View File

@ -113,118 +113,38 @@ display:
summary: ''
description: ''
columns:
field_title: field_title
field_name: field_name
field_first_name: field_first_name
field_organization: field_organization
field_position: field_position
field_service: field_service
field_activity_sector: field_activity_sector
field_employee: field_employee
field_address: field_address
field_phone: field_phone
field_email: field_email
field_naf: field_naf
field_siret: field_siret
field_vat_number_intra_ce: field_vat_number_intra_ce
views_bulk_operations_bulk_form: views_bulk_operations_bulk_form
name: name
mail: mail
operations: operations
roles_target_id: roles_target_id
status: status
field_member_type: field_member_type
field_company: field_company
field_showroom: field_showroom
access: access
created: created
field_memo: field_memo
info:
field_title:
views_bulk_operations_bulk_form:
align: ''
separator: ''
empty_column: false
responsive: ''
name:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_name:
sortable: false
default_sort_order: asc
align: ''
separator: '<br/>'
empty_column: false
responsive: ''
field_first_name:
mail:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_organization:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_position:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_service:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_activity_sector:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_employee:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: true
responsive: ''
field_address:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_phone:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_email:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_naf:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_siret:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_vat_number_intra_ce:
sortable: false
default_sort_order: asc
operations:
align: ''
separator: ''
empty_column: false
@ -236,7 +156,21 @@ display:
separator: ''
empty_column: false
responsive: ''
status:
field_member_type:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_company:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
field_showroom:
sortable: false
default_sort_order: asc
align: ''
@ -250,7 +184,21 @@ display:
separator: ''
empty_column: true
responsive: ''
default: access
created:
sortable: true
default_sort_order: desc
align: ''
separator: ''
empty_column: false
responsive: ''
field_memo:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
default: created
empty_table: false
row:
type: fields
@ -1758,6 +1706,706 @@ display:
context: '0'
menu_name: main
display_description: ''
fields:
views_bulk_operations_bulk_form:
id: views_bulk_operations_bulk_form
table: views
field: views_bulk_operations_bulk_form
relationship: none
group_type: group
admin_label: ''
label: 'Views bulk operations'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
batch: true
batch_size: 10
form_step: true
buttons: false
clear_on_exposed: false
action_title: Action
selected_actions:
-
action_id: 'entity:break_lock:user'
preconfiguration:
label_override: ''
-
action_id: user_unblock_user_action
preconfiguration:
label_override: ''
-
action_id: user_block_user_action
preconfiguration:
label_override: ''
-
action_id: user_remove_role_action
preconfiguration:
label_override: ''
-
action_id: user_add_role_action
preconfiguration:
label_override: ''
-
action_id: 'entity:save_action:user'
preconfiguration:
label_override: ''
plugin_id: views_bulk_operations_bulk_form
name:
id: name
table: users_field_data
field: name
relationship: none
group_type: group
admin_label: ''
label: Name
exclude: true
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: false
ellipsis: false
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: user_name
settings:
link_to_entity: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: user
entity_field: name
plugin_id: field
mail:
id: mail
table: users_field_data
field: mail
relationship: none
group_type: group
admin_label: ''
label: Email
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: email_mailto
settings: { }
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: user
entity_field: mail
plugin_id: field
operations:
id: operations
table: users
field: operations
relationship: none
group_type: group
admin_label: ''
label: 'Operations links'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
destination: false
entity_type: user
plugin_id: entity_operations
roles_target_id:
id: roles_target_id
table: user__roles
field: roles_target_id
relationship: none
group_type: group
admin_label: ''
label: Roles
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
type: ul
separator: ', '
entity_type: user
entity_field: roles
plugin_id: user_roles
field_member_type:
id: field_member_type
table: user__field_member_type
field: field_member_type
relationship: none
group_type: group
admin_label: ''
label: 'Member Type'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: list_default
settings: { }
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
field_company:
id: field_company
table: user__field_company
field: field_company
relationship: none
group_type: group
admin_label: ''
label: Company
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: target_id
type: entity_reference_label
settings:
link: true
group_column: target_id
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
field_showroom:
id: field_showroom
table: user__field_showroom
field: field_showroom
relationship: none
group_type: group
admin_label: ''
label: Showroom
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: target_id
type: entity_reference_label
settings:
link: true
group_column: target_id
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
access:
id: access
table: users_field_data
field: access
relationship: none
group_type: group
admin_label: ''
label: 'Last access'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: timestamp
settings:
date_format: html_date
custom_date_format: ''
timezone: ''
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: user
entity_field: access
plugin_id: field
created:
id: created
table: users_field_data
field: created
relationship: none
group_type: group
admin_label: ''
label: Created
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: timestamp
settings:
date_format: html_date
custom_date_format: ''
timezone: ''
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: user
entity_field: created
plugin_id: field
field_memo:
id: field_memo
table: user__field_memo
field: field_memo
relationship: none
group_type: group
admin_label: ''
label: Memo
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: basic_string
settings: { }
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
defaults:
fields: false
cache_metadata:
max-age: 0
contexts:

View File

@ -0,0 +1,5 @@
services:
materio_commerce.order_events_subscriber:
class: Drupal\materio_commerce\EventSubscriber\MaterioCommerceOrderEventsSubscriber
tags:
- { name: 'event_subscriber' }

View File

@ -0,0 +1,81 @@
<?php
// https://docs.drupalcommerce.org/commerce2/developer-guide/orders/workflows/react-to-workflow-transitions
namespace Drupal\materio_commerce\EventSubscriber;
use Drupal\commerce_order\Event\OrderEvent;
use Drupal\commerce_order\Event\OrderEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class EntityTypeSubscriber.
*
* @package Drupal\custom_events\EventSubscriber
*/
class MaterioCommerceOrderEventsSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*
* @return array
* The event names to listen for, and the methods that should be executed.
*/
public static function getSubscribedEvents() {
return [
OrderEvents::ORDER_PAID => 'onOrderPaid'
// OrderEvents::ORDER_CREATE => 'onOrderCreate'
// 'commerce_order.order.paid' => ['onOrderPaid', -100]
];
}
public function onOrderPaid(OrderEvent $event) {
$order = $event->getOrder();
$customer = $order->getCustomer();
foreach ($order->getItems() as $order_item) {
// Skip order items that do not have a license reference field.
// We check order items rather than the purchased entity to allow products
// with licenses to be purchased without the checkout flow triggering
// our synchronization. This is for cases such as recurring orders, where
// the license entity should not be put through the normal workflow.
// Checking the order item's bundle for our entity trait is expensive, as
// it requires loading the bundle entity to call hasTrait() on it.
// For now, just check whether the order item has our trait's field on it.
// @see https://www.drupal.org/node/2894805
if (!$order_item->hasField('license')) {
continue;
}
$purchased_entity = $order_item->getPurchasedEntity();
// This order item isn't "licensable" if the purchased entity it
// references isn't properly configured.
if (!$purchased_entity->hasField('license_type') || $purchased_entity->get('license_type')->isEmpty()) {
continue;
}
$sku = $purchased_entity->getSku();
switch ($sku) {
case 'web-monthly':
case 'web-annual':
$member_type = 0;
break;
case 'web-showroom-monthly':
case 'web-showroom-annual':
$member_type = 1;
break;
}
}
if(isset($member_type)){
$customer->set('field_member_type', $member_type);
$customer->save();
}
// \Drupal::messenger()->addStatus('HAHA Order '.$order->getOrderNumber().' paid: ' . $customer->getEmail());
}
// public function onOrderCreate(OrderEvent $event) {
// $order = $event->getOrder();
// $customer = $order->getCustomer();
// \Drupal::messenger()->addStatus('HAHA Order '.$order->getOrderNumber().' created: ' . $customer->getEmail());
// }
}