Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在magento2中获取信息签出来宾用户_Php_Plugins_Payment_Checkout_Magento2 - Fatal编程技术网

Php 如何在magento2中获取信息签出来宾用户

Php 如何在magento2中获取信息签出来宾用户,php,plugins,payment,checkout,magento2,Php,Plugins,Payment,Checkout,Magento2,我正在开发magento 2.1.1支付模块问题是,当我与(登录用户)结账时,我能够获得消费者的所有信息 但是如果我与(来宾用户)结帐,然后var_转储这个对象 $this->_checkoutSession->getQuote() 它向我显示有关我的卡的所有信息(价格、产品等),但有关消费者的所有其他数据均为空 这是我的密码 <?php namespace Fpay\Fastpay\Controller\Payment; use Magento\Framework\Control

我正在开发magento 2.1.1支付模块问题是,当我与(登录用户)结账时,我能够获得消费者的所有信息

但是如果我与(来宾用户)结帐,然后var_转储这个对象

$this->_checkoutSession->getQuote()

它向我显示有关我的卡的所有信息(价格、产品等),但有关消费者的所有其他数据均为空

这是我的密码

<?php 

namespace Fpay\Fastpay\Controller\Payment; 

use Magento\Framework\Controller\ResultFactory;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Sales\Model\Order;
use Magento\Quote\Api\GuestCartManagementInterface;


class Redirect extends \Magento\Framework\App\Action\Action
{

    protected $_customerSession;
    protected $resultPageFactory;
    protected $_paymentMethod;
    protected $_checkoutSession;
    protected $checkout;
    protected $cartManagement;
    protected $orderRepository;
    protected $_scopeConfig;
    protected $guestcartManagement;

    /**
     * @param \Magento\Framework\App\Action\Context $context
     * @param SessionManagerInterface $session
     * @param \Magento\Checkout\Model\Session $checkoutSession
     */
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Customer\Model\Session $customerSession,
        \Fpay\Fastpay\Model\PaymentMethod $paymentMethod,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        CartManagementInterface $cartManagement,
        GuestCartManagementInterface $guestcartManagement,
        array $data = []
    ) {
        $this->_customerSession = $customerSession;
        $this->_paymentMethod   = $paymentMethod;
        $this->_checkoutSession = $checkoutSession;
        $this->cartManagement   = $cartManagement;
        $this->guestcartManagement = $guestcartManagement;
        $this->orderRepository  = $orderRepository;
        $this->_scopeConfig     = $scopeConfig;

        parent::__construct($context);
    }

    protected function log($message, $level=null) {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info($message);
    }

    /**
     * Return checkout session.
     *
     * @return Magento\Backend\Model\Session|Magento\Backend\Model\Session\Quote
     */
    public function getCheckout()
    {
        $sessionClass = \Magento\Checkout\Model\Session::class;
        if ($this->isBackend()) {
            $sessionClass = \Magento\Backend\Model\Session\Quote::class;
        }

        return $this->objectManager->get($sessionClass);
    }  

    /**
     * Return true if this is a backend session.
     *
     * @return bool
     */
    public function isBackend()
    {
        return $this->appState->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;
    }

    public function execute(  )
    {

        try {   

            // Check The customer {Simple User, Guest User}

            // Object Contain Session Data
            $session = $this->_objectManager->get('Magento\Customer\Model\Session');

            if($session->isLoggedIn()) {

                // Logged User
                echo "Logged User =====================================<br>";
                $orderIncrementId = $this->cartManagement->placeOrder($this->_checkoutSession->getQuote()->getId());
                $order = $this->orderRepository->get($orderIncrementId);
                echo "Order Increment ID : " . $orderIncrementId . '<br>';
                echo "Order id           : " . $order->getId() . '<br>';
                echo 'Email              :' . $order->getCustomerEmail() . '<br>';
                echo "=================================================<br>";

            } else {

                // Guest User 
                echo "Guest User =====================================<br>";
                $order = $this->_paymentMethod->getFastpayCheckoutRedirection();
                echo "Order ID           : " . $order->getId() . '<br>';
                echo 'Email              :'  . $order->getCustomerEmail() . '<br>';
                echo "================================================<br>";

            }

            // clear quote data
            $this->getCheckout()->unsLastQuoteId()
                                ->unsLastSuccessQuoteId()
                                ->clearHelperData();


        } catch (\Exception $exception) {

            echo  $exception ;

        }

    }

} ?>

这是一个屏幕截图,显示了会话签出的内容


关于如何解决这个问题,您有什么想法吗?

您需要显示更多的代码。特别是,当用户是来宾用户时,将项目添加到购物车的代码。不需要显示更多的magento代码,我的问题是关于客户信息,这些信息在来宾模式下不可用。购物车信息可用