# rating (https://docs.salla.dev/twilight/react/sdk/rating)



Use `Salla.rating` after an order is delivered, when the customer rates it. The `salla-rating-modal` web component runs the whole flow, so check it first: see [`salla-rating-modal`](https://docs.salla.dev/twilight/react/web-components/salla-rating-modal).

```ts
// what can be rated for this order
const { data } = await Salla.rating.order(978);

await Salla.rating.store({ order_id: 978, rating: 5, comment: 'Fast and friendly' });
```

## Methods [#methods]

| Method               | Parameters                                                   | Does                                                   |
| -------------------- | ------------------------------------------------------------ | ------------------------------------------------------ |
| `order`              | `orderId` or `{ order_id }`                                  | Reads what the customer can rate for the order         |
| `store`              | `{ order_id, rating, comment? }`                             | Rates the store                                        |
| `products`           | `{ order_id, products: [{ product_id, rating, comment? }] }` | Rates the order's products                             |
| `shipping`           | `{ order_id, shipping_company_id, rating, comment? }`        | Rates the shipping company                             |
| `productEligibility` | `productId`                                                  | Whether the customer may rate this product. No events. |

`rating` is the number of stars.

```ts
await Salla.rating.products({
  order_id: 589,
  products: [
    { product_id: 5871, rating: 5, comment: 'Good quality' },
    { product_id: 2589, rating: 4 },
  ],
});
```

## Events [#events]

| Event                                                 | Fires when | Arguments                   |
| ----------------------------------------------------- | ---------- | --------------------------- |
| `rating::order.fetched` / `rating::order.not.fetched` | `order`    | response or error, order id |
| `rating::store.rated` / `rating::store.failed`        | `store`    | response or error, payload  |
| `rating::products.rated` / `rating::products.failed`  | `products` | response or error, payload  |
| `rating::shipping.rated` / `rating::shipping.failed`  | `shipping` | response or error, payload  |

## Gotchas [#gotchas]

* These calls need a logged-in customer.
* Each method without its payload rejects at once with "There is no "data"!", or for `order` with "There is no "order_id"!".

## See also [#see-also]

* [Order](https://docs.salla.dev/twilight/react/sdk/order)
* [Comment](https://docs.salla.dev/twilight/react/sdk/comment)
