0

I want to send another email after pressing place order. But could not get the value entered by request param in observer. Here is my code

Mymodule\CheckoutCustom\etc\events.xml

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_model_service_quote_submit_before">
        <observer name="Mymodule_checkout_affter" instance="Mymodule\CheckoutCustom\Observer\EmailCc" />
    </event>
</config>

Mymodule\CheckoutCustom\Observer\EmailCc.php

use Magento\Framework\App\RequestInterface;
class EmailCc implements \Magento\Framework\Event\ObserverInterface
{
    protected $request;

    public function __construct(
        RequestInterface $request
    )
    {
        $this->request = $request;
    }

    /**
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {

        $emailCCfrontend = $this->request->getParam('checkout_email_cc');

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/templog.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info($emailCCfrontend);
    }
}

checkout_index_index.xml

    <body>
        <referenceBlock name="checkout.root">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shipping-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="shippingAddress" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="before-form" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="checkout_email_cc" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Magento_Ui/js/form/element/abstract</item>
                                                                    <item name="config" xsi:type="array">
                                                                        <item name="customScope" xsi:type="string">customCheckoutForm</item>
                                                                        <item name="template" xsi:type="string">ui/form/field</item>
                                                                        <item name="elementTmpl" xsi:type="string">ui/form/element/email</item>
                                                                    </item>
                                                                    <item name="provider" xsi:type="string">checkoutProvider</item>
                                                                    <item name="dataScope" xsi:type="string">customCheckoutForm.checkout_email_cc</item>
                                                                    <item name="label" xsi:type="string">Email CC</item>
                                                                    <item name="sortOrder" xsi:type="string">1</item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
0
use Magento\Framework\App\Request\Http;

class EmailCc implements \Magento\Framework\Event\ObserverInterface
{
private $request;
public function __construct(
        Http $request
    ) {
        $this->request = $request;

    }

public function execute(\Magento\Framework\Event\Observer $observer)
{

    $emailCCfrontend = $this->request->getParam('checkout_email_cc');
    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/templog.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info($emailCCfrontend);
}


}
1
  • Thanks for the answer but it doesn't get the value of checkout_email_cc. Do you have any more answers. – nhungo duc Dec 22 '20 at 8:30

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.