Skip to content

Allow sorting of a product's prices by any key, e.g. unit_price #115

Description

@wallacio

Description

For products with multiple prices (e.g. a product which has monthly and annual subscription prices), I would expect to be able to sort the product's prices by some known Price key, eg unit_price, and define the sort order. The prices are currently ordered by ID, as defined in elements/Product.php:

private function createPriceQuery(): PriceQuery
{
return Price::find()
->owner($this)
->orderBy(['id' => SORT_ASC]);
}

In the same way that Product::getPrices() can be passed criteria (per issue #97, resolved by PR #98), it would be very nice to be able to pass a sort order override.

Steps to reproduce

  1. Set up a Product in Stripe
  2. Add multiple prices to that Product
  3. Retrieve the prices for the product using product.prices or product.getPrices()
  4. Observe that the order is fixed by ID

Additional info

  • Craft version: 5.10
  • PHP version: 8.4
  • Stripe plugin: 1.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions