Skip to main content

How to

Send an order note to an external system

<?php

namespace MyVendor\MyModule\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Simpler\Checkout\Event\Event;
use Simpler\Checkout\Event\Submit\AfterOrderNoteCreatedEvent;

class MyObserver implements ObserverInterface
{
public function execute(Observer $observer)
{
/** @var AfterOrderNoteCreatedEvent $event */
$event = $observer->getData(Event::KEY);

if ($note = $event->getNote()){
$orderId = $event->getOrder()->getEntityId();
// Todo: Send $note to external system for order with id $orderId.
}
}
}

Expose available pickup locations

<?php

namespace MyVendor\MyModule\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Simpler\Checkout\Api\Data\PickupLocationInterfaceFactory;
use Simpler\Checkout\Event\PickupLocationsRequestedEvent;
use Simpler\Checkout\Event\Event;

class Foo implements ObserverInterface
{
/**
* @var PickupLocationInterfaceFactory
*/
private $factory;

public function __construct(PickupLocationInterfaceFactory $factory)
{
$this->factory = $factory;
}

public function execute(Observer $observer)
{
/** @var PickupLocationsRequestedEvent $event */
$event = $observer->getData(Event::KEY);

$locations = $event->getPickupLocations();

// Todo: Fetch stored locations instead of hardcoding them.
$location1 = $this->factory->create()->setId('foo')->setName('Foo');
$location2 = $this->factory->create()->setId('bar')->setName('Bar');

$locations->addPickupLocation($location1);
$locations->addPickupLocation($location2);
}

}

Get the store pickup id

<?php

namespace MyVendor\MyModule\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Simpler\Checkout\Event\Event;
use Simpler\Checkout\Event\Submit\AfterShippingMethodAddedEvent;

class MyObserver implements ObserverInterface
{
public function execute(Observer $observer)
{
/** @var AfterShippingMethodAddedEvent $event */
$event = $observer->getData(Event::KEY);

$storeID = $event->getPickupStoreId();
// Todo: Store id for later usage.
}
}

Get invoicing data

<?php

namespace MyVendor\MyModule\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Simpler\Checkout\Event\Event;
use Simpler\Checkout\Event\Submit\AfterCustomerInvoiceCreated;

class MyObserver implements ObserverInterface
{
public function execute(Observer $observer)
{
/** @var AfterCustomerInvoiceCreated $event */
$event = $observer->getData(Event::KEY);

$invoice = $event->getInvoice();
// $invoice->getCompanyName();
// $invoice->getActivity();
// $invoice->getTaxId();
// $invoice->getTaxAuthority();
// $invoice->getCompanyAddress();
}
}