-
Notifications
You must be signed in to change notification settings - Fork 2
/
commerce_xquantity.module
77 lines (70 loc) · 2.74 KB
/
commerce_xquantity.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* @file
* Contains commerce_xquantity.module.
*/
use Drupal\commerce_xquantity\Entity\XquantityOrderItem;
use Drupal\commerce_xquantity\Form\XquantityAddTocartForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_entity_type_alter().
*/
function commerce_xquantity_entity_type_alter(array &$entity_types) {
$entity_types['commerce_order_item']->setClass(XquantityOrderItem::class);
$entity_types['commerce_order_item']->setFormClass('add_to_cart', XquantityAddTocartForm::class);
}
/**
* Implements hook_field_widget_info_alter().
*/
function commerce_xquantity_field_widget_info_alter(array &$info) {
$info['xnumber']['class'] = 'Drupal\commerce_xquantity\Plugin\Field\FieldWidget\XquantityWidget';
}
/**
* Implements hook_TYPE_alter().
*
* Allows to alter or remove the 'An Item added to your cart.' message.
*
* @see \Drupal\commerce_xquantity\Form\XquantityAddTocartForm::submitForm()
* @see \Drupal\commerce_cart\EventSubscriber\CartEventSubscriber::displayAddToCartMessage()
*/
function commerce_xquantity_xquantity_added_to_cart_msg_alter(&$msg, XquantityAddTocartForm $form) {
// Alter the message using data from an order, order item or variation.
// $msg = t('Congratulations! @entity added to <a href=":url">your cart</a>.', [
// @entity' => $form->getEntity()->label(),
// ':url' => Drupal\Core\Url::fromRoute('commerce_cart.page')->toString(),
// ]);
// OR, remove the message.
// $msg = NULL;
}
/**
* Implements hook_TYPE_alter().
*
* Allows to alter or remove the quantity price adjustments.
*
* @see \Drupal\commerce_xquantity\Field\FieldWidget\XquantityWidget::formElement()
* @see \Drupal\commerce_xquantity\Plugin\views\field\XquantityEditQuantity::viewsForm()
*/
function commerce_xquantity_xquantity_add_to_cart_qty_prices_alter(&$form_object, $widget, FormStateInterface $form_state) {
// if ($qty_prices = $form_object->quantityPrices) {
// $form_object->quantityPrices = [];
// foreach ($qty_prices as $index => $adjustment) {
// // Change quantity price adjustments.
// $form_object->quantityPrices[] = $adjustment;
// }
// }
// // OR, remove quantity price adjustments.
// $form_object->quantityPrices = NULL;
}
/**
* Implements hook_TYPE_alter().
*
* Allows to alter or remove the 'Price adjustments for An Item:' message.
*
* @see \Drupal\commerce_xquantity\Field\FieldWidget\XquantityWidget::formElement()
* @see \Drupal\commerce_xquantity\Plugin\views\field\XquantityEditQuantity::viewsForm()
*/
function commerce_xquantity_xquantity_add_to_cart_qty_prices_msg_alter(&$msg, $widget, FormStateInterface $form_state) {
// $msg = new $msg('Add more -> pay less for the %label!', $msg->getArguments());
// // OR, remove the message.
// $msg = NULL;
}