Before proceeding to upgrade, please ensure you’re at Spree 6.0.
How to upgrade
- Spree CLI
- Without CLI
spree:upgrade runs the data steps below in order. Each one is safe to run again.
Data steps
Scheduled jobs
Spree 6.1 adds three jobs that must run on a schedule. The upgrade adds them to yourconfig/recurring.yml for you, in its last step.
What the step does depends on where it runs:
- In development it adds every Spree job the file lacks, at the end of the
production:section, and leaves the rest of the file alone. Review the change and commit it. - On a deployed server it changes nothing. A file inside a release is not the one to edit. It fails, naming the missing jobs, until a release that schedules them is deployed. So run the upgrade in development first, as usual.
- On another scheduler it never writes. When the app has a
config/schedule.yml,config/sidekiq.ymlorconfig/schedule.rb, the step prints the jobs with their cron lines for you to add there, and on a deployed server it fails until that file mentions them. The background jobs guide has aconfig/schedule.ymlto copy from. Aconfig/recurring.ymlleft beside one of those files is not what runs, so it is ignored. With no schedule file to read at all, the step prints the list and passes.
production: section is an alias of another, the step cannot add to it safely: it stops, changes nothing and names the jobs for you to add by hand.
To keep a job out, leave its entry in the production: section as a comment: the step counts a job mentioned there as scheduled. A job that only another section runs, such as staging:, is still missing from production. You can run the step on its own with spree task install:recurring_jobs (bin/rails spree:install:recurring_jobs without the CLI), and DRY_RUN=1 lists what is missing without changing anything.
Behavior changes
Categories and collections are published per channel
The Store API serves a category or collection only on channels where it is published. Unpublishing a category hides its subcategories too. After the backfill every existing category and collection is published on every active channel, so shoppers see no change. New categories and collections created through the Admin API, the dashboard, CSV import,Spree.category_create_workflow or Spree.collection_create_workflow are published on every active channel unless the request sends publications. Code that creates them with create! directly must go through the workflow or publish them itself, or they are invisible on every storefront:
server/app/services/my_app/category_importer.rb
POST /api/v3/admin/channels/:id/add_categories and add_collections take a list of ids, or in Ruby channel.publish_records(Spree::Category, ids).
category.published, category.unpublished, collection.published and collection.unpublished are new events. They are sent when a record becomes visible on a channel or stops being visible there, so a publication scheduled for next week sends published next week. Publishing in bulk (add_products, bulk_add_to_channels, the create workflows) sends them from a background job. Products gain product.published and product.unpublished on the same terms.
The Store API also stops filtering products by a hidden category: q[in_category] and q[in_categories] skip categories that are not published on the channel, a product’s categories leave them out, and conditions on the categories association (q[categories_name_cont] and similar) match only the categories the channel shows.
Publications are saved with the record
Apublications set on a product, category or collection is now written when the record saves, in the same transaction. Before, a product’s set was written the moment it was assigned, so a save that failed validation had already changed where the product was published.
- Ruby code that assigns
product.product_publications = [...]on a saved product must now callsave. - A row naming a publication or a channel the store does not have raises
ActiveRecord::RecordNotFound(a 404 from the Admin API). It used to be skipped, which unpublished the record from every channel the request left out. - On products the field is now
publications, the name categories and collections use.product_publicationsstill works on reads and writes and is removed in Spree 6.6. Products also gain the nested/products/:id/publicationsendpoints.
Collections mix rules, hand-picked products and exclusions
A collection with rules now accepts hand-picked products too, and any collection can exclude products. Adding products to a rule-based collection used to return a 422; it now succeeds.automaticis ignored on write and deprecated there (removed from requests in Spree 6.6). A collection is automatic while its rules apply; sendrules: []to remove them.- Rules left on a collection that was manual in 6.0 stay inactive until the collection’s
rulesare next written, even unchanged. The dashboard says so on such a collection, and saving it there applies them. Review them first. - Rows of
spree_product_collectionscarry asource(manualorrule). Code that inserts memberships directly must set it. The column becomes required in Spree 6.4. - A product’s
collection_idsin the Admin API lists and sets the collections it is hand-picked into. Memberships created by rules are kept when you write it. - Removing products from a collection takes out hand-picked products only. A product the rules match stays, because it would come back the next time they ran. To keep it out, exclude it.
- An exclusion keeps the rules from matching a product. A hand-picked product cannot be excluded (the request is a 422): remove it instead. Hand-picking an excluded product lifts the exclusion.
Rule changes regenerate collections in the background
Saving a collection’s rules used to rebuild its products inside the request. It now queuesSpree::Collections::RegenerateProductsJob, so the response returns at once and the products follow when the job has run. Code that creates a rule-based collection and reads its products straight away must wait for the job, or call collection.regenerate_products itself.
Rule types now state what they read about a product (reads :prices), and a write names what it changed: product.auto_match_collections(changed: [:prices]). A custom rule type that declares nothing is re-checked on every product change, as in 6.0; declaring reads spares it the changes it does not care about. Code that changes products with update_all, insert_all or another path that skips callbacks should call Spree::Product.bulk_auto_match_collections(store, product_ids, changed: [...]) afterwards.
Store API product search filters by collection through in_collection only
q[in_collection] accepts only collections published on the request’s channel; any other collection filters to nothing. Ransack conditions on the collections association (q[collections_id_eq] and similar) are no longer accepted by the Store API, because they could reach unpublished collections. Use q[in_collection] instead.
Old collection and category permalinks keep working
A request for a renamed collection or category by its old permalink now returns the record instead of a 404. Compare the returnedpermalink with the requested one to redirect.
Sale rules read their own currency
sale and price collection rules compare prices in the currency named by their preferences.currency, or the store’s default currency when it is empty. Existing rules name none, so they keep using the default currency.
A sale rule no longer needs a value and takes is_equal_to (on sale) or is_not_equal_to (not on sale). contains and does_not_contain, which 6.0 also accepted, are saved as those two.
The Google feed sends each variant’s own GTIN
The Google Merchant Center feed now fillsg:gtin for each variant, in this order: the variant’s barcode, then a storefront-visible variant custom field with the key gtin, then the product’s gtin custom field when the feed holds a single variant of the product (one that is not discontinued and has a price in the store’s currency). It sends at most one, and only a valid GTIN: 8, 12, 13 or 14 digits with a correct check digit, outside the in-store and coupon ranges Google refuses. Spaces and hyphens are removed.
What a merchant may notice:
- Barcodes that hold GTINs now appear in the feed, with nothing to configure.
- A barcode or
gtinfield that is not a valid GTIN is no longer sent. The feed tries the next source, or sends no GTIN. - A product with several variants in the feed no longer copies its product-level
gtincustom field onto every variant, since Google refuses one GTIN on several variants. Those variants are sent without a GTIN until each variant’s barcode is filled in.
Prefixed ID prefixes are lowercase letters only
has_prefix_id now raises an ArgumentError at load time for a prefix with an underscore or a digit, such as has_prefix_id :size_guide. A prefixed ID is read up to its first underscore, so with an underscore the model’s IDs could never be looked up, and with a digit they were not recognised when sent as a reference such as size_guide_id. Change the prefix to letters only (has_prefix_id :sizeguide). The model’s IDs change with it, so update any that clients have stored.
