Skip to content

User group and price list combined#28

Open
JustShah wants to merge 20 commits into
mainfrom
user-group-and-price-list-combined
Open

User group and price list combined#28
JustShah wants to merge 20 commits into
mainfrom
user-group-and-price-list-combined

Conversation

@JustShah

Copy link
Copy Markdown

This is a combined PR for Price list and user group feature

contains the changes from:

  1. Add user groups and automatically associate users to groups upon signup: Add user groups and automatically associate users to groups upon signup #20
  2. Add price list and price list items: Add price list and price list items  #21
  3. Restrict pricelist price update from product page: Restrict pricelist price update from product page #22
  4. Implement User Group Pricing with Price Selector: Introduce User Group Pricing to the price selector Price Selector #23
  5. Provide basic group functionality for customer segmentation: Provide basic group functionality for customer segmentation #27

Added associations in Spree::User model for user groups to support grouping users for targeted pricing and management.
Created Spree::UserGroup model with associations to users and stores to enable flexible user group management.
Updated locale files to include translations for user groups.
Added migrations to create spree_user_groups table and add user group references to users and stores.
- Added UserGroupsController to manage user groups.
- Created views for user group management, including:
  - New user group form (`new.html.erb`)
  - User group edit form (`edit.html.erb`)
  - User group index view (`index.html.erb`)
  - Partial view for user group form fields.
- Enhanced user management by allowing assignment of user groups to users in the user form.
- Updated store form to include a selection for the default cart user group.
- Added breadcrumb navigation for improved user experience in the admin panel.

This feature allows administrators to create, edit, and manage user groups, facilitating better organization and access control for users within the Spree application.
- Created a new users sub-menu partial to manage user-related navigation, including links to users and user groups.

These enhancements improve the organization of the admin interface, making it easier for administrators to manage user groups effectively.
- Updated UsersController to assign the default user group to new users if the current store has the `enforce_group_upon_signup` setting enabled.
- Added a checkbox in the store settings form to allow administrators to enable or disable the `enforce_group_upon_signup` feature.
- Included a new translation key for the `enforce_group_upon_signup` label in the English locale file.

This feature ensures that all new users are automatically added to a specified user group, improving user management and organization within the Spree application.
JustShah added 15 commits April 15, 2025 11:57
- Introduced `Spree::PriceList` model to manage collections of prices associated with specific user groups and countries.
- Added optional association for `price_list` on `user_group`
- Created `Spree::PriceListItem` model to establish a many-to-many relationship between prices and price lists.
- Updated `Spree::Price` model to include associations with price lists through price list items.
- Added `contain_taxes` attribute to the `Spree::Price` model to indicate whether prices include taxes.
- Implemented validations for the new models to ensure data integrity.
- Added necessary database migrations to create price lists and price list items tables.

These changes enhance the pricing structure by allowing for more flexible pricing strategies based on user groups and geographical considerations.
- Introduced PriceListsController to handle price list operations.
- Created views for managing price lists, including:
  - New price list form (`new.html.erb`)
  - Price list edit form (`edit.html.erb`)
  - Price list index view (`index.html.erb`)
  - Partial views for price list form fields and price list information.
- Implemented form fields for name, country, currency, and tax inclusion.
- Added functionality to display price details associated with each price list.
- Included breadcrumb navigation for better user experience in the admin panel.

This feature allows administrators to create, edit, and manage price lists effectively, enhancing the overall product pricing strategy.
- Introduced PriceListItemsController to handle price list item operations.
- Created views for managing price list items, including:
  - New price list item form (`new.html.erb`)
  - Price list item edit form (`edit.html.erb`)
  - Partial view for price list item form fields.
- Implemented functionality to associate price list items with specific price lists and variants.
- Added support for entering price details, including amount, currency and taxes.
- Enhanced breadcrumb navigation for better user experience in the admin panel.

This feature allows administrators to create, edit, and manage price list items, facilitating more flexible pricing strategies for products within the Spree application.
- Updated product sub-menu to include a link to price lists if the user has admin permissions.
- Added routes for managing price lists and their associated price list items.
- Updated backend configuration to include price lists in the admin menu, ensuring proper access control based on user permissions.

These enhancements improve the organization of the admin interface, making it easier for administrators to manage price lists effectively.
This commits adds column on user group to display and select the associated price list
for a user group.
This commit adds a boolean is_pricelist_price to spree price model,
which can be used to identify whether the price has been created for price lists or
the price has been created from products section.
Implemented `check_pricelist_price` in variant API and price admin controllers to prevent the user from updating prices which are associated to a price list.
- Added a new localization key for the error message indicating that a price belongs to a price list and cannot be edited or deleted.
- Updated the master variant price table and the general price table in the admin interface to:
  - Prevent editing and deleting of prices that belong to a price list.
  - Display a message indicating the associated price lists for prices that are part of a price list.
- Added hidden field for is_pricelist_price to price list item form.
A new scope `without_pricelist` in the `Spree::Price` model to allow filtering of prices that are not associated with any price list.
The purpose of this change is to allow the system to differentiate between prices that are managed by price lists and those that are not.
This scope is useful for filtering and querying prices that should be treated as standalone (i.e., not tied to a price list).
…ptions

Introduced Spree::Variant::PricingOptionsWithUserGroup, a class that defines the
necessary pricing attributes (currency, country, user group) for selecting prices.
The reason for adding this class is to provide a flexible way
of defining pricing options that consider user groups,
alongside other factors such as country and currency.
By incorporating user group information into pricing options,
we can manage more complex pricing models where different user groups may receive different pricing for the same product variant.
The class Spree::Variant::PriceSelectorByUserGroup, which selects the appropriate price for a product variant
based on user group pricing options. The primary reason for this change is to allow for user group-specific pricing
by incorporating a class that can dynamically select the correct price based on user group and other pricing options
(such as country and currency). This facilitates the implementation of price differentiation for various customer segments.

The class can be used by setting
```
Spree.config do |config|
 config.variant_price_selector_class = 'Spree::Variant::PriceSelectorByUserGroup
end
```
in `config/initializers/spree.rb`
- Implemented the `set_user_group` method in `Spree::Api::UsersController`.
- This method assigns the default user group to a new user if the current store has the `enforce_group_upon_signup` setting enabled.
- Ensures that new users are automatically added to the specified user group during signup.
- Modified the `user_attributes` preference in `Spree::ApiConfiguration` to include `:user_group_id`.
- This change allows the user group information to be included in API responses for user details.
- Updated the user request specs to test the assignment of the default user group upon user creation.
- Added scenarios to verify that the user group is assigned when `enforce_group_upon_signup` is enabled and not assigned when it is disabled.
- Updated the `@@user_attributes` in `Spree::PermittedAttributes` to include `:user_group_id`.
- This allows the user group to be permitted during user creation and updates via the API.
@JustShah JustShah force-pushed the user-group-and-price-list-combined branch from a45c95d to 33fe2a5 Compare April 15, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant