I am trying to customize extension by adding it to newsletter subscribers, and when I select/check subscribers and send email, I get error as the title suggests.


1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): An item needs to be selected. Select and try again.

Exception #0 (Magento\Framework\Exception\LocalizedException): An item needs to be selected. Select and try again.
<pre>#1 MageVision\MassEmailCustomers\Controller\Adminhtml\Email\MassSend->execute() called at [vendor/magento/framework/App/Action/Action.php:108]

I have added necessary classes to the PHP i think, my code is below


I assume its being thrown from line :119 $this->send($item);.

Can anyone please suggest me whats wrong here?

My XML file is:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="adminhtml.newslettrer.subscriber.grid.massaction">
                <argument name="options" xsi:type="array">
                    <item name="mass_email_customer" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Email to Customers</item>
                        <item name="url" xsi:type="string">massemailcustomers/email/massSend</item>
                        <item name="confirm" xsi:type="string" translate="true">Are you sure you want to send an email to the selected subscriber(s)?</item>

Reading your file, the send function does start by initiating inline translation and then at the end of the function terminate the inline translation. I assume you’re doing this to enable your email to be translated in your store locale.

To do this, the more conventional way is to use store emulation process.

Below is the code to trigger a store emulation.

  public function __construct(
        \Magento\Store\Model\App\Emulation $emulation,
    ) {
    $this->emulation->startEnvironmentEmulation(Store::DEFAULT_STORE_ID, Area::AREA_FRONTEND);
  • I absolutely and totally did not get you xD – nix Aug 2 '20 at 19:09
  • Thanks for your honesty, I updated my answer – Herve Tribouilloy Aug 2 '20 at 19:14
  • ah I see, but even implementing this won't help me with the error I am getting. When I check (subscribed) customer and from action I click Email to Customer I does not show how many records I selected, but in Sales or Customer tab, it does show me record, and also as the error suggests, somehow its sending an empty subscriber list to massSend.php file. – nix Aug 2 '20 at 19:19
  • Good shout, looks like your post data don’t go through. Will try to dig this tomorrow evening if still a problem at your end. – Herve Tribouilloy Aug 2 '20 at 20:32
  • Your controller should implement httppostinterface.. that could explain why your post data don’t go through. See magento.stackexchange.com/questions/253585/… – Herve Tribouilloy Aug 2 '20 at 20:37

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.