Skip to main content

Hooks

The default behavior of Simpler Checkout is to exactly match the behavior of your PrestaShop. This affects coupons, discounts and/or available shipping methods.

If you want to modify the checkout behavior only for the customers using Simpler Checkout you can use the programmatic hooks offered by our plugin to dynamically update the behavior of the Simpler Checkout form.

Customizing available shipping methods

The actionFilterDeliveryOptionList action hook allows you to modify the shipping rates & methods available to customers using Simpler Checkout. It accepts the resolved delivery option list for the cart and should return the modified ones.

Example: Removing a shipping rate from Simpler

<?php
class MyCarrierConditionDisablerModule extends Module
{

public function install()
{
return parent::install() && $this->registerHook('actionFilterDeliveryOptionList');
}

public function hookActionFilterDeliveryOptionList($params)
{
$deliveryOptionList = $params['delivery_option_list'];

if(0 == date('w') || 6 == date('w')){ // sundays or saturdays
// find carrier in $deliveryOptionList, and remove it
}
}
}

Handling multiple store locations for Pickup in PrestaShop

Since the Prestashop built-in "Pickup from Store" carrier does not have this functionality! The goal of this section is to help them support a custom carrier that offers multiple pickup points for a single carrier

Hook: actionSimplerCheckoutStores

Description

This hook is triggered periodically by Simpler to sync store information for the "Pickup from Store" option. By using this hook, you can modify the response to include store IDs and details, which Simpler will present to the customer during checkout.

Example Code:

public function hookActionSimplerCheckoutStores($params)
{
if(isset($params['response'])){
$params['response']['title'] = 'Pickup from store';
$params['response']['shippingId'] = '1'; // Shipping option ID for pickup
$params['response']['stores'] = [
['id' => '1', 'title' => 'Stadiou 21, Athens'],
['id' => '2', 'title' => 'Tsimiski 12, Thessaloniki'],
];
}
}

Parameters:

  • $params['response']: The response array that will be returned to Simpler, containing store information.

Usage:

  • Use the stores array to send store IDs and addresses to Simpler, enabling the customer to choose a pickup location.

Hook: actionSimplerCheckoutSubmitOrder

The actionSimplerCheckoutSubmitOrder hook is triggered when an order is submitted through Simpler Checkout. In the context of handling multiple store locations, this hook can be used to retrieve the store ID of the selected pickup location, which is included in the $params['order_request']['pickup_store_id'].

Parameters

The hook provides the following parameters:

  • order (Order object, passed by reference): The order object that represents the submitted order. Developers can modify the order data directly through this parameter.
  • invoice (Array): An array containing invoice data associated with the order. This can be useful for modules that need to access or log invoice-specific information.
  • order_request (Array): An array containing additional data related to the order request, which can be used for further custom processing or logic.

Example Code:

public function hookActionSimplerCheckoutSubmitOrder($params)
{
if(isset($params['order_request']['pickup_store_id']) && !empty($params['order_request']['pickup_store_id'])){
$storeId = $params['order_request']['pickup_store_id'];
// You can now use the $storeId as required, such as storing it in a custom module
}
}

Usage:

  • Retrieve the store_id from $params['order_request']['pickup_store_id] and process it according to your module's requirements. This could involve storing it in a module designed to manage store data, like "Pickup Locations."

Retrieve Invoice data upon order submission

To retrieve invoice information, as it is not supported natively by PrestaShop, you can use the actionSimplerCheckoutSubmitOrder hook, as mentioned earlier.

Parameters

The hook provides the following parameters:

  • order (Order object, passed by reference): The order object that represents the submitted order. Developers can modify the order data directly through this parameter.
  • invoice (Array): An array containing invoice data associated with the order. This can be useful for modules that need to access or log invoice-specific information.
  • order_request (Array): An array containing additional data related to the order request, which can be used for further custom processing or logic.

Example Usage

Below is an example of how to use the actionSimplerCheckoutSubmitOrder hook in a module:

<?php
public function hookActionSimplerCheckoutSubmitOrder($params)
{
// Check if the 'order' parameter is set
if (isset($params['order'])) {
// Check if the 'invoice' parameter is set and not empty
if (isset($params['invoice']) && !empty($params['invoice'])) {
// Add invoice data to the order note for future reference
$params['order']->note = 'Invoice data: ' . json_encode($params['invoice']);
$params['order']->update(); // Save changes to the order object
}
}
}

Retrieve Box Now data upon order submission

For developers utilizing a custom Box Now module, the actionSimplerCheckoutSubmitOrder hook offers a method to retrieve locker information associated with an order after submission.

Parameters

The hook provides the following parameters:

  • order (Order object, passed by reference): The order object that represents the submitted order. Developers can modify the order data directly through this parameter.
  • invoice (Array): An array containing invoice data associated with the order. This can be useful for modules that need to access or log invoice-specific information.
  • order_request (Array): An array containing additional data related to the order request, which can be used for further custom processing or logic.

Example Usage

Below is an example demonstrating how to use the actionSimplerCheckoutSubmitOrder hook within a module:

<?php
public function hookActionSimplerCheckoutSubmitOrder($params)
{
// Verify if the 'order' parameter is available
if (isset($params['order'])) {
// Verify if the 'order_request' parameter is present and not empty
if (isset($params['order_request']) && !empty($params['order_request'])) {
// Ensure that the shipping method ID is set to 'BOX_NOW'
if (isset($params['order_request']['shipping_method_id'])
&& $params['order_request']['shipping_method_id'] == "BOX_NOW_ID") {
// Confirm that the 'box_now' parameter is available and not empty
if (isset($params['order_request']['box_now'])
&& !empty($params['order_request']['box_now'])) {
// Access and utilize locker data as needed
$locker_id = $params['order_request']['box_now']['locker_id'];
$name = $params['order_request']['box_now']['name'];
$address = $params['order_request']['box_now']['address'];
$postcode = $params['order_request']['box_now']['postcode'];
$latitude = $params['order_request']['box_now']['lat'];
$longitude = $params['order_request']['box_now']['lng'];

// Get order id
$order_id = isset($params['order']->id)?$params['order']->id:0;

// Implement custom processing with locker data here

}
}
}
}
}