-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing product brand guidelines #138
Open
shahmayur001
wants to merge
2
commits into
solidusio:main
Choose a base branch
from
gms-electronics:product_brand_guides
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
sidebar_position: 10 | ||
--- | ||
# Introduction | ||
Brands are a frequently required information in ecommerce. | ||
They allow | ||
* more comprehensive analytics; | ||
* They allow your customers to filter products from a certain manufacturer; | ||
* They are frequently used in product feeds for marketing platforms such as Google Shopping. | ||
|
||
With the integration of Brands inside Solidus all above detailed scenarios are possible. | ||
|
||
# How to Use a Custom Brand Selector | ||
|
||
In Solidus, a product's brand is determined using a configurable `brand_selector_class`. By default, this is set to `Spree::TaxonBrandSelector`, which identifies the brand by associating the product with a taxon under the taxonomy named `"Brands"`. | ||
|
||
This guide explains how to implement and configure a custom brand selector to suit your application's unique requirements. | ||
|
||
## Default Behavior | ||
|
||
By default, the `Spree::TaxonBrandSelector` works as follows: | ||
|
||
- It fetches all taxons associated with a product. | ||
- It filters the taxons by checking if they belong to the `"Brands"` taxonomy. | ||
- It returns the first matching taxon as the brand. | ||
|
||
Here is the default configuration: | ||
|
||
```ruby | ||
Spree.config do |config| | ||
# ... | ||
config.brand_selector_class = 'Spree::TaxonBrandSelector' | ||
end | ||
``` | ||
|
||
# Implementing a Custom Brand Selector | ||
|
||
To override the default behavior, you can create a new class that implements the same interface as `Spree::TaxonBrandSelector`. | ||
|
||
For example, let's say you want to define brands based on specific product properties rather than taxons. Here's how you can do it: | ||
|
||
## Step 1: Create Your Custom Class | ||
|
||
```ruby title="app/models/my_store/custom_brand_selector.rb" | ||
module MyStore | ||
class CustomBrandSelector | ||
def initialize(product) | ||
@product = product | ||
end | ||
|
||
def call | ||
# Replace this with your custom logic. | ||
# For instance, returning a specific brand based on a product's property: | ||
@product.custom_brand_property | ||
end | ||
|
||
private | ||
|
||
attr_reader :product | ||
end | ||
end | ||
``` | ||
|
||
## Step 2: Update the Configuration | ||
|
||
To use your custom brand selector, update the initializer to configure the `brand_selector_class`: | ||
|
||
```ruby title="config/initializers/spree.rb" | ||
Spree.config do |config| | ||
# ... | ||
config.brand_selector_class = 'MyStore::CustomBrandSelector' | ||
end | ||
``` | ||
|
||
|
||
## Verifying the Custom Behavior | ||
|
||
Once you've implemented and configured your custom class, you can verify its behavior by calling the `brand` method on any product. This method will now use your custom selector logic: | ||
|
||
```ruby title="Example: Verifying Custom Brand Selector" | ||
product = Spree::Product.find(1) | ||
puts product.brand # Outputs the result of your custom logic | ||
``` | ||
|
||
[order_adjustments_recalculator]: https://github.com/solidusio/solidus/blob/v3.3/core/app/models/spree/promotion/order_adjustments_recalculator.rb | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kennyadsl we will have to put any other changes or contributions on hold till we understand the governance of the repo better.