1

I need to create a script that let customer to get status connected on Magento 2 when he connect in an external website (CakePhp) NB: Magento and CakePhp are in the same server.

when I use this script:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface');
$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface');

$customerEmail ="[email protected]";

$CustomerModel = $objectManager->create('Magento\Customer\Model\Customer');
$CustomerModel->setWebsiteId(1); //Here 1 means Store ID**
$CustomerModel->loadByEmail($customerEmail);
$customerId = $CustomerModel->getId();

echo $customerId ;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
// Load customer
$customer = $objectManager->create('Magento\Customer\Model\Customer')->load($customerId);
// Load customer session
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
$customerSession->setCustomerAsLoggedIn($customer);
if($customerSession->isLoggedIn()) {
    echo "Customer Logged in";
}else{
    echo "customer is Not Logged in";
}
?>

When I execute this code I have this error in cakephp

Error: Cannot redeclare Zend\Diactoros\createUploadedFile()
File /vendor/laminas/laminas-diactoros/src/functions/create_uploaded_file.legacy.php

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.