{"id":20672104,"url":"https://github.com/workarea-commerce/workarea-product-badges","last_synced_at":"2025-07-09T17:05:27.522Z","repository":{"id":44075976,"uuid":"203650802","full_name":"workarea-commerce/workarea-product-badges","owner":"workarea-commerce","description":"Badges? We don't need no stinking BADGES!","archived":false,"fork":false,"pushed_at":"2023-01-04T08:58:46.000Z","size":588,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-30T16:27:41.683Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://plugins.workarea.com/plugins/badges","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/workarea-commerce.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-21T19:25:31.000Z","updated_at":"2020-12-14T14:54:55.000Z","dependencies_parsed_at":"2023-02-02T06:15:35.135Z","dependency_job_id":null,"html_url":"https://github.com/workarea-commerce/workarea-product-badges","commit_stats":null,"previous_names":["workarea-commerce/workarea-product_badges"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/workarea-commerce/workarea-product-badges","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workarea-commerce%2Fworkarea-product-badges","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workarea-commerce%2Fworkarea-product-badges/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workarea-commerce%2Fworkarea-product-badges/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workarea-commerce%2Fworkarea-product-badges/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/workarea-commerce","download_url":"https://codeload.github.com/workarea-commerce/workarea-product-badges/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workarea-commerce%2Fworkarea-product-badges/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264445498,"owners_count":23609612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T20:32:03.680Z","updated_at":"2025-07-09T17:05:27.483Z","avatar_url":"https://github.com/workarea-commerce.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Workarea Badges\n================================================================================\n\nBadges plugin for the Workarea platform.\nAdds badges to product summary and product detail views.\n\nBadges can be added to products manually, or via a product import by specifying\na comma-separated list in the product[:badges] field.\n\nIn addition to custom badges via the product[:badges] field this plugin provides\nautomatic badging for products. Out of the box automatic badges are:\n\n* New\n* Sale\n* Best Seller\n\nGetting Started\n--------------------------------------------------------------------------------\n\nAdd the gem to your application's Gemfile:\n\n```ruby\n# ...\ngem 'workarea-product_badges'\n# ...\n```\n\nUpdate your application's bundle.\n\n```bash\ncd path/to/application\nbundle\n```\n\nConfiguration\n--------------------------------------------------------------------------------\n\nThe following configuration can be added to your host app and adjusted as necessary:\n\n```ruby\nWorkarea.configure do |config|\n  config.product_badges = {\n    new_threshold: 30,\n    new_date_field: :created_at,\n    number_of_top_sellers: 10,\n    max_badges: nil,\n    sort: -\u003e(badges) { badges.sort_by{ |b| [\"New\", \"Sale\", \"Best Seller\"].find_index(b) || 999 } }\n  }\nend\n```\n\n### new_threshold\n\n* type: integer\n* default: 30\n* products created in this time will receive a 'New' badge\n\n### new_date_field\n\n* type: symbol\n* default: :created_at\n* Specify which field will be used to calculate whether a product should display\n  the 'new' badge.\n\n### number_of_top_sellers\n\n* type: integer\n* default: 10\n* Description: Number of products from top sellers to apply a badge to\n\n### max_badges\n\n* type: integer\n* default: nil\n* Description: limits the number of badges that can be applied to any product\n\n### sort\n\n* type: Lambda\n* default: -\u003e(badges) { badges.sort_by{ |b| [\"New\", \"Sale\", \"Best Seller\"].find_index(b) || 999 } }\n* Description: Specify the order in which badges should appear, this lambda can\n  be updated to sort badges according to any business logic without decoration.\n  By default the plugin will sort automatic badges first followed by custom badges.\n  Custom badges will display in the order they appear in the admin.\n\n#### Implementing a custom sort class\n\nFor more complicated sorting logic, a sorting class can be implemented as long as\nit responds to .call example\n\n```ruby\nclass MyBadgeSort\n  def self.call(badges)\n    new(badges).results\n  end\n\n  def initialize(badges)\n    @badges = badges\n  end\n\n  def results\n    # do all sorts of crazy complex stuff\n  end\nend\n```\n\nThen update your configuration to:\n\n```ruby\n  Workarea.config.product_badges[:sort] = MyBadgeSort\n```\n\nAdding new automatic badges\n--------------------------------------------------------------------------------\n\nTo add a new automatic badge in your host application you should decorate the\nproduct_view_model automatic_badges method, calling super and injecting your badge\nto the array.\n\nExample:\n\n```ruby\nmodule Workarea\n  decorate Storefront::ProductViewModel, with: :your_app_name do\n    def automatic_badges\n      super \u003c\u003c custom_badge_method\n    end\n\n    private\n\n    def custom_badge_method\n      if logic_for_automatic_badge\n        t('workarea.storefront.products.badges.[custom_badge_key]')\n      end\n    end\n  end\nend\n```\n\nWorkarea Commerce Documentation\n--------------------------------------------------------------------------------\n\nSee [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.\n\nLicense\n--------------------------------------------------------------------------------\n\nWorkarea Product Badges is released under the [Business Software License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkarea-commerce%2Fworkarea-product-badges","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkarea-commerce%2Fworkarea-product-badges","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkarea-commerce%2Fworkarea-product-badges/lists"}