Lazy File Manager
| Current Path : /home/cruisin2/sas.cruisingclub.org/modules/uc_actable/ |
| PPPath/home/cruisin2/sas.cruisingclub.org/modules/uc_actable |
| Current File : /home/cruisin2/sas.cruisingclub.org/modules/uc_actable/uc_actable.module.bak |
<?php
use Drupal\Core\Url;
use Drupal\uc_cart\CartInterface;
use Drupal\uc_order\Entity\Order;
use Drupal\uc_order;
use Drupal\node\Entity\Node;
use Drupal\uc_order\OrderInterface;
use Drupal\uc_order\OrderProductInterface;
function uc_actable_uc_checkout_complete($order){
return uc_actable_order_actions($order);
}
function uc_actable_order_actions(&$order){
// first, get the order info
$oid = ($order->order_id->value);
$tokens = false;
foreach($order->products as $id=>&$product){
$nid = $product->nid->target_id;
$node = Node::load($nid); // get the underlying product
// check for token handling
if(isset($node->field_actable_token->target_id) || isset($o_product['tokens']) ){
// check for SKU-specific constraint
if(isset($node->field_actable_token_sku)){
$oktokens = $node->field_actable_token_sku->getValue(); //valid SKUs for token issuance
$skutokens = array();
foreach($oktokens as $oktoken){
$skutokens[] = $oktoken['value']; //make an array of valid tokens
}
if(count($skutokens)>0){
$model = $product->model->value; // the order item's SKU
if(in_array($model, $skutokens)){
$dotoken = true; // passed token test!
} else {
$dotoken = false; // failed token test
}
} else{
$dotoken = true; //no listed SKU is no constraint
}//
}else{
$dotoken = true; // no constraint by SKU
}
if($dotoken){
$token_nid = $node->field_actable_token->target_id;
$tokens=array();
$qty = $product->qty->value;
for($x=0; $x < $qty; $x++){
$tokens[] = uc_actable_assign_token($oid, $id, $token_nid);
}
} // end of got tokens
}// end of token handling
// check for special message
if(isset($node->field_buyer_message->value) ){
uc_actable_client_extra_mail($order, $product, $node, $tokens);
} //end of special message
//check for race entry
// now create a regatta entry if the regatta is set
if(\Drupal::moduleHandler()->moduleExists('arr') && isset($node->field_regatta->target_id) ){
$regatta_id = $node->field_regatta->target_id;
uc_actable_enter_race($order, $product, $regatta_id);
}
}
}
function uc_actable_enter_race($order, $product, $regatta_id){
$attributes = $product->data->attributes;
$fields = array('boat_name'=>"Boat Name", 'boat_type'=>"Boat Type", 'contact_email'=>"Contact Email",
'mobile_phone'=>"Contact Phone Number", 'rating_claimed'=>"Rating",
'requested_division'=>"Desired Division", 'sail_number'=>"Sail Number", 'skipper_first'=>"Skipper First",
'skipper_last'=>"Skipper Last", 'yacht_club'=>"Yacht Club",'series'=>"Race or Series" );
$entarray = array();
foreach($fields as $key=>$field ){
if(isset($attributes[$field] ) ){
$entarray[$key] = $attributes[$field];
}
}
$entry = arr_make_entry($regatta_id, $entarray);
}
function uc_actable_assign_token($oid, $opid, $token_nid){
$sql = 'SELECT * FROM {uc_actable_tokens} WHERE nid = :nid AND order_product_id IS NULL ORDER BY `token` LIMIT 1'; // get next blank token
$result = db_query($sql, array(':nid' => $token_nid) )->fetchAssoc();
if(!$result) return false; //tell the world we failed
$token = $result['token'] ;
//----------- structured version of update!
$connection = \Drupal::database();
$num_updated = $connection->update('uc_actable_tokens')
->fields([
'order_product_id' => $opid,
'order_id' => $oid,
'changed'=>time(),
])
->condition('token', $token, '=')
->condition('nid', $token_nid, '=')
->execute();
if($num_updated > 0){
return $token;
} else {
return "Error! Please Contact Us";
}
}
function uc_actable_client_extra_mail($order, $product, $node = null, $tokens=null){
$to = $order->getEmail();
if($node && $title = $node->field_special_message_subject->value){
$params['subject'] = $title;
} else{
$params['subject'] = 'A message about ' . $product->title->value;
}
$mailManager = \Drupal::service('plugin.manager.mail');
$module = 'uc_actable';
$key = 'customer special';
if($node) {$params['message'] = $node->field_buyer_message->value;}
if(isset($tokens) && $tokens != false){ // add token info
$tokmess = 'Token (code) information: ';
foreach($tokens as $token){
$tokmess .= "$token";
}
//$tokmess .= '</ul>';
$params['tokenmess'] = $tokmess;
}
$attr = $product->data->attributes;
$onotes = "Order line item detail\n{$product->qty->value} x {$product->title->value} \n";
foreach($attr as $heading=>$att){
$onotes .= " > $heading: " . implode(', ',$att) . "\n";
}
//$onotes .= '</ul>';
$params['order'] = $onotes;
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$send = true;
$result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send);
if ($result['result'] !== true) {
drupal_set_message(t('There was a problem sending you an informational email. Please contact us.'), 'error');
}
else {
drupal_set_message(t('Check your email (' . $to . ') for a receipt and a separate informational message.'));
}
}
function uc_actable_mail($key, &$message, $params) {
$options = array(
'langcode' => $message['langcode'],
);
switch ($key) {
case 'customer special':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = $params['subject'];
$message['body'][] = $params['message'];
if(isset($params['tokenmess']) ) {$message['body'][] = $params['tokenmess'];}
$message['body'][] = '<hr>';
$message['body'][] = $params['order'];
break;
}
}
?>Da3s File Manager Version 1.0, Coded By Da3s HaCkEr
Email: R0@hotmail.com
