Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/Ecombricks/InventorySales/Controller/Adminhtml/Order/Create/Save/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/Ecombricks/InventorySales/Controller/Adminhtml/Order/Create/Save/SourceTrait.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See LICENSE.txt for license details.
 */
namespace Ecombricks\InventorySales\Controller\Adminhtml\Order\Create\Save;

/**
 * Create order save controller source trait
 */
trait SourceTrait
{
    
    /**
     * Authorize
     * 
     * @return bool
     */
    protected function authorize()
    {
        $session = $this->_getSession();
        return $this->_authorization->isAllowed('Magento_Customer::manage') || 
            $session->getCustomerId() || 
            $session->getQuote()->getCustomerIsGuest();
    }
    
    /**
     * Get payment method checks
     * 
     * @return array
     */
    protected function getPaymentMethodChecks()
    {
        return [
            \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_INTERNAL,
            \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY,
            \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY,
            \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
            \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL,
        ];
    }
    
    /**
     * Prepare payment
     * 
     * @return $this
     */
    protected function preparePayment()
    {
        $paymentData = $this->getRequest()->getPost('payment');
        if (empty($paymentData)) {
            return $this;
        }
        $paymentData['checks'] = $this->getPaymentMethodChecks();
        $orderCreate = $this->_getOrderCreateModel();
        $orderCreate->setPaymentData($paymentData);
        $orderCreate->getQuote()->getPayment()->addData($paymentData);
        return $this;
    }
    
    /**
     * Add exception message
     * 
     * @param \Exception $exception
     * @return $this
     */
    protected function addExceptionMessage(\Exception $exception)
    {
        $message = $exception->getMessage();
        if (empty($message)) {
            return $this;
        }
        $this->messageManager->addErrorMessage($message);
        return $this;
    }
    
    /**
     * Execute
     * 
     * @return $this
     */
    public function inventoryExecute()
    {
        $path = 'sales/*/';
        $pathParams = [];
        $session = $this->_getSession();
        $orderCreate = $this->_getOrderCreateModel();
        $request = $this->getRequest();
        try {
            if (!$this->authorize()) {
                return $this->resultForwardFactory->create()->forward('denied');
            }
            $orderCreate->getQuote()->setCustomerId($session->getCustomerId());
            $this->_processActionData('save');
            $this->preparePayment();
            $orders = $orderCreate->setIsValidate(true)->importPostData($request->getPost('order'))->createOrder();
            $session->clearStorage();
            $this->messageManager->addSuccessMessage(__('You created the orders.'));
            if (count($orders) == 1 && $this->_authorization->isAllowed('Magento_Sales::actions_view')) {
                $pathParams = ['order_id' => current($orders)->getId()];
                $path = 'sales/order/view';
            } else {
                $path = 'sales/order/index';
            }
        } catch (\Magento\Framework\Exception\PaymentException $exception) {
            $orderCreate->saveQuote();
            $this->addExceptionMessage($exception);
        } catch (\Magento\Framework\Exception\LocalizedException $exception) {
            $session->setCustomerId((int) $session->getQuote()->getCustomerId());
            $this->addExceptionMessage($exception);
        } catch (\Exception $exception) {
            $this->messageManager->addExceptionMessage($exception, __('Orders saving error: %1', $exception->getMessage()));
        }
        return $this->resultRedirectFactory->create()->setPath($path, $pathParams);
    }
    
}

Spamworldpro Mini