solidusio / solidus_subscriptions

An extension to add subscriptions to your Solidus store.
BSD 3-Clause "New" or "Revised" License
48 stars 53 forks source link

Allow updating subscription information in cart #282

Closed kennyadsl closed 1 year ago

kennyadsl commented 1 year ago

Closes #279

Summary

Spree::LineItem already has defined in its model accepts_nested_attributes_for :subscription_line_items so we can leverage this to update a nested model of the line item.

The API call should be:

# https://example.com/api/orders/{order_number}/line_items/{line_item_id}

{
  "line_item": {
    "quantity": 1
  }
  "subscription_line_items_attributes": {
    "id": {subscription_line_item_id}
    "interval_length": 15,
  }
}

This "strange" unnested format is required for the way we are updating line items in the API line_item controller: https://github.com/solidusio/solidus/blob/e878076f2ed670d07654ab6293a16588743f2fa6/api/app/controllers/spree/api/line_items_controller.rb#L29.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed: