Skip to main content

Customize Behaviour

Custom BoxNow Modules

Simpler offers built-in support for official BoxNow modules, but you might have opted for a different solution. You can extend Simpler's behaviour to support your BoxNow module by implementing the following steps.

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>

Business Invoices

You can configure Simpler to allow shoppers to supply their business information for invoicing purposes during checkout. If you opt to do this, you will have to create an observer to collect the invoicing information and supply it to your own models.

You can do so by creating an observer for the simpler_checkout_after_customer_invoice_created 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_customer_invoice_created">
<observer name="my_custom_order_observer" instance="MyModule\Invoices\Observer\CollectSimplerInvoiceDataObserver" shared="true" />
</event>
</config>
src/Observer/CollectSimplerInvoiceDataObserver.php
namespace MyModule\Invoices\Observer;

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

class CollectSimplerInvoiceDataObserver implements ObserverInterface
{
public function execute($observer Observer)
{
$order = $observer->getData('order');
/** @var \Simpler\Checkout\Api\Data\OrderInvoiceInterface $invoiceData */
$invoiceData = $observer->getData('invoice_data');

if ($invoiceData) {
$companyName = $invoiceData->getCompanyName()
$taxId = $invoiceData->getTaxId();
$companyAddress = $invoiceData->getCompanyAddress();
// your implementation to store the data here
}
}
}

Custom Addons Integration

If your store offers additional services such as gift wrapping, carbon offset, or insurance, you can declare them through the Simpler Checkout API using custom addons.

To integrate these addons in Magento, you need to implement two observers in your module. These observers will be triggered during the checkout flow to both:

  • Declare available addons during the /quote request.
  • Process selected addons during the /submit request.

Events

The Simpler module dispatches two events that allow you to extend the quote and order data:

Event NameDescription
simpler_checkout_collect_addonsFired during quote collection. Use this to declare available addons.
simpler_checkout_before_order_placedFired before the order is saved. Use this to read selected addons.

Registering Observers

In your module’s etc/events.xml file, register your observers as follows:

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_before_order_placed">
<observer name="add_addons_to_order" instance="Your\Namespace\Observer\SimplerBeforeOrderPlacedObserver" shared="true" />
</event>
<event name="simpler_checkout_collect_addons">
<observer name="add_addons_to_quote" instance="Your\Namespace\Observer\SimplerCollectAddonsObserver" shared="true" />
</event>
</config>

Declaring Available Addons

Create an observer that listens to the simpler_checkout_collect_addons event and declares the addons your store supports:

src/Observer/SimplerCollectAddonsObserver.php
namespace Your\Namespace\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Simpler\Checkout\Api\Data\Addons\AddonInterfaceFactory;
use Simpler\Checkout\Api\Data\Addons\AddonOptionInterfaceFactory;
use Simpler\Checkout\Helper\AddonType;

class SimplerCollectAddonsObserver implements ObserverInterface
{
protected $addonFactory;
protected $addonOptionFactory;

public function __construct(
AddonInterfaceFactory $addonFactory,
AddonOptionInterfaceFactory $addonOptionFactory
) {
$this->addonFactory = $addonFactory;
$this->addonOptionFactory = $addonOptionFactory;
}

public function execute(Observer $observer)
{
$magentoQuote = $observer->getEvent()->getData('magento_quote');
$simplerQuote = $observer->getEvent()->getData('simpler_quote');

// Create a new addon (e.g. Gift Wrap)
$addon = $this->addonFactory->create();
$addon->setType(AddonType::GIFT_WRAP);
$addon->setSupportMessage(true); // Allow user to enter a message

// Define only one option for gift wrapping
$option = $this->addonOptionFactory->create();
$option->setId('wrap1'); // Set your option_id
$option->setNetCents(500);
$option->setTaxCents(100);
$option->setTotalCents(600);

$addon->addOption($option); // Add this option to addon
$simplerQuote->addAddon($addon); // Add this addon to response
}
}

Processing Selected Addons

When the user completes their order, Simpler will send the selected addon(s) as part of the /submit request. You can capture these and apply custom logic before the order is placed.

Example observer for simpler_checkout_before_order_placed:

src/Observer/SimplerBeforeOrderPlacedObserver.php
namespace Your\Namespace\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Simpler\Checkout\Api\Data\Addons\SelectedAddonInterfaceFactory;
use Simpler\Checkout\Helper\AddonType;

class SimplerBeforeOrderPlacedObserver implements ObserverInterface
{
protected $selectedAddonFactory;

public function __construct(
SelectedAddonInterfaceFactory $selectedAddonFactory
) {
$this->selectedAddonFactory = $selectedAddonFactory;
}

public function execute(Observer $observer)
{
$quote = $observer->getEvent()->getData('quote');
$request = $observer->getEvent()->getData('request');

if ($addons = $request->getAddons()) {
foreach ($addons as $addon) {

// Check if addon type is GIFT_WRAP
if ($addon->getType() === AddonType::GIFT_WRAP) {

// Check if selected option_id equals 'wrap1'
if ($addon->getOptionId() == 'wrap1') {

// Add your data to the quote to be collected by your collector
$quote->setData('custom_gift_wrap_fee_amount', 100);

// Save the message if exists
if ($message = $addon->getMessage()) {
// Your code
}
}
}
}
}
}
}