Fold for Craft CMS

Console commands

The commands a store locator needs on the command line: import a chain's worth of shops, geocode them without a web request timing out, export them again, and sync from Commerce.

All of them

CommandWhat it doesEdition
fold/locations/groupsLists location groups and how many locations each holdsLite
fold/locations/geocodeGeocodes every location that needs it, inline, with progressLite
fold/locations/queue-geocodingQueues the same work for the queue runner insteadLite
fold/locations/import <file.csv>Imports locations from a CSVPro
fold/locations/exportExports locations as CSV or JSONPro
fold/commerce/syncCreates or updates a location for every Commerce inventory locationPro + Commerce
fold/commerce/locationsLists Commerce inventory locations and what each is linked toCommerce
fold/searches/purgeDeletes search log rows older than --daysLite

Geocoding

php craft fold/locations/geocode
php craft fold/locations/geocode --group=retail
php craft fold/locations/geocode --force

Runs in the foreground and prints each location as it is placed — ✓ Uptown 35.22690, -80.84330 or ✗ Ballantyne The address could not be placed on the map. — then a summary.

Without --force, only locations that need it are looked up: never geocoded, not found, or whose address has changed. Locations placed by hand are skipped. --force looks up every location again, placed by hand or not, so use it deliberately.

With Nominatim selected, the command waits 1.1 seconds between lookups, as Nominatim's usage policy requires — and every Nominatim request on the site shares one lock that keeps them a second apart, so a geocode run and the live locator cannot add up to more than the policy allows. 340 shops is a six-minute command. That is the honest cost of a free geocoder, and why this is a console command rather than a button that would time out.

php craft fold/locations/queue-geocoding

Pushes one queue job per location that is awaiting coordinates or could not be placed, for sites that would rather the queue did the waiting. This is what Geocode pending on the locations index does too.

Import and export (Pro)

php craft fold/locations/import stores.csv --group=retail --dry-run
php craft fold/locations/import stores.csv --group=retail
php craft fold/locations/export --format=json --file=stores.json
OptionApplies toMeaning
--group=<handle>import, export, geocodeWhich group. Required for import when there is more than one group.
--dry-runimportParse and report; write nothing
--format=csv\|jsonexportDefaults to csv
--file=<path>exportWhere to write; stdout if omitted
--forcegeocodeRe-geocode everything

Import exits non-zero if any row failed. See Import and export for the columns.

Commerce

php craft fold/commerce/sync --group=retail
php craft fold/commerce/locations

sync matches on the inventory location's ID, so it is safe to run on a schedule: a second run reports everything unchanged, and a run after a warehouse moves updates its address. --group defaults to the first group. See Commerce stock.

Search log

php craft fold/searches/purge              # uses the Keep searches for setting
php craft fold/searches/purge --days=30

Craft's garbage collection already prunes the log to Keep searches for; this is for doing it now, or on a cron of your own. If retention is set to keep searches forever (0) and no --days is given, it refuses rather than guessing.

Exit codes

Every command exits non-zero when it refuses — no group given where one is needed, an unknown group handle, a Pro command on Lite, Commerce not installed — so a script that runs them stops where it should.