Our EE Addons have Moved!
Our ExpressionEngine Add-ons have been acquired by EE Harbor. Head over there for documentation, info and support.
Our ExpressionEngine Add-ons have been acquired by EE Harbor. Head over there for documentation, info and support.
If you need to extend Shortlist with extra validation, event triggers or notification features, you can easily use the built in hooks to trigger your own custom extensions. The available hooks are :
shortlist_item_add_before
shortlist_item_add_after
shortlist_list_create_before
shortlist_list_create_after
The item-add-before hook can be used to add additional validation and extended data handling before an item is added to a list. This hook is fired after the basic validation and prep work has been done, but prior to adding the item to the list. At this point you can stop the item being added, alter any values, or add your own new values.
The hook is passed a $data array of the values for the item, which holds all the values.
Note The extra:.. data values are already encoded by this point. If you want to alter them you must first unserialize the values, and reserialize before returning.
Note To stop processing, simply set the ee()->extensions->end_script to be TRUE
If we wanted to add some extra validation, we could do something like this :
public function shortlist_item_add_before(&$itemData) { $entry_id = $itemData['entry_id']; // The entry_id of the item about to be added $list_id = $itemData['list_id']; // the id of the list about to be added to $member_id = $itemData['member_id']; // The member_id - be aware, this could be 0 for guests if($member_id == '0') { // This user is a guest. Limit them to only having 5 items in their lists .. some checks here if($totalItemCount > 5) { ee()->extensions->end_script = TRUE; return; } } } //etc... return; }
This is triggered immediately after an item is added to a list. You can use this to add your own notifications.
The hook gets two params $data, and $item_id. $data is the full array of item data, the same as the before hook. $item_id, is the id of the newly created item.
If we wanted to send a notification after an item is added :
public function shortlist_item_add_after($itemData, $itemId) { $entry_id = $itemData['entry_id']; // The entry_id of the item about to be added $list_id = $itemData['list_id']; // the id of the list about to be added to $member_id = $itemData['member_id']; // The member_id - be aware, this could be 0 for guests // something custom to pass this data to create a notification.. return; }
This is triggered immediately before a list is created. This triggers both from automatic actions (default lists, auto list add), and from direct user actions.
The hook gets two parameters - $data, an array of details about the list to be created, and $make_default, a bool to indicate if this is to be set as a defautl list after creation.
Note To stop processing, simply set the ee()->extensions->end_script to be TRUE
If we wanted to set the list title for all new lists to have a personalized name for the user :
public function shortlist_list_create_before(&$listData, $makeDefault) { $member_id = $itemData['member_id']; // The member_id - be aware, this could be 0 for guests if($member_id != '0') { // Get the member details $member = $this->getMemberDetails($member_id); // for example $listData['title'] = $member['first_name'] . "'s Wishlist"; } return; }
This is triggered immediately after a list is created. The list will still be empty at this point.
The hook gets 3 params of data, an array $listData, $makeDefault - a bool to flag if the list was made default, and $listId, the id of the newly created list.
If we wanted to send a notification after a list is created :
public function shortlist_list_create_after($listData, $makeDefault, $listId) { $entry_id = $listData['entry_id']; // The entry_id of the item about to be added $member_id = $itemData['member_id']; // The member_id - be aware, this could be 0 for guests // something custom to pass this data to create a notification.. return; }
These examples are only the simplest possible setup. With the data available you could integrate Charge member subscriptions into a larger existing membership system.
Contact support if you need any assistance with this or any other hooks.