Price lists and customer groups#5
Draft
JustShah wants to merge 9 commits into
Draft
Conversation
- Added associations to Spree::Price model for price lists and price list items. - Created Spree::PriceList model with associations to price list items and prices, and added validation for the name attribute. - Created Spree::PriceListItem model with associations to price lists and prices, and added validations for presence of price_list and price attributes. - Updated locale files to include translations for price lists and related notifications. - Created migrations to add spree_price_lists and spree_price_list_items tables with necessary fields and references. These changes introduce a new price list feature, allowing for the organization and management of different pricing strategies. The associations and validations ensure data integrity and proper relationships between models. The locale updates provide necessary translations for the new feature, and the migrations set up the required database schema.
- Added belongs_to association to Spree::User for user groups. - Updated Spree::PriceList to include association with user groups. - Added belongs_to association to Spree::Store for default user group. - Created Spree::UserGroup model with associations to users, store, and price list, and added validation for group_name. - Updated locale files to include translations for user groups and related notifications. - Created migrations to add spree_user_groups table and references to user_group in users and stores tables. - Updated permitted attributes to include price_list_attributes and user_group_attributes. These changes introduce user groups, allowing for the organization of users into groups with specific price lists. The associations and validations ensure data integrity and proper relationships between models. The locale updates provide necessary translations for the new feature, and the migrations set up the required database schema.
- Created Spree::Admin::PriceListsController with load_data method to load prices for selection. - Added views for price lists: form, edit, index, and new. - The form view includes fields for name and associated prices. - The index view lists all price lists with links to edit and delete. - The new and edit views provide forms for creating and updating price lists. These changes introduce an admin interface for managing price lists, allowing administrators to create, edit, and delete price lists and associate them with prices. The views and controller actions ensure a seamless user experience for managing price lists within the admin panel.
- Created Spree::Admin::UserGroupsController with load_data method to load price lists for selection. - Added views for user groups: form, edit, index, and new. - The form view includes fields for group name and associated price list. - The index view lists all user groups with links to edit and delete. - The new and edit views provide forms for creating and updating user groups. These changes introduce an admin interface for managing user groups, allowing administrators to create, edit, and delete user groups and associate them with price lists. The views and controller actions ensure a seamless user experience for managing user groups within the admin panel.
- Updated Spree::Admin::UsersController to permit user_group_id attribute if the user has manage permissions. - Modified user form to include a field for selecting user group if the user has appropriate permissions. - Updated store form to include a field for selecting default user group. These changes allow administrators to assign user groups to users and set default user groups for stores through the admin interface. The updates ensure that user group management is integrated into the user and store forms, providing a seamless experience for administrators.
- Updated product sub-menu to include a tab for price lists if the user has admin permissions. - Created a new users sub-menu partial to include tabs for users and user groups. - Added routes for price lists and user groups in the backend routes configuration. - Updated backend configuration to include menu items for price lists and user groups under the appropriate conditions. - Adjusted backend configuration spec to account for the new menu items. These changes integrate price lists and user groups into the admin navigation, providing easy access to these features for administrators. The updates ensure that the new functionality is seamlessly incorporated into the existing admin interface.
- Created Spree::Api::PriceListsController with actions for index, show, create, update, and destroy. - Created Spree::Api::UserGroupsController with actions for index, show, create, update, and destroy. - Updated API helpers to include permitted attributes for price lists and user groups. - Added routes for price lists and user groups in the API routes configuration. - Updated API configuration to include preferences for price list and user group attributes. - Adjusted API specs to account for the new attributes in stores and users. These changes introduce API endpoints for managing price lists and user groups, allowing for CRUD operations through the API The updates ensure that the new functionality is accessible via the API, providing a comprehensive solution for managin price lists and user groups programmatically.
- Created Spree::Variant::PriceSelectorByUserGroup to select prices based on user group and other pricing options.
- Added Spree::Variant::PricingOptionsWithUserGroup to handle pricing options including user group, currency, and country.
- Implemented logic to apply the following priority for price selection:
1. If a SKU requested by a user has a price in the user-assigned group price list, apply that.
2. If a user has no price list or the SKU is not present on the price list, apply the default store price list SKU pricethrough the default group setting.
3. If neither price lists (neither the group-inherited user price list nor the default user group price list) are presentor have the requested SKU listed, return the current default price.
These changes introduce a new price selection mechanism that takes user groups into account, allowing for more granular andflexible pricing strategies. The new classes and methods ensure that prices are selected and applied based on the user'sgroup, currency, and country, enhancing the overall pricing functionality.
This commit adds logic to recalculate line item price once the user is associated to the order, The current flow of code used to create the line item and order once the product was added to cart. To calculate accurate pricing for the user, we have added a new method which is called after the user is associated to the order and based on the conditions for calculating price based on user group the line item price is recalculated.
7e0cf27 to
a5bd73f
Compare
fthobe
requested changes
Apr 4, 2025
| super || variant_tax_category_id | ||
| end | ||
|
|
||
| def recalculate_price |
There was a problem hiding this comment.
@JustShah did you try if we really need this? change of user should automatically trigger recalculations.
|
|
||
| has_many :orders, class_name: "Spree::Order" | ||
|
|
||
| belongs_to :default_user_group, class_name: 'Spree::UserGroup', optional: true |
There was a problem hiding this comment.
Please align the naming of default user group with the documentation in the issue
| @@ -0,0 +1,63 @@ | |||
| # frozen_string_literal: true | |||
|
|
|||
| module Spree | |||
There was a problem hiding this comment.
the api was still up for discussion, please provide copy and pasted json of your proposal. Please do not extend the prediscussed and documented frame of the issue. If there's written TBD either provide a suggestion inside the issue in written from BEFORE INTITIATING THE WORK or wait on a proposal
b4b0c1c to
b65baaf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP.