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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Checkout with digital products (#12534)
Damian Kaczmarczyk63cd47e60cfa
diff --git a/admin/app/controllers/spree/admin/line_items_controller.rb b/admin/app/controllers/spree/admin/line_items_controller.rbindex 461b589994..9656111ce0 100644--- a/admin/app/controllers/spree/admin/line_items_controller.rb+++ b/admin/app/controllers/spree/admin/line_items_controller.rb@@ -80,6 +80,13 @@ module Spreeredirect_to spree.edit_admin_order_path(@order, line_item_updated: true)end+ def reset_digital_links_limit+ @line_item.digital_links.update_all(access_counter: 0, created_at: Time.current, updated_at: Time.current)+ flash[:success] = Spree.t('admin.successfully_reset_digital_links_limit')++ redirect_to spree.edit_admin_order_path(@order)+ end+privatedef model_classdiff --git a/admin/app/views/spree/admin/orders/_line_item.html.erb b/admin/app/views/spree/admin/orders/_line_item.html.erbindex 2743ad42ff..15bfecf887 100644--- a/admin/app/views/spree/admin/orders/_line_item.html.erb+++ b/admin/app/views/spree/admin/orders/_line_item.html.erb@@ -1,5 +1,5 @@<%= turbo_frame_tag dom_id(line_item), class: "border-bottom px-3 order-line-items__form hover-light" do %>- <%= render 'spree/admin/variants/variant', variant: line_item.variant %>+ <%= render "spree/admin/variants/variant", variant: line_item.variant %><span class="d-flex align-items-center justify-content-center"><%= line_item.single_money.to_html %></span>@@ -19,8 +19,56 @@<%= line_item.display_total %></span><span class="d-flex align-items-center justify-content-end">- <% if can?(:edit, line_item) %>- <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_order_line_item_path(@order, line_item), class: 'with-tip btn btn-sm btn-light', no_text: true, data: {test_id: :edit_line_item} %>++ <% if line_item.digital_links.any? && can?(:edit, line_item) %>+ <div class="dropdown">+ <button+ class="btn btn-sm btn-light"+ type="button"+ data-toggle="dropdown"+ aria-expanded="false"+ >+ <%= icon "dots-vertical", class: "mr-0" %>+ </button>+ <div class="dropdown-menu dropdown-menu-right w-100" style="min-width: 200px;">+ <%= link_to_with_icon "edit",+ Spree.t(:edit),+ spree.edit_admin_order_line_item_path(@order, line_item),+ class: "btn-light dropdown-item",+ data: {+ test_id: :edit_line_item,+ } %>+ <%= link_to_with_icon "refresh",+ Spree.t("admin.reset_digital_link_download_limits"),+ spree.reset_digital_links_limit_admin_order_line_item_path(@order, line_item),+ data: {+ turbo_method: :post,+ turbo_confirm: Spree.t(:are_you_sure),+ turbo_frame: :_top,+ },+ class: "btn-light dropdown-item" %>+ </div>+ </div>+ <% elsif line_item.digital_links.any? %>+ <%= link_to_with_icon "refresh",+ Spree.t("admin.reset_digital_link_download_limits"),+ spree.reset_digital_links_limit_admin_order_line_item_path(@order, line_item),+ data: {+ turbo_method: :post,+ turbo_confirm: Spree.t(:are_you_sure),+ turbo_frame: :_top,+ },+ no_text: true,+ class: "with-tip btn btn-sm btn-light" %>+ <% elsif can?(:edit, line_item) %>+ <%= link_to_with_icon "edit",+ Spree.t(:edit),+ spree.edit_admin_order_line_item_path(@order, line_item),+ class: "with-tip btn btn-sm btn-light",+ no_text: true,+ data: {+ test_id: :edit_line_item,+ } %><% end %></span><% end %>diff --git a/admin/app/views/spree/admin/orders/_line_items.html.erb b/admin/app/views/spree/admin/orders/_line_items.html.erbindex 9cad266c17..952212b295 100644--- a/admin/app/views/spree/admin/orders/_line_items.html.erb+++ b/admin/app/views/spree/admin/orders/_line_items.html.erb@@ -1,5 +1,5 @@-<%= turbo_frame_tag dom_id(@order, :line_items), class: "card mb-4 overflow-hidden" do %>+<%= turbo_frame_tag dom_id(@order, :line_items), class: "card mb-4" do %><% if @line_items.any? %><div class="card-header d-flex justify-content-between align-items-center"><h5 class="card-title d-flex align-items-center">diff --git a/admin/app/views/spree/admin/orders/_shipment.html.erb b/admin/app/views/spree/admin/orders/_shipment.html.erbindex 561a18adc8..76f9a12b21 100644--- a/admin/app/views/spree/admin/orders/_shipment.html.erb+++ b/admin/app/views/spree/admin/orders/_shipment.html.erb@@ -55,22 +55,24 @@<% end %><% end %>- <%= turbo_frame_tag dom_id(shipment, :tracking), class: "hover-light border-top px-3 d-flex justify-content-between align-items-center min-h-14" do %>- <div class="py-3">- <% if shipment.tracked? %>- <strong><%= Spree.t(:tracking) %>: </strong>- <% if shipment.tracking_url.present? %>- <span><%= link_to shipment.tracking, shipment.tracking_url, target: '_blank', rel: "noopener noreferrer" %></span>- <% elsif shipment.tracking.present? %>- <span><%= shipment.tracking %></span>+ <% unless shipment.digital? %>+ <%= turbo_frame_tag dom_id(shipment, :tracking), class: "hover-light border-top px-3 d-flex justify-content-between align-items-center min-h-14" do %>+ <div class="py-3">+ <% if shipment.tracked? %>+ <strong><%= Spree.t(:tracking) %>: </strong>+ <% if shipment.tracking_url.present? %>+ <span><%= link_to shipment.tracking, shipment.tracking_url, target: '_blank', rel: "noopener noreferrer" %></span>+ <% elsif shipment.tracking.present? %>+ <span><%= shipment.tracking %></span>+ <% end %>+ <% else %>+ <%= Spree.t('admin.add_tracking_details') %><% end %>- <% else %>- <%= Spree.t('admin.add_tracking_details') %>- <% end %>- </div>+ </div>- <% if can?(:update, shipment) && (!order.canceled? && !shipment.canceled?) %>- <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_order_shipment_path(order, shipment), class: 'edit-tracking btn btn-light btn-sm with-tip', no_text: true, title: Spree.t(:edit) %>+ <% if can?(:update, shipment) && (!order.canceled? && !shipment.canceled?) %>+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_order_shipment_path(order, shipment), class: 'edit-tracking btn btn-light btn-sm with-tip', no_text: true, title: Spree.t(:edit) %>+ <% end %><% end %><% end %>@@ -78,11 +80,15 @@<div class="card-footer d-flex justify-content-end"><% if shipment.tracked? %><%= link_to_with_icon 'send.svg', Spree.t(:ship), spree.ship_admin_order_shipment_path(order, shipment), class: 'ml-auto btn btn-primary mb-0', data: {turbo_method: :post, turbo_confirm: Spree.t(:are_you_sure)} %>- <% else %>+ <% elsif !shipment.digital? %><span class="ship-tooltip with-tip ship ml-auto btn btn-primary disabled mb-0" data-toggle="tooltip" data-placement="left" title="Before marking shipment as shipped please provide tracking details"><%= icon 'send.svg'%><%= Spree.t(:ship) %></span>+ <% else %>+ <span class="text-muted w-100">+ <%= Spree.t('admin.digital_shipment_fulfillment_note') %>+ </span><% end %></div><% end %>diff --git a/admin/app/views/spree/admin/stores/form/_basic.html.erb b/admin/app/views/spree/admin/stores/form/_basic.html.erbindex 5d4ffb5655..4ed8fea821 100644--- a/admin/app/views/spree/admin/stores/form/_basic.html.erb+++ b/admin/app/views/spree/admin/stores/form/_basic.html.erb@@ -110,5 +110,46 @@</div></div>- <%= render 'spree/admin/stores/form/custom', f: f %>+ <div class="col-lg-6">+ <div class="card mb-4">+ <div class="card-header">+ <h5 class="card-title"><%= Spree.t(:digital_assets) %></h5>+ </div>+ <div class="card-body">+ <p class="text-muted">+ Digital assets are files that can be downloaded by customers after+ purchase.+ </p>+ <div class="custom-control custom-checkbox mb-3">+ <%= f.check_box :preferred_limit_digital_download_days,+ class: "custom-control-input" %>+ <%= f.label :preferred_limit_digital_download_days, class: "custom-control-label" %>+ <%= f.error_message_on :preferred_limit_digital_download_days %>+ </div>+ <div class="form-group">+ <%= f.label :preferred_digital_asset_authorized_days %>+ <%= f.number_field :preferred_digital_asset_authorized_days,+ class: "form-control",+ min: 1 %>+ <%= f.error_message_on :preferred_digital_asset_authorized_days %>+ </div>++ <div class="custom-control custom-checkbox mb-3">+ <%= f.check_box :preferred_limit_digital_download_count,+ class: "custom-control-input" %>+ <%= f.label :preferred_limit_digital_download_count, class: "custom-control-label" %>+ <%= f.error_message_on :preferred_limit_digital_download_count %>+ </div>+ <div class="form-group">+ <%= f.label :preferred_digital_asset_authorized_clicks %>+ <%= f.number_field :preferred_digital_asset_authorized_clicks,+ class: "form-control",+ min: 1 %>+ <%= f.error_message_on :preferred_digital_asset_authorized_clicks %>+ </div>+ </div>+ </div>+ </div>++ <%= render "spree/admin/stores/form/custom", f: f %></div>diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.ymlindex 6c1c2ed9fa..d06e1181a5 100644--- a/admin/config/locales/en.yml+++ b/admin/config/locales/en.yml@@ -52,6 +52,7 @@ en:top_products: Top productsview_report: View reportwhats_happening_on: Here's what's happening on <strong>%{store_name}</strong> today.+ digital_shipment_fulfillment_note: This shipment will be marked as fulfilled once the user downloads the digital productdisplay_on_options:back_end: Only on admin panelboth: On both admin panel & storefront@@ -175,6 +176,7 @@ en:variants:option_types_link: To add more option types please go to <a href="%{link}">Option Types</a>report_created: Your report is being generated. You will receive an email with a download link when it is ready!+ reset_digital_link_download_limits: Reset download limitsresponse_code: Response Codesend_payment_link: Send Payment Linkshipment_transfer:@@ -202,6 +204,7 @@ en:setup: Setup Tax Ratesstorefront: Storefrontsuccessful: Successful+ successfully_reset_digital_links_limit: Download limits have been resettaxon_rules:all_conditions: all conditionsany_condition: any conditiondiff --git a/admin/config/routes.rb b/admin/config/routes.rbindex dc499dc44a..35c5b72b4d 100644--- a/admin/config/routes.rb+++ b/admin/config/routes.rb@@ -66,7 +66,11 @@ Spree::Core::Engine.add_routes dopost :transferendend- resources :line_items, except: :show+ resources :line_items, except: :show do+ member do+ post :reset_digital_links_limit+ end+ endresources :customer_returns, except: [:index, :destroy], controller: 'orders/customer_returns'resources :return_authorizations, except: [:index, :destroy], controller: 'orders/return_authorizations'resources :payments, except: [:index, :show] dodiff --git a/api/lib/spree/api/testing_support/v2/current_order.rb b/api/lib/spree/api/testing_support/v2/current_order.rbindex 727bb2097b..22f103595a 100644--- a/api/lib/spree/api/testing_support/v2/current_order.rb+++ b/api/lib/spree/api/testing_support/v2/current_order.rb@@ -18,8 +18,10 @@ shared_context 'order with a physical line item' doendshared_context 'order with a digital line item' do- let!(:digital) { create(:digital) }- let!(:variant_digital) { digital.variant }+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+ let(:variant_digital) { create(:variant, product: digital_product) }+ let!(:digital) { create(:digital, variant: variant_digital) }let!(:line_item) { create(:line_item, variant: variant_digital, order: order, currency: currency) }let!(:headers) { headers_bearer }@@ -30,8 +32,10 @@ shared_context 'order with a digital line item' doendshared_context 'order with a physical and digital line item' do- let!(:digital) { create(:digital) }- let!(:variant_digital) { digital.variant }+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:product_digital) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+ let(:variant_digital) { create(:variant, product: product_digital) }+ let!(:digital) { create(:digital, variant: variant_digital) }let!(:digital_line_item) { create(:line_item, variant: variant_digital, order: order, currency: currency) }let!(:physical_line_item) { create(:line_item, order: order, currency: currency) }@@ -87,7 +91,8 @@ shared_examples 'returns valid cart JSON' doexpect(json_response['data']).to have_attribute(:display_pre_tax_item_amount).with_value(order.display_pre_tax_item_amount.to_s)expect(json_response['data']).to have_attribute(:pre_tax_total).with_value(order.pre_tax_total.to_s)expect(json_response['data']).to have_attribute(:display_pre_tax_total).with_value(order.display_pre_tax_total.to_s)- expect(json_response['data']).to have_relationships(:user, :line_items, :variants, :billing_address, :shipping_address, :payments, :shipments, :promotions)+ expect(json_response['data']).to have_relationships(:user, :line_items, :variants, :billing_address, :shipping_address, :payments, :shipments,+ :promotions)endenddiff --git a/core/app/models/spree/digital.rb b/core/app/models/spree/digital.rbindex d4543699f5..1d143a4064 100644--- a/core/app/models/spree/digital.rb+++ b/core/app/models/spree/digital.rb@@ -13,5 +13,6 @@ module Spreevalidates :variant, presence: truedelegate :product, to: :variant+ delegate :filename, :content_type, to: :attachmentendenddiff --git a/core/app/models/spree/digital_link.rb b/core/app/models/spree/digital_link.rbindex b517f83111..120219e2b7 100644--- a/core/app/models/spree/digital_link.rb+++ b/core/app/models/spree/digital_link.rb@@ -20,6 +20,9 @@ module Spreevalidates :digital, :line_item, presence: truevalidates :access_counter, numericality: { greater_than_or_equal_to: 0 }+ delegate :filename, :content_type, to: :digital+ delegate :order, to: :line_item+def authorizable?!(expired? || access_limit_exceeded?)end@@ -43,7 +46,9 @@ module Spree# This method should be called when a download is initiated.# It returns +true+ or +false+ depending on whether the authorization is granted.def authorize!- authorizable? && increment!(:access_counter, touch: true) ? true : false+ ActiveRecord::Base.connected_to(role: :writing) do+ authorizable? && increment!(:access_counter, touch: true)+ endenddef reset!diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rbindex e186bee37e..677f9f4227 100644--- a/core/app/models/spree/line_item.rb+++ b/core/app/models/spree/line_item.rb@@ -53,6 +53,8 @@ module Spreedelegate :tax_zone, to: :orderdelegate :digital?, to: :variant+ scope :with_digital_assets, -> { joins(:variant).merge(Spree::Variant.with_digital_assets) }+attr_accessor :target_shipmentself.whitelisted_ransackable_associations = %w[variant order tax_category]diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex dc8cf2321a..402e72dd18 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -275,9 +275,9 @@ module Spreeline_items.exists?end- # Does this order require a physical delivery.+ # Does this order require a delivery (physical or digital).def delivery_required?- !digital?+ true # true for Spree, can be decoratedend# Is this a free order in which case the payment step should be skippeddiff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rbindex 115595efb9..6015629ee0 100644--- a/core/app/models/spree/order/checkout.rb+++ b/core/app/models/spree/order/checkout.rb@@ -109,6 +109,7 @@ module Spreebefore_transition to: :delivery, do: :create_shipment_tax_charge!before_transition from: :delivery, do: :apply_free_shipping_promotionsbefore_transition to: :delivery, do: :apply_unassigned_promotions+ after_transition to: :delivery, do: :go_to_payment_if_fully_digital!endbefore_transition to: :resumed, do: :ensure_line_item_variants_are_not_discontinueddiff --git a/core/app/models/spree/order/digital.rb b/core/app/models/spree/order/digital.rbindex 8467463edf..c4ec4f7d37 100644--- a/core/app/models/spree/order/digital.rb+++ b/core/app/models/spree/order/digital.rb@@ -14,7 +14,7 @@ module Spreeenddef digital_line_items- line_items.select(&:digital?)+ line_items.with_digital_assets.distinctenddef digital_links@@ -22,12 +22,19 @@ module Spreeenddef create_digital_links- digital_line_items.each do |line_item|+ digital_line_items.includes(variant: :digitals).each do |line_item|line_item.variant.digitals.each do |digital|line_item.digital_links.create!(digital: digital)endendend++ def go_to_payment_if_fully_digital!+ return unless digital?+ return unless delivery?++ next!+ endendendenddiff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rbindex 67f34971bf..d059b46558 100644--- a/core/app/models/spree/shipment.rb+++ b/core/app/models/spree/shipment.rb@@ -59,7 +59,8 @@ module Spreejoins(:selected_shipping_rate).where(Spree::ShippingRate.arel_table[:shipping_method_id].not_eq(nil)).select(Spree::ShippingRate.arel_table[:shipping_method_id])- }+ }+ scope :digital_delivery, -> { joins(:shipping_methods).merge(Spree::ShippingMethod.digital) }delegate :store, :currency, to: :orderdelegate :amount_in_cents, to: :display_cost@@ -153,7 +154,7 @@ module Spree## @return [Boolean]def shippable?- can_ship? && tracked?+ can_ship? && (tracked? || digital?)end# Returns true if not all of the shipment's line items are fully shipped@@ -174,7 +175,7 @@ module Spreedef determine_state(order)return 'canceled' if canceled? || order.canceled?return 'pending' unless order.can_ship?- return 'pending' if inventory_units.any? &:backordered?+ return 'pending' if inventory_units.any?(&:backordered?)return 'shipped' if shipped?order.paid? || Spree::Config[:auto_capture_on_dispatch] ? 'ready' : 'pending'@@ -196,7 +197,7 @@ module Spreedef free?return true if final_price == BigDecimal(0)- return with_free_shipping_promotion?+ with_free_shipping_promotion?enddef with_free_shipping_promotion?@@ -228,6 +229,10 @@ module Spreeinventory_units.includes(:line_item).map(&:line_item).uniqend+ def digital?+ shipping_method.calculator.is_a?(Spree::Calculator::Shipping::DigitalDelivery)+ end+ManifestItem = Struct.new(:line_item, :variant, :quantity, :states)def manifestdiff --git a/core/app/models/spree/shipping_method.rb b/core/app/models/spree/shipping_method.rbindex db76729f81..6141b2e396 100644--- a/core/app/models/spree/shipping_method.rb+++ b/core/app/models/spree/shipping_method.rb@@ -35,6 +35,10 @@ module Spreevalidates :estimated_transit_business_days_max, numericality: { greater_than_or_equal_to: 1 }, allow_nil: truevalidate :at_least_one_shipping_category+ scope :digital, lambda {+ joins(:calculator).where(spree_calculators: { type: Spree::Calculator::Shipping::DigitalDelivery.to_s })+ }+if defined?(PgSearch)# full text searchinclude PgSearch::Modeldiff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex c1edcea146..22350d117c 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -60,6 +60,7 @@ module Spreehas_many :checkouts, -> { incomplete }, class_name: 'Spree::Order', inverse_of: :storehas_many :orders, class_name: 'Spree::Order'has_many :line_items, through: :orders, class_name: 'Spree::LineItem'+ has_many :digital_links, through: :line_items, class_name: 'Spree::DigitalLink'has_many :shipments, through: :orders, class_name: 'Spree::Shipment'has_many :payments, through: :orders, class_name: 'Spree::Payment'has_many :return_authorizations, through: :orders, class_name: 'Spree::ReturnAuthorization'diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex 2fe29a6b84..38c37b99ff 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -122,6 +122,8 @@ module Spreejoins(:option_values).where(Spree::OptionValue.table_name => { name: option_value, option_type_id: option_type_ids })}+ scope :with_digital_assets, -> { joins(:digitals) }+if defined?(PgSearch)include PgSearch::Model@@ -475,9 +477,9 @@ module Spree@backordered ||= !in_stock? && stock_items.exists?(backorderable: true)end- # Is this variant to be downloaded by the customer?+ # Is this variant purely digital? (no physical product)def digital?- digitals.present?+ product.digital?enddef clear_in_stock_cachediff --git a/core/app/services/spree/checkout/advance.rb b/core/app/services/spree/checkout/advance.rbindex 82ab8a892d..6f967816dc 100644--- a/core/app/services/spree/checkout/advance.rb+++ b/core/app/services/spree/checkout/advance.rb@@ -47,7 +47,7 @@ module Spreeprivatedef cannot_make_transition?(order, state = nil)- order.state == state || order.confirm? || order.complete? || order.errors.present?+ order.state == state || order.confirm? || order.complete? || order.errors.present? || order.passed_checkout_step?(state)enddef report_advance_error(error, order)diff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 845fc79998..300dc0b1ec 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -152,6 +152,10 @@ en:meta_description: Meta Descriptionmeta_keywords: Meta Keywordsname: Site Name+ preferred_digital_asset_authorized_clicks: Download clicks limit+ preferred_digital_asset_authorized_days: Download days limit+ preferred_limit_digital_download_count: Limit digital links download count+ preferred_limit_digital_download_days: Limit digital links download daysseo_robots: SEO Robotsseo_title: SEO Titleurl: Site URL@@ -630,6 +634,7 @@ en:are_you_sure_delete: Are you sure you want to delete this record?associated_adjustment_closed: The associated adjustment is closed, and will not be recalculated. Do you want to open it?at_symbol: "@"+ attachments: Attachmentsaudit_log: Audit Logauthor: Authorauthorization_failure: Authorization Failure@@ -876,6 +881,7 @@ en:digital:digital_delivery: Digital Deliverydigital_assets: Digital assets+ digital_link_unauthorized: You are not authorized to access this assetdimension_units:centimeter: Centimeter (cm)foot: Foot (ft)@@ -1359,7 +1365,7 @@ en: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}"+ subject: 'Payment link for order #%{number}'store_owner_notification_email:heading: New Order Receivedinstructions: You have received a new order.diff --git a/core/lib/spree/testing_support/factories/calculator_factory.rb b/core/lib/spree/testing_support/factories/calculator_factory.rbindex 430c461ba4..aac6bbe037 100644--- a/core/lib/spree/testing_support/factories/calculator_factory.rb+++ b/core/lib/spree/testing_support/factories/calculator_factory.rb@@ -29,4 +29,8 @@ FactoryBot.define dofactory :non_free_shipping_calculator, class: Spree::Calculator::Shipping::FlatRate doafter(:create) { |c| c.set_preference(:amount, 20.0) }end++ factory :digital_shipping_calculator, class: Spree::Calculator::Shipping::DigitalDelivery do+ after(:create) { |c| c.set_preference(:amount, 0) }+ endenddiff --git a/core/lib/spree/testing_support/factories/shipping_method_factory.rb b/core/lib/spree/testing_support/factories/shipping_method_factory.rbindex e0db7feb5b..e92f9aa6e0 100644--- a/core/lib/spree/testing_support/factories/shipping_method_factory.rb+++ b/core/lib/spree/testing_support/factories/shipping_method_factory.rb@@ -18,5 +18,14 @@ FactoryBot.define dofactory :free_shipping_method, class: Spree::ShippingMethod doassociation(:calculator, factory: :shipping_no_amount_calculator, strategy: :build)end++ factory :digital_shipping_method, class: Spree::ShippingMethod do+ association(:calculator, factory: :digital_shipping_calculator, strategy: :build)++ before(:create) do |shipping_method|+ shipping_method.shipping_categories.delete_all+ shipping_method.shipping_categories << create(:shipping_category, name: 'Digital')+ end+ endendenddiff --git a/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb b/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rbindex 4d461ec555..c6900f26d5 100644--- a/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb+++ b/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb@@ -22,9 +22,12 @@ RSpec.describe Spree::Calculator::Shipping::DigitalDelivery doenddescribe '#available?' do+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+let(:digital_order) doorder = create(:order)- variants = 3.times.map { create(:variant, digitals: [FactoryBot.create(:digital)]) }+ variants = 3.times.map { create(:variant, digitals: [FactoryBot.create(:digital)], product: digital_product) }package = Spree::Stock::Package.new(create(:stock_location), [])variants.each do |v|add_line_item_to_order(order, v, 1)@@ -36,7 +39,7 @@ RSpec.describe Spree::Calculator::Shipping::DigitalDelivery dolet(:mixed_order) doorder = create(:order)- variants = 2.times.map { create(:variant, digitals: [FactoryBot.create(:digital)]) }+ variants = 2.times.map { create(:variant, digitals: [FactoryBot.create(:digital)], product: digital_product) }variants << create(:variant)package = Spree::Stock::Package.new(create(:stock_location), [])variants.each do |v|diff --git a/core/spec/models/spree/order/checkout_spec.rb b/core/spec/models/spree/order/checkout_spec.rbindex 370f57fcdf..be8a169e20 100644--- a/core/spec/models/spree/order/checkout_spec.rb+++ b/core/spec/models/spree/order/checkout_spec.rb@@ -70,7 +70,7 @@ describe Spree::Order, type: :model doexpect(order.passed_checkout_step?('delivery')).to be trueend- context '#checkout_steps' do+ describe '#checkout_steps' docontext 'when confirmation not required' dobefore doallow(order).to receive_messages confirmation_required?: false@@ -450,16 +450,19 @@ describe Spree::Order, type: :model doendcontext 'default credit card' do- let(:digital) { create(:digital) }+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+ let(:variant_digital) { create(:variant, product: digital_product) }before doorder.user = FactoryBot.create(:user)order.email = '[email protected]'order.payments << FactoryBot.create(:payment)+ create(:digital, variant: variant_digital)# make sure we will actually capture a paymentallow(order).to receive_messages(payment_required?: true)- order.line_items << FactoryBot.create(:line_item, variant: digital.variant)+ order.line_items << FactoryBot.create(:line_item, variant: variant_digital)Spree::OrderUpdater.new(order).updateorder.save!diff --git a/core/spec/models/spree/order/digital_spec.rb b/core/spec/models/spree/order/digital_spec.rbindex 62f74ca1f2..cdd3666dff 100644--- a/core/spec/models/spree/order/digital_spec.rb+++ b/core/spec/models/spree/order/digital_spec.rb@@ -1,14 +1,17 @@require 'spec_helper'describe Spree::Order, type: :model do+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+context 'line_item analysis' doit 'understands that all products are digital' doorder = create(:order)3.times do- add_line_item_to_order(order, create(:variant, digitals: [create(:digital)]), 1)+ add_line_item_to_order(order, create(:variant, digitals: [create(:digital)], product: digital_product), 1)endexpect(order.digital?).to be true- add_line_item_to_order(order, create(:variant, digitals: [create(:digital)]), 4)+ add_line_item_to_order(order, create(:variant, digitals: [create(:digital)], product: digital_product), 4)expect(order.digital?).to be trueend@@ -28,19 +31,19 @@ describe Spree::Order, type: :model doit 'understands that not all products are digital' doorder = create(:order)3.times do- add_line_item_to_order(order, create(:variant, digitals: [create(:digital)]), 1)+ add_line_item_to_order(order, create(:variant, digitals: [create(:digital)], product: digital_product), 1)end- add_line_item_to_order(order, create(:variant), 1) # this is the analog product+ add_line_item_to_order(order, create(:variant, digitals: [create(:digital)]), 1) # this is the analog productexpect(order.digital?).to be false- add_line_item_to_order(order, create(:variant, digitals: [create(:digital)]), 4)+ add_line_item_to_order(order, create(:variant, digitals: [create(:digital)], product: digital_product), 4)expect(order.digital?).to be falseendendcontext 'Spree::Cart::AddItem.call' do- it 'should add digital Variants of quantity 1 to an order' do+ it 'adds digital Variants of quantity 1 to an order' doorder = create(:order)- variants = 3.times.map { create(:variant, digitals: [create(:digital)]) }+ variants = 3.times.map { create(:variant, digitals: [create(:digital)], product: digital_product) }variants.each do |v|add_line_item_to_order(order, v, 1)end@@ -49,9 +52,9 @@ describe Spree::Order, type: :model doexpect(order.line_items.third.variant).to eq(variants[2])end- it 'should handle quantity higher than 1 when adding one specific digital Variant' do+ it 'handles quantity higher than 1 when adding one specific digital Variant' doorder = create(:order)- digital_variant = create(:variant, digitals: [create(:digital)])+ digital_variant = create(:variant, digitals: [create(:digital)], product: digital_product)add_line_item_to_order(order, digital_variant, 3)expect(order.line_items.first.quantity).to eq(3)add_line_item_to_order(order, digital_variant, 2)@@ -59,17 +62,17 @@ describe Spree::Order, type: :model doendend- context '#digital?/#some_digital?' do+ describe '#digital?/#some_digital?' dolet(:digital_order) doorder = create(:order)- variants = 3.times.map { create(:variant, digitals: [create(:digital)]) }+ variants = 3.times.map { create(:variant, digitals: [create(:digital)], product: digital_product) }variants.each { |v| add_line_item_to_order(order, v, 1) }orderendlet(:mixed_order) doorder = create(:order)- variants = 2.times.map { create(:variant, digitals: [create(:digital)]) }+ variants = 2.times.map { create(:variant, digitals: [create(:digital)], product: digital_product) }variants << create(:variant)variants.each { |v| add_line_item_to_order(order, v, 1) }order@@ -82,17 +85,17 @@ describe Spree::Order, type: :model doorderend- it 'should return true/true for a digital order' do+ it 'returns true/true for a digital order' doexpect(digital_order).to be_digitalexpect(digital_order).to be_some_digitalend- it 'should return false/true for a mixed order' do+ it 'returns false/true for a mixed order' doexpect(mixed_order).not_to be_digitalexpect(mixed_order).to be_some_digitalend- it 'should return false/false for an exclusively non-digital order' do+ it 'returns false/false for an exclusively non-digital order' doexpect(non_digital_order).not_to be_digitalexpect(non_digital_order).not_to be_some_digitalenddiff --git a/core/spec/models/spree/order_contents_spec.rb b/core/spec/models/spree/order_contents_spec.rbindex f329022dcb..fef60953d0 100644--- a/core/spec/models/spree/order_contents_spec.rb+++ b/core/spec/models/spree/order_contents_spec.rb@@ -9,7 +9,7 @@ describe Spree::OrderContents, type: :model dolet(:order) { create(:order, user: user, store: store) }let(:variant) { create(:variant) }- context '#add' do+ describe '#add' docontext 'given quantity is not explicitly provided' doit 'adds one line item' doline_item = subject.add(variant)@@ -129,7 +129,7 @@ describe Spree::OrderContents, type: :model doendend- context '#remove' do+ describe '#remove' docontext 'given an invalid variant' doit 'raises an exception' doexpect do@@ -143,7 +143,7 @@ describe Spree::OrderContents, type: :model doline_item = subject.add(variant, 3)subject.remove(variant)- expect(line_item.quantity).to eq(2)+ expect(line_item.reload.quantity).to eq(2)endend@@ -169,7 +169,7 @@ describe Spree::OrderContents, type: :model doline_item = subject.add(variant, 3)subject.remove(variant, 1)- expect(line_item.quantity).to eq(2)+ expect(line_item.reload.quantity).to eq(2)endcontext 'when store_credits payment' do@@ -207,7 +207,7 @@ describe Spree::OrderContents, type: :model doendend- context '#remove_line_item' do+ describe '#remove_line_item' docontext 'given a shipment' doit 'ensure shipment calls update_amounts instead of order calling ensure_updated_shipments' doline_item = subject.add(variant, 1)diff --git a/core/spec/models/spree/stock/splitter/digital_spec.rb b/core/spec/models/spree/stock/splitter/digital_spec.rbindex 4bec992d07..a6457940bf 100644--- a/core/spec/models/spree/stock/splitter/digital_spec.rb+++ b/core/spec/models/spree/stock/splitter/digital_spec.rb@@ -8,13 +8,17 @@ module Spreelet(:packer) { build(:stock_packer) }- let(:item1) { create(:inventory_unit, variant: create(:digital).variant) }- let(:item2) { create(:inventory_unit, variant: create(:variant)) }- let(:item3) { create(:inventory_unit, variant: create(:variant)) }- let(:item4) { create(:inventory_unit, variant: create(:digital).variant) }- let(:item5) { create(:inventory_unit, variant: create(:digital).variant) }+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:product1) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+ let(:product2) { create(:product) }- it 'splits each package by product' do+ let(:item1) { create(:inventory_unit, variant: create(:variant, product: product1, digitals: [create(:digital)])) }+ let(:item2) { create(:inventory_unit, variant: create(:variant, product: product2)) }+ let(:item3) { create(:inventory_unit, variant: create(:variant, product: product2)) }+ let(:item4) { create(:inventory_unit, variant: create(:variant, product: product1, digitals: [create(:digital)])) }+ let(:item5) { create(:inventory_unit, variant: create(:variant, product: product1, digitals: [create(:digital)])) }++ it 'splits each package by product digital status' dopackage1 = Package.new(packer.stock_location)package1.add item1, :on_handpackage1.add item2, :on_handdiff --git a/storefront/app/controllers/spree/account/orders_controller.rb b/storefront/app/controllers/spree/account/orders_controller.rbindex dd61606e2b..c8e9e2d15c 100644--- a/storefront/app/controllers/spree/account/orders_controller.rb+++ b/storefront/app/controllers/spree/account/orders_controller.rb@@ -3,13 +3,13 @@ module Spreeclass OrdersController < BaseController# GET /account/ordersdef index- @orders = orders_scope.page(params[:page]).per(25)+ @orders = orders_scope.order(created_at: :desc).page(params[:page]).per(25)end# GET /account/orders/:iddef show@order = orders_scope.find_by!(number: params[:id])- @shipments = @order.shipments+ @shipments = @order.shipments.includes(:stock_location, :address, selected_shipping_rate: :shipping_method, inventory_units: :line_item)endprivatediff --git a/storefront/app/controllers/spree/checkout_controller.rb b/storefront/app/controllers/spree/checkout_controller.rbindex 8637f02c49..2fe0867d4a 100644--- a/storefront/app/controllers/spree/checkout_controller.rb+++ b/storefront/app/controllers/spree/checkout_controller.rb@@ -219,6 +219,8 @@ module Spree'payment'elsif @order.state == 'cart''address'+ elsif @order.digital? && @order.delivery?+ 'address'else@order.stateenddiff --git a/storefront/app/controllers/spree/digital_links_controller.rb b/storefront/app/controllers/spree/digital_links_controller.rbnew file mode 100644index 0000000000..80d417fc2f--- /dev/null+++ b/storefront/app/controllers/spree/digital_links_controller.rb@@ -0,0 +1,49 @@+module Spree+ class DigitalLinksController < StoreController+ def show+ if digital_link.authorize!+ mark_shipment_as_fullfiled if digital_link.access_counter == 1++ if defined?(ActiveStorage::Service::DiskService) && ActiveStorage::Blob.service.instance_of?(ActiveStorage::Service::DiskService)+ send_file(+ ActiveStorage::Blob.service.path_for(attachment.key),+ filename: digital_link.filename.to_s,+ type: digital_link.content_type.to_s,+ status: :ok+ ) and return+ else+ redirect_to attachment.url(+ expires_in: current_store.preferred_digital_asset_link_expire_time.seconds,+ disposition: 'attachment',+ host: current_store.formatted_url_or_custom_domain+ ), allow_other_host: true and return+ end+ end++ flash[:error] = Spree.t(:digital_link_unauthorized)+ redirect_to spree.order_path(digital_link.order)+ end++ private++ def mark_shipment_as_fullfiled+ ActiveRecord::Base.connected_to(role: :writing) do+ Spree::Shipment.transaction do+ shipments.each(&:ship)+ end+ end+ end++ def digital_link+ @digital_link ||= current_store.digital_links.find_by!(token: params[:id])+ end++ def shipments+ @shipments ||= digital_link.line_item.shipments.digital_delivery+ end++ def attachment+ @attachment ||= digital_link.digital.attachment+ end+ end+enddiff --git a/storefront/app/controllers/spree/orders_controller.rb b/storefront/app/controllers/spree/orders_controller.rbindex 44feae9ab6..06c579020c 100644--- a/storefront/app/controllers/spree/orders_controller.rb+++ b/storefront/app/controllers/spree/orders_controller.rb@@ -14,9 +14,9 @@ module Spreedef show@order = complete_order_finder.new(number: params[:id], token: params[:token], store: current_store).execute.first- raise ActiveRecord::RecordNotFound if @order.blank?+ raise ActiveRecord::RecordNotFound if @order.blank? || !authorize_access- @shipments = @order.shipments+ @shipments = @order.shipments.includes(:stock_location, :address, selected_shipping_rate: :shipping_method, inventory_units: :line_item)end# PUT /cart@@ -48,6 +48,12 @@ module Spreeprivate+ def authorize_access+ return true if @order.user_id.nil?++ @order.user == try_spree_current_user+ end+def find_order_by_cookieif order_token.present?current_store.orders.incomplete.not_canceled.diff --git a/storefront/app/helpers/spree/checkout_helper.rb b/storefront/app/helpers/spree/checkout_helper.rbindex a55f1f5625..c18764f5c3 100644--- a/storefront/app/helpers/spree/checkout_helper.rb+++ b/storefront/app/helpers/spree/checkout_helper.rb@@ -2,21 +2,21 @@ module Spreemodule CheckoutHelperdef checkout_progress(numbers: false)states = (@order.checkout_steps - ['complete']).unshift('cart')+ states -= ['delivery'] if @order.digital?+items = states.each_with_index.map do |state, i|text = Spree.t("order_state.#{state}").titleizetext.prepend("#{i.succ}. ") if numberscss_classes = ['breadcrumb-item']- current_index = states.index(@order.state)- state_index = states.index(state)- if state_index < current_index+ if @order.passed_checkout_step?(state)link_content = text- if state == 'cart'- link_url = spree.cart_url(host: current_store.url_or_custom_domain, order_token: @order.token)- else- link_url = spree.checkout_state_path(@order.token, state)- end+ link_url = if state == 'cart'+ spree.cart_url(host: current_store.url_or_custom_domain, order_token: @order.token)+ else+ spree.checkout_state_path(@order.token, state)+ endtext = link_to(link_content, link_url)css_classes << 'text-primary'@@ -25,8 +25,7 @@ module Spreecontent_tag('li', text, class: "breadcrumb-item #{state == @order.state ? 'font-bold' : 'text-text'}")endend- content = content_tag('ol', raw(items.join("\n")), class: 'breadcrumb flex items-center py-6 gap-2', id: "checkout-step-#{@order.state}")- content+ content_tag('ol', raw(items.join("\n")), class: 'breadcrumb flex items-center py-6 gap-2', id: "checkout-step-#{@order.state}")enddef checkout_available_payment_methods@@ -48,7 +47,8 @@ module Spreeenddef quick_checkout_enabled?(order)- order.payment_required? && order.shipments.count <= 1+ order.payment_required? && order.shipments.count <= 1 &&+ (order.digital? || !order.some_digital?) # Either fully digital or not digital at allenddef can_use_store_credit_on_checkout?(order)diff --git a/storefront/app/views/spree/checkout/edit.html.erb b/storefront/app/views/spree/checkout/edit.html.erbindex 73c0bbaf62..a2726cf3c1 100644--- a/storefront/app/views/spree/checkout/edit.html.erb+++ b/storefront/app/views/spree/checkout/edit.html.erb@@ -65,9 +65,11 @@<% end %></div></div>- <div class="text-xs">- <%= link_to Spree.t(:edit), spree.checkout_state_path(@order.token, 'delivery'), class: 'text-dark' %>- </div>+ <% unless @order.digital? %>+ <div class="text-xs">+ <%= link_to Spree.t(:edit), spree.checkout_state_path(@order.token, 'delivery'), class: 'text-dark' %>+ </div>+ <% end %></div><% end %></div>diff --git a/storefront/app/views/themes/default/spree/checkout/complete.html.erb b/storefront/app/views/themes/default/spree/checkout/complete.html.erbindex c3fc33b57b..be0c6de329 100644--- a/storefront/app/views/themes/default/spree/checkout/complete.html.erb+++ b/storefront/app/views/themes/default/spree/checkout/complete.html.erb@@ -8,8 +8,8 @@<div class="border p-3 rounded-md"><h5 class="mb-3 font-semibold pb-3 border-b font-body">- <%= Spree.t('storefront.checkout.order_success') %>- </h6>+ <%= Spree.t("storefront.checkout.order_success") %>+ </h5><p class="mb-0"><%= Spree.t('storefront.checkout.order_success_message') %></p>@@ -57,6 +57,28 @@<% end %></div></div>++ <% if @order.digital_links.any? %>+ <div class="border p-3 rounded-md mt-4">+ <h5 class="mb-3 font-bold pb-3 border-b font-body"><%= Spree.t(:attachments) %></h5>++ <ul class="flex flex-col gap-2">+ <% @order.digital_line_items.each do |line_item| %>+ <li class="flex flex-col gap-1">+ <span class="font-bold"><%= line_item.product.name %></span>+ <ul class="flex flex-col gap-1">+ <% line_item.digital_links.each do |digital_link| %>+ <li>+ <%= link_to "#{Spree.t(:download)} #{digital_link.filename}",+ spree.digital_link_path(digital_link.token) %>+ </li>+ <% end %>+ </ul>+ </li>+ <% end %>+ </ul>+ </div>+ <% end %></div>-<%= render_storefront_partials(:checkout_complete_partials) if order_just_completed?%>+<%= render_storefront_partials(:checkout_complete_partials) if order_just_completed? %>diff --git a/storefront/app/views/themes/default/spree/shared/_order_line_item.html.erb b/storefront/app/views/themes/default/spree/shared/_order_line_item.html.erbindex 909be3c1d6..5fd8314bd6 100644--- a/storefront/app/views/themes/default/spree/shared/_order_line_item.html.erb+++ b/storefront/app/views/themes/default/spree/shared/_order_line_item.html.erb@@ -1,29 +1,65 @@-<div>+<% line_item = inventory_unit.line_item %>++<div class="flex flex-col gap-4"><div class="flex gap-4"><div class="flex-shrink-0"><% image = line_item.variant.default_image %><% if image.present? && image.attached? && image.variable? %><%= link_to spree_storefront_resource_url(line_item.product, relative: true) do %>- <%= image_tag main_app.cdn_image_url(image.variant(spree_image_variant_options(resize_to_fit: [256, 256]))), width: 128, loaging: :lazy %>+ <%= image_tag main_app.cdn_image_url(+ image.variant(spree_image_variant_options(resize_to_fit: [256, 256])),+ ),+ width: 128,+ loaging: :lazy %><% end %><% end %></div><div class="flex flex-col gap-2"><div class="font-medium uppercase">- <%= link_to line_item.name, spree_storefront_resource_url(line_item.product, relative: true) %>+ <%= link_to line_item.name,+ spree_storefront_resource_url(line_item.product, relative: true) %></div><div class="font-medium"><%= line_item.display_price %></div><div class="flex flex-wrap gap-2">- <%= render 'spree/shared/line_item_options', line_item: line_item %>- <div class="h-[30px] border border-default px-2 inline-flex items-center hover:border-dashed hover:border-primary text-sm">- <%= Spree.t(:quantity) %>: <%= line_item.quantity %>+ <%= render "spree/shared/line_item_options", line_item: line_item %>+ <div+ class="+ h-[30px] border border-default px-2 inline-flex items-center hover:border-dashed+ hover:border-primary text-sm+ "+ >+ <%= Spree.t(:quantity) %>:+ <%= inventory_unit.quantity %></div></div></div></div>- <div class="mt-3">- <%= link_to Spree.t(:order_again), spree_storefront_resource_url(line_item.product, relative: true), class: 'link' %>+ <% if line_item.digital_links.any? %>+ <div class="flex flex-col gap-2">+ <span class="font-medium"><%= Spree.t(:attachments) %></span>+ <ul class="flex flex-col gap-1">+ <% line_item.digital_links.each do |digital_link| %>+ <li>+ <% if digital_link.authorizable? %>+ <%= link_to "#{Spree.t(:download)} #{digital_link.filename}",+ spree.digital_link_path(digital_link.token) %>+ <% else %>+ <span class="text-neutral cursor-not-allowed">+ <%= Spree.t(:download) %>+ <%= digital_link.filename %>+ (<%= Spree.t(:expired) %>)+ </span>+ <% end %>+ </li>+ <% end %>+ </ul>+ </div>+ <% end %>+ <div>+ <%= link_to Spree.t(:order_again),+ spree_storefront_resource_url(line_item.product, relative: true),+ class: "link" %></div></div>diff --git a/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erb b/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erbindex 310e6d8ce9..06aea0109e 100644--- a/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erb+++ b/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erb@@ -6,7 +6,8 @@<%= Spree.t(:delivery_address) %></div><div class="!leading-[1.375rem] text-neutral-800">- <%= render 'spree/shared/address', address: shipment.address || shipment.order.ship_address %>+ <%= render "spree/shared/address",+ address: shipment.address || shipment.order.ship_address %></div></div><div class="text-sm lg:w-1/2 lg:flex justify-between">@@ -18,41 +19,55 @@<% if shipment.shipping_method.present? %><%= shipment.shipping_method.name %><% else %>- <%= Spree.t('shipment_states.canceled') %>+ <%= Spree.t("shipment_states.canceled") %><% end %>- <br >+ <br><% if shipment.stock_location.present? %>- <%= Spree.t(:shipped_from) %> <%= shipment.stock_location.name %>+ <%= Spree.t(:shipped_from) %>+ <%= shipment.stock_location.name %><% end %></div></div>- <div class="mt-4 lg:-mt-2 lg:-mr-2">- <% if shipment.shipped? && shipment.tracked? && shipment.tracking_url.present? %>- <%= link_to Spree.t(:track_items), shipment.tracking_url, class: "!px-3 !py-1 block btn-primary !leading-6 text-sm text-center", target: :_blank %>- <% else %>- <button class="!px-3 !py-1 block btn-primary !leading-6 text-sm text-center" disabled><%= Spree.t(:track_items) %></button>+ <% unless shipment.digital? %>+ <div class="mt-4 lg:-mt-2 lg:-mr-2">+ <% if shipment.shipped? && shipment.tracked? && shipment.tracking_url.present? %>+ <%= link_to Spree.t(:track_items),+ shipment.tracking_url,+ class: "!px-3 !py-1 block btn-primary !leading-6 text-sm text-center",+ target: :_blank %>+ <% else %>+ <button+ class="+ !px-3 !py-1 block btn-primary !leading-6 text-sm text-center+ "+ disabled+ ><%= Spree.t(:track_items) %></button>+ <% end %>+ </div><% end %>- </div></div></div><% if shipment.canceled? && shipment.shipped_at.present? %><%# No message if shipment has been shipped already %><% elsif shipment.canceled? && shipment.shipped_at.nil? %><div class="alert-warning text-sm uppercase mt-3 px-3 py-2">- <strong><%= Spree.t(:shipment) %> <%= Spree.t('shipment_states.canceled') %></strong>.+ <strong><%= Spree.t(:shipment) %>+ <%= Spree.t("shipment_states.canceled") %></strong>.<%= Spree.t(:shipment_refunded_message) %></div>- <% elsif shipment.shipped? && shipment.tracked? %>- <% else %>+ <% elsif !shipment.digital? %><div class="text-sm uppercase text-center bg-neutral-100 mt-3 px-3 py-2"><%= Spree.t(:no_tracking_present) %></div><% end %></div>- <hr class="border-accent mx-4" >+ <hr class="border-accent mx-4"><div class="grid grid-cols-1 gap-4 lg:gap-6 p-4 lg:p-6">- <%= render partial: 'spree/shared/order_line_item', collection: shipment.line_items, as: :line_item, cached: spree_base_cache_scope %>+ <%= render partial: "spree/shared/order_line_item",+ collection: shipment.inventory_units,+ as: :inventory_unit,+ cached: spree_base_cache_scope %></div></li>diff --git a/storefront/config/routes.rb b/storefront/config/routes.rbindex 37cd721ff5..1832370ff2 100644--- a/storefront/config/routes.rb+++ b/storefront/config/routes.rb@@ -80,6 +80,9 @@ Spree::Core::Engine.add_routes doresources :contacts, only: [:new, :create]get '/contact', to: 'contacts#new', as: 'contact'+ # Digital Links+ resources :digital_links, only: [:show]+root to: 'home#index'endenddiff --git a/storefront/spec/controllers/spree/digital_links_controller_spec.rb b/storefront/spec/controllers/spree/digital_links_controller_spec.rbnew file mode 100644index 0000000000..254c390815--- /dev/null+++ b/storefront/spec/controllers/spree/digital_links_controller_spec.rb@@ -0,0 +1,80 @@+require 'spec_helper'++RSpec.describe Spree::DigitalLinksController, type: :controller do+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:order) { create(:order) }+ let(:product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+ let(:digital) { create(:digital) }+ let(:variant) { create(:variant, digitals: [digital], product: product) }+ let!(:line_item) { create(:line_item, order: order, variant: variant) }+ let(:digital_link) { create(:digital_link, line_item: line_item, digital: digital) }+ let!(:shipment) do+ create(:shipment, state: 'ready', order: order).tap do |shipment|+ shipment.shipping_methods.delete_all+ shipment.add_shipping_method(digital_shipping_method, true)+ end+ end++ describe '#show' do+ context 'with valid digital link' do+ context 'when first access' do+ it 'marks shipment as fulfilled' do+ allow(controller).to receive(:send_file)+ get :show, params: { id: digital_link.token }+ expect(shipment.reload.state).to eq('shipped')+ end+ end++ context 'when using DiskService' do+ it 'sends the file directly' do+ expect(controller).to receive(:send_file).with(+ anything,+ filename: digital.filename,+ type: digital.content_type,+ status: :ok+ )+ get :show, params: { id: digital_link.token }+ end+ end++ context 'when using cloud storage' do+ before do+ stub_const('ActiveStorage::Service::S3Service', Class.new)+ allow(ActiveStorage::Blob).to receive(:service).and_return(+ instance_double('ActiveStorage::Service::S3Service', instance_of?: false)+ )+ allow_any_instance_of(ActiveStorage::Attachment).to receive(:url).with(+ expires_in: @default_store.preferred_digital_asset_link_expire_time.seconds,+ disposition: 'attachment',+ host: anything+ ).and_return('https://example.com/file.pdf')+ end++ it 'redirects to the cloud storage URL' do+ get :show, params: { id: digital_link.token }+ expect(response).to redirect_to('https://example.com/file.pdf')+ end+ end+ end++ context 'with unauthorized digital link' do+ before do+ digital_link.update(access_counter: @default_store.preferred_digital_asset_authorized_clicks + 1)+ end++ it 'redirects to order path with error' do+ get :show, params: { id: digital_link.token }+ expect(flash[:error]).to eq Spree.t(:digital_link_unauthorized)+ expect(response).to redirect_to(spree.order_path(order))+ end+ end++ context 'with invalid digital link token' do+ it 'raises ActiveRecord::RecordNotFound' do+ expect do+ get :show, params: { id: 'invalid_token' }+ end.to raise_error(ActiveRecord::RecordNotFound)+ end+ end+ end+enddiff --git a/storefront/spec/controllers/spree/orders_controller_spec.rb b/storefront/spec/controllers/spree/orders_controller_spec.rbindex 440912f925..5d96afa60f 100644--- a/storefront/spec/controllers/spree/orders_controller_spec.rb+++ b/storefront/spec/controllers/spree/orders_controller_spec.rb@@ -9,6 +9,7 @@ describe Spree::OrdersController, type: :controller dorender_viewsbefore do+ allow(controller).to receive_messages(try_spree_current_user: user)allow(controller).to receive(:current_store).and_return(store)end@@ -50,7 +51,7 @@ describe Spree::OrdersController, type: :controller doallow(controller).to receive_messages(try_spree_current_user: user)end- context '#update' do+ describe '#update' docontext 'with authorization' dobefore doallow(controller).to receive :check_authorization@@ -73,7 +74,7 @@ describe Spree::OrdersController, type: :controller doend# Regression test for #2750- context '#update' do+ describe '#update' dobefore doallow(user).to receive :last_incomplete_spree_orderallow(controller).to receive :set_current_order@@ -104,7 +105,7 @@ describe Spree::OrdersController, type: :controller doenddescribe '#show' do- let(:order) { create(:completed_order_with_totals, store: store) }+ let(:order) { create(:completed_order_with_totals, store: store, user: user) }it 'renders the show template' doget :show, params: { id: order.number, token: order.token }@@ -113,9 +114,19 @@ describe Spree::OrdersController, type: :controller docontext 'when order is not found' doit 'raises ActiveRecord::RecordNotFound' do- expect {+ expect doget :show, params: { id: 'invalid', token: order.token }- }.to raise_error(ActiveRecord::RecordNotFound)+ end.to raise_error(ActiveRecord::RecordNotFound)+ end+ end++ context 'when order belongs to another user' do+ let(:order) { create(:completed_order_with_totals, store: store, user: create(:user)) }++ it 'raises ActiveRecord::RecordNotFound' do+ expect do+ get :show, params: { id: order.number, token: order.token }+ end.to raise_error(ActiveRecord::RecordNotFound)endendenddiff --git a/storefront/spec/helpers/spree/checkout_helper_spec.rb b/storefront/spec/helpers/spree/checkout_helper_spec.rbnew file mode 100644index 0000000000..71dc2fb457--- /dev/null+++ b/storefront/spec/helpers/spree/checkout_helper_spec.rb@@ -0,0 +1,55 @@+require 'spec_helper'++describe Spree::CheckoutHelper do+ describe '#quick_checkout_enabled?' do+ let(:digital_shipping_method) { create(:digital_shipping_method) }+ let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }+ let(:digital_variant) { create(:variant, product: digital_product, digitals: [create(:digital)]) }+ let(:digital_line_item) { create(:line_item, variant: digital_variant, quantity: 1, order: order) }+ let(:physical_line_item) { create(:line_item, quantity: 1, order: order) }+ let(:order) { create(:order) }++ it 'returns true if the order is fully digital' do+ digital_line_item+ order.update_totals++ expect(helper.quick_checkout_enabled?(order)).to be true+ end++ it 'returns true if the order has no digital products at all' do+ physical_line_item+ order.update_totals++ expect(helper.quick_checkout_enabled?(order)).to be true+ end++ it 'returns false if the order has physical products and some digital products' do+ physical_line_item+ digital_line_item+ order.update_totals++ expect(helper.quick_checkout_enabled?(order)).to be false+ end++ it 'returns false if order has many shipments' do+ physical_line_item+ digital_line_item+ order.update_totals+ order.create_proposed_shipments++ expect(order.shipments.count).to eq(2)++ expect(helper.quick_checkout_enabled?(order)).to be false+ end++ it 'returns false if order does not require payment' do+ physical_line_item.update(price: 0)+ order.update_totals++ expect(order.total).to eq(0)+ expect(order.payment_required?).to be false++ expect(helper.quick_checkout_enabled?(order)).to be false+ end+ end+end