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/old/app/code/Magecomp/Savecartpro/Controller/Customer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Magecomp/Savecartpro/Controller/Customer/Addcart.php
<?php
namespace Magecomp\Savecartpro\Controller\Customer;

use Magecomp\Savecartpro\Model\SavecartprodetailFactory;
use Magento\Checkout\Model\Cart;
class Addcart extends \Magento\Framework\App\Action\Action
{
    protected $messageManager;
    protected $custsession;
    protected $_responseFactory;
    protected $_url;
    protected $_request;
    protected $modelsavecartdetail;
    protected $cart;
    protected $formkey;
    protected $serialize;

    public function __construct(\Magento\Framework\App\Action\Context $context,
                                \Magento\Customer\Model\Session $custsession,
                                \Magento\Framework\App\ResponseFactory $responseFactory,
                                SavecartprodetailFactory $modelsavecartdetail,
                                \Magento\Framework\Serialize\Serializer\Json $serialize,
                                Cart $cart)
    {
        $this->custsession = $custsession;
        $this->_responseFactory = $responseFactory;
        $this->modelsavecartdetail = $modelsavecartdetail;
        $this->cart = $cart;
        $this->serialize = $serialize;
        parent::__construct($context);
    }

    public function execute()
    {
        if($this->custsession->isLoggedIn())
        {
            try {

                $data = $this->_request->getParams();
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $formkey = $objectManager->get('\Magento\Framework\Data\Form\FormKey');
                if(array_key_exists('selectcart',$data) && count($data['selectcart'])>0)
                {
                    foreach ($data['selectcart'] as $quotedata)
                    {
                        $quotedetailCollection = $this->modelsavecartdetail->create()
                            ->getCollection()
                            ->addFieldToFilter('savecart_id', $quotedata);

                        foreach ($quotedetailCollection->getData() as $col) {
                            $obj_product = $objectManager->create('Magento\Catalog\Model\Product');
                            $Configdata = $this->serialize->unserialize($col['quote_config_prd_data']);
                            array_push($Configdata, 'form_key', $formkey->getFormKey());
                            $_product = $obj_product->load($col['quote_prd_id']);
                            $this->cart->addProduct($_product, $Configdata);
                        }
                        $this->cart->save();
                    }
                    $message = "Your cart has been successfully added to cart";
                    $this->messageManager->addSuccess($message);
                    $accUrl = $this->_url->getUrl('checkout/cart/');
                    $this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
                    $this->setRefererUrl($accUrl);
                }
                else
                {
                    $message = "Please select any cart";
                    $this->messageManager->addError($message);
                    $accUrl = $this->_url->getUrl('savecartpro/customer/cartlist');
                    $this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
                    $this->setRefererUrl($accUrl);
                }
            }
            catch(\Exception $e)
            {
                $this->messageManager->addError($e->getMessage());
                $accUrl = $this->_url->getUrl('savecartpro/customer/cartlist');
                $this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
                $this->setRefererUrl($accUrl);
            }
        }
        else
        {
            $accUrl = $this->_url->getUrl('customer/account/login');
            $this->_responseFactory->create()->setRedirect($accUrl)->sendResponse();
            $this->setRefererUrl($accUrl);
        }
    }
}

Spamworldpro Mini