0

I've tried to add a Js layout in sales_order_create_index.xml in which I override Magento_Sales::order/create/shipping/method/form.phtml

There's not much I did but to call

    <script type="text/x-magento-init">
        {
            "#cc-ts-trigger": {
                "Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
            }
        }
    </script>

its working fine when the page is being reloaded which is calling sales_order_create_index.xml.

My problem is when a you select another shipping method, this will create an ajax call in Magento\Sales\Controller\Adminhtml\Order\Create\LoadBlock

so i also need to put the same jslayout config in sales_order_create_load_block_shipping_method.xml

they're both using Magento_Sales::order/create/shipping/method/form.phtml as their template. but for some reasons the ajax call cannot render sales_order_create_load_block_shipping_method.xml if the template has the type="text/x-magento-init" script.

It works fine if i remove it.

here is the code of Magento\Sales\Controller\Adminhtml\Order\Create\LoadBlock

public function execute()
{
    $request = $this->getRequest();
    try {
        $this->_initSession()->_processData();
    } catch (\Magento\Framework\Exception\LocalizedException $e) {
        $this->_reloadQuote();
        $this->messageManager->addErrorMessage($e->getMessage());
    } catch (\Exception $e) {
        $this->_reloadQuote();
        $this->messageManager->addExceptionMessage($e, $e->getMessage());
    }

    $asJson = $request->getParam('json');
    $block = $request->getParam('block');

    /** @var \Magento\Framework\View\Result\Page $resultPage */
    $resultPage = $this->resultPageFactory->create();
    if ($asJson) {
        $resultPage->addHandle('sales_order_create_load_block_json');
    } else {
        $resultPage->addHandle('sales_order_create_load_block_plain');
    }

    if ($block) {
        $blocks = explode(',', $block);
        if ($asJson && !in_array('message', $blocks)) {
            $blocks[] = 'message';
        }

        foreach ($blocks as $block) {
            $resultPage->addHandle('sales_order_create_load_block_' . $block);
        }
    }

    $result = $resultPage->getLayout()->renderElement('content');
    if ($request->getParam('as_js_varname')) {
        $this->_objectManager->get(\Magento\Backend\Model\Session::class)->setUpdateResult($result);
        return $this->resultRedirectFactory->create()->setPath('sales/*/showUpdateResult');
    }
    return $this->resultRawFactory->create()->setContents($result);
}

I think the error $resultPage->addHandle() cannot process template with type="text/x-magento-init" but im not sure how to fix this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.