-1

I created this button:

medienshop-dev/magento/app/code/UV/Bestellung/Plugin/Button.php

<?php

namespace UV\Bestellung\Plugin;

class Buttons
{
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'){
        #$url = $subject->getUrl('bestellschein/order/custom');
        $url = "";
        $buttonList->add(
            'bestellschein',
            ['label' => __('Bestellschein'), 'onclick' => 'how to call PHP?', 'class' => 'reset'],
            -1
        );
    }
}
}

?>

The button is working but I don't know how to call a controller when the button is clicked. It should print the package slip of an order.

I would like to call this one:

/magento/app/code/UV/Bestellung/Model/Order/Pdf/Shipment.php

Any suggestion how to do that? Thanks!

2
  • Use Ajax, that's what you need. Commented Apr 12, 2018 at 8:14
  • can you show me an example? Commented Apr 12, 2018 at 8:14

1 Answer 1

0
$url = $subject->getUrl('your/custom/url');
$buttonList->add(
    'bestellschein',
    ['label' => __('Bestellschein'), 'onclick' => 'window.location="'.$url.'";', 'class' => 'reset'],
    -1
);
3
  • what would the URL for "/magento/app/code/UV/Bestellung/Model/Order/Pdf/Shipment.php" ? Commented Apr 12, 2018 at 8:27
  • @L.Klmn this is Model class, it never has URL. You need to look into that Bestellung module for right controller. Commented Apr 12, 2018 at 8:34
  • Ah when I create a route I can go for getUrl('frontname/model/order/pdf/shipment'); :-) Commented Apr 12, 2018 at 8:37

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