Magento Asked by Anis Agrebi on October 1, 2021
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 MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$storeManager = $obj->get('MagentoStoreModelStoreManagerInterface');
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$productMetadata = $objectManager->get('MagentoFrameworkAppProductMetadataInterface');
$customerEmail ="[email protected]";
$CustomerModel = $objectManager->create('MagentoCustomerModelCustomer');
$CustomerModel->setWebsiteId(1); //Here 1 means Store ID**
$CustomerModel->loadByEmail($customerEmail);
$customerId = $CustomerModel->getId();
echo $customerId ;
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
// Load customer
$customer = $objectManager->create('MagentoCustomerModelCustomer')->load($customerId);
// Load customer session
$customerSession = $objectManager->create('MagentoCustomerModelSession');
$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 ZendDiactoroscreateUploadedFile()
File /vendor/laminas/laminas-diactoros/src/functions/create_uploaded_file.legacy.php
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP