1

How to set item in core registry ? I have created order list , now i want load current order set in core registry in custom module.

 public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Payment\Helper\Data $paymentHelper,
        \Magento\Sales\Api\Data\OrderInterface $order,
        array $data = []
    ) {
        $this->_paymentHelper = $paymentHelper;
        $this->_coreRegistry = $registry;
        $this->httpContext = $httpContext;
        $this->order = $order;
        parent::__construct($context, $data);
        $this->_isScopePrivate = true;
    }

    /**
     * @return void
     */
    protected function _prepareLayout()
    {
        $this->pageConfig->getTitle()->set(__('Order # %1', $this->getOrder()->getRealOrderId()));
        $infoBlock = $this->_paymentHelper->getInfoBlock($this->getOrder()->getPayment(), $this->getLayout());
        $this->setChild('payment_info', $infoBlock);
    }

    /**
     * @return string
     */
    public function getPaymentInfoHtml()
    {
        return $this->getChildHtml('payment_info');
    }

    /**
     * Retrieve current order model instance
     *
     * @return \Magento\Sales\Model\Order
     */
    public function getOrder()
    {
        $data = $this->getRequest()->getParams('id');
        return $order = $this->order->loadByIncrementId($data);

    }




in core file 



public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Payment\Helper\Data $paymentHelper,
        array $data = []
    ) {
        $this->_paymentHelper = $paymentHelper;
        $this->_coreRegistry = $registry;
        $this->httpContext = $httpContext;
        parent::__construct($context, $data);
        $this->_isScopePrivate = true;
    }

    /**
     * @return void
     */
    protected function _prepareLayout()
    {
        $this->pageConfig->getTitle()->set(__('Order # %1', $this->getOrder()->getRealOrderId()));
        $infoBlock = $this->_paymentHelper->getInfoBlock($this->getOrder()->getPayment(), $this->getLayout());
        $this->setChild('payment_info', $infoBlock);
    }

    /**
     * @return string
     */
    public function getPaymentInfoHtml()
    {
        return $this->getChildHtml('payment_info');
    }

    /**
     * Retrieve current order model instance
     *
     * @return \Magento\Sales\Model\Order
     */
    public function getOrder()
    {
        return $this->_coreRegistry->registry('current_order');
    }

2 Answers 2

3

In order to ,get a registry variable then you should register that variable.

So. you should add $this->_coreRegistry->register('current_order',$order ) at getOrder() function.

So you need some change at getOrder()

  public function getOrder()
    {
        $data = $this->getRequest()->getParams('id');
        return $order = $this->order->loadByIncrementId($data);

    }

to

  public function getOrder()
    {
        $data = $this->getRequest()->getParams('id');
         $order = $this->order->loadByIncrementId($data);
         /* if aleady exits then remove and set new once */
         if($this->_coreRegistry->registry('current_order')){

             $this->_coreRegistry->unregister('current_order');
         }
         $this->_coreRegistry->register('current_order',$order );
        return $order;   
    }
4
  • it gives error : "current_order" already exists
    – Ishu
    Commented Feb 22, 2017 at 7:42
  • Again 1 exception(s): Exception #0 (RuntimeException): Renderer for type "simple" does not exist.
    – Ishu
    Commented Feb 22, 2017 at 7:48
  • where you getting this error
    – Amit Bera
    Commented Feb 22, 2017 at 7:49
  • when i load this current order in registry and get order details then it produces this error.
    – Ishu
    Commented Feb 22, 2017 at 7:52
1

Resolved this issue: set these lines in your layout file:

<update handle="sales_order_item_renderers"/>
<update handle="sales_order_item_price"/>
<update handle="sales_order_info_links"/>
1
  • @marius. good intercept
    – Amit Bera
    Commented Feb 22, 2017 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.