2

I have added a custom button in product edit page using product_form.xml like below :

app/code/Company/Module/view/adminhtml/ui_component/product_form.xml

<?xml version="1.0" encoding="UTF-8"?>

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="buttons" xsi:type="array">
            <item name="set-to-sold" xsi:type="string">Company\Module\Block\Adminhtml\Product\Edit\Button\SoldButton</item>
        </item>
    </argument>
</form>

app/code/Company/Module/Block/Adminhtml/Product/Edit/Button/SoldButton.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Brainvire\ProductType\Block\Adminhtml\Product\Edit\Button;

use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic;

class SoldButton extends Generic
{

    /**
     * @return array
     */
    public function getButtonData()
    {
    return [
        'label' => __('Diamond is SOLD'),
        'disabled' => true,
        'on_click' => sprintf("location.href = '%s';", $this->getUrl('producttype/product/sold')),                
        'class' => 'save primary',
        'sort_order' => 5,
    ]; 

    }
}

the button is added like below :

enter image description here

This is working perfectly. A button is added, and a confirm box is also displayed on button click. But now i want to add a popup and call custom phtml in that popup on button click.

Any ideas how to proceed. Thanks in advance.

13
  • You can add a custom phtml file in which you can create your popup and popup trigger event, and add that custom phtml file using layout file for only product add/edit page before body end. Commented May 28, 2019 at 6:02
  • how to add that phtml file using layout ? Commented May 28, 2019 at 6:03
  • Maybe you can refer this : magento.stackexchange.com/a/205780/51548 Commented May 28, 2019 at 6:08
  • I think you can not call phtml file in alert widget popup. there is no parameter to set template see here devdocs.magento.com/guides/v2.3/javascript-dev-guide/widgets/… Commented May 28, 2019 at 6:14
  • @ChiragPatel - I do not want to call phtml inside the alert widget popup. I want to simply open a popup on button click. Commented May 28, 2019 at 6:16

0

Your Answer

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

Browse other questions tagged or ask your own question.