Skip to content

[Admin][Settings][Shipments] Introduce shipping method creation and modification capability #6232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

JustShah
Copy link
Contributor

@JustShah JustShah commented May 7, 2025

Add Admin UI and Feature Specs for Shipping Methods

Solves: Solidus Admin (view)

This PR implements a complete admin interface for managing Shipping Methods in Solidus Admin, along with feature specs and UI components.

Shipping Method Form Component

  • Built using ui/forms/field and ui/panel components.
  • Panels include:
    • Details: Name, admin name, code, carrier, service level, tracking URL.
    • Pricing: Calculator selection and preference fields.
    • Taxation: Tax category select.
    • Availability: Stores, zones, stock locations, availability toggles.
    • Organization: Shipping categories.
  • JavaScript interactivity:
    • Toggles preference fields based on selected calculator.
    • Shows/hides stock locations based on "Available to all" checkbox.

Calculator Support

  • Dropdown to select calculator type (e.g., Flat Rate, Per Item).
  • Dynamically renders preference fields based on calculator class.
  • Supports various field types:
    • Decimal (e.g., preferred_amount, preferred_flat_percent)
    • Integer
    • String
    • Currency

Controller Enhancements

  • ShippingMethodsController updated to:
    • Inherit from SolidusAdmin::ResourcesController
    • Handle assignment of shipping_categories and zones
    • Permit nested calculator_attributes and multiple select values like store_ids

UI Improvements

  • Index page:
    • Displays shipping methods
    • Includes edit links
  • New/Edit pages:
    • Form rendered via components
    • Locale support for all labels and UI copy

image
image

@JustShah JustShah force-pushed the admin-shipping-add-edit branch 3 times, most recently from 7a76917 to 2aee7da Compare May 7, 2025 06:47
Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.86%. Comparing base (f55384c) to head (b13304f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6232      +/-   ##
==========================================
+ Coverage   88.83%   88.86%   +0.02%     
==========================================
  Files         850      857       +7     
  Lines       18328    18359      +31     
==========================================
+ Hits        16281    16314      +33     
+ Misses       2047     2045       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JustShah JustShah force-pushed the admin-shipping-add-edit branch 7 times, most recently from 48b4946 to ae87ce1 Compare May 7, 2025 09:39
# frozen_string_literal: true

class SolidusAdmin::ShippingMethods::Edit::Component < SolidusAdmin::Resources::Edit::Component
include SolidusAdmin::Layout::PageHelpers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: bad indentation

@elia
Copy link
Member

elia commented May 23, 2025

While trying to save I got:

Unpermitted parameters: :store_ids, :zones. Context: { controller: SolidusAdmin::ShippingMethodsController, action: create, request: #<ActionDispatch::Request:0x000000032c6199d0>, params: {"authenticity_token"=>"[FILTERED]", "shipping_method"=>{"name"=>"Foo", "admin_name"=>"foo-bar", "code"=>"baz", "carrier"=>"UPS", "service_level"=>"123", "tracking_url"=>"foo.com/?track=:tracking", "calculator_type"=>"Spree::Calculator::Shipping::FlatPercentItemTotal", "calculator_attributes"=>{"preferred_flat_percent"=>"23"}, "tax_category_id"=>"1", "store_ids"=>"1", "zones"=>["1"], "available_to_all"=>"1", "available_to_users"=>"1"}, "controller"=>"solidus_admin/shipping_methods", "action"=>"create"} }

@elia elia requested a review from Copilot May 23, 2025 14:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces an admin UI that enables the creation and modification of shipping methods in Solidus Admin. Key changes include adding new components for creating, editing, and listing shipping methods; integrating a dynamic form for calculator preferences; and updating related routes and translations.

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

File Description
admin/app/components/solidus_admin/shipping_methods/new/* New components to render the “new shipping method” form and related translations
admin/app/components/solidus_admin/shipping_methods/* Components for listing, editing, and form management of shipping methods
admin/app/components/solidus_admin/calculators/* New calculator preference components with dynamic preference fields

value: @shipping_method.stock_location_ids,
class: "fullwidth",
multiple: true,
label: '',
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing a descriptive label for the stock locations select field to improve accessibility, for example using a translation key or clear text such as 'Stock Locations'.

Suggested change
label: '',
label: t('.stock_locations'),

Copilot uses AI. Check for mistakes.

@JustShah JustShah force-pushed the admin-shipping-add-edit branch from ae87ce1 to c1b1f44 Compare May 26, 2025 10:12
JustShah added 9 commits May 26, 2025 15:47
- Added form fields for shipping method details, pricing, taxation, availability, and organization.
- Implemented JavaScript to toggle stock location visibility based on checkbox state.
- Added translations for the form component.
- Added fields using form component.
- Added translations for the new component.
- Added feature spec for shipping method creation.
- Added fields using form component.
- Added translations for the edit component.
- Added feature spec to edit exisiting shipping method.
- Updated the index component to use new paths for editing and creating shipping methods.
- Refactored columns to use helper methods for better readability.
- Added links to edit shipping methods directly from the index.
- Refactored the controller to use `SolidusAdmin::ResourcesController`.
- Updated permitted parameters to include new fields.
- Updated routes to include all actions except `show` for shipping methods.
- Added locale translations for shipping method actions.
- Added a dropdown to select calculator type and render preferences based on the selected type.
- Implemented JavaScript to toggle visibility of preferences based on the selected calculator type.
- Implemented text fields for decimal and integer preferences with appropriate input types and steps.
- Implemented text fields for string preferences.
- Updated the `component.rb` file to handle multiple select fields.
@JustShah JustShah force-pushed the admin-shipping-add-edit branch from c1b1f44 to b13304f Compare May 26, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants