Question

When a customer placed an order , We will place order in processing state. After that QC team will pack the order when the QC is completed then they will change the order status to QC Passed .

Now i want to show "SHIP" button on QC Passed state only. For remaining order status it won't be show. How can i implement this? enter image description here

Was it helpful?

Solution

app/code/SR/MagentoCommunity/etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Backend\Block\Widget\Context">
        <plugin name="remove_button_from_sales_veiw" type="SR\MagentoCommunity\Plugin\Widget\Context" sortOrder="1"/>
    </type>
</config>

app/code/SR/MagentoCommunity/Plugin/Widget/Context.php

<?php

namespace SR\MagentoCommunity\Plugin\Widget;

use Magento\Framework\Registry;

class Context
{
    /**
     * @var Registry
     */
    private $registry;

    /**
     * Context constructor.
     *
     * @param Registry $registry
     */
    public function __construct(
        Registry $registry
    ) {
        $this->registry = $registry;
    }

    /**
     * @param \Magento\Backend\Block\Widget\Context $subject
     * @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
     * @return mixed
     */
    public function afterGetButtonList(
        \Magento\Backend\Block\Widget\Context $subject,
        $buttonList
    ) {
        if ($subject->getRequest()->getFullActionName() == 'sales_order_view') {
            if ($this->getOrder() && ($this->getOrder()->getStatus() == 'pending')) {
                $buttonList->remove('order_ship');
            }
        }

        return $buttonList;
    }

    /**
     * Retrieve order model object
     *
     * @return \Magento\Sales\Model\Order
     */
    private function getOrder()
    {
        return $this->registry->registry('sales_order');
    }
}

Replace following condition to your condition :

if ($this->getOrder() && ($this->getOrder()->getStatus() == 'pending')) {

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top