user role mgmt : added subscriptions info

This commit is contained in:
Bachir Soussi Chiadmi 2022-11-18 16:14:54 +01:00
parent ac04ae5f5e
commit a88d00f3b9
1 changed files with 35 additions and 6 deletions

View File

@ -97,6 +97,7 @@ function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$
'@num' => $order_number, '@num' => $order_number,
'@state' => $order_state '@state' => $order_state
)), $order_url); )), $order_url);
} }
$description .= t("-- @product: @variation | license state: <b>@license_state</b> | granted: @granted | expires: @expires | @license_link | @order_link<br/>", array( $description .= t("-- @product: @variation | license state: <b>@license_state</b> | granted: @granted | expires: @expires | @license_link | @order_link<br/>", array(
@ -202,23 +203,51 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
$order = $license->getOriginatingOrder(); $order = $license->getOriginatingOrder();
if ($order) { if ($order) {
$order_url = $order->toUrl(); // payments
$order_state = $order->get('state')->first()->getValue()['value']; $payment_storage = \Drupal::entityTypeManager()->getStorage('commerce_payment');
$order_number = $order->get('order_number')->first()->getValue()['value']; $payments = $payment_storage->loadByProperties(['order_id' => $order->id()]);
$order_link = Link::fromTextAndUrl(t("order @num (@state)", array( if (!empty($payments)) {
'@num' => $order_number, $first_payment = array_shift($payments);
'@state' => $order_state $gateway = $first_payment->get('payment_gateway')->first()->getValue()['target_id'];
)), $order_url);
} }
$description .= t("-- @product: @variation | license state: <b>@license_state</b> | granted: @granted | expires: @expires | @license_link | @order_link<br/>", array( // order info and link
$order_url = $order->toUrl();
$order_state = $order->get('state')->first()->getValue()['value'];
// $order_number = $order->get('order_number')->first()->getValue()['value'];
$order_link = Link::fromTextAndUrl(t("order (@gateway @state)", array(
// '@num' => $order_number,
'@state' => $order_state,
'@gateway' => isset($gateway) ? $gateway : ''
)), $order_url);
// susbcriptions
$susbcription_storage = \Drupal::entityTypeManager()->getStorage('commerce_subscription');
$subsriptions = $susbcription_storage->loadByProperties(['initial_order' => $order->id()]);
if (!empty($subsriptions)) {
$first_subscription = array_shift($subsriptions);
$subscription_url = $first_subscription->toUrl();
$subscription_title = $first_subscription->getTitle();
$subscription_state = $first_subscription->get('state')->first()->getValue()['value'];
$subscription_payment_method = $first_subscription->getPaymentMethod();
$subscription_payment_method_label = $subscription_payment_method->label()->render();
$subscription_link = Link::fromTextAndUrl(t("subscription @title @state [@pm_label]", array(
'@title' => $subscription_title,
'@state' => $subscription_state,
'@pm_label' => $subscription_payment_method_label
)), $subscription_url);
}
}
$description .= t("-- @product: @variation | license state: <b>@license_state</b> | granted: @granted | expires: @expires | @license_link | @subscription_link | @order_link<br/>", array(
'@product' => $product ? $product->getTitle() : t('no product'), '@product' => $product ? $product->getTitle() : t('no product'),
'@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'), '@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'),
'@license_state' => $license_state, '@license_state' => $license_state,
'@granted' => date('d-m-Y', $granted), '@granted' => date('d-m-Y', $granted),
'@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires), '@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
'@license_link' => $license_link->toString(), '@license_link' => $license_link->toString(),
'@order_link' => $order ? $order_link->toString() : t('no order') '@subscription_link' => isset($subscription_link) ? $subscription_link->toString() : t('no subscription'),
'@order_link' => isset($order) ? $order_link->toString() : t('no order')
)); ));
} }