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/cartforge.co/app/code/CartForge/PrivateProductRequest/Controller/Request/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/app/code/CartForge/PrivateProductRequest/Controller/Request/Save.php
<?php

namespace CartForge\PrivateProductRequest\Controller\Request;

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Stdlib\DateTime\DateTime;


class Save extends Action
{
    protected $customerSession;
    protected $customerRepository;
    protected $requestFactory;
    protected $date;
    protected $resourceConnection;

    public function __construct(
        Context                     $context,
        CustomerSession             $customerSession,
        CustomerRepositoryInterface $customerRepository,
        ResourceConnection          $resourceConnection,
        DateTime                    $date
    )
    {
        parent::__construct($context);
        $this->customerSession = $customerSession;
        $this->customerRepository = $customerRepository;
        $this->resourceConnection = $resourceConnection;
        $this->date = $date;
    }

    public function execute()
    {
        $postData = $this->getRequest()->getPostValue();

        if (!$postData) {
            return $this->_redirect('*/*/');
        }

        $customerId = $this->customerSession->getCustomerId();

        if ($customerId) {
            try {
                $customer = $this->customerRepository->getById($customerId);
            } catch (\Exception $e) {
                $this->messageManager->addErrorMessage(__('Failed to retrieve customer data.'));
                return $this->_redirect('*/*/');
            }
        }

        try {
            $connection = $this->resourceConnection->getConnection();
            $tableName = $this->resourceConnection->getTableName('private_product_requests');


            // Automatically set created_at and updated_at
            $postData['customer_id'] = $customerId;

            $postData['created_at'] = $this->date->gmtDate();
            $postData['updated_at'] = $this->date->gmtDate();
            $postData['status'] = 'pending';

            unset($postData['form_key']);


            if (!$postData['description']) {
                $postData['description'] = null;
            }

            $connection->insert($tableName, $postData);

            $this->messageManager->addSuccessMessage(__('Your request has been submitted successfully.'));
        } catch (\Exception $e) {
            $this->messageManager->addErrorMessage(__('There was an error submitting your request.'));
            return $this->_redirect('*/*/');
        }

        return $this->_redirect('*/*/success');
    }
}

Spamworldpro Mini