Files
newwalls.pl/override/controllers/front/OrderConfirmationController.php
2024-12-17 13:43:22 +01:00

211 lines
7.0 KiB
PHP

<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter;
class OrderConfirmationControllerCore extends FrontController
{
public $ssl = true;
public $php_self = 'order-confirmation';
public $id_cart;
public $id_module;
public $id_order;
public $reference;
public $secure_key;
public $order_presenter;
/**
* Initialize order confirmation controller.
*
* @see FrontController::init()
*/
public function init()
{
FrontController::init();
if (Configuration::get('freeorderconfirmation_oc') == 1) {
$cart = $this->context->cart;
if (true === (bool)Tools::getValue('free_order')) {
$this->checkFreeOrder();
$this->id_cart = (int)$this->context->cart->id;
$this->id_order = Order::getIdByCartId((int)($this->id_cart));
$this->secure_key = Tools::getValue('key', false);
$order = new Order((int)($this->id_order));
$this->reference = $order->reference;
$freeorderconfirmation = Module::getInstanceByName('freeorderconfirmation');
$redirectLink = $freeorderconfirmation::getOrderConfirmationPage($this->id_order);
if ($redirectLink != false) {
Tools::redirect($redirectLink);
}
$this->order_presenter = new OrderPresenter();
} elseif (Tools::getValue('id_order', 'false') != 'false') {
$this->id_order = Tools::getValue('id_order');
$order = new Order($this->id_order);
$this->id_cart = (int)$order->id_cart;
$this->order = $order;
$this->customer = $this->context->customer;
if ($this->context->customer->id == $this->order->id_customer) {
$this->order_presenter = new OrderPresenter();
} else {
parent::init();
}
} else {
parent::init();
}
} else {
parent::init();
}
}
/**
* Assign template vars related to page content.
*
* @see FrontController::initContent()
*/
public function initContent()
{
if (Configuration::isCatalogMode()) {
Tools::redirect('index.php');
}
$order = new Order(Order::getIdByCartId((int) ($this->id_cart)));
$presentedOrder = $this->order_presenter->present($order);
$register_form = $this
->makeCustomerForm()
->setGuestAllowed(false)
->fillWith(Tools::getAllValues());
parent::initContent();
$this->context->smarty->assign([
'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation($order),
'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn($order),
'order' => $presentedOrder,
'register_form' => $register_form,
]);
if ($this->context->customer->is_guest) {
/* If guest we clear the cookie for security reason */
$this->context->customer->mylogout();
}
$this->setTemplate('checkout/order-confirmation');
}
/**
* Execute the hook displayPaymentReturn.
*/
public function displayPaymentReturn($order)
{
if (!Validate::isUnsignedId($this->id_module)) {
return false;
}
return Hook::exec('displayPaymentReturn', ['order' => $order], $this->id_module);
}
/**
* Execute the hook displayOrderConfirmation.
*/
public function displayOrderConfirmation($order)
{
/*
$id_cart = $this->id_cart;
$order_object = new Order($this->id_order);
$order_reference = $order_object->reference;
$cur_cart = new Cart((int) $id_cart);
$productList = $cur_cart->getProducts();
foreach ($productList as $product) {
$id_product = $product['id_product'];
$txt_name2 = $id_cart."_".$id_product.".txt";
$txt_dir2 = _PS_IMG_DIR_.'wycinek/'.$txt_name2;
$quantity = $product['cart_quantity'];
if (file_exists($txt_dir2)){
$txt_content2 = file_get_contents($txt_dir2);
$txt_content2 .= "QUANTITY:".$quantity."\n";
$txt_content2 .= "ORDER_REFERENCE:".$order_reference."\n";
file_put_contents($txt_dir2,$txt_content2);
$source_img_dir = _PS_IMG_DIR_.'wycinek/'.$id_cart."_".$id_product.".jpg";
$copy_img_dir = _PS_IMG_DIR_.'wycinek/kupione/'.$id_cart."_".$id_product.".jpg";
$source_txt_dir = _PS_IMG_DIR_.'wycinek/'.$id_cart."_".$id_product.".txt";
$copy_txt_dir = _PS_IMG_DIR_.'wycinek/kupione/'.$id_cart."_".$id_product.".txt";
$source_img_content = file_get_contents($source_img_dir);
file_put_contents($copy_img_dir,$source_img_content);
$source_txt_content = file_get_contents($source_txt_dir);
file_put_contents($copy_txt_dir,$source_txt_content);
}
}
*/
return Hook::exec('displayOrderConfirmation', ['order' => $order]);
}
/**
* Check if an order is free and create it.
*/
protected function checkFreeOrder()
{
$cart = $this->context->cart;
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0) {
Tools::redirect($this->context->link->getPageLink('order'));
}
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
Tools::redirect($this->context->link->getPageLink('order'));
}
$total = (float) $cart->getOrderTotal(true, Cart::BOTH);
if ($total > 0) {
Tools::redirect($this->context->link->getPageLink('order'));
}
$order = new PaymentFree();
$order->validateOrder(
$cart->id,
Configuration::get('PS_OS_PAYMENT'),
0,
$this->trans('Free order', [], 'Admin.Orderscustomers.Feature'),
null,
[],
null,
false,
$cart->secure_key
);
}
}