Cart Counter for Shopware 6: installation and configuration
Install, seed the index and configure the "In more than 20 carts" badge on Shopware 6.5, 6.6 and 6.7.
The DfCartPopularity plugin displays a badge on the product detail page showing how many carts currently contain the product, for example “In more than 20 carts”. The count is built on your real cart data.
Requirements
- Shopware 6.5, 6.6 or 6.7, self hosted (Shopware Cloud SaaS does not accept server plugins)
- PHP 8.1 or higher
- SSH access for the console commands and the theme compilation
Installation
Upload the ZIP through Extensions then My extensions, or copy the folder into custom/plugins/, then run:
bin/console plugin:refresh
bin/console plugin:install --activate DfCartPopularity
bin/console cache:clear
./bin/build-storefront.sh
The storefront compilation is required once, to include the badge stylesheet. On an environment driven by a deployment pipeline, that step is usually already part of the standard process.
Seed the index
After installation the index is empty: counters start at zero and fill up as customers update their carts. To display credible figures from day one, run the rebuild:
bin/console df:cart-popularity:rebuild
The command reads the carts already stored in the shop and populates the index. It is idempotent and can be run again safely. The --truncate option empties the index before rebuilding.
Carts already turned into orders are removed from the cart table by Shopware. The rebuild therefore only sees active carts, which is exactly the expected scope.
Configuration
Settings, System, Plugins, DataFirefly Cart Popularity, then Configure. Every option can be overridden sales channel by sales channel.
Display
- Enable the badge: cart tracking keeps running when the badge is off, so the data is ready the day you switch it on.
- Minimum threshold (default 5): below that number of carts nothing is rendered.
- Display mode: rounded tier or exact number.
- Tier step (default 10): a count of 23 is displayed as “more than 20”. When the count is lower than the step, the plugin falls back to the exact number rather than announcing a false tier.
- Placement: above or below the buy box.
- Badge style: soft background, outlined or plain text.
Counting rules
- Time window (default 7 days): only carts updated within that window are counted. A value of 0 disables the window.
- Active carts only: excludes carts already turned into orders.
- Scope to sales channel: prevents a spike on one shop from inflating the counter of another.
- Aggregate variants: every variant of a product shares the parent counter. Switch it off when each variant needs its own counter.
Performance and retention
- Cache lifetime (default 900 seconds): the counting query runs once per lifetime and per product. A value of 0 disables the cache. The cache is flushed automatically whenever the configuration is saved.
- Retention (default 60 days): older records are deleted. Housekeeping runs automatically, at most once an hour, without depending on the message queue.
Customise the wording
The badge wording lives in Shopware snippets. Settings, Snippets, then search for dfCartPopularity. Three keys are available:
dfCartPopularity.badge.textTier: tier mode, contains the number placeholderdfCartPopularity.badge.textExact: exact mode, contains the number placeholderdfCartPopularity.badge.textSingular: exact mode with a single cart
The placeholder is written %count% and must be kept in your wording. English, German, French, Spanish, Italian and Polish translations are shipped.
How the counting works
Shopware serializes the whole cart into a payload column of the cart table, often compressed. No SQL query can therefore know what a cart contains without deserializing it. The plugin maintains its own df_cart_popularity table mapping a cart token, a product, a sales channel, a quantity and an ordered flag.
That table is synchronized on every cart persistence through CartSavedEvent, in two indexed queries. The CartConvertedEvent event marks the rows as ordered when the order is placed. Rendering then performs a plain distinct count over a composite index, kept in cache.
No personal data is recorded: the index only holds the cart token, which is a pseudonymous technical identifier, the product reference, the sales channel and timestamps.
CLI commands
bin/console df:cart-popularity:rebuild
bin/console df:cart-popularity:rebuild --truncate
bin/console df:cart-popularity:cleanup
bin/console df:cart-popularity:cleanup --days=30
Troubleshooting
The badge does not show up
Check in order: the badge is enabled for that sales channel, the number of carts reaches the threshold, the time window does not exclude every cart, and the storefront was recompiled after installation. Also flush the HTTP cache if the page is served from cache.
The badge shows up unstyled
The plugin stylesheet is included in the theme compilation. Run ./bin/build-storefront.sh or bin/console theme:compile again.
The rebuild command reports skipped carts
Those carts use a payload format the command cannot read, typically an external cart storage. They will be indexed normally on the customer’s next change, since event based tracking works regardless of the storage mode.
Uninstall
Uninstalling with user data removal drops the df_cart_popularity table and the plugin configuration. Keeping user data leaves the table in place, and the counters resume as they were on reinstall.