Skip to content

Commit

Permalink
Add example event code
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Jul 13, 2023
1 parent 4fc79cd commit 7c69899
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/commerce/4.x/extend/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1854,3 +1854,23 @@ Event::on(
}
);
```

### `modifyPurchasablesTableQuery`

The event that is triggered retrieving the list of purchasables for the add a line item feature on the order edit page.

This example adds a condition to the query to only return purchasables with a SKU that contains `foo`

```php
use craft\commerce\controllers\OrdersController;
use craft\commerce\events\ModifyPurchasablesTableQueryEvent;

Event::on(
OrdersController::class,
OrdersController::EVENT_MODIFY_PURCHASABLES_TABLE_QUERY,
function(ModifyPurchasablesTableQueryEvent $event) {
$likeOperator = Craft::$app->getDb()->getIsPgsql() ? 'ILIKE' : 'LIKE';
$event->query->andWhere([$likeOperator, 'sku', 'foo']);
}
);
```

0 comments on commit 7c69899

Please sign in to comment.