문제

I have a custom functionality for creating an order, I want to transfer the custom LastOrderId to the success page to which the user gets after submitting the form.

The controller responsible for submitting the form returns a redirect app/code/Qq/Www/Controller/Order/Create.php

return $resultRedirect->setPath('dv_sample/success');

The controller responsible for rendering the success page app/code/Qq/Www/Controller/Success/Index.php

class Index extends \Magento\Framework\App\Action\Action
{
    private $pageFactory;

    protected $customerSession;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory,
        \Magento\Customer\Model\Session $customerSession
    ) {
        parent::__construct($context);
        $this->pageFactory = $pageFactory;
        $this->customerSession = $customerSession;
    }

    public function execute()
    {
        if (!$this->customerSession->getLastSampleRealOrderId()) {
            /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
            $resultRedirect = $this->resultRedirectFactory->create();
            return $resultRedirect->setPath('building-bed-page');
        }
        return $this->pageFactory->create();
    }
}

Block app/code/Qq/Www/Block/Success.php

    protected $customerSession;

    public $_storeManager;

    public function __construct(
        Template\Context $context,
        \Magento\Customer\Model\Session $customerSession,
        array $data = []
    ) {
        $this->customerSession = $customerSession;
        parent::__construct($context, $data);
    }


    public function lastSampleRealOrderId()
    {
        $incrementOrderId = $this->customerSession->getLastSampleRealOrderId();

        if ($incrementOrderId) {
            $this->customerSession->setLastSamleRealOrderId(null);
        }

        return $incrementOrderId;
    }

Template app/code/Qq/Www/view/frontend/templates/success/index/success_page.phtml

After submitting the form locally, I get a saxest page in which I see all the data including the ID order. <?= $block->lastSampleRealOrderId() ?>

But after uploading to the server, the order is not visible, data does not come

도움이 되었습니까?

해결책

I think the problem lies on the surface, but you don’t see it.

experience has shown that many developers turn off block, full page, and layout caches when developing.

most likely you have them enabled for production. try temporarily disabling full page cache and you will see your result.

if this helps add cacheable="false" to your layout

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top