<!--?php
session_start();
$output = '';
$items = '';
$basket_total = 0;
$errors = array();
$success = array();
//---------------------------------------------------------------
// Get user profile if they are logged in
$user = $modx--->getUser();
$profile = $user->getOne('Profile');
//-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
/*$profile = $modx->user->getOne('Profile');*/
$extended = $profile->get('extended');
echo $extended['company'];
//-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
// Get posted variables
$name = $profile->fullname;
//$company = $profile->company;
$address = $profile->address;
$city = $profile->city;
$postcode = $profile->zip;
$country = $profile->country;
$email = $profile->email;
$phone = $profile->phone;
//---------------------------------------------------------------
$basket = $_SESSION['basket'];
foreach ($basket as $key => $item) {
$items .= $modx->getChunk('duraflex.quote.row', $item);
$basket_total += $item['quantity'] * $item['price'];
}
//---------------------------------------------------------------
if (isset($_POST['submit'])) {
// Get posted variables
$name = $_POST['name'];
/*$company = $_POST['company'];*/
$company = $extended['company'];
$address = $_POST['address'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$email = $_POST['email'];
$phone = $_POST['phone'];
// Get MODX settings
$to = '[email protected]'; //$modx->getOption('emailsender');
$from = $modx->getOption('emailsender');
$site_name = $modx->getOption('site_name');
$subject = "Duraflex: Quote request by $name";
$message = $modx->getChunk('duraflex.quote.email', array(
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
));
// Send email: TODO
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->reset();
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $from);
$modx->mail->set(modMail::MAIL_FROM_NAME, $site_name);
$modx->mail->set(modMail::MAIL_SENDER, $from);
$modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$modx->mail->address('to', $to);
$modx->mail->address('to', '[email protected]');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'[FormIt] An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
return false;
}
$modx->mail->reset();
$output = $modx->getChunk('duraflex.quote.confirmation', array(
'title' => $title,
'errors' => implode('<li>', $errors),
'success' => implode('</li><li>', $success),
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
));
// Save to user account if applicable
if ($user = $modx->getUser()) {
// Save their order to the database
if ($modx->addPackage('duraflex', MODX_CORE_PATH . 'components/duraflex/model/', 'me')) {
$order = $modx->newObject('Duraflex');
$order->set('userid', $user->get('id'));
$order->set('status', 'new');
$order->set('orderdate', date("Y-m-d H:i:s"));
$order->set('data', json_encode($basket));
$order->save();
}
// Update user profile with the details they entered?
// if ($profile = $modx->getObject('modUserProfile', array('internalKey' => $id))) {
// $fullname = $profile->get('fullname');
// }
}
// Destroy basket
unset($_SESSION['basket']);
} else {
$output = $modx->getChunk('duraflex.quote', array(
'title' => $title,
'errors' => implode('</li><li>', $errors),
'success' => implode('</li><li>', $success),
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
'basket_total' => $basket_total,
));
}
return $output;
</li>