forked from saltonmassally/Drupal-CAC-Modules
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9d3050
commit f094bbf
Showing
20 changed files
with
1,044 additions
and
306 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Commerce CAC Integration | ||
type: module | ||
description: Adds payments and commerce integration for the CAC | ||
package: Corporate Affairs Commission | ||
dependencies: | ||
- drupal:user | ||
- drupal:block | ||
- drupal:node | ||
- cac_base | ||
- webform | ||
- commerce | ||
- commerce_payment | ||
- commerce_cart | ||
- commerce_checkout | ||
core: '8.x' | ||
project: 'commerce_cac' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Handles payments for the CAC project | ||
*/ | ||
|
||
|
||
/** Implements hook_entity_base_field_info(). | ||
*/ | ||
function commerce_cac_entity_base_field_info(EntityTypeInterface $entity_type) { | ||
$fields = []; | ||
|
||
// Add a 'State field' to all webform submissions | ||
if ($entity_type->id() === 'webform_submission') { | ||
|
||
// The values shown in options are 'administrator' and 'user'. | ||
$fields['processing_state'] = BaseFieldDefinition::create('list_string') | ||
->setLabel(t('Processing State')) | ||
->setDescription(t('The state of the submission.')) | ||
->setSettings([ | ||
'allowed_values' => [ | ||
STATE_PENDING => 'Pending', | ||
STATE_DONE => 'Completed', | ||
STATE_PROCESSING => 'Processing', | ||
STATE_REJECTED => 'Rejected', | ||
], | ||
]) | ||
// Set the default value of this field to 'user'. | ||
->setDefaultValue('pending'); | ||
/* ->setDisplayOptions('view', [ | ||
'label' => 'above', | ||
'type' => 'string', | ||
'weight' => -2, | ||
]) | ||
->setDisplayOptions('form', [ | ||
'type' => 'options_select', | ||
'weight' => -2, | ||
]) | ||
->setDisplayConfigurable('form', TRUE) | ||
->setDisplayConfigurable('view', TRUE);*/ | ||
|
||
} | ||
|
||
return $fields; | ||
} | ||
|
||
|
||
/** | ||
* hook_entity_update | ||
* @param \Drupal\Core\Entity\EntityInterface $entity | ||
* | ||
* React to webform submissions being saved | ||
*/ | ||
function commerce_cac_entity_update(Drupal\Core\Entity\EntityInterface $entity) { | ||
if ($entity->getEntityTypeId() == "webform_submission") { | ||
$in_cart = FALSE; | ||
if (!$entity->get("in_draft")->value == FALSE && !$in_cart) { | ||
/** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */ | ||
$order_item = $this->entity; | ||
/** @var \Drupal\commerce\PurchasableEntityInterface $purchased_entity */ | ||
$purchased_entity = $order_item->getPurchasedEntity(); | ||
|
||
$order_type_id = $this->orderTypeResolver->resolve($order_item); | ||
$store = $this->selectStore($purchased_entity); | ||
$ | ||
cart = $this->cartProvider->getCart($order_type_id, $store); | ||
if (!$cart) { | ||
$cart = $this->cartProvider->createCart($order_type_id, $store); | ||
} | ||
$this->cartManager->addOrderItem($cart, $order_item, $form_state->get(['settings', 'combine'])); | ||
// Other submit handlers might need the cart ID. | ||
$form_state->set('cart_id', $cart->id()); | ||
|
||
drupal_set_message($this->t('@entity added to @cart-link.', [ | ||
'@entity' => $purchased_entity->label(), | ||
'@cart-link' => Link::createFromRoute($this->t('your cart', [], ['context' => 'cart link']), 'commerce_cart.page')->toString(), | ||
])); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.