Warning: chmod(): Operation not permitted in /var/www/alexvillarreal/wp-content/plugins/custom-post-type-ui/custom-post-type-ui.php on line 8
403WebShell
403Webshell
Server IP : 74.208.250.37  /  Your IP : 216.73.216.114
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ubuntu 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : miferval ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/araltecservicios/app/Controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/araltecservicios/app/Controller/CheckoutController.php
<?php
declare(strict_types=1);

namespace App\Controller;

use App\Controller\MailerController;
use App\Model\CustomerModel;
use App\Model\OrderModel;
use Mosaico\Controller\BaseController;

class CheckoutController extends BaseController
{

	/**
	 * @var CustomerModel
	 */
	protected $customerModel;	

	/**
	 * @var OrderModel
	 */
	protected $orderModel;

	/**
	 * @var MailerController
	 */
	protected $mailController;

	public function __construct()
	{
	    $this->customerModel = new CustomerModel;
	    $this->orderModel = new OrderModel;
	    $this->mailController = new MailerController;
	}

	public function checkGuestCustomer($customer)
	{
		$query = $this->customerModel->getGuestCustomer($customer['email']);
		if ($query->num_rows > 0) {
			$data = $query->row;
			$data['customer'] = 1;
			$_SESSION['customer'] = ['id' => $data['id_customer'], 'email' => $data['email']];
		} else {
			$data['customer'] = 0;
			unset($_SESSION['customer']);
		}

		echo json_encode($data);
	}

	public function insertOrder($data)
	{
		$env = $this->getEnv();

		if (!isset($_SESSION['customer'])) {
			try {
				$this->customerModel->insertCustomer($data);
				$_SESSION['customer']['id'] = $this->customerModel->getLastCustomerId();
			} catch(Exception  $e) {
				echo 'Caught exception: ',  $e->getMessage(), "\n";
				$_SESSION['customer']['id'] = 0;
			}
		}

		$bytes = random_bytes(20);
		$token = bin2hex($bytes);

		$_SESSION['order'] = array(
			'subject'		=> 'Confirmacion de nueva orden',
			'id_user'		=> $_SESSION['customer']['id'],
			'email' 		=> $data['email'],
			'firstname'	 	=> $data['firstname'],
			'lastname'	 	=> $data['lastname'],
			'street'		=> $data['street'],
			'city'			=> $data['city'],
			'state'			=> $data['state'],
			'zip'			=> $data['zip_code'],
			'phone'			=> $data['phone'], 
			'order_html' 	=> $this->orderHtml(),
			'order_html_div'=> $this->orderHtmlDiv($_SESSION['cart']),
			'order_token' 	=> $token,
			'subtotal'		=> $data['subtotal'],
			'discount'		=> $data['discount'],
			'shipping'		=> $data['shipping'],
			'total' 		=> $data['total'],
			'payment'		=> $data['payment'],
			'payment-detail'=> 'Transferencia Bancaria',
			'type'			=> 'Public',
			'message'		=> $data['message'],
			'mail_cc'		=> $env['MAIL_CC'],
			'mail_bcc'		=> $env['MAIL_BCC'],
			'mail_from'		=> $env['MAIL_FROM'],
			'company'		=> $env['MAIL_COMPANY'],
			'website'		=> $env['MAIL_WEB'],
		);

		$this->orderModel->insertOrder($_SESSION['order']);
		$id_order = $this->orderModel->getLastOrderId();

		foreach ($_SESSION['cart'] as $item) {
			$item['id_order'] = $id_order;
			$this->orderModel->insertOrderItems($item);
		}

		if ($data['payment'] == 'paypal') {
			$data['id_order'] = $id_order;
			$this->orderModel->insertOrderPayment($data); 
			$_SESSION['order']['payment-detail'] = 'Pagado con PayPal ID: '.$data['transaction_id'];
		}

		$data['send_mail'] = $this->mailController->sendOrderNotice($_SESSION['order']);
		

		unset($_SESSION['cart']);
		unset($_SESSION['paypal']);

		echo json_encode($data);
	}

	public function getLastId()
	{
		echo 'Last ID: ' . $this->orderModel->getLastOrderId();
	}

	public function orderHtml()
	{
		$total 		= 0;
		$qty		= 0;
		$shipping 	= 0;
		$discount 	= 0;
		$html = '<table width="750" align="center"><thead style="background:#dddddd;color:#222222;"><tr align="center"><th>SKU</th><th>Producto</th><th>Cantidad</th><th>Precio</th><th align="right">Subtotal</th></tr></thead><tbody>';

		foreach ($_SESSION['cart'] as $item) :
			$price = number_format((float) $item['price'], 2);
			$subtotal = $item['qty'] * $item['price'];
			$total = $total + $subtotal;
			$qty	= $qty + $item['qty'];
			$html .= '<tr align="center">
				<td>' . $item['sku'] . '</td>
				<td>' . $item['name'] . '</td>
				<td>' . $item['qty'] . '</td>
				<td>' . $price . '</td>
				<td align="right">$' . number_format($subtotal , 2) . '</td>
				</tr>';
		endforeach;
		
		$grandTotal = $total - $discount + $shipping;
		$html .= '</tbody><tfoot style="background:#dddddd;color:#222222;"><tr>
				<td colspan="4" align="right">SubTotal:</td>
				<td align="right">$' . number_format($total , 2) . '</td>
				</tr><tr>
				<td colspan="4" align="right">Envio:</td>
				<td align="right">$' . number_format($shipping , 2) . '</td>
				</tr><tr>
				<td colspan="4" align="right"><b>TOTAL:</b></td>
				<td align="right"><b>$' . number_format($grandTotal , 2) . '</b></td>
				</tr></tfoot></table>';

		return $html;		
	}

	public function orderHtmlDiv($cart_items)
	{
		$total 		= 0;
		$qty		= 0;
		$shipping 	= 0;
		$discount 	= 0;
		$html = '<div id="cartItems">
					<div class="row bg-blue text-white text-center py-2 h6">
						<div class="col-md-6">
							Producto
						</div>
						<div class="col-md-2">
							Precio
						</div>
						<div class="col-md-1">
							Cantidad
						</div>
						<div class="col-md-2">
							SubTotal
						</div>
					</div>
					<div class="bg-light text-center">';
			foreach ($cart_items as $item) :
				$subtotal = $item['qty'] * $item['price'];
				$total = $total + $subtotal;
				$qty	= $qty + $item['qty'];
			$html .= '<div class="row py-1 lh-lg">
						<div class="d-none d-md-inline-block col-md-1">
							<img src="/images/products/' . $item['image'] . '" height="100" />
						</div>
						<div class="col-2 col-md-2">
							' . $item['sku'] . '
						</div>
						<div class="d-none d-md-inline-block col-md-3">
							' . $item['name'] . '
						</div>
						<div class="col-2 col-md-2">
							$' . number_format((float)$item['price'], 2) . '
						</div>
						<div class="col-2 col-md-1">
							' . $item['qty'] . '		
						</div>
						<div class="col-2 col-md-2">
							$' .  number_format((float)$subtotal , 2) . '
						</div>
					</div>';
			endforeach;
			$html .= '</div>
						<div class="row pt-3 m-md-0">
						<div class="col-md-4 offset-md-8">
							<div class="h3">Total</div>
							<div class="h6 border border-secondary rounded">
								<div class="row p-2">
									<div class="fw-bold col-6">SubTotal:</div>
									<div class="col-6">$ ' . number_format($total , 2) . '</div>
								</div>
								<div class="row p-2">
									<div class="fw-bold col-6">Envio:</div>
									<div class="col-6">$' . number_format($shipping , 2) . '</div>
								</div>';
			$grandTotal = $total - $discount + $shipping;
            $html .= '<div class="row m-0 bg-blue text-white p-2">
						<div class="fw-bold col-6">Total:</div>
						<div class="col-6">$' . number_format($grandTotal , 2) . '</div>
								</div>
							</div>
						</div>
					</div></div>';
			return $html;		
					
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit