2019-12-13 11:54:32 +11:00
|
|
|
import Route from "@ember/routing/route";
|
2019-12-02 18:58:14 +11:00
|
|
|
import Product from "discourse/plugins/discourse-subscriptions/discourse/models/product";
|
2023-12-01 18:30:36 +00:00
|
|
|
import { inject as service } from "@ember/service";
|
2019-10-10 13:52:55 +11:00
|
|
|
|
2019-12-13 11:54:32 +11:00
|
|
|
export default Route.extend({
|
2023-12-01 18:30:36 +00:00
|
|
|
router: service(),
|
|
|
|
|
|
2019-10-10 13:52:55 +11:00
|
|
|
model() {
|
2019-11-04 16:37:21 +11:00
|
|
|
return Product.findAll();
|
2020-09-16 09:53:50 -05:00
|
|
|
},
|
2023-05-04 13:52:04 +00:00
|
|
|
|
|
|
|
|
afterModel(products) {
|
|
|
|
|
if (products.length === 1) {
|
|
|
|
|
const product = products[0];
|
|
|
|
|
|
|
|
|
|
if (this.currentUser && product.subscribed && !product.repurchaseable) {
|
2023-12-01 18:30:36 +00:00
|
|
|
this.router.transitionTo(
|
2023-05-04 13:52:04 +00:00
|
|
|
"user.billing.subscriptions",
|
|
|
|
|
this.currentUser.username
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2023-12-01 18:30:36 +00:00
|
|
|
this.router.transitionTo("subscribe.show", product.id);
|
2023-05-04 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-10-10 13:52:55 +11:00
|
|
|
});
|