commerce_xquantity.module in Commerce Extended Quantity 8
Contains commerce_xquantity.module.
File
commerce_xquantity.moduleView source
<?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;
}
Functions
Name | Description |
---|---|
commerce_xquantity_entity_type_alter | Implements hook_entity_type_alter(). |
commerce_xquantity_field_widget_info_alter | Implements hook_field_widget_info_alter(). |
commerce_xquantity_xquantity_added_to_cart_msg_alter | Implements hook_TYPE_alter(). |
commerce_xquantity_xquantity_add_to_cart_qty_prices_alter | Implements hook_TYPE_alter(). |
commerce_xquantity_xquantity_add_to_cart_qty_prices_msg_alter | Implements hook_TYPE_alter(). |