Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Merge pull request #14670 from spree/fix/v-3642

Łukasz Adamczyk7f249f650c04
diff --git a/docs/developer/core-concepts/events.mdx b/docs/developer/core-concepts/events.mdx
index 6662406289..6eaeed960e 100644
--- a/docs/developer/core-concepts/events.mdx
+++ b/docs/developer/core-concepts/events.mdx
@@ -41,7 +41,8 @@ On top of that, meaningful business moments get their own events:
| Event | Meaning |
|---|---|
-| `order.placed` | A customer completed checkout |
+| `order.placed` | An order was placed — one per order, so a checkout that split across several sellers publishes one per seller |
+| `order_group.completed` | A checkout that split finished — one event for the whole purchase |
| `order.paid` | Payment is settled in full |
| `order.canceled` | The order was cancelled |
| `order.fulfilled` / `order.delivered` | Everything has shipped / arrived |
diff --git a/docs/developer/core-concepts/sellers.mdx b/docs/developer/core-concepts/sellers.mdx
index dc8cb7e4b5..c18703420d 100644
--- a/docs/developer/core-concepts/sellers.mdx
+++ b/docs/developer/core-concepts/sellers.mdx
@@ -287,6 +287,16 @@ curl -X PATCH https://your-store.com/api/v3/admin/orders/or_UkLWZg9DAJ/complete
</CodeGroup>
+### One confirmation, and it describes the purchase
+
+The customer made one purchase, so they get one confirmation email — sent from the group, not from any of its orders. Each child order is placed silently.
+
+If you replace the confirmation email, replace it at the group level too: the email a customer receives for a split checkout is `Spree::OrderGroupMailer`, reacting to the `order_group.completed` event, and a re-send from any child order in the admin sends the purchase's email rather than that child's. A checkout that doesn't split is unaffected and still sends the ordinary order confirmation.
+
+<Note>
+**Orders and deliveries are different counts.** Three seller orders do not mean three parcels. When several sellers' goods ship from one warehouse, the checkout quotes one delivery charge, and the split divides that charge between the orders rather than charging for it again — so one box arrives. Ask the group for `fulfillment_groups` to get the parcels that really ship; each one knows its delivery method, its cost, the goods it carries and who is sending it. Counting child orders instead promises the customer deliveries that will never arrive.
+</Note>
+
## Commission
Commission is what the marketplace charges for the sale — configured as **rates**, and recorded per sale as immutable **commission lines**.
diff --git a/docs/plans/6.0-cart-order-split.md b/docs/plans/6.0-cart-order-split.md
index 1f800065b8..c9e4c19a1a 100644
--- a/docs/plans/6.0-cart-order-split.md
+++ b/docs/plans/6.0-cart-order-split.md
@@ -216,7 +216,7 @@ Triggered by subscribers on payment, refund, fulfillment, and return events —
### Completion side-effect parity checklist
-Everything today's `finalize!` + `after_transition to: :complete` chain does is accounted for in the flow above or explicitly relocated: adjustment freeze (→ split-adjustments order-level freeze), payment/shipment status updates (→ UpdateStatuses), `status: 'placed'`, `completed_at`, update hooks, risk check (`considered_risky` + `order.updated`), `order.completed` event, coupon-code use, gift-card redeem, newsletter subscribe, user-account creation, digital links (→ `FulfillmentProvider::Digital`, idempotent + per-quantity — fixing the current checkout-callback's non-idempotent one-per-line-item behavior), confirmation email (already event-driven via the emails subscriber; unchanged).
+Everything today's `finalize!` + `after_transition to: :complete` chain does is accounted for in the flow above or explicitly relocated: adjustment freeze (→ split-adjustments order-level freeze), payment/shipment status updates (→ UpdateStatuses), `status: 'placed'`, `completed_at`, update hooks, risk check (`considered_risky` + `order.updated`), `order.completed` event, coupon-code use, gift-card redeem, newsletter subscribe, user-account creation, digital links (→ `FulfillmentProvider::Digital`, idempotent + per-quantity — fixing the current checkout-callback's non-idempotent one-per-line-item behavior), confirmation email (already event-driven via the emails subscriber; unchanged for a checkout that does not split — a split one confirms once from its `OrderGroup` instead, see `6.0-multi-vendor-marketplace.md`).
## Migration Path
diff --git a/docs/plans/6.0-multi-vendor-marketplace.md b/docs/plans/6.0-multi-vendor-marketplace.md
index a8b961b1ab..eebe64b019 100644
--- a/docs/plans/6.0-multi-vendor-marketplace.md
+++ b/docs/plans/6.0-multi-vendor-marketplace.md
@@ -4,7 +4,7 @@
**Target:** Spree 6.0 (the "Marketplace" release)
**Depends on:** `6.0-cart-order-split.md` (Cart/Order split + dual-FK `LineItem` owner (`cart_id`/`order_id`, `#owner` method) — **expanded 2026-07-27; Phase 3 design can now freeze against it**), `6.0-6.1-split-adjustments.md` (TaxLine/Discount/Fee replace polymorphic Adjustment), `6.0-order-routing.md` (per-seller stock location), `6.0-fulfillment-and-delivery.md` (Fulfillment/DeliveryMethod vocabulary, per-seller delivery selection), `6.0-admin-spa.md` (seller panel composition), `6.0-admin-api.md` (Marketplace endpoints), `6.0-platform-auth.md` (`Spree::AdminUser` is the seller principal; strategy registries + JWT audiences — shipped in PR #14380), `6.0-admin-rbac.md` (permission catalog, `RoleUser` resource typing, seller audience direction — shipped in PR #14412)
**Author:** Damian + Claude
-**Last updated:** 2026-08-20
+**Last updated:** 2026-09-16
## Summary
@@ -712,6 +712,7 @@ Seller notifications are **event-driven, with OSS mailers included** — split a
- **Back-office emails to sellers and admins live in core**, next to the existing back-office mailers (`Spree::ExportMailer`, `Spree::ImportMailer`, `Spree::InvitationMailer`, `Spree::ReportMailer`): a `Spree::SellerMailer` ports the legacy set — seller approved/rejected/suspended (to the seller's team), onboarding started/submitted-for-review (to store admins), new seller order, payout completed — wired as subscribers to the lifecycle events below. Seller *invitations* need nothing new: they already ride core's `InvitationMailer` via the `Invitation` rail. Core-resident means seller email works in every installation, regardless of gems.
- **Consumer-facing emails** (e.g. the per-seller shipment tracking emails customers receive) belong to `spree/emails` (rebuilt + modernized in 5.6, optional) — or to the storefront's own email stack via webhooks, for headless setups that own transactional email.
+- **The purchase confirmation is sent once, from the group**: `order_group.completed` → `Spree::OrderGroupEmailSubscriber` → `Spree::OrderGroupMailer`, with every child order placing silently. It describes the whole purchase and counts its deliveries from fulfillments rather than from child orders — see the Resolved Decisions entry for why those differ. A checkout that does not split keeps the plain `Spree::OrderMailer` path untouched.
Either way the events are the seam — subscribers/webhooks feed n8n/Slack/custom stacks, including OSS payout automation: `seller_payout.due` → webhook → operator's banking flow → `POST /seller_payouts/:id/complete`.
@@ -787,6 +788,7 @@ Even before this lands, work touching adjacent areas should:
## Resolved Decisions
+- **One purchase, one confirmation — sent from the group, not its first child** (RESOLVED 2026-09-16, shipped). A split checkout was already deliberate about sending a single confirmation, and wrong about which one: `complete_orders` silenced every child but the first, so the customer received that child's own email — its number, its items, its delivery, its total — with nothing in it to say the rest of the purchase existed. On a mixed basket the first-party child sorts first, so a $374.97 purchase of three items confirmed $50.67 and one item, and the $324.30 it did not mention included both sellers' goods. The email now hangs off the `order_group.completed` event this plan already named as the seam and which nothing had ever subscribed to: every child places silently, `Spree::OrderGroupEmailSubscriber` answers the group, and `Spree::OrderGroupMailer` renders the whole purchase — the number the customer saw at checkout (`R1001`, not `R1001-1`), every item, and the total actually paid. **The email counts deliveries from fulfillments, never from child orders**, because the two are not the same number. Where one warehouse serves several sellers the packer builds one package and the split divides its single quote between the children (see "Splitting a parcel between sellers divides everything hanging off it"), so three orders ship as one parcel; where sellers hold their own stock, three orders are three parcels each keeping its own untouched quote. `Spree::FulfillmentGroup` collapses divided halves back together on `[stock_location_id, delivery_method_id]` — the pair `clone_fulfillment` preserves, and one the packer cannot produce twice on its own, since it builds one package per location per order — so the customer is told how many times a courier will call rather than how many sellers they bought from. The delivery method alone will not answer it: `available_to_sellers` lets two warehouses be quoted on one shared marketplace method, and keying on the method would merge two real parcels. Two things had to ship with it. The **store-owner notification** moved to the group as well — it rode inside the first child's confirmation, so silencing the children would have removed it entirely — and the admin **resend** on a grouped child re-sends the group's email, or that back door would put the partial one back. Idempotency is a pair of delivered flags on `spree_order_groups` mirroring the order's, because replay re-publishes the group event. Grouped **cancellation** is deliberately untouched: it is opt-in per child (`Orders::Cancel` defaults `notify_customer: false`), so it is not misfiring on its own.
- **Seller delivery → marketplace-owned profiles, seller-owned methods** (RESOLVED 2026-09-01, **implemented 2026-09-01**). Decision 13: profiles, zones and origin groups never carry a `seller_id`; `DeliveryMethod` gains a nullable `seller_id` and an `available_to_sellers` switch; a package's seller is its stock location's and its eligible methods are decided in the estimator alone; seller methods are internal-rate and manual-fulfillment only, carrier accounts staying the operator's; `DeliveryOriginGroup#covers_location?` is true for seller locations; "at least one way to ship" is a computed onboarding requirement; `delivery_methods` becomes its own seller-grantable catalog resource. Replaces the bare `seller_id` promise the Seller API and Order splitting sections carried since 2026-08-15.
- **A seller assigns their product's type and delivery profile; the operator files it** (RESOLVED 2026-09-01, shipped). Partly reverses the 2026-08-26 change that took the whole Categorization card off the seller branch. A product type is not filing — it is the template that hands a seller their option types and delivery profile — and the profile is what makes their goods quotable at all: every seller product was landing on the store default, so nothing a seller sold could be digital or oversized. `product_type_id` and `delivery_profile_id` are readable and writable on `/seller/products`, resolved against the seller's store (a foreign id is a 404), backed by read-only `GET /seller/product_types` (under `read_product_types`, the key `6.0-seller-product-submission.md` minted for exactly this) and `GET /seller/delivery_profiles` (under `read_products` — the vocabulary a product form fills in, not a setting a seller holds a key on). Categories, collections and tags stay off the branch: filing a listing is the operator's, done at review.
- **The split adopts the paid order rather than replacing it, and moves rows rather than copying them** (RESOLVED 2026-08-20, shipped). Completion builds one draft order holding the whole basket so it can be paid as one; the split then makes that order the group's first child and hands the other partitions' rows to new siblings. The alternative — build N fresh orders and destroy the original — was written first and rejected on two counts: the original is the record the payment was taken against and the row carrying the unique `cart_id` that makes completion replayable, so destroying it orphans money and breaks resumption. Rows **move** (`update_all` on the owner FK) rather than being re-copied from the cart, because everything was costed once inside the completion lock and re-deriving would ask the pricing and tax engines a question already answered — possibly getting a different one. The group takes the order's number so the customer keeps the reference they saw at checkout, and children suffix off it (`R1001-1`), following the same reads-its-parent shape as fulfillment and payment numbers.
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index 83cf13d9b6..32704050e2 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -59,6 +59,15 @@ Rejected: refusing to complete a multi-seller admin order. A customer asking a m
**Plans amended:** `6.0-multi-vendor-marketplace.md` (Constraints on Current Work, Resolved Decisions), `6.0-cart-order-split.md` (the Gates line).
+## 2026-09-16: A split checkout confirms once from its OrderGroup, and counts deliveries from parcels
+
+**Context:** A checkout spanning several sellers splits into one order per seller and deliberately sent a single confirmation email — but it sent the *first child order's* own email, carrying that order's number, items, delivery and total. On a mixed basket the first-party child sorts first, so a $374.97 purchase of three items confirmed $50.67 and one item, with nothing to say the rest existed (V-3642). The workflow already published `order_group.completed` and nothing had ever subscribed to it.
+
+**Decision:** The confirmation moves onto that event. Every child of a split places with `notify_customer: false`, `Spree::OrderGroupEmailSubscriber` answers the group, and `Spree::OrderGroupMailer` renders the whole purchase under the number the customer saw at checkout. The email is organised **by parcel**, and a parcel is a set of fulfillments sharing `[stock_location_id, delivery_method_id]` — collapsed by `Spree::FulfillmentGroup`, because when one warehouse serves several sellers the packer builds one package and the split divides its single quote across the children, so three orders can ship in one box. The store-owner notification moves to the group with it, and an admin resend on a grouped child sends the group's email. Two delivered flags on `spree_order_groups` mirror the order's, since replay re-publishes the event.
+
+**Consequences:** "How many orders" and "how many deliveries" are now understood to be different questions, and any surface telling a customer what to expect must answer the second from fulfillments. Delivery method alone cannot key it — `available_to_sellers` lets two warehouses be quoted on one shared marketplace method — and a location alone cannot either, so the pair is the rule. A single-partition checkout is untouched and keeps `Spree::OrderMailer`. Grouped cancellation is left as it is: it is opt-in per child, so it is not misfiring on its own. The storefront's own confirmation page reads `order.items`, which the group serializer does not expose, so it needs the same treatment separately.
+
+
## 2026-09-16: Two catalogs on one company charge the best of them, and every order line says which agreement priced it
**Context:** Nothing stopped an operator assigning a second catalog to a company — the audience picker offered the company again with no warning — and once both were active the buyer was charged from whichever catalog sorted first, not the cheaper one. Reported against a company holding a 5%-off catalog and a contract catalog with a quantity break: at 24 units the buyer paid $2,280.00 where the company's other agreement said $1,200.00, and reversing the two catalogs' order reversed the outcome (V-3635). The tie-break was the documented design — `Catalog#position`, which is the order of the store-wide catalogs screen — so a merchant dragging that list to tidy it changed what companies paid, with no screen anywhere listing a company's catalogs to show it had happened.
diff --git a/packages/admin-sdk/src/types/generated/OrderGroup.ts b/packages/admin-sdk/src/types/generated/OrderGroup.ts
index 76ff5c2819..a8ea1283e4 100644
--- a/packages/admin-sdk/src/types/generated/OrderGroup.ts
+++ b/packages/admin-sdk/src/types/generated/OrderGroup.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 4726e16b2f9b121b60a2883025f8f4dc
+// Typelizer digest 91408acfe7ed647580ade4bcf5f8ea5f
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Address, Order, Payment} from '@/types'
@@ -22,6 +22,8 @@ interface OrderGroup {
cart_id: string | null;
seller_count: number;
includes_first_party: boolean;
+ confirmation_delivered: boolean;
+ store_owner_notification_delivered: boolean;
created_at: string;
updated_at: string;
payments: Array<Payment>;
diff --git a/spree/api/app/serializers/spree/api/v3/admin/order_group_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/order_group_serializer.rb
index 9d3e7fb652..8c9db627fd 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/order_group_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/order_group_serializer.rb
@@ -13,6 +13,8 @@ module Spree
cart_id: 'string | null',
seller_count: :number,
includes_first_party: :boolean,
+ confirmation_delivered: :boolean,
+ store_owner_notification_delivered: :boolean,
created_at: :string, updated_at: :string
attribute :customer_id do |group|
@@ -34,6 +36,11 @@ module Spree
group.includes_first_party?
end
+ # A split checkout is confirmed once, from here — every child order
+ # places silently, so their own flags are false and only the group
+ # can answer whether the customer was told.
+ attributes :confirmation_delivered, :store_owner_notification_delivered
+
attributes :created_at, :updated_at
# Re-declared against the admin serializers. Inheriting the store
diff --git a/spree/core/app/models/spree/fulfillment_group.rb b/spree/core/app/models/spree/fulfillment_group.rb
new file mode 100644
index 0000000000..434d55fbb0
--- /dev/null
+++ b/spree/core/app/models/spree/fulfillment_group.rb
@@ -0,0 +1,127 @@
+module Spree
+ # One real parcel of a purchase, across however many orders it belongs to.
+ #
+ # A checkout that spans several sellers divides into one order per seller,
+ # and a parcel holding more than one seller's goods divides with them: the
+ # split clones the fulfillment onto each sibling and apportions the one
+ # delivery charge the customer was quoted between the halves
+ # (+Spree::Carts::SplitBySeller+). So "how many orders" and "how many
+ # parcels" are different numbers, and anything telling a customer what to
+ # expect has to answer the second — three orders shipping out of one
+ # warehouse are still one box, and saying otherwise promises deliveries that
+ # will never arrive.
+ #
+ # Ephemeral, never persisted: it is a reading of the fulfillments, and they
+ # remain the record.
+ class FulfillmentGroup
+ include ActiveModel::Model
+ include ActiveModel::Attributes
+
+ attr_accessor :fulfillments
+
+ # Collapses divided halves back into the parcels that actually ship.
+ #
+ # Halves of a divided parcel share their origin and their delivery method,
+ # because the clone copies both. Genuinely separate parcels differ in at
+ # least one: a seller shipping from their own warehouse differs in origin
+ # even when quoted on a marketplace method the operator shares with them
+ # (+DeliveryMethod#available_to_sellers+), and two parcels leaving one
+ # warehouse differ in method. The pair is safe as an identity because the
+ # packer builds one package per stock location per order, so it cannot
+ # produce two same-origin same-method fulfillments on its own — only the
+ # split can.
+ #
+ # @param fulfillments [Enumerable<Spree::Fulfillment>]
+ # @return [Array<Spree::FulfillmentGroup>] in the order the fulfillments
+ # were given, so a caller that ordered them decides how the parcels read
+ def self.build_from(fulfillments)
+ fulfillments.group_by { |fulfillment| identity(fulfillment) }.
+ map { |_identity, members| new(fulfillments: members) }
+ end
+
+ # @return [Array] origin and delivery method — see {.build_from}
+ def self.identity(fulfillment)
+ [fulfillment.stock_location_id, fulfillment.selected_delivery_rate&.delivery_method_id]
+ end
+
+ # @return [Spree::DeliveryMethod, nil]
+ def delivery_method
+ primary.delivery_method
+ end
+
+ # What the customer chose to be delivered by, named as they were shown it —
+ # a provider rate carries its own label ("UPS Ground"), a calculated one
+ # reads through to the method.
+ #
+ # @return [String, nil]
+ def name
+ primary.selected_delivery_rate&.name || delivery_method&.name
+ end
+
+ # @return [Spree::StockLocation, nil]
+ def stock_location
+ primary.stock_location
+ end
+
+ # What this parcel costs to deliver: the halves' apportioned shares added
+ # back up, which is what the customer was quoted for it before the split
+ # divided anything.
+ #
+ # @return [BigDecimal]
+ def cost
+ fulfillments.sum { |fulfillment| fulfillment.discounted_cost.to_d }
+ end
+
+ # @return [String, Spree::Money] the forwarder's placeholder while a
+ # freight rate is unpriced, money otherwise
+ def display_cost(**options)
+ return primary.display_cost(**options) if unpriced?
+
+ Spree::Money.new(cost, { currency: primary.currency }.merge(options))
+ end
+
+ # @return [Boolean]
+ def unpriced?
+ fulfillments.any?(&:unpriced?)
+ end
+
+ # @return [Array<Spree::LineItem>] every line this parcel carries part of
+ def line_items
+ fulfillments.flat_map(&:line_items).uniq
+ end
+
+ # What the parcel carries, each line with the quantity *this* parcel holds.
+ #
+ # A line item can be packed from two warehouses, which puts it in two
+ # parcels — printing the line's own quantity in both would show the
+ # customer more goods than they bought, and charge for them twice.
+ #
+ # @return [Array<Spree::Fulfillment::ManifestItem>]
+ def manifest
+ fulfillments.flat_map(&:manifest).group_by(&:line_item).map do |line_item, items|
+ Spree::Fulfillment::ManifestItem.new(line_item, line_item.variant, items.sum(&:quantity), nil)
+ end
+ end
+
+ # Who is shipping it. More than one only where a marketplace's own
+ # warehouse ships several sellers' goods in one box.
+ #
+ # @return [Array<Spree::Seller>]
+ def sellers
+ fulfillments.filter_map { |fulfillment| fulfillment.order&.seller }.uniq
+ end
+
+ # @return [Array<Spree::Order>]
+ def orders
+ fulfillments.filter_map(&:order).uniq
+ end
+
+ private
+
+ # The half that answers for the parcel. Every half carries the same origin,
+ # method and rate name — only the money was divided.
+ def primary
+ fulfillments.first
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/order_group.rb b/spree/core/app/models/spree/order_group.rb
index be2e852861..d6ac4e9019 100644
--- a/spree/core/app/models/spree/order_group.rb
+++ b/spree/core/app/models/spree/order_group.rb
@@ -55,15 +55,23 @@ module Spree
has_many :payments, class_name: 'Spree::Payment', inverse_of: :order_group, dependent: :restrict_with_error
has_many :payment_splits, through: :payments, class_name: 'Spree::PaymentSplit', source: :payment_splits
+ # What the customer bought and the money hanging off it, reached through
+ # the children that own it. A purchase-level reader is not a second source
+ # of truth — it is the same rows, asked for as one basket, which is how the
+ # customer's own confirmation has to describe them.
+ has_many :line_items, through: :orders, class_name: 'Spree::LineItem', source: :line_items
+ has_many :fulfillments, through: :orders, class_name: 'Spree::Fulfillment', source: :fulfillments
+ has_many :discounts, through: :orders, class_name: 'Spree::Discount', source: :discounts
+ has_many :fees, through: :orders, class_name: 'Spree::Fee', source: :fees
+
# Brings the ship/bill pair with the shipping_address/billing_address
# aliases every other purchase surface reads them by.
#
# Only the associations and aliases apply here. The concern's checkout
- # helpers — shipping_address_required?, assign_default_addresses! — reach
- # for line items, fulfillments and digital goods, none of which a group
- # has: they belong to its children, which answer those questions for
- # themselves. A group's addresses are copies made when the checkout
- # divided, so nothing asks it to work them out.
+ # helpers — shipping_address_required?, assign_default_addresses! — are
+ # about working an address out, and a group's addresses are copies made
+ # when the checkout divided, so nothing asks it to. They also read digital
+ # goods, which only a child can answer for.
include Spree::Purchase::Addresses
# What a marketplace asks about a group. Kept out of the class itself so
# this stays the neutral primitive its other consumers need.
@@ -81,7 +89,6 @@ module Spree
self.whitelisted_ransackable_associations = %w[orders customer]
extend Spree::DisplayMoney
- money_methods :total, :item_total
# What the customer was charged for the whole checkout, and what it was
# charged for — the sums of what each child independently computed. Never
@@ -104,6 +111,9 @@ module Spree
end
end
+ money_methods(*ROLLED_UP_TOTALS)
+ money_methods :gift_card_total
+
alias ship_total delivery_total
# Where the checkout was made from, carried on the children because they
@@ -114,6 +124,68 @@ module Spree
orders.first&.last_ip_address
end
+ # @return [String, nil]
+ def locale
+ orders.first&.locale
+ end
+
+ # @return [String, nil]
+ def po_number
+ orders.first&.po_number
+ end
+
+ # Who to address the purchase to, read off the addresses the checkout
+ # copied onto the group — the same answer +Spree::Order#name+ gives, so a
+ # customer-facing document greets them identically either way.
+ #
+ # @return [String, nil]
+ def name
+ (bill_address || ship_address)&.full_name
+ end
+
+ # The parcels this purchase actually ships in — not one per child order.
+ # A parcel divided between sellers is counted once, because one box leaves
+ # the warehouse however many orders its contents belong to. See
+ # +Spree::FulfillmentGroup+ for why the two numbers differ.
+ #
+ # Ordered by child, so first-party goods lead and sellers follow in the
+ # order the split filed them, and the same purchase reads the same way
+ # twice.
+ #
+ # @return [Array<Spree::FulfillmentGroup>]
+ def fulfillment_groups
+ Spree::FulfillmentGroup.build_from(
+ fulfillments.
+ includes(:stock_location, { order: :seller }, { selected_delivery_rate: :delivery_method }).
+ order(:order_id, :id)
+ )
+ end
+
+ # What was bought that no parcel carries — a downloaded album, a gift card
+ # sent by email. Without it a confirmation organised by parcel would list
+ # everything the customer is waiting for and silently omit what they
+ # already have.
+ #
+ # @param groups [Array<Spree::FulfillmentGroup>] the parcels, when the
+ # caller has already built them — rebuilding re-reads the fulfillments
+ # @return [Array<Spree::LineItem>]
+ def unfulfilled_line_items(groups = fulfillment_groups)
+ line_items.to_a - groups.flat_map(&:line_items)
+ end
+
+ # What the customer paid with a gift card. Not rolled up from the children:
+ # the group claims the payments at completion, so a child's own
+ # +gift_card_total+ — which reads its payments — answers zero for every one
+ # of them, and the confirmation would omit a deduction its total makes.
+ #
+ # @return [BigDecimal]
+ def gift_card_total
+ return 0.to_d if gift_card.nil?
+
+ store_credit_ids = payments.store_credits.valid.pluck(:source_id)
+ Spree::StoreCredit.where(id: store_credit_ids, originator: gift_card).sum(:amount)
+ end
+
# @return [String, nil] the group's fulfillment position, in the same
# vocabulary a single order uses, rolled up across children
def fulfillment_status
diff --git a/spree/core/app/workflows/spree/carts/complete.rb b/spree/core/app/workflows/spree/carts/complete.rb
index 49247db90f..d94d2925c9 100644
--- a/spree/core/app/workflows/spree/carts/complete.rb
+++ b/spree/core/app/workflows/spree/carts/complete.rb
@@ -427,8 +427,8 @@ module Spree
# that workflow can give both of them.
#
# It answers with the group when the basket divided, and the first of
- # its children is the order this checkout carries on with: that is the
- # one holding the confirmation email.
+ # its children is the order this checkout carries on with. No child holds
+ # the confirmation: the customer is confirmed from the group.
def complete_orders
result = Spree.order_complete_workflow.call(order: order, payment_pending: payment_pending)
failure(cart, code: 'completion_failed', message: result.error) if result.failure?
@@ -455,7 +455,7 @@ module Spree
# otherwise. The single answer to "which orders came out of here", so
# placement and tax filing can never disagree about the set.
def placed_orders
- order_group.present? ? order_group.orders.to_a : [order]
+ order_group.present? ? order_group.orders.to_a.sort_by(&:id) : [order]
end
def complete_cart
diff --git a/spree/core/app/workflows/spree/orders/complete.rb b/spree/core/app/workflows/spree/orders/complete.rb
index 4b0a5e8c4e..9ee249a527 100644
--- a/spree/core/app/workflows/spree/orders/complete.rb
+++ b/spree/core/app/workflows/spree/orders/complete.rb
@@ -101,6 +101,10 @@ module Spree
# carrying the caller's notify_customer, which a freshly loaded one
# would not.
@order_group = result.value
+ # No child order is the purchase, this one included, so the customer is
+ # confirmed from the group instead and every child places silently.
+ @notify_customer_of_purchase = order.notify_customer
+ order.notify_customer = false
step :allocate_payment_splits
end
@@ -226,9 +230,9 @@ module Spree
#
# They place without processing payments, because the money was taken
# against the whole basket before the division and the group now holds
- # it, and silently, because one purchase means one confirmation email.
- # Only the ones still in draft, so a replay finishes an interrupted
- # division instead of re-placing what already went out.
+ # it, and silently, as every child of a division does. Only the ones
+ # still in draft, so a replay finishes an interrupted division instead of
+ # re-placing what already went out.
def complete_sibling_orders
return if order_group.nil?
@@ -242,7 +246,10 @@ module Spree
return unless order_group.orders.all?(&:placed?)
- order_group.publish_event('order_group.completed')
+ order_group.publish_event(
+ 'order_group.completed',
+ order_group.event_payload.merge(notify_customer: @notify_customer_of_purchase)
+ )
end
def place_sibling(sibling)
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index 91350d43e5..2b77c818ca 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -849,15 +849,6 @@ en:
company_invitations:
email_mismatch: This invitation was sent to a different email address.
not_pending: This invitation is no longer pending and cannot be revoked.
- company_mailer:
- invitation_email:
- action: Accept invitation
- expiry_notice: This invitation link will expire in 30 days.
- greeting: Hi,
- ignore_notice: If you were not expecting this invitation, you can safely ignore this email.
- instructions: You have been invited to join %{company} on %{store}. Accept the invitation to start purchasing on the company's behalf.
- subject: invitation to join %{company}
- title: Join %{company}
compare_at_amount: Compare at amount
compare_at_price: Compare at price
complete: complete
@@ -917,21 +908,6 @@ en:
anonymize_failed: The erasure could not be completed and nothing was changed
customer_group: Customer Group
customer_groups: Customer Groups
- customer_mailer:
- data_export_email:
- action: Download Your Data
- expiry_notice: This download link expires on %{date}.
- greeting: Hello,
- ignore_notice: If you did not request a copy of your data, please contact us.
- instructions: Your copy of the personal data we hold about you is ready. Use the button below to download it.
- subject: Your Data Is Ready to Download
- password_reset_email:
- action: Reset Password
- expiry_notice: This password reset link will expire shortly. If you did not request this, no action is needed.
- greeting: Hi %{name},
- ignore_notice: If you did not request a password reset, you can safely ignore this email. Your password will not be changed.
- instructions: We received a request to reset your password. Click the button below to choose a new password.
- subject: Password Reset Instructions
customer_support_email: Customer Support Email
customers: Customers
cut: Cut
@@ -990,14 +966,6 @@ en:
developers: Developers
digital:
digital_delivery: Digital Delivery
- digital_asset_mailer:
- files_ready_email:
- available_until: Available until %{date}
- dear_customer: Dear %{name},
- instructions: The files from your order %{number} are ready to download.
- store_team: "%{store_name} Team"
- subject: Your files are ready
- thanks: Thank you for your business.
digital_assets: Digital assets
digital_assets_attachment_must_be_private: Upload the file to private storage before attaching it
discontinue_on: Discontinue On
@@ -1150,17 +1118,6 @@ en:
free_shipping: Free Shipping
from: From
front_end: Front End
- fulfillment_mailer:
- fulfilled_email:
- dear_customer: Dear %{name},
- delivery_method: 'Delivery method: %{delivery_method}'
- fulfillment_summary: Fulfillment summary for order
- instructions: Your order %{number} has been fulfilled
- store_team: "%{store_name} Team"
- subject: Fulfillment Notification
- thanks: Thank you for your business.
- track_information: 'Tracking Information: %{tracking}'
- track_link: 'Tracking Link: %{url}'
fulfillments:
errors:
backordered_units: This fulfillment holds backordered units and cannot be handed over yet
@@ -1336,16 +1293,6 @@ en:
new_state: New State
new_user: New User
new_variant: New Variant
- newsletter_mailer:
- email_confirmation:
- dear_customer: Hey,
- ignore_disclaimer: If you didn't request this, please ignore this email.
- instructions: Please click the button below to verify your email address.
- message_copy_link: 'If the button doesn''t work please copy and paste the following link to your browser:'
- store_team: "%{store_name} Team"
- subject: Verify your email address
- thanks: Thank you
- verify_email_address_link: Verify email address
newsletter_subscribers: Newsletter Subscribers
next: Next
no_cc_type: N/A
@@ -1377,34 +1324,6 @@ en:
order: Order
order_canceled: Order canceled
order_cannot_be_deleted: Completed orders and orders with settled payments cannot be deleted
- order_mailer:
- cancel_email:
- dear_customer: Hey %{name},
- instructions: Your order has been CANCELED. Please retain this cancellation information for your records.
- order_summary_canceled: Order %{number} Summary [CANCELED]
- subject: Cancellation of Order
- thanks: Thank you for
- confirm_email:
- dear_customer: Hey %{name},
- instructions: Please review and retain the following order information for your records.
- order_summary: Order %{number} Summary
- subject: Order Confirmation
- thanks: Thank you
- payment_link_email:
- message: Please click the button below to pay for your order.
- message_copy_link: 'If the button doesn''t work please copy and paste the following link to your browser:'
- pay_for_order: Pay for order
- subject: 'Payment link for order #%{number}'
- po_number: 'PO Number: %{number}'
- store_owner_notification_email:
- heading: New Order Received
- instructions: You have received a new order.
- order_summary: Order %{number} Summary
- subject: "%{store_name} received a new order"
- thanks: Thank you
- store_team: "%{store_name} Team"
- subtotal: 'Subtotal:'
- total: 'Order Total:'
order_not_found: We couldn't find your order. Please try that action again.
order_number: Order %{number}
order_resumed: Order resumed
@@ -2008,16 +1927,6 @@ en:
return: return
return_errors:
outside_window: This order is outside the %{days}-day return window
- return_mailer:
- refunded_email:
- dear_customer: Dear %{name},
- instructions: Your return for order %{number} has been refunded.
- refund_summary: Refund Summary
- returned_items: Returned Items
- store_team: "%{store_name} Team"
- subject: Return Refunded
- thanks: Thank you for your business.
- total_refunded: 'Total refunded: %{total}'
return_quantity: Return Quantity
returned: Returned
returns: Returns
@@ -2058,22 +1967,6 @@ en:
selected_quantity_not_available: selected of %{item} is not available.
seller: Seller
seller_access_denied: You do not have access to this seller.
- seller_mailer:
- approved_email:
- action: Go to your dashboard
- heading: You're approved
- message: Your application to sell on %{store_name} has been approved. You can now list products and start taking orders.
- subject: You're approved to sell on %{store_name}
- get_in_touch: If you think this is a mistake, reply to this email or contact us at %{store_email}.
- greeting: Hi %{seller_name},
- rejected_email:
- heading: About your application
- message: Your application to sell on %{store_name} has not been accepted.
- subject: Your application to sell on %{store_name}
- suspended_email:
- heading: Your account has been suspended
- message: Selling on %{store_name} has been paused for your account. Your products and order history are unaffected.
- subject: Your %{store_name} account has been suspended
seller_membership_required: This account does not belong to any seller.
seller_payout_nothing_to_settle: This seller has nothing to settle right now.
seller_requirement_types:
@@ -2138,17 +2031,6 @@ en:
ship_total: Ship Total
shipment: Shipment
shipment_adjustments: Shipment adjustments
- shipment_mailer:
- shipped_email:
- dear_customer: Dear %{name},
- instructions: Your order %{number} has been shipped
- shipment_summary: Shipment Summary for order
- shipping_method: 'Shipping method: %{shipping_method}'
- store_team: "%{store_name} Team"
- subject: Shipment Notification
- thanks: Thank you for your business.
- track_information: 'Tracking Information: %{tracking}'
- track_link: 'Tracking Link: %{url}'
shipment_state: Shipment State
shipments: Shipments
shipped: Shipped
diff --git a/spree/core/db/migrate/20260916000001_add_email_delivery_flags_to_spree_order_groups.rb b/spree/core/db/migrate/20260916000001_add_email_delivery_flags_to_spree_order_groups.rb
new file mode 100644
index 0000000000..3c1cf35d33
--- /dev/null
+++ b/spree/core/db/migrate/20260916000001_add_email_delivery_flags_to_spree_order_groups.rb
@@ -0,0 +1,14 @@
+class AddEmailDeliveryFlagsToSpreeOrderGroups < ActiveRecord::Migration[8.1]
+ def change
+ # The same pair spree_orders carries, for the same reason: a confirmation
+ # is sent once, and completion is replayable — a resumed finalize
+ # re-publishes order_group.completed, so without a record of what was sent
+ # a customer gets the same email twice. These say what happened, not what
+ # the purchase is, so unlike the group's statuses they cannot be derived
+ # from the children.
+ add_column :spree_order_groups, :confirmation_delivered, :boolean, default: false
+ add_column :spree_order_groups, :store_owner_notification_delivered, :boolean, default: false
+
+ add_index :spree_order_groups, :confirmation_delivered
+ end
+end
diff --git a/spree/core/lib/spree/testing_support/factories/order_group_factory.rb b/spree/core/lib/spree/testing_support/factories/order_group_factory.rb
index 0484fae745..3da7f65d27 100644
--- a/spree/core/lib/spree/testing_support/factories/order_group_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/order_group_factory.rb
@@ -5,6 +5,55 @@ FactoryBot.define do
currency { 'USD' }
email { customer&.email }
+ # A split checkout as it actually leaves completion: each child holding a
+ # seller's item and the parcel that ships it. `:with_orders` builds bare
+ # orders, which is enough for roll-up arithmetic and not enough for
+ # anything that renders the purchase.
+ #
+ # One stock location per seller by default, so each parcel is quoted on its
+ # own delivery method and the group ships in as many parcels as it has
+ # children. Pass `shared_stock_location: true` for the marketplace-fulfilled
+ # shape instead: every child ships out of one warehouse on one method, which
+ # is what a divided parcel looks like after the split clones it.
+ trait :with_parcels do
+ transient do
+ sellers_count { 2 }
+ shared_stock_location { false }
+ end
+
+ after(:create) do |group, evaluator|
+ shared_location = create(:stock_location, name: "Shared #{group.number}") if evaluator.shared_stock_location
+ shared_method = create(:delivery_method, name: "Shared #{group.number}") if evaluator.shared_stock_location
+
+ evaluator.sellers_count.times do |index|
+ seller = create(:seller, :approved, store: group.store)
+ order = create(
+ :order_with_line_items,
+ store: group.store,
+ order_group: group,
+ seller: seller,
+ number: "#{group.number}-#{index + 1}",
+ customer: group.customer,
+ currency: group.currency,
+ line_items_count: 1
+ )
+ order.line_items.each { |line_item| line_item.update_columns(seller_id: seller.id) }
+
+ # The order factory already built the parcel; this decides where it
+ # ships from and by what, which is what the grouping reads.
+ fulfillment = order.fulfillments.first
+ fulfillment.update_columns(
+ stock_location_id: (shared_location || create(:stock_location, name: "#{seller.name} warehouse")).id
+ )
+ fulfillment.delivery_rates.destroy_all
+ fulfillment.add_delivery_method(shared_method || create(:delivery_method, name: "#{seller.name} delivery"), true)
+ order.recalculate_totals!
+ end
+
+ group.orders.reload
+ end
+ end
+
trait :with_orders do
transient do
sellers_count { 2 }
diff --git a/spree/core/lib/spree/testing_support/factories/payment_factory.rb b/spree/core/lib/spree/testing_support/factories/payment_factory.rb
index bcc79dc108..cc55a0ab8b 100644
--- a/spree/core/lib/spree/testing_support/factories/payment_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/payment_factory.rb
@@ -29,7 +29,12 @@ FactoryBot.define do
end
factory :store_credit_payment, class: Spree::Payment, parent: :payment do
- payment_method { create(:store_credit_payment_method, store: (order || cart).store) }
- source { create(:store_credit, store: (order || cart).store, customer: (order || cart).customer) }
+ # An order group owns payments like a cart or an order does, and a split
+ # checkout paid with store credit is exactly where that matters.
+ payment_method { create(:store_credit_payment_method, store: (order || cart || order_group).store) }
+ source do
+ owner = order || cart || order_group
+ create(:store_credit, store: owner.store, customer: owner.customer)
+ end
end
end
diff --git a/spree/core/spec/models/spree/order_group_spec.rb b/spree/core/spec/models/spree/order_group_spec.rb
index deeb76f585..06b293d63d 100644
--- a/spree/core/spec/models/spree/order_group_spec.rb
+++ b/spree/core/spec/models/spree/order_group_spec.rb
@@ -54,6 +54,136 @@ RSpec.describe Spree::OrderGroup, type: :model do
end
end
+ describe '#fulfillment_groups' do
+ # The whole point: "how many orders" and "how many parcels" are different
+ # numbers, and a customer is owed the second.
+ it 'counts one parcel per warehouse-and-method, not one per child order' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 3)
+
+ expect(group.orders.count).to eq(3)
+ expect(group.fulfillment_groups.size).to eq(3)
+ end
+
+ it 'collapses the halves of a parcel the split divided' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 3, shared_stock_location: true)
+
+ expect(group.orders.count).to eq(3)
+ expect(group.fulfillment_groups.size).to eq(1)
+ end
+
+ it 'gives a divided parcel back the whole charge the customer was quoted' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2, shared_stock_location: true)
+ quoted = group.fulfillments.sum(&:discounted_cost)
+
+ expect(group.fulfillment_groups.sole.cost).to eq(quoted)
+ end
+
+ it 'carries the goods and the sellers of every half it collapsed' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2, shared_stock_location: true)
+ parcel = group.fulfillment_groups.sole
+
+ expect(parcel.line_items).to match_array(group.line_items)
+ expect(parcel.sellers).to match_array(group.sellers)
+ end
+
+ # Fulfillment#delivery_method falls back to an unselected rate, and the
+ # split's clone copies only the selected one — so the fallback would leave
+ # two halves of one box looking like two parcels.
+ it 'collapses halves whose rate was never selected' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2, shared_stock_location: true)
+ first, second = group.fulfillments.order(:id).to_a
+ first.delivery_rates.update_all(selected: false)
+ second.delivery_rates.destroy_all
+
+ expect(group.reload.fulfillment_groups.size).to eq(1)
+ end
+
+ it 'names each parcel by the rate the customer chose' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2)
+
+ expect(group.fulfillment_groups.map(&:name)).to all(be_present)
+ end
+ end
+
+ describe 'a line packed from two warehouses' do
+ let(:group) { create(:order_group, :with_parcels, store: store, sellers_count: 1) }
+ let(:order) { group.orders.sole }
+ let(:line_item) { order.line_items.sole }
+
+ before do
+ line_item.update_columns(quantity: 3)
+ order.fulfillments.sole.fulfillment_items.sole.update_columns(quantity: 2)
+ second_parcel = create(:fulfillment, order: order, stock_location: create(:stock_location, name: 'Overflow'), tracking: nil)
+ second_parcel.fulfillment_items.destroy_all
+ second_parcel.fulfillment_items.create!(
+ order_id: order.id, variant_id: line_item.variant_id, line_item_id: line_item.id, quantity: 1
+ )
+ group.reload
+ end
+
+ it 'ships in two parcels' do
+ expect(group.fulfillment_groups.size).to eq(2)
+ end
+
+ # Both parcels carry the same line, so printing the line's own quantity in
+ # each would show the customer more goods than they bought.
+ it 'tells each parcel only what it carries' do
+ expect(group.fulfillment_groups.map { |parcel| parcel.manifest.sum(&:quantity) }).to contain_exactly(2, 1)
+ end
+
+ it 'still counts the line once as fulfilled' do
+ expect(group.unfulfilled_line_items).to be_empty
+ end
+ end
+
+ describe '#gift_card_total' do
+ # The group claims every payment at completion, so a child asked for its
+ # own gift-card total answers zero — and a confirmation rolling those up
+ # would omit a deduction its own total line makes.
+ it 'reads the payments the group holds, not the children it took them from' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2)
+ gift_card = create(:gift_card, store: store, amount: 25)
+ store_credit = create(:store_credit, amount: 25, originator: gift_card, store: store)
+ group.orders.first.update!(gift_card: gift_card)
+ create(:store_credit_payment, order: nil, order_group: group, source: store_credit, amount: 25)
+
+ expect(group.reload.gift_card_total).to eq(25)
+ end
+
+ it 'is zero without a gift card' do
+ expect(create(:order_group, store: store).gift_card_total).to eq(0)
+ end
+ end
+
+ describe '#unfulfilled_line_items' do
+ it 'is empty when every item travels in a parcel' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2)
+
+ expect(group.unfulfilled_line_items).to be_empty
+ end
+
+ # A download has nothing to ship, and a confirmation organised by parcel
+ # would otherwise never mention it.
+ it 'names what no parcel carries' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2)
+ digital_order = create(:order, store: store, order_group: group)
+ download = create(:line_item, order: digital_order)
+
+ expect(group.reload.unfulfilled_line_items).to match_array([download])
+ end
+ end
+
+ describe 'facts about the purchase rather than one seller\'s part of it' do
+ it 'answers for the locale, the PO number and who to address' do
+ group = create(:order_group, :with_parcels, store: store, sellers_count: 2)
+ group.orders.each { |order| order.update_columns(locale: 'de', po_number: 'PO-4471') }
+
+ expect(group.reload.locale).to eq('de')
+ expect(group.po_number).to eq('PO-4471')
+ expect(group.name).to eq(group.bill_address&.full_name || group.ship_address&.full_name)
+ end
+ end
+
describe '#sellers' do
it 'names the sellers it reached, first-party contributing none' do
create(:order, store: store, order_group: group)
diff --git a/spree/core/spec/workflows/spree/carts/complete_split_spec.rb b/spree/core/spec/workflows/spree/carts/complete_split_spec.rb
index b4a74197f3..9d19bdc0bf 100644
--- a/spree/core/spec/workflows/spree/carts/complete_split_spec.rb
+++ b/spree/core/spec/workflows/spree/carts/complete_split_spec.rb
@@ -572,6 +572,51 @@ module Spree
end
end
+ # One purchase, one confirmation — and no child order is the purchase, so
+ # none of them sends it. The customer's email hangs off the group instead
+ # (Spree::OrderGroupEmailSubscriber).
+ describe 'the confirmation' do
+ let(:cart) { cart_for(nil, seller, other_seller) }
+
+ # Asserted on the payload rather than the records: notify_customer is an
+ # in-memory flag, and the group reloads its children after placing them.
+ it 'places every child silently', :events do
+ placements = []
+ allow(Spree::Events).to receive(:publish) do |name, payload, *|
+ placements << payload if name == 'order.placed'
+ end
+
+ described_class.call(cart: cart)
+
+ expect(placements.size).to eq(3)
+ expect(placements.map { |payload| payload[:notify_customer] }).to all(be false)
+ end
+
+ # The old shape marked the first child confirmed and left the customer
+ # with an email covering a fraction of what they paid.
+ it 'leaves no child claiming it confirmed the purchase' do
+ group = described_class.call(cart: cart).value
+
+ expect(group.orders.map(&:confirmation_delivered)).to all(be false)
+ end
+
+ it 'announces the purchase once, whatever the children', :events do
+ events = []
+ allow(Spree::Events).to receive(:publish) { |name, *| events << name }
+
+ described_class.call(cart: cart)
+
+ expect(events.count('order_group.completed')).to eq(1)
+ end
+
+ it 'leaves a checkout that did not split to send its own' do
+ order = described_class.call(cart: cart_for(seller, seller)).value
+
+ expect(order).to be_a(Spree::Order)
+ expect(order.notify_customer).to be_nil
+ end
+ end
+
# The commission engine listens for order.placed, which every child
# publishes on its own — so a split checkout charges each seller with no
# marketplace code in the commission engine at all.
diff --git a/spree/core/spec/workflows/spree/orders/complete_spec.rb b/spree/core/spec/workflows/spree/orders/complete_spec.rb
index 14a4f2776c..54c8602b6d 100644
--- a/spree/core/spec/workflows/spree/orders/complete_spec.rb
+++ b/spree/core/spec/workflows/spree/orders/complete_spec.rb
@@ -227,6 +227,33 @@ module Spree
draft.reload
end
+ # The group event is what confirms the customer, so an operator
+ # completing a draft quietly must not be answered with an email.
+ it 'carries a silent completion onto the group event', :events do
+ draft = draft_for(seller, other_seller)
+ payloads = []
+ allow(Spree::Events).to receive(:publish) do |name, payload, *|
+ payloads << payload if name == 'order_group.completed'
+ end
+
+ described_class.call(order: draft, notify_customer: false)
+
+ expect(payloads.size).to eq(1)
+ expect(payloads.first[:notify_customer]).to be false
+ end
+
+ it 'leaves an ordinary division free to confirm the purchase', :events do
+ draft = draft_for(seller, other_seller)
+ payloads = []
+ allow(Spree::Events).to receive(:publish) do |name, payload, *|
+ payloads << payload if name == 'order_group.completed'
+ end
+
+ described_class.call(order: draft)
+
+ expect(payloads.first[:notify_customer]).to be_nil
+ end
+
it 'stamps a single seller onto the order' do
draft = draft_for(seller, seller)
diff --git a/spree/emails/app/mailers/spree/order_group_mailer.rb b/spree/emails/app/mailers/spree/order_group_mailer.rb
new file mode 100644
index 0000000000..589e127aef
--- /dev/null
+++ b/spree/emails/app/mailers/spree/order_group_mailer.rb
@@ -0,0 +1,51 @@
+module Spree
+ # The purchase a customer made, when it produced more than one order.
+ #
+ # A checkout spanning several sellers divides into one order per seller, and
+ # no one of them is the purchase — each holds a single seller's items,
+ # delivery and total. So the confirmation is sent from the group: one email
+ # naming the number the customer saw at checkout, every item they bought, the
+ # total they actually paid, and the parcels it will arrive in.
+ #
+ # Kept separate from +Spree::OrderMailer+ rather than folded into it: a
+ # checkout that does not split is still one order and still sends that
+ # email unchanged, and a storefront replacing one document should not have to
+ # inherit the other.
+ class OrderGroupMailer < BaseMailer
+ helper Spree::MailHelper
+
+ # @param order_group [Spree::OrderGroup, Integer, String] record or id
+ # @param resend [Boolean] prefixes the subject, for an admin re-send
+ def confirm_email(order_group, resend = false)
+ @order_group = find_order_group(order_group)
+ # Assigned rather than left to BaseMailer#current_store, which memoizes
+ # off @order and would otherwise fall back to the default store — the
+ # wrong store's name, logo and footer on a multi-store install.
+ @current_store = @order_group.store
+
+ with_store_locale(@current_store, @order_group.locale) do
+ subject = order_email_subject(
+ @current_store, Spree.t('order_group_mailer.confirm_email.subject'), @order_group.number, resend: resend
+ )
+ mail(to: @order_group.email, subject: subject, store_url: @current_store.storefront_url)
+ end
+ end
+
+ def store_owner_notification_email(order_group)
+ @order_group = find_order_group(order_group)
+ @current_store = @order_group.store
+
+ with_store_locale(@current_store) do
+ subject = Spree.t('order_group_mailer.store_owner_notification_email.subject', store_name: @current_store.name)
+ mail(to: @current_store.new_order_notifications_email, subject: subject,
+ store_url: @current_store.storefront_url)
+ end
+ end
+
+ private
+
+ def find_order_group(order_group)
+ order_group.respond_to?(:id) ? order_group : Spree::OrderGroup.find(order_group)
+ end
+ end
+end
diff --git a/spree/emails/app/subscribers/spree/order_email_subscriber.rb b/spree/emails/app/subscribers/spree/order_email_subscriber.rb
index 499c58b006..5ae9ca1857 100644
--- a/spree/emails/app/subscribers/spree/order_email_subscriber.rb
+++ b/spree/emails/app/subscribers/spree/order_email_subscriber.rb
@@ -27,14 +27,19 @@ module Spree
order.update_column(:confirmation_delivered, true)
end
+ # An admin resends from an order, because an order is what they are looking
+ # at. On a split checkout the document to send is still the purchase's —
+ # sending this child's would put back the partial confirmation the group
+ # email exists to replace.
def resend_confirmation_email(event)
order = find_order(event)
return unless order
+ return order.order_group.publish_event('order_group.resend_confirmation_email') if order.grouped?
store = order.store
return unless store.prefers_send_consumer_transactional_emails?
- OrderMailer.confirm_email(order.id).deliver_later
+ OrderMailer.confirm_email(order.id, true).deliver_later
order.update_column(:confirmation_delivered, true)
end
@@ -50,6 +55,9 @@ module Spree
end
def send_store_owner_notification(order)
+ # A divided checkout tells the store about the purchase once, from the
+ # group, rather than once per seller order.
+ return if order.grouped?
return if order.store_owner_notification_delivered?
return if order.store.new_order_notifications_email.blank?
diff --git a/spree/emails/app/subscribers/spree/order_group_email_subscriber.rb b/spree/emails/app/subscribers/spree/order_group_email_subscriber.rb
new file mode 100644
index 0000000000..575b6d4b04
--- /dev/null
+++ b/spree/emails/app/subscribers/spree/order_group_email_subscriber.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+module Spree
+ # The confirmation for a checkout that produced more than one order.
+ #
+ # Its child orders place silently (+Spree::Carts::Complete#complete_orders+),
+ # because none of them is the purchase — this is what tells the customer what
+ # they bought, what they paid and how it arrives.
+ class OrderGroupEmailSubscriber < Spree::Subscriber
+ subscribes_to 'order_group.completed', 'order_group.resend_confirmation_email'
+
+ on 'order_group.completed', :send_confirmation_email
+ on 'order_group.resend_confirmation_email', :resend_confirmation_email
+
+ private
+
+ def send_confirmation_email(event)
+ order_group = find_order_group(event)
+ return unless order_group
+
+ send_customer_confirmation(order_group, event)
+ send_store_owner_notification(order_group)
+ end
+
+ # The operator is a different audience: silencing the customer, or turning
+ # their receipts off, says nothing about whether the store wants to hear
+ # about the sale.
+ def send_customer_confirmation(order_group, event)
+ return if order_group.confirmation_delivered?
+ return if event.payload['notify_customer'] == false
+ return unless order_group.store.prefers_send_consumer_transactional_emails?
+
+ OrderGroupMailer.confirm_email(order_group.id).deliver_later
+ order_group.update_column(:confirmation_delivered, true)
+ end
+
+ def resend_confirmation_email(event)
+ order_group = find_order_group(event)
+ return unless order_group
+ return unless order_group.store.prefers_send_consumer_transactional_emails?
+
+ OrderGroupMailer.confirm_email(order_group.id, true).deliver_later
+ order_group.update_column(:confirmation_delivered, true)
+ end
+
+ # One notification per purchase, like the customer's. Told about the
+ # checkout rather than about each seller's share of it, because that is
+ # what happened.
+ def send_store_owner_notification(order_group)
+ return if order_group.store_owner_notification_delivered?
+ return if order_group.store.new_order_notifications_email.blank?
+
+ OrderGroupMailer.store_owner_notification_email(order_group.id).deliver_later
+ order_group.update_column(:store_owner_notification_delivered, true)
+ end
+
+ def find_order_group(event)
+ Spree::OrderGroup.find_by_prefix_id(event.payload['id'])
+ end
+ end
+end
diff --git a/spree/emails/app/views/spree/order_group_mailer/confirm_email.html.erb b/spree/emails/app/views/spree/order_group_mailer/confirm_email.html.erb
new file mode 100644
index 0000000000..4836eef8db
--- /dev/null
+++ b/spree/emails/app/views/spree/order_group_mailer/confirm_email.html.erb
@@ -0,0 +1,38 @@
+<%= render 'spree/shared/purchased_items_styles' %>
+
+<% fulfillment_groups = @order_group.fulfillment_groups %>
+<% unfulfilled_line_items = @order_group.unfulfilled_line_items(fulfillment_groups) %>
+
+<%= render layout: 'spree/shared/mailer_hero' do %>
+ <h1><%= Spree.t('order_group_mailer.confirm_email.subject') %></h1>
+ <p class="greeting"><%= Spree.t('order_group_mailer.confirm_email.dear_customer', name: name_for(@order_group)) %></p>
+ <p><%= Spree.t('order_group_mailer.confirm_email.instructions', number: @order_group.number) %></p>
+ <%# What the customer most needs and least expects: this arrives in more
+ than one delivery. Counted from the parcels, never from the orders the
+ checkout divided into — several sellers shipping out of one warehouse
+ send one box. %>
+ <% if fulfillment_groups.many? %>
+ <p><%= Spree.t('order_group_mailer.confirm_email.arriving_separately', count: fulfillment_groups.size) %></p>
+ <% end %>
+<% end %>
+
+<% if @order_group.po_number.present? %>
+ <p class="f-fallback"><%= Spree.t('order_mailer.po_number', number: @order_group.po_number) %></p>
+<% end %>
+
+<% fulfillment_groups.each_with_index do |fulfillment_group, index| %>
+ <%= render 'spree/shared/fulfillment_group_section',
+ fulfillment_group: fulfillment_group,
+ position: index + 1,
+ count: fulfillment_groups.size %>
+<% end %>
+
+<% if unfulfilled_line_items.any? %>
+ <%= render 'spree/shared/order_summary_section',
+ heading: Spree.t('order_group_mailer.nothing_to_ship'),
+ line_items: unfulfilled_line_items,
+ order: @order_group,
+ totals: false %>
+<% end %>
+
+<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
diff --git a/spree/emails/app/views/spree/order_group_mailer/confirm_email.text.erb b/spree/emails/app/views/spree/order_group_mailer/confirm_email.text.erb
new file mode 100644
index 0000000000..e3f2fd091e
--- /dev/null
+++ b/spree/emails/app/views/spree/order_group_mailer/confirm_email.text.erb
@@ -0,0 +1,26 @@
+<% fulfillment_groups = @order_group.fulfillment_groups %>
+<% unfulfilled_line_items = @order_group.unfulfilled_line_items(fulfillment_groups) %>
+<%= Spree.t('order_group_mailer.confirm_email.dear_customer', name: name_for(@order_group)) %>
+
+<%= Spree.t('order_group_mailer.confirm_email.instructions', number: @order_group.number) %>
+<% if fulfillment_groups.many? %>
+<%= Spree.t('order_group_mailer.confirm_email.arriving_separately', count: fulfillment_groups.size) %>
+<% end %>
+<%= render 'spree/shared/po_number', order: @order_group %>
+<% fulfillment_groups.each_with_index do |fulfillment_group, index| %>
+============================================================
+<%= render 'spree/shared/fulfillment_group_section',
+ fulfillment_group: fulfillment_group,
+ position: index + 1,
+ count: fulfillment_groups.size %>
+<% end %>
+<% if unfulfilled_line_items.any? %>
+============================================================
+<%= Spree.t('order_group_mailer.nothing_to_ship') %>
+<% unfulfilled_line_items.each do |item| %>
+ <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text -%> (<%= item.quantity %>) <%= Spree.t('at_symbol') %> <%= item.single_money %> = <%= item.display_amount %>
+<% end %>
+<% end %>
+<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
+<%= Spree.t('order_group_mailer.confirm_email.thanks') %>
+<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.html.erb b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.html.erb
new file mode 100644
index 0000000000..0860fa5ae0
--- /dev/null
+++ b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.html.erb
@@ -0,0 +1,14 @@
+<%= render 'spree/shared/purchased_items_styles' %>
+
+<%= render layout: 'spree/shared/mailer_hero' do %>
+ <h1><%= Spree.t('order_group_mailer.store_owner_notification_email.heading') %></h1>
+ <p><%= Spree.t('order_group_mailer.store_owner_notification_email.instructions', count: @order_group.orders.size) %></p>
+<% end %>
+
+<%= render 'spree/shared/order_summary_section',
+ heading: Spree.t('order_group_mailer.store_owner_notification_email.purchase_summary', number: @order_group.number),
+ line_items: @order_group.line_items,
+ order: @order_group,
+ totals: false %>
+
+<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
diff --git a/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.text.erb b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.text.erb
new file mode 100644
index 0000000000..0caaf15ee5
--- /dev/null
+++ b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.text.erb
@@ -0,0 +1,11 @@
+<%= Spree.t('order_group_mailer.store_owner_notification_email.instructions', count: @order_group.orders.size) %>
+
+============================================================
+<%= Spree.t('order_group_mailer.store_owner_notification_email.purchase_summary', number: @order_group.number) %>
+============================================================
+<%= render 'spree/shared/po_number', order: @order_group %>
+<% @order_group.line_items.each do |item| %>
+ <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text -%> (<%= item.quantity %>) <%= Spree.t('at_symbol') %> <%= item.single_money %> = <%= item.display_amount %>
+<% end %>
+<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
+<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/shared/_fulfillment_group_section.html.erb b/spree/emails/app/views/spree/shared/_fulfillment_group_section.html.erb
new file mode 100644
index 0000000000..5a35ca8337
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_fulfillment_group_section.html.erb
@@ -0,0 +1,37 @@
+<%# One real parcel of a purchase, with the goods it carries and what it cost
+ to deliver. Locals: fulfillment_group, position, count.
+
+ A purchase arriving in one parcel is not numbered — "Delivery 1 of 1"
+ tells the customer nothing they did not already assume.
+
+ Rendered from the parcel's manifest rather than its line items: a line
+ packed from two warehouses travels in two parcels, and its own quantity
+ describes the whole order rather than this box. %>
+<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">
+ <tr>
+ <td>
+ <h3 class="f-fallback">
+ <% if count > 1 %>
+ <%= Spree.t('order_group_mailer.delivery_numbered', position: position, count: count) %>
+ <% else %>
+ <%= Spree.t('order_group_mailer.delivery') %>
+ <% end %>
+ </h3>
+ <% if fulfillment_group.sellers.any? %>
+ <p class="f-fallback sub"><%= Spree.t('order_group_mailer.sold_by', sellers: fulfillment_group.sellers.map(&:name).to_sentence) %></p>
+ <% end %>
+ <% fulfillment_group.manifest.each do |item| %>
+ <%= render 'spree/shared/purchased_items_table/line_item',
+ line_item: item.line_item,
+ quantity: item.quantity,
+ amount: Spree::Money.new(item.line_item.price * item.quantity, currency: item.line_item.currency) %>
+ <% end %>
+ <table class="summary purchase_content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: Spree.t(:shipping),
+ sub: fulfillment_group.name,
+ value: fulfillment_group.display_cost %>
+ </table>
+ </td>
+ </tr>
+</table>
diff --git a/spree/emails/app/views/spree/shared/_fulfillment_group_section.text.erb b/spree/emails/app/views/spree/shared/_fulfillment_group_section.text.erb
new file mode 100644
index 0000000000..615333e5b1
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_fulfillment_group_section.text.erb
@@ -0,0 +1,12 @@
+<% if count > 1 %>
+<%= Spree.t('order_group_mailer.delivery_numbered', position: position, count: count) %>
+<% else %>
+<%= Spree.t('order_group_mailer.delivery') %>
+<% end %>
+<% if fulfillment_group.sellers.any? %>
+<%= Spree.t('order_group_mailer.sold_by', sellers: fulfillment_group.sellers.map(&:name).to_sentence) %>
+<% end %>
+<% fulfillment_group.manifest.each do |item| %>
+ <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text -%> (<%= item.quantity %>) <%= Spree.t('at_symbol') %> <%= item.line_item.single_money %> = <%= Spree::Money.new(item.line_item.price * item.quantity, currency: item.line_item.currency) %>
+<% end %>
+ <%= Spree.t(:shipping) %>: <%= fulfillment_group.name %> <%= fulfillment_group.display_cost %>
diff --git a/spree/emails/app/views/spree/shared/_purchase_totals.html.erb b/spree/emails/app/views/spree/shared/_purchase_totals.html.erb
new file mode 100644
index 0000000000..15631e2ef4
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_purchase_totals.html.erb
@@ -0,0 +1,62 @@
+<%# Every figure of the whole purchase, once. Locals: order_group.
+
+ Deliberately not the order summary's own totals block: that one reaches
+ into one order's fulfillments and money rows, and a purchase has neither
+ of its own. These read the group's roll-up of what each child independently
+ computed. Delivery is one line here and broken down per parcel above. %>
+<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">
+ <tr>
+ <td>
+ <h3 class="f-fallback"><%= Spree.t(:order_summary) %></h3>
+ <table class="summary purchase_content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: Spree.t('order_mailer.subtotal'),
+ value: order_group.display_item_total %>
+
+ <% order_group.discounts.promotion.to_a.group_by(&:label).each do |label, discounts| %>
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: Spree.t(:promotion),
+ sub: label,
+ value: Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
+ <% end %>
+
+ <% if order_group.delivery_total != 0 %>
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: Spree.t(:shipping),
+ value: order_group.display_delivery_total %>
+ <% end %>
+
+ <% if order_group.additional_tax_total != 0 %>
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: Spree.t(:tax),
+ value: order_group.display_additional_tax_total %>
+ <% end %>
+
+ <% if order_group.gift_card_total.positive? %>
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: Spree.t(:gift_card),
+ value: safe_join(['-', order_group.display_gift_card_total.to_html]) %>
+ <% end %>
+
+ <% order_group.discounts.manual.to_a.group_by(&:label).each do |label, discounts| %>
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: label,
+ value: Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
+ <% end %>
+
+ <% order_group.fees.to_a.group_by(&:label).each do |label, fees| %>
+ <% amount = fees.sum(&:amount) %>
+ <% next if amount.zero? %>
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ label: label,
+ value: Spree::Money.new(amount, currency: order_group.currency) %>
+ <% end %>
+
+ <%= render 'spree/shared/purchased_items_table/summary_row',
+ row_class: 'summary_total',
+ label: Spree.t('order_mailer.total'),
+ value: order_group.display_total_minus_store_credits %>
+ </table>
+ </td>
+ </tr>
+</table>
diff --git a/spree/emails/app/views/spree/shared/_purchase_totals.text.erb b/spree/emails/app/views/spree/shared/_purchase_totals.text.erb
new file mode 100644
index 0000000000..af817c13a2
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_purchase_totals.text.erb
@@ -0,0 +1,24 @@
+============================================================
+<%= Spree.t('order_mailer.subtotal') %> <%= order_group.display_item_total %>
+<% order_group.discounts.promotion.to_a.group_by(&:label).each do |label, discounts| %>
+ <%= Spree.t(:promotion) %>: <%= label %> <%= Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
+<% end %>
+<% if order_group.delivery_total != 0 %>
+ <%= Spree.t(:shipping) %>: <%= order_group.display_delivery_total %>
+<% end %>
+<% if order_group.additional_tax_total != 0 %>
+ <%= Spree.t(:tax) %>: <%= order_group.display_additional_tax_total %>
+<% end %>
+<% if order_group.gift_card_total.positive? %>
+ <%= Spree.t(:gift_card) %>: -<%= order_group.display_gift_card_total %>
+<% end %>
+<% order_group.discounts.manual.to_a.group_by(&:label).each do |label, discounts| %>
+ <%= label %> <%= Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
+<% end %>
+<% order_group.fees.to_a.group_by(&:label).each do |label, fees| %>
+ <% amount = fees.sum(&:amount) %>
+ <% next if amount.zero? %>
+ <%= label %> <%= Spree::Money.new(amount, currency: order_group.currency) %>
+<% end %>
+============================================================
+<%= Spree.t('order_mailer.total') %> <%= order_group.display_total_minus_store_credits %>
diff --git a/spree/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb b/spree/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb
index 800d65338f..4f5e13a68c 100644
--- a/spree/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb
+++ b/spree/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb
@@ -1,3 +1,8 @@
+<%# One purchased line. Locals: line_item, and optionally quantity + amount
+ for a view showing part of a line — a parcel carrying two of the three
+ ordered, say — where the line's own figures describe more than is there. %>
+<% quantity = local_assigns.fetch(:quantity, line_item.quantity) %>
+<% amount = local_assigns.fetch(:amount, line_item.display_amount) %>
<table class="item" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="item_image" width="96" valign="middle">
@@ -12,8 +17,8 @@
<% end %>
</td>
<td class="item_amount" align="right" valign="middle">
- <p class="item_qty f-fallback"><%= line_item.quantity %> x <%= line_item.single_money %></p>
- <p class="item_price f-fallback"><%= line_item.display_amount %></p>
+ <p class="item_qty f-fallback"><%= quantity %> x <%= line_item.single_money %></p>
+ <p class="item_price f-fallback"><%= amount %></p>
</td>
</tr>
</table>
diff --git a/spree/emails/config/i18n-tasks.yml b/spree/emails/config/i18n-tasks.yml
new file mode 100644
index 0000000000..9613adde44
--- /dev/null
+++ b/spree/emails/config/i18n-tasks.yml
@@ -0,0 +1,22 @@
+base_locale: en
+
+data:
+ yaml:
+ write:
+ # do not wrap lines at 80 characters
+ line_width: -1
+
+ # Core's keys are read but never written here: the mailers and their
+ # templates share the vocabulary every Spree surface uses (shipping, tax,
+ # promotion) and only own the copy of the emails themselves.
+ external:
+ - "<%= File.expand_path('../core/config/locales', Dir.pwd) %>/%{locale}.yml"
+
+# Find translate calls
+search:
+ paths:
+ - 'app'
+ - 'lib'
+
+# The PatternMapper for Spree.t
+<% I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper', patterns: [['\bSpree\.t[( ]\s*%{key}', 'spree.%{key}']] %>
diff --git a/spree/emails/config/locales/en.yml b/spree/emails/config/locales/en.yml
new file mode 100644
index 0000000000..062324392c
--- /dev/null
+++ b/spree/emails/config/locales/en.yml
@@ -0,0 +1,141 @@
+---
+en:
+ spree:
+ company_mailer:
+ invitation_email:
+ action: Accept invitation
+ expiry_notice: This invitation link will expire in 30 days.
+ greeting: Hi,
+ ignore_notice: If you were not expecting this invitation, you can safely ignore this email.
+ instructions: You have been invited to join %{company} on %{store}. Accept the invitation to start purchasing on the company's behalf.
+ subject: invitation to join %{company}
+ title: Join %{company}
+ customer_mailer:
+ data_export_email:
+ action: Download Your Data
+ expiry_notice: This download link expires on %{date}.
+ greeting: Hello,
+ ignore_notice: If you did not request a copy of your data, please contact us.
+ instructions: Your copy of the personal data we hold about you is ready. Use the button below to download it.
+ subject: Your Data Is Ready to Download
+ password_reset_email:
+ action: Reset Password
+ expiry_notice: This password reset link will expire shortly. If you did not request this, no action is needed.
+ greeting: Hi %{name},
+ ignore_notice: If you did not request a password reset, you can safely ignore this email. Your password will not be changed.
+ instructions: We received a request to reset your password. Click the button below to choose a new password.
+ subject: Password Reset Instructions
+ digital_asset_mailer:
+ files_ready_email:
+ available_until: Available until %{date}
+ dear_customer: Dear %{name},
+ instructions: The files from your order %{number} are ready to download.
+ store_team: "%{store_name} Team"
+ subject: Your files are ready
+ thanks: Thank you for your business.
+ fulfillment_mailer:
+ fulfilled_email:
+ dear_customer: Dear %{name},
+ delivery_method: 'Delivery method: %{delivery_method}'
+ fulfillment_summary: Fulfillment summary for order
+ instructions: Your order %{number} has been fulfilled
+ store_team: "%{store_name} Team"
+ subject: Fulfillment Notification
+ thanks: Thank you for your business.
+ track_information: 'Tracking Information: %{tracking}'
+ track_link: 'Tracking Link: %{url}'
+ newsletter_mailer:
+ email_confirmation:
+ dear_customer: Hey,
+ ignore_disclaimer: If you didn't request this, please ignore this email.
+ instructions: Please click the button below to verify your email address.
+ message_copy_link: 'If the button doesn''t work please copy and paste the following link to your browser:'
+ store_team: "%{store_name} Team"
+ subject: Verify your email address
+ thanks: Thank you
+ verify_email_address_link: Verify email address
+ order_group_mailer:
+ confirm_email:
+ arriving_separately:
+ one: Your order is arriving in one delivery.
+ other: Your order is arriving in %{count} separate deliveries.
+ dear_customer: Hey %{name},
+ instructions: Please review and retain the following information about order %{number} for your records.
+ subject: Order Confirmation
+ thanks: Thank you
+ delivery: Delivery
+ delivery_numbered: Delivery %{position} of %{count}
+ nothing_to_ship: Nothing to ship
+ sold_by: Sold by %{sellers}
+ store_owner_notification_email:
+ heading: New Order Received
+ instructions:
+ one: You have received a new order.
+ other: You have received a new order, split across %{count} seller orders.
+ purchase_summary: Order %{number} Summary
+ subject: "%{store_name} received a new order"
+ order_mailer:
+ cancel_email:
+ dear_customer: Hey %{name},
+ instructions: Your order has been CANCELED. Please retain this cancellation information for your records.
+ order_summary_canceled: Order %{number} Summary [CANCELED]
+ subject: Cancellation of Order
+ thanks: Thank you for
+ confirm_email:
+ dear_customer: Hey %{name},
+ instructions: Please review and retain the following order information for your records.
+ order_summary: Order %{number} Summary
+ subject: Order Confirmation
+ thanks: Thank you
+ payment_link_email:
+ message: Please click the button below to pay for your order.
+ message_copy_link: 'If the button doesn''t work please copy and paste the following link to your browser:'
+ pay_for_order: Pay for order
+ subject: 'Payment link for order #%{number}'
+ po_number: 'PO Number: %{number}'
+ store_owner_notification_email:
+ heading: New Order Received
+ instructions: You have received a new order.
+ order_summary: Order %{number} Summary
+ subject: "%{store_name} received a new order"
+ thanks: Thank you
+ store_team: "%{store_name} Team"
+ subtotal: 'Subtotal:'
+ total: 'Order Total:'
+ return_mailer:
+ refunded_email:
+ dear_customer: Dear %{name},
+ instructions: Your return for order %{number} has been refunded.
+ refund_summary: Refund Summary
+ returned_items: Returned Items
+ store_team: "%{store_name} Team"
+ subject: Return Refunded
+ thanks: Thank you for your business.
+ total_refunded: 'Total refunded: %{total}'
+ seller_mailer:
+ approved_email:
+ action: Go to your dashboard
+ heading: You're approved
+ message: Your application to sell on %{store_name} has been approved. You can now list products and start taking orders.
+ subject: You're approved to sell on %{store_name}
+ get_in_touch: If you think this is a mistake, reply to this email or contact us at %{store_email}.
+ greeting: Hi %{seller_name},
+ rejected_email:
+ heading: About your application
+ message: Your application to sell on %{store_name} has not been accepted.
+ subject: Your application to sell on %{store_name}
+ suspended_email:
+ heading: Your account has been suspended
+ message: Selling on %{store_name} has been paused for your account. Your products and order history are unaffected.
+ subject: Your %{store_name} account has been suspended
+ shipment_mailer:
+ shipped_email:
+ dear_customer: Dear %{name},
+ instructions: Your order %{number} has been shipped
+ shipment_summary: Shipment Summary for order
+ shipping_method: 'Shipping method: %{shipping_method}'
+ store_team: "%{store_name} Team"
+ subject: Shipment Notification
+ thanks: Thank you for your business.
+ track_information: 'Tracking Information: %{tracking}'
+ track_link: 'Tracking Link: %{url}'
diff --git a/spree/emails/lib/spree/emails/engine.rb b/spree/emails/lib/spree/emails/engine.rb
index 803f9577c2..e71fc71e75 100644
--- a/spree/emails/lib/spree/emails/engine.rb
+++ b/spree/emails/lib/spree/emails/engine.rb
@@ -21,6 +21,7 @@ module Spree
config.after_initialize do
Spree.subscribers.concat [
Spree::OrderEmailSubscriber,
+ Spree::OrderGroupEmailSubscriber,
Spree::FulfillmentEmailSubscriber,
Spree::ReturnEmailSubscriber,
Spree::NewsletterSubscriberEmailSubscriber,
diff --git a/spree/emails/lib/spree/emails/previews/order_group_preview.rb b/spree/emails/lib/spree/emails/previews/order_group_preview.rb
new file mode 100644
index 0000000000..d6c8a2d4e7
--- /dev/null
+++ b/spree/emails/lib/spree/emails/previews/order_group_preview.rb
@@ -0,0 +1,30 @@
+require 'spree/core/previews/preview_data'
+
+# Preview the purchase confirmation for a split checkout at
+# /rails/mailers/spree/order_group
+class Spree::OrderGroupPreview < ActionMailer::Preview
+ include Spree::PreviewData::LocaleParam
+
+ def confirm_email
+ Spree::OrderGroupMailer.confirm_email(order_group)
+ end
+
+ def store_owner_notification_email
+ Spree::OrderGroupMailer.store_owner_notification_email(order_group)
+ end
+
+ private
+
+ # The most recent split checkout. Nothing to preview until a store has one —
+ # a group only exists where a basket spanned several sellers.
+ #
+ # The locale the preview toolbar asks for is applied to the children in
+ # memory (never saved), because a group reads its locale from them.
+ def order_group
+ group = Spree::OrderGroup.last
+ return group if group.nil? || locale.blank?
+
+ group.orders.load.each { |order| order.locale = locale }
+ group
+ end
+end
diff --git a/spree/emails/spec/i18n_spec.rb b/spree/emails/spec/i18n_spec.rb
new file mode 100644
index 0000000000..eacd60d02f
--- /dev/null
+++ b/spree/emails/spec/i18n_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+require 'i18n/tasks'
+
+RSpec.describe I18n do
+ let(:i18n) { I18n::Tasks::BaseTask.new }
+ let(:missing_keys) { i18n.missing_keys }
+ let(:inconsistent_interpolations) { i18n.inconsistent_interpolations }
+
+ it 'does not have missing keys' do
+ expect(missing_keys).to be_empty,
+ "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them"
+ end
+
+ it 'files are normalized' do
+ non_normalized = i18n.non_normalized_paths
+ error_message = "The following files need to be normalized:\n" \
+ "#{non_normalized.map { |path| " #{path}" }.join("\n")}\n" \
+ "Please run `i18n-tasks normalize' to fix"
+ expect(non_normalized).to be_empty, error_message
+ end
+
+ it 'does not have inconsistent interpolations' do
+ error_message = "#{inconsistent_interpolations.leaves.count} i18n keys have inconsistent interpolations.\n" \
+ "Run `i18n-tasks check-consistent-interpolations' to show them"
+ expect(inconsistent_interpolations).to be_empty, error_message
+ end
+end
diff --git a/spree/emails/spec/mailers/spree/order_group_mailer_spec.rb b/spree/emails/spec/mailers/spree/order_group_mailer_spec.rb
new file mode 100644
index 0000000000..fa4f902ac1
--- /dev/null
+++ b/spree/emails/spec/mailers/spree/order_group_mailer_spec.rb
@@ -0,0 +1,216 @@
+require 'spec_helper'
+require 'email_spec'
+
+describe Spree::OrderGroupMailer, type: :mailer do
+ include EmailSpec::Helpers
+ include EmailSpec::Matchers
+
+ let!(:store) { @default_store }
+ let(:group) do
+ create(:order_group, :with_parcels, store: store, sellers_count: 2, email: '[email protected]')
+ end
+
+ def parts_of(message)
+ [message.html_part.body.to_s, message.text_part.body.to_s]
+ end
+
+ describe '#confirm_email' do
+ it 'goes to the address the purchase was made with' do
+ expect(described_class.confirm_email(group).to).to eq(['[email protected]'])
+ end
+
+ # The number the customer saw at checkout. A child's number (R1001-1) is
+ # one seller's share of it, and quoting that is how the old email managed
+ # to describe a fraction of the purchase.
+ it 'names the purchase, not one of its orders' do
+ message = described_class.confirm_email(group)
+
+ expect(message.subject).to include("##{group.number}")
+ expect(message.subject).not_to include("##{group.number}-1")
+ end
+
+ it 'lists every item the customer bought' do
+ parts_of(described_class.confirm_email(group)).each do |body|
+ group.line_items.each { |line_item| expect(body).to include(line_item.name) }
+ end
+ end
+
+ it 'states the total actually paid' do
+ parts_of(described_class.confirm_email(group)).each do |body|
+ expect(body).to include(group.display_total.to_s)
+ end
+ end
+
+ it 'names who sold what' do
+ parts_of(described_class.confirm_email(group)).each do |body|
+ group.sellers.each { |seller| expect(body).to include(seller.name) }
+ end
+ end
+
+ it 'accepts an id as readily as the record' do
+ expect(Spree::OrderGroup).to receive(:find).with(group.id).and_return(group)
+
+ described_class.confirm_email(group.id).message
+ end
+
+ it 'prefixes a re-send so the customer knows it is not a second purchase' do
+ expect(described_class.confirm_email(group, true).subject).to include('[RESEND]')
+ end
+
+ # BaseMailer#current_store memoizes off @order, which a group never sets —
+ # left to the fallback this would be the default store's branding.
+ it 'is sent by the store the purchase was made in' do
+ other_store = create(:store, name: 'Second Store', url: 'other.example.com')
+ other_group = create(:order_group, :with_parcels, store: other_store, sellers_count: 2)
+
+ expect(described_class.confirm_email(other_group).subject).to start_with('Second Store')
+ end
+
+ describe 'the deliveries it promises' do
+ it 'describes one per parcel when sellers ship their own goods' do
+ parts_of(described_class.confirm_email(group)).each do |body|
+ expect(body).to include('Delivery 1 of 2')
+ expect(body).to include('Delivery 2 of 2')
+ end
+ end
+
+ it 'says how many to expect' do
+ expect(described_class.confirm_email(group).text_part.body.to_s).
+ to include('arriving in 2 separate deliveries')
+ end
+
+ # Several sellers out of one warehouse is one box. Counting orders here
+ # would promise deliveries that never arrive.
+ it 'describes one delivery when the split merely divided a parcel' do
+ shared = create(:order_group, :with_parcels, store: store, sellers_count: 3,
+ shared_stock_location: true)
+
+ parts_of(described_class.confirm_email(shared)).each do |body|
+ expect(body).to include('Delivery')
+ expect(body).not_to include('Delivery 1 of')
+ end
+ end
+
+ it 'does not promise separate deliveries for a single parcel' do
+ shared = create(:order_group, :with_parcels, store: store, sellers_count: 2,
+ shared_stock_location: true)
+
+ expect(described_class.confirm_email(shared).text_part.body.to_s).
+ not_to include('separate deliveries')
+ end
+
+ it 'charges for each parcel once' do
+ message = described_class.confirm_email(group)
+ quoted = group.fulfillment_groups.sum { |parcel| parcel.cost }
+
+ expect(quoted).to eq(group.delivery_total)
+ expect(message.text_part.body.to_s).to include(group.display_delivery_total.to_s)
+ end
+ end
+
+ # SplitBySeller apportions an order-level fee into one row per child, all
+ # carrying the same label — so a $12 handling fee on a three-seller
+ # checkout is three rows of $4 in the database and one charge to the
+ # customer.
+ describe 'a fee the split apportioned across the children' do
+ before do
+ group.orders.each { |order| create(:fee, order: order, amount: 4, label: 'Handling fee') }
+ group.reload
+ end
+
+ it 'charges for it once, at what it came to' do
+ parts_of(described_class.confirm_email(group)).each do |body|
+ expect(body.scan('Handling fee').size).to eq(1)
+ expect(body).to include('$8.00')
+ end
+ end
+ end
+
+ describe 'a line packed from two warehouses' do
+ before do
+ order = group.orders.first
+ line_item = order.line_items.first
+ line_item.update_columns(quantity: 3)
+ order.fulfillments.sole.fulfillment_items.sole.update_columns(quantity: 2)
+ overflow = create(:fulfillment, order: order, stock_location: create(:stock_location, name: 'Overflow'), tracking: nil)
+ overflow.fulfillment_items.destroy_all
+ overflow.fulfillment_items.create!(
+ order_id: order.id, variant_id: line_item.variant_id, line_item_id: line_item.id, quantity: 1
+ )
+ group.reload
+ end
+
+ # The line is in both parcels; its own quantity describes the order.
+ it 'tells each parcel what it carries rather than what was ordered' do
+ text = described_class.confirm_email(group).text_part.body.to_s
+
+ expect(text).to include('(2)')
+ expect(text).to include('(1)')
+ expect(text).not_to include('(3)')
+ end
+ end
+
+ describe 'goods that ship in no parcel' do
+ before do
+ digital_order = create(:order, store: store, order_group: group)
+ create(:line_item, order: digital_order)
+ group.reload
+ end
+
+ it 'still lists them, under their own heading' do
+ parts_of(described_class.confirm_email(group)).each do |body|
+ expect(body).to include('Nothing to ship')
+ expect(body).to include(group.unfulfilled_line_items.first.name)
+ end
+ end
+ end
+
+ describe 'a buyer who gave a purchase order number' do
+ before { group.orders.each { |order| order.update_columns(po_number: 'PO-4471') } }
+
+ it 'reconciles against it in both parts' do
+ parts_of(described_class.confirm_email(group.reload)).each do |body|
+ expect(body).to include('PO-4471')
+ end
+ end
+ end
+
+ # Spree::Money#to_html turns the first space into &nbsp;, which is right in
+ # the HTML part and prints the raw entity in the text one. Invisible in
+ # USD, where nothing is formatted with a space.
+ it 'writes money as plain text in the text part' do
+ krona_store = create(:store, name: 'Krona Store', url: 'krona.example.com',
+ default_currency: 'SEK', supported_currencies: 'SEK')
+ krona = create(:order_group, :with_parcels, store: krona_store, sellers_count: 2, currency: 'SEK')
+
+ text = described_class.confirm_email(krona).text_part.body.to_s
+
+ expect(text).to include(krona.display_delivery_total.to_s)
+ expect(text).not_to include('&nbsp;')
+ end
+
+ it 'renders in the locale the purchase was made in' do
+ I18n.backend.store_translations(
+ :'pt-BR', spree: { order_group_mailer: { confirm_email: { subject: 'Confirmação de Pedido' } } }
+ )
+ group.orders.each { |order| order.update_columns(locale: 'pt-BR') }
+
+ expect(described_class.confirm_email(group.reload).subject).to include('Confirmação de Pedido')
+ end
+ end
+
+ describe '#store_owner_notification_email' do
+ before { store.update!(new_order_notifications_email: '[email protected]') }
+
+ it 'goes to the address the store nominated' do
+ expect(described_class.store_owner_notification_email(group).to).to eq(['[email protected]'])
+ end
+
+ it 'describes the whole purchase' do
+ parts_of(described_class.store_owner_notification_email(group)).each do |body|
+ expect(body).to include(group.number)
+ group.line_items.each { |line_item| expect(body).to include(line_item.name) }
+ end
+ end
+ end
+end
diff --git a/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rb b/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rb
index 1736643326..ee42505997 100644
--- a/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rb
+++ b/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rb
@@ -134,6 +134,47 @@ RSpec.describe Spree::OrderEmailSubscriber do
end
end
+ describe 'the store owner on a divided checkout' do
+ let(:group) { create(:order_group, store: store) }
+ let(:order) { create(:completed_order_with_totals, store: store, order_group: group) }
+
+ # Each child publishes its own order.placed, so without this the operator
+ # hears about one purchase once per seller. The group's own notification
+ # covers it.
+ it 'is left to the group rather than told per child' do
+ allow(Spree::OrderMailer).to receive(:confirm_email).and_return(double(deliver_later: true))
+
+ expect(Spree::OrderMailer).not_to receive(:store_owner_notification_email)
+
+ subscriber.send(:send_confirmation_email, mock_event(order))
+ end
+ end
+
+ describe 'order.resend_confirmation_email event' do
+ it 'sends the order confirmation again, marked as a re-send' do
+ expect(Spree::OrderMailer).to receive(:confirm_email).with(order.id, true).
+ and_return(double(deliver_later: true))
+
+ subscriber.send(:resend_confirmation_email, mock_event(order))
+ end
+
+ # An admin resends from an order because an order is what they are looking
+ # at, but on a split checkout the document is the purchase's — sending this
+ # child's would put back the partial confirmation the group email replaced.
+ context 'when the order came out of a split checkout' do
+ let(:group) { create(:order_group, store: store) }
+ let(:order) { create(:completed_order_with_totals, store: store, order_group: group) }
+
+ it 'hands the re-send to the purchase' do
+ expect(Spree::OrderMailer).not_to receive(:confirm_email)
+ expect_any_instance_of(Spree::OrderGroup).to receive(:publish_event).
+ with('order_group.resend_confirmation_email')
+
+ subscriber.send(:resend_confirmation_email, mock_event(order))
+ end
+ end
+ end
+
describe 'order.canceled event' do
it 'sends cancel email' do
expect(Spree::OrderMailer).to receive(:cancel_email).with(order.id).and_return(double(deliver_later: true))
diff --git a/spree/emails/spec/subscribers/spree/order_group_email_subscriber_spec.rb b/spree/emails/spec/subscribers/spree/order_group_email_subscriber_spec.rb
new file mode 100644
index 0000000000..cd38219bd6
--- /dev/null
+++ b/spree/emails/spec/subscribers/spree/order_group_email_subscriber_spec.rb
@@ -0,0 +1,134 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Spree::OrderGroupEmailSubscriber do
+ let(:store) { create(:store, new_order_notifications_email: '[email protected]') }
+ let(:group) { create(:order_group, store: store) }
+ let(:subscriber) { described_class.new }
+
+ def mock_event(order_group)
+ double('Event', payload: { 'id' => order_group.prefixed_id })
+ end
+
+ before do
+ store.update!(preferences: store.preferences.merge(send_consumer_transactional_emails: true))
+ allow(Spree::OrderGroupMailer).to receive(:store_owner_notification_email).
+ and_return(double(deliver_later: true))
+ end
+
+ describe 'order_group.completed' do
+ it 'confirms the purchase' do
+ expect(Spree::OrderGroupMailer).to receive(:confirm_email).with(group.id).
+ and_return(double(deliver_later: true))
+
+ subscriber.send(:send_confirmation_email, mock_event(group))
+ end
+
+ it 'records that it did' do
+ allow(Spree::OrderGroupMailer).to receive(:confirm_email).and_return(double(deliver_later: true))
+
+ expect { subscriber.send(:send_confirmation_email, mock_event(group)) }.
+ to change { group.reload.confirmation_delivered }.from(false).to(true)
+ end
+
+ # Completion is replayable, and a resumed finalize re-publishes the event.
+ it 'does not confirm a purchase twice' do
+ group.update_column(:confirmation_delivered, true)
+
+ expect(Spree::OrderGroupMailer).not_to receive(:confirm_email)
+
+ subscriber.send(:send_confirmation_email, mock_event(group))
+ end
+
+ # Matches the single-order subscriber: turning customer receipts off must
+ # not stop the store hearing about its own sales (spree/spree#14724).
+ it 'still tells the store when customer receipts are switched off' do
+ store.update!(preferences: store.preferences.merge(send_consumer_transactional_emails: false))
+
+ expect(Spree::OrderGroupMailer).not_to receive(:confirm_email)
+ expect(Spree::OrderGroupMailer).to receive(:store_owner_notification_email).
+ and_return(double(deliver_later: true))
+
+ subscriber.send(:send_confirmation_email, mock_event(group))
+ end
+
+ # An operator completing a draft quietly says so on the group event, which
+ # is the only thing that reaches this subscriber. It silences the customer
+ # and not the store, which is a different audience.
+ it 'does not confirm the customer when the completion asked to stay silent' do
+ expect(Spree::OrderGroupMailer).not_to receive(:confirm_email)
+ expect(Spree::OrderGroupMailer).to receive(:store_owner_notification_email).
+ and_return(double(deliver_later: true))
+
+ subscriber.send(:send_confirmation_email,
+ double('Event', payload: { 'id' => group.prefixed_id, 'notify_customer' => false }))
+ end
+
+ it 'ignores a group it cannot find' do
+ expect(Spree::OrderGroupMailer).not_to receive(:confirm_email)
+
+ subscriber.send(:send_confirmation_email, double('Event', payload: { 'id' => 'ogrp_missing' }))
+ end
+
+ describe 'the store owner' do
+ before { allow(Spree::OrderGroupMailer).to receive(:confirm_email).and_return(double(deliver_later: true)) }
+
+ # One notification per purchase, like the customer's — it used to ride
+ # inside the first child order's confirmation.
+ it 'is told about the purchase once' do
+ expect(Spree::OrderGroupMailer).to receive(:store_owner_notification_email).with(group.id).
+ and_return(double(deliver_later: true))
+
+ expect { subscriber.send(:send_confirmation_email, mock_event(group)) }.
+ to change { group.reload.store_owner_notification_delivered }.from(false).to(true)
+ end
+
+ it 'is left alone when the store nominated no address' do
+ store.update!(new_order_notifications_email: nil)
+
+ expect(Spree::OrderGroupMailer).not_to receive(:store_owner_notification_email)
+
+ subscriber.send(:send_confirmation_email, mock_event(group))
+ end
+
+ # A replay that gets as far as stamping the customer's flag and no
+ # further still owes the operator their notification.
+ it 'is still told when a replay finds the customer already confirmed' do
+ group.update_column(:confirmation_delivered, true)
+
+ expect(Spree::OrderGroupMailer).not_to receive(:confirm_email)
+ expect(Spree::OrderGroupMailer).to receive(:store_owner_notification_email).with(group.id).
+ and_return(double(deliver_later: true))
+
+ expect { subscriber.send(:send_confirmation_email, mock_event(group)) }.
+ to change { group.reload.store_owner_notification_delivered }.from(false).to(true)
+ end
+
+ it 'is not told twice' do
+ group.update_column(:store_owner_notification_delivered, true)
+
+ expect(Spree::OrderGroupMailer).not_to receive(:store_owner_notification_email)
+
+ subscriber.send(:send_confirmation_email, mock_event(group))
+ end
+ end
+ end
+
+ describe 'order_group.resend_confirmation_email' do
+ it 'sends the purchase confirmation again, marked as a re-send' do
+ expect(Spree::OrderGroupMailer).to receive(:confirm_email).with(group.id, true).
+ and_return(double(deliver_later: true))
+
+ subscriber.send(:resend_confirmation_email, mock_event(group))
+ end
+
+ it 'resends even though the first one was delivered' do
+ group.update_column(:confirmation_delivered, true)
+
+ expect(Spree::OrderGroupMailer).to receive(:confirm_email).and_return(double(deliver_later: true))
+
+ subscriber.send(:resend_confirmation_email, mock_event(group))
+ end
+ end
+end