私は支払い方法モジュールを作成しました。このモジュールでは、ログインしたときに、Magento \ Quote \ Api \ CartManagementInterfaceインターフェイスから注文IDを取得できました。私がゲストだったとき、私はMagento \ Quote \ Api \ CartManagementInterfaceインターフェイスから注文IDを取得できませんでした。 Googleで検索したところ、ゲストのユーザーインターフェイスが変更されていることが判明しましたMagento \ Quote \ Api \ GuestCartManagementInterface私もこのインタフェースを試してみましたが、依然としてゲストの顧客の注文IDを取得するために働いていません。 Place orderボタンをクリックすると、My moduleコントローラが呼び出されます。 私のコントローラコードを以下に示します。Magento 2:Place Orderボタンをクリックした後、ゲストの顧客の注文IDを取得するにはどうすればいいですか?
<?php
namespace Mageniks\Testpayment\Controller\Payment;
use Magento\Framework\Controller\ResultFactory;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Api\GuestCartManagementInterface;
class Redirect extends \Magento\Framework\App\Action\Action
{
/**
* Customer session model
*
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
protected $resultPageFactory;
protected $_paymentMethod;
protected $_checkoutSession;
protected $checkout;
protected $cartManagement;
protected $guestcartManagement;
protected $orderRepository;
protected $_scopeConfig;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Mageniks\Testpayment\Model\PaymentMethod $paymentMethod,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
CartManagementInterface $cartManagement,
GuestCartManagementInterface $guestcartManagement
) {
$this->_customerSession = $customerSession;
parent::__construct($context);
$this->_paymentMethod = $paymentMethod;
$this->_checkoutSession = $checkoutSession;
$this->cartManagement = $cartManagement;
$this->guestcartManagement = $guestcartManagement;
$this->orderRepository = $orderRepository;
$this->_scopeConfig = $scopeConfig;
}
public function execute()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$orderId = '';
if($customerSession->isLoggedIn())
{
// FOR LOGIN CUSTOMER GET ORDER ID
$orderId = $this->cartManagement->placeOrder($this->_checkoutSession->getQuote()->getId());
}
else
{
// FOR GUEST CUSTOMER GET ORDER ID
try
{
$orderId = $this->guestcartManagement->placeOrder($this->_checkoutSession->getQuote()->getId());
} catch (\Exception $e)
{
echo $e->getMessage();
}
}
$order = $this->orderRepository->get($orderId);
if ($order){
$order->setState($this->_scopeConfig->getValue('payment/testpayment/new_order_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
$order->setStatus($this->_scopeConfig->getValue('payment/testpayment/new_order_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
$order->save();
}
}
}
?>
注文ボタンをクリックした後、コントローラ内のゲスト顧客の注文IDを取得するにはどうすればよいですか?私を助けてください。どんな助けもありがとう。
おかげ
成功したページmagentoはゲストユーザの注文IDも自動的に表示します。または、注文IDを取得するためにsessionを使用することもできます。 – urfusion
私はmagento 2を使用しています。私はcheckoutセッションから注文IDを取得しようとしていましたが、空白になります:$ this-> _ checkoutSession($ checkoutSession - > getLastRealOrderId(); – Niks
私のコントローラは成功ページの前に呼ばれていますので、注文オブジェクトを取得することができません – Niks