diff --git a/packages/Webkul/CatalogRule/src/Repositories/CatalogRuleRepository.php b/packages/Webkul/CatalogRule/src/Repositories/CatalogRuleRepository.php index efd4dc2ad..a0f5caad2 100644 --- a/packages/Webkul/CatalogRule/src/Repositories/CatalogRuleRepository.php +++ b/packages/Webkul/CatalogRule/src/Repositories/CatalogRuleRepository.php @@ -159,7 +159,11 @@ class CatalogRuleRepository extends Repository if ($attribute->code == 'tax_category_id') { $options = $this->getTaxCategories(); } else { - $options = $attribute->options; + if ($attribute->type === 'select') { + $options = $attribute->options()->orderBy('sort_order')->get(); + } else { + $options = $attribute->options; + } } if ($attribute->validation == 'decimal') diff --git a/packages/Webkul/Category/src/Models/Category.php b/packages/Webkul/Category/src/Models/Category.php index 0bb2a776c..70e95f12a 100755 --- a/packages/Webkul/Category/src/Models/Category.php +++ b/packages/Webkul/Category/src/Models/Category.php @@ -65,12 +65,14 @@ class Category extends TranslatableModel implements CategoryContract */ public function filterableAttributes() { - return $this->belongsToMany(AttributeProxy::modelClass(), 'category_filterable_attributes')->with('options'); + return $this->belongsToMany(AttributeProxy::modelClass(), 'category_filterable_attributes')->with(['options' => function($query) { + $query->orderBy('sort_order'); + }]); } /** * Getting the root category of a category - * + * * @return Category */ public function getRootCategory(): Category @@ -124,7 +126,7 @@ class Category extends TranslatableModel implements CategoryContract if ($category->id === $this->id) { return $category; } - + return $this->findInTree($category->children); } } \ No newline at end of file