Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
397bf9a
Added configuration to get brand from product
JustShah Nov 20, 2024
b4d51e1
Removed extra space
JustShah Nov 20, 2024
f8fa831
Corrected the reference
JustShah Nov 20, 2024
eeb60c9
Added more test cases
JustShah Nov 22, 2024
75b3af2
Merge branch 'add_brand_from_config' of https://github.com/gms-electr…
JustShah Nov 22, 2024
273a9da
Merge branch 'solidusio:main' into add_brand_from_config
fthobe Nov 27, 2024
02519e0
Fixed store validation issue
JustShah Dec 2, 2024
fd9f796
Merge branch 'add_brand_from_config' of https://github.com/gms-electr…
JustShah Dec 2, 2024
4191737
Updated sample data for brand
JustShah Dec 2, 2024
ff80b7c
Code improvement
JustShah Dec 2, 2024
74fdb6c
Merge pull request #1 from solidusio/main
fthobe Dec 2, 2024
aeb106d
Corrected the reference
JustShah Nov 20, 2024
bb43382
Fixed store validation issue
JustShah Dec 2, 2024
80dab82
chore(github labeler): Add labels for new promotion gems
tvdeyen Nov 15, 2024
a2e288f
Feat(Admin): Dynamic routing proxies
mamhoff Nov 15, 2024
f0e3649
Fix(Admin menus): Stable promotion menu items
mamhoff Nov 15, 2024
4541a6c
Feat(SolidusPromotions): Allow viewing both promotion systems
mamhoff Nov 15, 2024
b7bbce3
Include solidus_legacy_promotions in release task
mamhoff Nov 19, 2024
4650646
Add `#authorization_subject` to Promotions controllers
mamhoff Nov 19, 2024
e9a111c
Fix admin promotions controller
mamhoff Nov 19, 2024
bf2ee9e
Release solidus_admin/v0.3.2
tvdeyen Nov 19, 2024
110e054
Allow PORT to be specified when using `bin/dev`
forkata Nov 14, 2024
c95c7b2
Updated sample data for brand
JustShah Dec 2, 2024
03aba31
Code improvement
JustShah Dec 2, 2024
2cfdb98
Merge branch 'add_brand_from_config' of https://github.com/gms-electr…
JustShah Dec 2, 2024
b670f55
Revert "Updated sample data for brand"
fthobe Dec 2, 2024
96974e0
Added Sample Data for Brands
fthobe Dec 2, 2024
a80f7cb
Create Solidus Sample Brand
fthobe Dec 2, 2024
139348a
Merge branch 'add_brand_from_config' of https://github.com/gms-electr…
fthobe Dec 2, 2024
ef5c3fb
Bugfix Sample Data
fthobe Dec 2, 2024
9bf8919
Merge branch 'add_brand_from_config' of https://github.com/gms-electr…
JustShah Dec 2, 2024
3eac54b
Code cleanup
JustShah Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ def gallery
@gallery ||= Spree::Config.product_gallery_class.new(self)
end

def brand
Spree::Config.brand_selector_class.new(self).call
end

private

def any_variants_not_track_inventory?
Expand Down
22 changes: 22 additions & 0 deletions core/app/models/spree/taxon_brand_selector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Spree
class TaxonBrandSelector
BRANDS_TAXONOMY_NAME = "Brands"

def initialize(product)
@product = product
end

def call
product.taxons
.joins(:taxonomy)
.where(spree_taxonomies: { name: BRANDS_TAXONOMY_NAME })
.first
end

private

attr_reader :product
end
end
7 changes: 7 additions & 0 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ def payment_canceller
# Spree::StoreCreditPrioritizer.
class_name_attribute :store_credit_prioritizer_class, default: 'Spree::StoreCreditPrioritizer'

# Allows finding brand for product.
#
# @!attribute [rw] brand_selector_class
# @return [Class] a class with the same public interfaces as
# Spree::TaxonBrandSelector.
class_name_attribute :brand_selector_class, default: 'Spree::TaxonBrandSelector'

# @!attribute [rw] taxon_image_style_default
#
# Defines which style to default to when style is not provided
Expand Down
46 changes: 46 additions & 0 deletions core/spec/models/spree/taxon_brand_selector_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Spree::TaxonBrandSelector, type: :model do
let(:taxonomy) { create(:taxonomy, name: "Brands") }
let(:taxon) { create(:taxon, taxonomy: taxonomy, name: "Brand A") }
let(:product) { create(:product, taxons: [taxon]) }

subject { described_class.new(product) }

describe "#call" do
context "when the product has a taxon under the 'Brands' taxonomy" do
it "returns the first taxon under 'Brands'" do
expect(subject.call).to eq(taxon)
end
end

context "when the product has multiple taxons under the 'Brands' taxonomy" do
let(:taxon_b) { create(:taxon, taxonomy: taxonomy, name: "Brand B") }
before { product.taxons << taxon_b }

it "returns the first taxon under 'Brands'" do
expect(subject.call).to eq(taxon)
end
end

context "when the product does not have a taxon under the 'Brands' taxonomy" do
let(:other_taxonomy) { create(:taxonomy, name: "Categories") }
let(:other_taxon) { create(:taxon, taxonomy: other_taxonomy, name: "Category A") }
let(:product) { create(:product, taxons: [other_taxon]) }

it "returns nil" do
expect(subject.call).to be_nil
end
end

context "when the product has no taxons" do
let(:product) { create(:product) }

it "returns nil" do
expect(subject.call).to be_nil
end
end
end
end
9 changes: 5 additions & 4 deletions sample/db/samples/taxonomies.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

store = Spree::Store.where(code: 'sample-store').first

taxonomies = [
{ name: "Categories" },
{ name: "Brand" }
{ name: "Categories", store: },
{ name: "Brands", store: }
]

taxonomies.each do |taxonomy_attrs|
Spree::Taxonomy.create!(taxonomy_attrs)
Spree::Taxonomy.find_or_create_by!(taxonomy_attrs)
end
33 changes: 33 additions & 0 deletions sample/db/samples/taxons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Spree::Sample.load_sample("products")

categories = Spree::Taxonomy.find_by!(name: "Categories")
brands = Spree::Taxonomy.find_by!(name: "Brands")

products = {
solidus_bottles: "Solidus Water Bottle",
Expand All @@ -29,6 +30,38 @@
name: "Categories",
taxonomy: categories,
},
{
name: "Brands",
taxonomy: brands
},
{
name: "Solidus",
taxonomy: brands,
parent: "Brands",
products: [
products[:solidus_bottles],
products[:solidus_tote],
products[:solidus_hoodie],
products[:solidus_mug_set],
products[:solidus_hat],
products[:solidus_sticker],
products[:solidus_notebook],
products[:solidus_tshirt],
products[:solidus_long_sleeve_tee],
products[:solidus_dark_tee],
products[:solidus_bottles],
products[:solidus_canvas_tote],
products[:solidus_cap]
]
},
{
name: "Solidus",
taxonomy: categories,
parent: "Brands",
products: [
products[:solidus_cap]
]
},
{
name: "Clothing",
taxonomy: categories,
Expand Down