Skip to content

API Support for Price Lists and Price List Items#30

Open
JustShah wants to merge 6 commits into
16-consider-price-lists-in-the-price-selectorfrom
13-add-the-api-for-pricelists
Open

API Support for Price Lists and Price List Items#30
JustShah wants to merge 6 commits into
16-consider-price-lists-in-the-price-selectorfrom
13-add-the-api-for-pricelists

Conversation

@JustShah

Copy link
Copy Markdown

This update introduces comprehensive API support for managing price lists and their associated prices in the Solidus store.

Key Changes:

Created API Endpoints

  • Implemented full CRUD actions for both price_lists and nested price_list_items.
  • Nested routes enable clean access to price list items scoped to a specific price list.

Nested Price Attribute Handling

  • price_list_items now accept price_attributes via nested attributes for seamless creation/updating of prices tied to the correct price list.

Validation Enhancements

  • Added model-level validations to Spree::PriceListItem to ensure that the currency and country ISO match those of the associated price list.
  • Introduced automatic fallback assignment of currency and country_iso from the price list if not provided explicitly.

Permitted Attributes Updates

  • Extended permitted attributes configuration to include :price_attributes, :price_list_attributes, and :price_list_item_attributes.

API Configuration

  • Updated the API preferences to control which price-related attributes can be submitted and returned in API responses.

Jbuilder Views

  • Implemented Jbuilder templates for structured JSON responses.

@JustShah JustShah linked an issue Apr 14, 2025 that may be closed by this pull request
@JustShah JustShah force-pushed the 16-consider-price-lists-in-the-price-selector branch from 4f039e0 to e741a9d Compare April 15, 2025 06:42
Added APIs to create, update, read and destroy price lists and price list items,
price list items accepts nested attribute for price which creates and updates only which are related to the price list.
- Added preferences for `:price_list_attributes`, `:price_attributes`, and `:price_list_item_attributes` in API configuration.
- This allows for better control over which attributes are permitted in API requests and responses.
- Added Jbuilder partial `_price_list_item.json.jbuilder` for rendering individual price list items.
- Created `index.json.jbuilder` to render a list of price list items and price lists with pagination.
- Created `show.json.jbuilder` to render a single price list item and price list.
- Added Jbuilder partial `_price_list.json.jbuilder` for rendering individual price lists.
Added nested routes for `price_list_items` under `price_lists` in the API routes.
This allows for better organization and access to price list items related to specific price lists.
- Added validations to `Spree::PriceListItem` for currency and country consistency.
- Implemented callbacks to set default currency and country based on the associated price list.
- Added `:price_attributes`, `:price_list_attributes`, and `:price_list_item_attributes` to permitted attributes.
- This ensures that these attributes can be safely handled in API requests.
@JustShah JustShah force-pushed the 13-add-the-api-for-pricelists branch from de53cc2 to 6d7c62f Compare April 15, 2025 06:45
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.

Add the API for pricelists

1 participant