Handling LemonStand events
Handling LemonStand events allows you to override or extend standard functionality of the application in many ways. For example, you can extend existing LemonStand models (customers, products etc), customize visitors shopping experience, execute some code before a front-store page is displayed and do other things. The list of events is growing constantly. Please contact us if you need to handle some event which is not listed below.
Handling events
To handle LemonStand events you need to develop a simple module. The process of developing LemonStand modules is described in this article. A simplest module can have only two files - the module information class and the module version information file. Event handlers can be defined in the module information class. To subscribe to system events use the subscribeEvents() method of the module information class. For example:
public function subscribeEvents()
{
Backend::$events->addEvent('shop:onNewOrder', $this, 'on_new_order');
}
The code subscribes a module information class to the shop:onNewOrder event. When it is triggered the on_new_order method (specified in the third parameter) will be called. This method (event handler) must be defined in the module information class. There are no special rules for event handler function names. Below is an example of the event handler code:
public function on_new_order($order_id)
{
// Find the order
$order = Shop_Order::create()->find_by_id($order_id);
if ($order)
{
// Do something with the order object
}
}Invoking custom module events from standard LemonStand pages
In some cases you will need to call an event handler in your module from a standard LemonStand page. The custom event solution allows you to trigger any event on some LemonStand pages in order to handle them in your custom module. The feature is supported in all back-end controllers, but implementation for the Products and Orders controllers differs from implementation in other controllers.
To call an event from your module, trigger a standard AJAX request to the onCustomEvent handler. In the extra POST fields specify the event name you want to be invoked on the server. The event handler should accept 2 parameters - the controller object and the record identifier, which you can use for loading the object from the database. For the Products and Orders controllers the second parameter is the product and order object. Thus, on the Edit Order page the second parameter will be the Shop_Order object, and on the Edit Product page the second parameter will be the Shop_Product object. Example:
// Button on the Order Preview page, which opens a popup window
// with a content provided by the Subscriptions module
<?= backend_ctr_button('Generate subscription invoice', 'generate_subscription_invoice',
array('href'=>'#', 'onclick'=>"new PopupForm(
'onCustomEvent', {
ajaxFields: {custom_event_handler: 'subscriptions:onGenerateInvoice'}
}); return false;
")) ?>
// Event subscription in the Subscriptions module
public function subscribeEvents()
{
Backend::$events->addEvent('subscriptions:onGenerateInvoice', $this, 'generate_order_invoice');
}
function generate_order_invoice($controller, $order)
{
$controller->renderPartial(PATH_APP.'/modules/subscriptions/partials/_generate_invoice.htm');
}List of LemonStand events
Below you will find list of events triggered by different LemonStand modules.
Core module events
Events provided by the LemonStand Core module.
- core:onSendEmail event - allows to override the email sending feature.
- onDeleteEmailTemplate event - triggered when a user tries to delete an email template.
- core:onInitialize event - this event is triggered when the system initialization finishes.
- core:onUninitialize event - this event is triggered when the script execution finishes.
- core:onProcessImage event - allow to process images with third-party image manipulation tools.
- core:onBeforeDatabaseQuery event - triggered before a SQL query is sent to the database.
- core:onAfterDatabaseQuery event - triggered after a SQL query is executed by the database.
User events - extending the user model, user-related user interface in the Administration Area
- core:onExtendUserModel event - allows to add new columns to the user model.
- core:onExtendUserForm event - allows to add new fields to the Create/Edit User form.
- core:onGetUserFieldOptions event - allows to populate custom user form drop-down, radio- and checkbox list fields with options.
CMS module events
Events provided by the LemonStand CMS module.
- cms:onBeforeDisplay event - triggered before a front-store page is displayed.
- cms:onAfterDisplay event - triggered after a front-end page is displayed.
- cms:onApplyPageSecurity event - allows to perform security check before a page is displayed.
- cms:onBeforeHandleAjax event - triggered before AJAX requests are processed.
- cms:onAfterHandleAjax event - triggered after AJAX requests are processed.
- cms:onPageNotFound - triggered when LS is unable to find a page to display, allows to bypass LemonStand's default 404 page.
- cms:onGetCustomerGroupId event - allows to override the result of the Cms_Controller::get_customer_group_id() method.
- cms:onBeforeRoute event - allows to override the default CMS routing process.
- cms:onGetActiveTheme event - triggered when finding the currently active CMS theme.
CMS page events - extending the page model, page-related user interface in the Administration Area.
- cms:onExtendPageModel event - allows to add new fields in the CMS page model.
- cms:onExtendPageForm event - allows to add new fields to the Create/Edit Page form.
- cms:onGetPageFieldOptions event - allows to populate custom CMS page form drop-down, radio- and checkbox list fields with options.
- cms:onDisplayPageForm event - allows to load extra CSS or JavaScript files on the Create/Edit Page page.
- cms:onDeletePage event - triggered when a user tries to delete a page in the Administration Area.
- cms:onGetPageNavigationVisibility event - allows to hide a page from automatically generated navigation menus.
- cms:onExtendPagesToolbar event - allows to add new buttons to the toolbar on the CMS/Pages page.
- cms:onGetPageContent event - triggered when fetching CMS page content, allows to alter it.
CMS partial events - extending the partial model, partial-related user interface in the Administration Area.
- cms:onExtendPartialModel event
- cms:onExtendPartialForm event - allows to add new fields to the Create/Edit Partial form.
- cms:onGetPartialFieldOptions event - allows to populate custom CMS partial form drop-down, radio- and checkbox list fields with options.
- cms:onExtendPartialsToolbar event - allows to add new buttons to the toolbar on the CMS/Partials page.
- cms:onDeletePartial event - triggered when a user tries to delete a partial in the Administration Area.
- cms:onGetPartialContent event - triggered when fetching CMS partial's content, allows to alter it.
CMS template/layout events - extending the template model, template-related user interface in the Administration Area.
- cms:onExtendTemplateModel event - allows to add new fields in the CMS template model.
- cms:onExtendTemplateForm event - allows to add new fields to the Create/Edit Template form.
- cms:onGetTemplateFieldOptions event - allows to populate custom CMS template/layout form drop-down, radio- and checkbox list fields with options.
- cms:onExtendTemplatesToolbar event - allows to add new buttons to the toolbar on the CMS/Templates page.
- cms:onDeleteTemplate event - triggered when a user tries to delete a template in the Administration Area.
- cms:onGetTemplateContent event - triggered when fetching CMS template/layout content, allows to alter it.
Shop module events
Events provided by the LemonStand Shop module. Some events listed below are described in the Extending existing models article.
Order events - extending order model, handling order status change, handling order information change, extending order-related user interface in the Administration Area.
- shop:onExtendOrderModel event - allows to extend order model. You can add new fields to the order model in the event handler.
- shop:onExtendOrderForm event - allows to add new fields to the Create/Edit Order form in the Administration Area.
- shop:onGetOrderFieldOptions event - allows to populate custom order form drop-down, radio- and checkbox list fields with options.
- shop:onNewOrder event - triggered on new order.
- shop:onOrderBeforeCreate event - this event is triggered before new order is placed.
- shop:onOrderError event - allows to process an order error.
- shop:onOrderBeforeStatusChanged event - triggered before an order changed its status.
- shop:onOrderStatusChanged event - triggered just after an order changed its status.
- shop:onBeforeOrderInternalStatusMessageSent - triggered before sending an order status change notification.
- shop:onExtendOrderPreviewToolbar event - allows to add new buttons to the toolbar above the Order Preview form.
- shop:onExtendOrderPreviewTabs event - allows you to add custom tabs to the Order Preview page.
- shop:onExtendOrdersToolbar event - allows to add new buttons to the toolbar above the order list in the Administration Area.
- shop:onDisplayOrdersPage event - allows to load extra CSS or JavaScript files on all order-related pages in the Administration Area.
- shop:onBeforeOrderRecordCreate event - triggered bafore an order record is saved to the database.
- shop:onOrderBeforeUpdate event - triggered before an order record is updated in the database.
- shop:onOrderStockChange event - fires before LemonStand updates inventory for products of a specific order.
- shop:onOrderAfterDelete event - triggered after an order has been deleted.
- shop:onOrderMarkedDeleted event - triggered after an order has been marked as deleted.
- shop:onOrderRestored event - triggered after a previously deleted order has been restored.
- shop:onConfigureOrdersPage - triggered when the Orders page is loaded, allows to configure the Orders page.
Order item events - extending order items, processing order item updates
- shop:onExtendOrderItemModel event - allows to add new columns to the order item model.
- shop:onExtendOrderItemForm event - allows to add custom fields to the Create/Edit Order Item form.
- shop:onOrderItemAdded event - triggered after an order item is added to an order.
- shop:onOrderItemUpdated event - triggered when an order item is updated.
- shop:onOrderItemDeleted event - triggered when an item is deleted from an order.
- shop:onGetOrderItemFieldOptions event - allows to populate custom order item form drop-down, radio- and checkbox list fields with options.
- shop:onGetOrderItemDisplayDetails event - allows to display custom information about an order item in the Administration Area.
Customer events - extending the customer model and customer-related user interface in the Administration Area
- shop:onExtendCustomerModel event - allows to extend customer model. You can add new fields to the customer model in the event handler.
- shop:onExtendCustomerForm event - allows to add new fields to the Create/Edit Customer form in the Administration Area.
- shop:onGetCustomerFieldOptions event - allows to populate custom customer form drop-down, radio- and checkbox list fields with options.
- shop:onExtendCustomerPreviewToolbar event - allows to add new buttons to the toolbar on the Shop/Customer/Preview page.
- shop:onDisplayCustomersPage event - allows to load extra CSS or JavaScript files on all customer-related pages in the Administration Area.
- shop:onCustomerUpdated event - triggered after a customer object has been updated.
- shop:onCustomerCreated event - triggered after a new customer has been created.
- shop:onAuthenticateCustomer event - allows to implement custom authentication scenarios.
- shop:onExtendCustomerGroupModel event - allows to extend customer group model. You can add new fields to the customer group model in the event handler.
- shop:onExtendCustomerGroupForm event - allows to add new fields to the Create/Edit Customer Group form in the Administration Area.
- shop:onGetCustomerGroupFieldOptions event - allows to populate custom customer group form drop-down, radio- and checkbox list fields with options.
Product events - extending the product model, product-related user interface in the Administration Area, handling file uploads on the Product Details page on the front-end website.
- shop:onExtendProductModel event - allows extend the product model with new fields.
- shop:onExtendProductForm event - allows to add new fields to the Create/Edit Product form.
- shop:onGetProductFieldOptions event - allows to populate custom product form drop-down, radio- and checkbox list fields with options.
- shop:onDisplayProductForm event - allows to load extra CSS or JavaScript files on the Create/Edit Product page.
- shop:onDisplayProductList event - allows to load extra CSS or JavaScript files on the Product List page.
- shop:onExtendProductsToolbar event - allows to add new buttons to the Product List toolbar.
- shop:onBeforeProductFileAdded event - triggered before file is added to the product on the Product Details page.
- shop:onAfterProductFileAdded event - triggered after a file has been uploaded to a product on the product details page.
- shop:onPreProcessProductCustomData event - allows to update product custom data fields before product is added to the cart.
- shop:onConfigureProductsController event - allows to load extra CSS or JavaScript files on all product-related pages in the Administration Area.
- shop:onProductOutOfStock event - triggered when a product goes out of stock.
- shop:onGetProductPriceNoTax event - allows to change the product price.
Product group events - extending the product group model, product group related user interface in the Administration Area.
- shop:onExtendCustomGroupModel event - allows to add new columns to the product group model.
- shop:onExtendCustomGroupForm event - allows to add new columns to the product group model.
- shop:onGetCustomGroupFieldOptions event - allows to populate custom product group form drop-down, radio- and checkbox list fields with options.
Extra option events - extending the product extra option model, extra option-related user interface in the Administration Area.
- shop:onExtendExtraOptionModel event - allows to add new columns to the product extra option model.
- shop:onExtendExtraOptionForm event - allows to add custom fields to the Create/Edit Extra Option form.
- shop:onGetExtraOptionFieldOptions event - allows to populate custom extra option form drop-down, radio- and checkbox list fields with options.
- shop:onGetProductExtraPrice - allows to overload a product extra's price.
Product option events - extending the product option model, option-related user interface in the Administration Area.
- shop:onExtendOptionModel event - allows to add new columns to the product option model.
- shop:onExtendOptionForm event - allows to add custom fields to the Create/Edit Option form.
- shop:onGetOptionFieldOptions event - allows to populate custom option form drop-down, radio- and checkbox list fields with options.
Product type events -extending the product type model, product type related user interface in the Administration Area .
- shop:onExtendProductTypeModel event - allows to extend the product type model. You can add new fields to the product type model in the event handler.
- shop:onExtendProductTypeForm event - allows to add custom fields to the Create/Edit Product Type form.
- shop:onGetProductTypeFieldOptions event - allows to populate custom product type form drop-down, radio- and checkbox list fields with options.
Product review events -extending the product review model, product review related user interface in the Administration Area .
- shop:onExtendProductReviewModel event - allows to extend the product review model. You can add new fields to the product review model in the event handler.
- shop:onExtendProductReviewForm event - allows to add new fields to the Product Review forms in the Administration Area (if implemented).
- shop:onProductReviewBeforeCreate event - triggered before a new product review record is created.
- shop:onProductReviewAfterCreate event - triggered after a new product review record is created.
Category events - extending the product category model and the category-related user interface in the Administration Area
- shop:onExtendCategoryModel event - allows extend the product category model with new fields.
- shop:onExtendCategoryForm event - allows to add new fields to the Create/Edit Category form.
- shop:onGetCategoryFieldOptions event - allows to populate custom category form drop-down, radio- and checkbox list fields with options.
Manufacturer events - extending the manufacturer model and manufacturer-related user interface in the Administration Area
- shop:onExtendManufacturerModel event - allows to extend the manufacturer model
- shop:onExtendManufacturerForm event - allows to add new fields to the Create/Edit Manufacturer form.
- shop:onGetManufacturerFieldOptions event - allows to populate custom manufacturer form drop-down, radio- and checkbox list fields with options.
Shopping cart item events - extending the shopping cart item model, handling shopping cart updates
- shop:onGetCartItemPrice event - allows to override a shopping cart item price.
- shop:onUpdateCartItemPrice event - allows to update a default shopping cart item price.
- shop:onBeforeAddToCart event - - this event is triggered before a product is added to the cart.
- shop:onAfterAddToCart event - triggered when a product is added to the shopping cart.
- shop:onBeforeRemoveFromCart event - triggered before an item is removed from the shopping cart.
- shop:onAfterRemoveFromCart event - is triggered after a product has been removed from the cart.
- shop:onBeforeSetCartQuantity event - triggered before a product quantity in the cart is changed.
- shop:onAfterSetCartQuantity event - triggered after a product quantity in the cart has been changed.
Invoice events - enabling the invoice support, processing invoice items
- shop:onExtendOrderInvoicesToolbar event - allows to add new buttons to the toolbar on the Invoices tab on the Order Preview page.
- shop:onNewInvoiceItemCopy event - allows to update an order item in a new invoice, when the invoice is created manually in the Administration Area.
- shop:onInvoiceSystemSupported event - allows to enable the invoice support.
- shop:onOrderSupportsInvoices event - allows to enable the invoice support for a specific order.
- shop:onAutomatedBillingSupported event - triggered when checking if automated billing is supported.
Shipping method events - altering the shipping cost, etc.
- shop:onUpdateShippingQuote event - allows to override shipping cost calculated by a shipping module.
- shop:onFilterShippingOptions event - allows to filter the shipping option list before it is displayed on the checkout pages.
- shop:onBeforeShippingQuote - allows to override shipping parameters before being sent to a shipping method.
Product search events - extending the product search
- shop:onRegisterProductSearchEvent event - allows to register custom product search extension functions.
Reporting events - extending the reports
- shop:onExtendReportFilters - allows to filter the order report and graph data by your own parameters in the Reports area.
List of undocumented events
Documentation for the following events will be added later.
Shop module
- shop:onBeforeOrdersRssExport
- shop:onCustomerAfterDelete
- shop:onExtendCustomerPreviewTabs
- shop:onExtendOrderPaymentTransactionsToolbar
- shop:onExtendOrderPreviewHeader
- shop:onExtendOrderStatusForm
- shop:onExtendOrderStatusModel
- shop:onGetOrderStatusFieldOptions
- shop:onGetOrderStatusFieldState
- shop:onExtendProductPreviewHeader
- shop:onExtendProductPreviewTabs
- shop:onExtendProductPreviewToolbar
- shop:onGetCategoryProductSortingQuery
- shop:onGetOrderFieldState
- shop:onGetProductFieldState
- shop:onGetProductSortColumns
- shop:onOrderCopyBillingAddress
- shop:onPrepareProductListData
- shop:onAfterOrderRecordFetch
Core module
- core:onAfterSoftwareUpdate
- core:onAfterSoftwareUpdateRequest
- core:onBeforeArchiveCreate
- core:onBeforeArchiveRestore
- core:onBeforeDatabaseConnect
- core:onBeforeFormRecordCreate
- core:onBeforeFormRecordDelete
- core:onBeforeFormRecordUpdate
- core:onBeforeFormRender
- core:onBeforeFormRenderPreview
- core:onBeforeListExport
- core:onBeforeListRecordDisplay
- core:onBeforeSoftwareUpdate
- core:onBeforeSoftwareUpdateRequest
- core:onFileBeforeCreate
- onFrontEndLogin
- onLogin
CMS module
- cms:onEvaluateCode
- cms:onBeforeTrackingCodeInclude
- cms:onGetPageBlockContent
- cms:onAfterRenderPartial
- cms:onBeforeDataExport
- cms:onBeforeDataImport
- cms:onBeforeRenderPartial
- cms:onListPageEditorSidebarTabs
- cms:onPreparePageListData
- cms:onPreparePartialListData
- cms:onPrepareTemplateListData
Backend module
- backend:onBeforeRemoteEvent
- backend:onBeforeRenderPage
- backend:onBeforeRenderPartial
- backend:onControllerReady
Next: shop:onExtendCustomerModel event
Previous: Using module access points
Return to Developing LemonStand modules

