Skip to content

Custom rule conditions

The plugin adds three rule conditions of its own and accepts a curated subset of Shopware’s stock conditions. Anything not on this page is silently skipped when a rule is evaluated for layout selection.

  • Type id: p2labCmsAssignRulesIsHomepageRule
  • Class: Rule\IsHomepageRule
  • Scope: category pages only. Returns false on product and landing-page scopes.

True when the visitor is on the navigation root of the active sales channel — i.e. categoryId === salesChannel.navigationCategoryId. False on every subcategory, every product page, every landing page.

Field:

  • Is homepage — boolean toggle.

Common pitfall: combining this with Sales Channel in an AND container. The combination matches only on the channel’s homepage. See the multi-sales-channel pitfall.

  • Type id: p2labCmsAssignRulesInCategoryRule
  • Class: Rule\InCategoryRule
  • Scope: product and category pages.

True when the product (or category being viewed) is directly assigned to one of the listed categories.

Fields:

  • Operatoris one of / is none of / is empty.
  • Categories — multi-select.

For a product, the check runs against product.categoryIds. For a category page, the check runs against [categoryId]. The condition does not look at the category tree — descendants of a listed category do not match. Use the next condition for tree-aware matching.

Item in category with children [P2Lab Layouts Assigner]

Section titled “Item in category with children [P2Lab Layouts Assigner]”
  • Type id: p2labCmsAssignRulesInCategoryWithChildrenRule
  • Class: Rule\InCategoryWithChildrenRule (extends the previous)
  • Scope: product and category pages.

True when the product (or category being viewed) is in any of the listed categories, OR in one of their descendants. The descendant check is done by looking up the Shopware category path (which stores the ancestor chain as |id1|id2|id3|).

Fields: same as Item in category.

Cost: one additional DB lookup per evaluation per category being checked. Prefer Item in category when descendant matching isn’t needed.

The plugin’s ConditionNameEnum::CONDITIONS list explicitly allows the following stock Shopware conditions:

  • Sales ChannelsalesChannel
  • Date rangedateRange
  • Day of weekdayOfWeek
  • Languagelanguage
  • Time rangetimeRange
  • Currencycurrency
  • Always validalwaysValid
  • Affiliate code, billing city / country / zip / state / street, campaign code, is company, age, created by admin, birthday, email, customer group, is active, is newsletter recipient, logged in, customer number, salutation, last name, custom field, default payment method, different addresses, tag, is guest, is new customer, number of reviews, order count, shipping city / country / zip / state / street, days since first login, days since last login, days since last order, order total amount.

(See Enum\ConditionNameEnum::CONDITIONS for the canonical list.)

  • AND containerandContainer
  • OR containerorContainer
  • All line items containerallLineItemsContainer (substituted with the plugin’s own MatchAllRule — see Replacement flow internals)

Anything not in CONDITIONS or CONTAINERS is silently skipped. This includes most cart / line-item / shipping / payment conditions:

  • Cart total, cart shipping cost, items in cart, line item promoted, line item with delivery date, line item required, line item taxonomy, line item promotion, etc.
  • Shipping method, payment method, shipping country (cart-scoped variant), etc.

These are intentionally excluded — they target the checkout flow, where there’s an actual cart to inspect, not the page-load flow where the plugin runs.

The Layout assignment modal shows a status badge per rule indicating whether all, some, or none of its conditions are supported. See Layout assignment modal.

The plugin doesn’t expose a public extension point for new conditions — you’d add them the same way Shopware does (register a Rule class plus its admin component) and then add the type id to ConditionNameEnum::CONDITIONS to enrol it in the matcher.