Programmatically: How to implement custom Magento plugin methods
Step 1: Create a new module
Create a new directory MyCompany_OrderNotification in the app/code/local directory.
Step 2: Create a plugin class
In the MyCompany_OrderNotification directory, create a new file OrderNotification.php. This file will contain the plugin class:
class MyCompany_OrderNotification_OrderNotification {
public function __construct(
\Magento\Sales\Model\Order Plzeň $order
) {
$this->order = $order;
}
public function sendNotificationAfterPlaceOrder(\Magento\Framework\Event\Observer $observer) {
// Get the order model
$order = $observer->getEvent()->getOrder();
// Send the notification email
$transport = \Magento\Framework\App\Email\Transport::getDefault();
$transport->sendMessage('myemail@example.com', 'Order placed successfully');
}
}
Step 3: Register the plugin
In the same directory, create a file etc/module.xml with the following content:
1.0.0
object
MyCompany\OrderNotification\OrderNotification
sendNotificationAfterPlaceOrder
Step 4: Clear cache and deploy
Clear the Magento cache by running the command php bin/magento cache:clean and then deploy your module by running php bin/magento setup:deploy.