2021-06-25 14:00:13 +02:00
|
|
|
<?php
|
2022-11-14 22:33:48 +01:00
|
|
|
// use Drupal\Core\Form\FormBuilder;
|
|
|
|
use \Drupal\Core\Link;
|
2021-07-07 11:58:02 +02:00
|
|
|
|
|
|
|
function materio_commerce_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
if ($form_id == 'commerce_checkout_flow_multistep_default') {
|
|
|
|
if ($form["#step_id"] == "review") {
|
|
|
|
$t="t";
|
|
|
|
// $form['buttons']['continue']['#value'] = t('Desired Custom Text Here');
|
|
|
|
$form['actions']['next']['#value'] = t('Place your order');
|
|
|
|
}
|
|
|
|
}
|
2021-08-23 00:46:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function materio_commerce_form_commerce_order_add_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
$currentUser = \Drupal::currentUser();
|
|
|
|
$roles = $currentUser->getRoles();
|
|
|
|
if (in_array("admin", $roles)){
|
|
|
|
$t="t";
|
|
|
|
$form['type']['#default_value'] = 'materio_order_type';
|
|
|
|
$form['type']['#disabled'] = true;
|
|
|
|
|
|
|
|
$form['customer']['uid']['#selection_handler'] = 'default:user_by_email';
|
|
|
|
}
|
2022-11-14 22:33:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
$mail = $form['account']['mail']['#default_value'];
|
|
|
|
$user_storage = \Drupal::entityTypeManager()->getStorage('user');
|
|
|
|
$users = $user_storage->loadByProperties(['mail' => $mail]);
|
|
|
|
$user = reset($users);
|
|
|
|
$roles = $user->getRoles();
|
|
|
|
|
|
|
|
$license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license');
|
|
|
|
$licenses = $license_storage->loadByProperties(['uid' => $user->id()]);
|
|
|
|
|
|
|
|
if ($licenses) {
|
|
|
|
$form['license'] = [
|
|
|
|
"#type" => 'fieldset',
|
|
|
|
"#title" => 'licenses'
|
|
|
|
];
|
|
|
|
foreach ($licenses as $lid => $license) {
|
|
|
|
$product_variation = $license->getPurchasedEntity();
|
|
|
|
$product = $product_variation->getProduct();
|
|
|
|
|
|
|
|
$infos = [];
|
|
|
|
$infos[] = $product->getTitle();
|
|
|
|
$infos[] = $product_variation->getTitle();
|
|
|
|
|
|
|
|
$granted = $license->getGrantedTime();
|
|
|
|
$infos[] = "granted: " . date('d-m-Y', $granted);
|
|
|
|
$expires = $license->getExpiresTime();
|
|
|
|
$infos[] = "expires: " . ($expires === "0" ? 'never' : date('d-m-Y', $expires));
|
|
|
|
|
|
|
|
$license_edit_url = $license->toUrl();
|
|
|
|
$license_link = Link::fromTextAndUrl('edit license', $license_edit_url);
|
|
|
|
$infos[] = $license_link->toString();
|
|
|
|
|
|
|
|
$order = $license->getOriginatingOrder();
|
|
|
|
$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("order " . $order_number . " (" . $order_state . ")", $order_url);
|
|
|
|
$infos[] = $order_link->toString();
|
|
|
|
|
|
|
|
$form['license']['license_'.$lid] = [
|
|
|
|
"#type" => 'item',
|
|
|
|
"#description" => implode(" | ", $infos)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-07 11:58:02 +02:00
|
|
|
}
|