0

I have created module to send email using mass actions, but it is showing 404 error.

etc/acl.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Magento_Backend::stores">
                    <resource id="Magento_Backend::stores_settings">
                        <resource id="Magento_Config::config">
                            <resource id="Vendor_MassEmailCustomers::massemailcustomers_configuration" title="Mass Email Customers Section" />
                        </resource>
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>

view/adminhtml/ui_components/sales_order_grid.xml

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <listingToolbar name="listing_top">
        <massaction name="listing_massaction">
            <action name="mass_email_rx">
                <settings>
                    <confirm>
                        <message translate="true">Are you sure to send Rx Missing Email to the selected customers?</message>
                        <title translate="true">Send Rx Missing Email</title>
                    </confirm>
                    <url path="massemailcustomers/email/rxSend"/>
                    <type>mass_email_rx</type>
                    <label translate="true">Send Rx Missing Email</label>
                </settings>
            </action>
            
        </massaction>
    </listingToolbar>
</listing>

etc/adminhtml/routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="massemailcustomers" frontName="massemailcustomers">
            <module name="Vendor_MassEmailCustomers" before="Magento_Backend" />
        </route>
    </router>
</config>

Conroller/Adminhtml/Email/RxSend.php

<?php

declare(strict_types=1);

namespace Vendor\MassEmailCustomers\Controller\Adminhtml\Email;

use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\Translate\Inline\StateInterface;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Backend\App\Action;
use Magento\Framework\Exception\LocalizedException;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory as SalesCollectionFactory;
use Vendor\MassEmailCustomers\Model\Config;
use Magento\Framework\App\Area;
use Magento\Sales\Model\Order;
use Magento\Framework\Exception\MailException;
use Magento\Backend\Model\View\Result\Redirect;

class RxSend extends Action
{
    /**
     * @var Filter
     */
    protected $filter;

    /**
     * @var salesCollectionFactory
     */
    protected $salesCollectionFactory;

    /**
     * @var CustomerCollectionFactory
     */
    protected $customerCollectionFactory;

    /**
     * @var Config
     */
    protected $config;

    /**
     * @var TransportBuilder
     */
    protected $transportBuilder;

    /**
     * @var StateInterface
     */
    protected $inlineTranslation;

    /**
     * @param Context $context
     * @param Filter $filter
     * @param Config $config
     * @param CustomerCollectionFactory $customerCollectionFactory
     * @param SalesCollectionFactory $salesCollectionFactory
     * @param TransportBuilder $transportBuilder
     * @param StateInterface $inlineTranslation
     */
    public function __construct(
        Context $context,
        Filter $filter,
        Config $config,
        CustomerCollectionFactory $customerCollectionFactory,
        SalesCollectionFactory $salesCollectionFactory,
        TransportBuilder $transportBuilder,
        StateInterface $inlineTranslation
    ) {
        $this->filter = $filter;
        $this->config = $config;
        $this->customerCollectionFactory = $customerCollectionFactory;
        $this->salesCollectionFactory = $salesCollectionFactory;
        $this->transportBuilder = $transportBuilder;
        $this->inlineTranslation = $inlineTranslation;
        parent::__construct($context);
    }

    /**
     * Execute action
     *
     * @return Redirect
     * @throws LocalizedException
     */
    public function execute()
    {
        var_dump("rx email to send");
    }
}

enter image description here

enter image description here

2
  • Clear your cahec and remove generated/*
    – Sohel Rana
    Nov 14 '21 at 2:57
  • Steps done so far (1) rm -rf generated/* (2) bin/magento s:d:c (3) bin/magento c:f (4) Removed browser cache and used incognito window, but still showing 404 error
    – ishaq
    Nov 15 '21 at 9:45
0

Please Run below command and check once

php bin/magento setup:di:compile

this will generates DI configuration and all missing classes that can be auto-generated

4
  • Done this many time still same 404 error
    – ishaq
    Nov 15 '21 at 9:46
  • make sure your rule has permission to access this controller Nov 15 '21 at 9:49
  • I have added acl.xml also, check my updated question.
    – ishaq
    Nov 15 '21 at 10:07
  • Don't know what was the issue behind it, but since I was using Bitnami VM so stopped the VM and started again and 404 error disappeared now and the code is working as expected.
    – ishaq
    Nov 15 '21 at 13:10
0

I think it because your controller did not return correct type. Controller should return type page Magento\Framework\Controller\ResultFactory if you want to use this url as a page.

if it's only a execute controller you can handle logic and return redirect to another page. DI Magento\Framework\Controller\Result\RedirectFactory and then return $this->resultRedirectFactory->create()->setPath('*/*/');

Hope it help

1
  • Thanks for your answer, but the issue was 404, and apparently it was related to the router before reaching to controller execute method. However, issue is resolved now after I restarted the Bitnami VM.
    – ishaq
    Nov 16 '21 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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