Magento 2: how can Override vendor\magento\module-sales\Block\Adminhtml\Order\View.php to remove/disable “Ship” button
Domanda
To Disable/Remove “ship” Button from sales->order->view (click) -> Ship
I commented in core file vendor\magento\module-sales\Block\Adminhtml\Order\View.php
below code .
if ($this->_isAllowedAction(
'Magento_Sales::ship'
) && $order->canShip() && !$order->getForcedShipmentWithInvoice()
) {
$this->addButton(
'order_ship',
[
'label' => __('Ship'),
'onclick' => 'setLocation(\'' . $this->getShipUrl() . '\')',
'class' => 'ship'
]
);
}.
now how can i ovveride block to remove this function
Soluzione
Please try to create your custom module to override sales block. also, please check with below url which is very helpful to you how to override
https://webkul.com/blog/overriding-rewriting-classes-magento2/
and add block with extends
<?php
namespace Vendorname\Modulename\Block\Adminhtml\Order;
use Magento\Framework\View\Element\Template;
class View extends Magento\Sales\Block\Adminhtml\Order\View {
public function functionname() // which have default in Magento\Sales\Block\Adminhtml\Order\View
{
return "Override Text";
}
}
Altri suggerimenti
To remove ship
button in admin order view page
app/code/Vendor/Module/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\Button\Toolbar">
<plugin name="remove_ship_button" type="Vendor\Module\Plugin\RemoveButton" />
</type>
</config>
app/code/Vendor/Module/Plugin/RemoveButton.php
<?php
namespace Vendor\Module\Plugin;
class RemoveButton
{
public function beforePushButtons(
\Magento\Backend\Block\Widget\Button\Toolbar\Interceptor $subject,
\Magento\Framework\View\Element\AbstractBlock $context,
\Magento\Backend\Block\Widget\Button\ButtonList $buttonList
) {
$this->_request = $context->getRequest();
if($this->_request->getFullActionName() == 'sales_order_view'){
$buttonList->remove('order_ship');//Button id
}
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange