Skip to main content

Compatibility with Custom Modules

Supporting Custom BoxNow Modules

BoxNow shipping methods

In order for Simpler to recognize your shipping method as a BoxNow method and show the locker selection widget, you will have to listen to the simpler_checkout_around_create_shipping_option event, and set the shipping option's type to BOX_NOW.

Create an observer

src/Observer/FlagBoxNowMethod.php
namespace MyModule\CustomBoxNowModule\Observer;

use Magento\Framework\Event\{Observer,ObserverInterface};

class FlagBoxNowMethod implements ObserverInterface
{

public function execute(Observer $observer)
{
$method = $observer->getData('shipping_method');
if ($method->getCarrierCode() == 'my_custom_boxnow_method_slug') {
$option = $observer->getData('shipping_option');
$option->setType("BOX_NOW");
}
}

}

Connect your observer to the Simpler event

src/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="simpler_checkout_around_create_shipping_option">
<observer name="my_custom_observer" instance="MyModule\CustomBoxNowModule\Observer\FlagBoxNowMethod" shared="true" />
</event>
</config>

Getting the selected locker

During the order submission, the customer will select their desired locker in the Simpler Checkout window and it will be stored alongside their order on Simpler. Since you will need the selected locker id during the order submission, you can create a second observer that will fetch the locker information that you can then store on the finalized order.

Create the observer

src/Observer/SetBoxNowLockerId.php
namespace MyModule\CustomBoxNowModule\Observer;

use Magento\Framework\Event\{Observer,ObserverInterface};

class SetBoxNowLockerId implements ObserverInterface
{
public function execute($observer Observer)
{
$order = $observer->getData('order');
$request = $observer->getData('request');

if ($bn = $request->getBoxNow()) {
$order->setBoxNowLockerId($bn->getLockerId());
$order->setBoxNowLockerAddress($bn->getAddress());
}
}
}

Connect your observer to the Simpler event

src/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="simpler_checkout_after_order_placed">
<observer name="my_custom_order_observer" instance="MyModule\CustomBoxNowModule\Observer\SetBoxNowId" shared="true" />
</event>
</config>