feat(medusa): categories can be ranked based on position (#3341)
* chore: categories can be ranked based on position * chore: fix tests * chore: sort categories by order * chore: fix bug where mpath relationship is messed up * chore: enable linting - lint changes * Update packages/medusa/src/repositories/product-category.ts Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com> * chore: fixed specs * chore: cleanup repository to new typeorm interfaces + cleanup * chore: revert repository changes due to incorrect sql * chore: addressed pr reviews --------- Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com> Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
This commit is contained in:
co-authored by
Frane Polić
adrien2p
parent
67ba8be02b
commit
0a6aa0e624
@@ -17,6 +17,7 @@ import {
|
||||
|
||||
@Entity()
|
||||
@Tree("materialized-path")
|
||||
@Index(["parent_category_id", "rank"], { unique: true })
|
||||
export class ProductCategory extends SoftDeletableEntity {
|
||||
static productCategoryProductJoinTable = "product_category_product"
|
||||
static treeRelations = ["parent_category", "category_children"]
|
||||
@@ -51,6 +52,9 @@ export class ProductCategory extends SoftDeletableEntity {
|
||||
@TreeChildren({ cascade: true })
|
||||
category_children: ProductCategory[]
|
||||
|
||||
@Column({ nullable: false, default: 0 })
|
||||
rank: number
|
||||
|
||||
@ManyToMany(() => Product, { cascade: ["remove", "soft-remove"] })
|
||||
@JoinTable({
|
||||
name: ProductCategory.productCategoryProductJoinTable,
|
||||
@@ -119,6 +123,10 @@ export class ProductCategory extends SoftDeletableEntity {
|
||||
* type: boolean
|
||||
* description: A flag to make product category visible/hidden in the store front
|
||||
* default: false
|
||||
* rank:
|
||||
* type: integer
|
||||
* description: An integer that depicts the rank of category in a tree node
|
||||
* default: 0
|
||||
* category_children:
|
||||
* description: Available if the relation `category_children` are expanded.
|
||||
* type: array
|
||||
|
||||
Reference in New Issue
Block a user