-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add organization structured data fields to Spree stores for SEO
- Added new fields to spree_stores to support organization structured data for SEO. - Fields include legal_name, contact_email, contact_phone, description, vat_id, tax_id, address1, address2, city, zipcode, state_name, country_id, and state_id. - This update enhances SEO by allowing structured data markup for better search engine visibility.
- Loading branch information
1 parent
7205ff0
commit 4d128b4
Showing
8 changed files
with
264 additions
and
10 deletions.
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
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 |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
|
||
module Spree::Api | ||
describe 'Stores', type: :request do | ||
let(:country) { create :country, states_required: true } | ||
let(:country_without_states) { create :country, states_required: false } | ||
let(:state) { create :state, name: 'maryland', abbr: 'md', country: } | ||
let!(:base_attributes) { Spree::Api::Config.store_attributes } | ||
|
||
let!(:store) do | ||
create(:store, name: "My Spree Store", url: "spreestore.example.com") | ||
end | ||
|
@@ -22,6 +27,58 @@ module Spree::Api | |
default: false) | ||
end | ||
|
||
describe "store state validation" do | ||
context "when store country has states_required" do | ||
it "is invalid without a state" do | ||
store = Spree::Store.new(name: "Test Store", country: country, state: nil, url: "spreestore.example.com", | ||
mail_from_address: "[email protected]", code: "test-store",) | ||
expect(store).not_to be_valid | ||
expect(store.errors[:state]).to include("can't be blank") | ||
end | ||
|
||
it "is valid with a state" do | ||
store = Spree::Store.new(name: "Test Store", country: country, state: state, url: "spreestore.example.com", | ||
mail_from_address: "[email protected]", code: "test-store",) | ||
expect(store).to be_valid | ||
end | ||
end | ||
|
||
context "when store country has no states" do | ||
it "is valid without a state" do | ||
store = Spree::Store.new(name: "Test Store", country: country_without_states, state: nil, url: "spreestore.example.com", | ||
mail_from_address: "[email protected]", code: "test-store",) | ||
expect(store).to be_valid | ||
end | ||
end | ||
|
||
it "is valid without an address and without country/state" do | ||
expect(store).to be_valid | ||
end | ||
|
||
it "is valid with only correct country and state" do | ||
store = Spree::Store.create!( | ||
name: "Test Store", | ||
url: "spreestore.example.com", | ||
mail_from_address: "spreestore.example.com", | ||
code: "test-store", | ||
address1: "123 Main St", | ||
city: "New York", | ||
zipcode: "10001", | ||
state: state, | ||
country: country, | ||
) | ||
expect(store).to be_valid | ||
end | ||
end | ||
|
||
describe "#index" do | ||
it "ensures the API store attributes match the expected attributes" do | ||
get spree.api_stores_path | ||
first_store = json_response["stores"].first | ||
expect(first_store.keys).to include(*base_attributes.map(&:to_s)) | ||
end | ||
end | ||
|
||
it "can list the available stores" do | ||
get spree.api_stores_path | ||
expect(json_response["stores"]).to match_array([ | ||
|
@@ -37,7 +94,20 @@ module Spree::Api | |
"default_currency" => nil, | ||
"code" => store.code, | ||
"default" => true, | ||
"available_locales" => ["en"] | ||
"available_locales" => ["en"], | ||
"legal_name" => nil, | ||
"contact_email" => nil, | ||
"contact_phone" => nil, | ||
"description" => nil, | ||
"tax_id" => nil, | ||
"vat_id" => nil, | ||
"address1" => nil, | ||
"address2" => nil, | ||
"city" => nil, | ||
"zipcode" => nil, | ||
"country_id" => nil, | ||
"state_id" => nil, | ||
"state_name" => nil | ||
}, | ||
{ | ||
"id" => non_default_store.id, | ||
|
@@ -51,7 +121,20 @@ module Spree::Api | |
"default_currency" => nil, | ||
"code" => non_default_store.code, | ||
"default" => false, | ||
"available_locales" => ["en"] | ||
"available_locales" => ["en"], | ||
"legal_name" => nil, | ||
"contact_email" => nil, | ||
"contact_phone" => nil, | ||
"description" => nil, | ||
"tax_id" => nil, | ||
"vat_id" => nil, | ||
"address1" => nil, | ||
"address2" => nil, | ||
"city" => nil, | ||
"zipcode" => nil, | ||
"country_id" => nil, | ||
"state_id" => nil, | ||
"state_name" => nil | ||
} | ||
]) | ||
end | ||
|
@@ -70,7 +153,20 @@ module Spree::Api | |
"default_currency" => nil, | ||
"code" => store.code, | ||
"default" => true, | ||
"available_locales" => ["en"] | ||
"available_locales" => ["en"], | ||
"legal_name" => nil, | ||
"contact_email" => nil, | ||
"contact_phone" => nil, | ||
"description" => nil, | ||
"tax_id" => nil, | ||
"vat_id" => nil, | ||
"address1" => nil, | ||
"address2" => nil, | ||
"city" => nil, | ||
"zipcode" => nil, | ||
"country_id" => nil, | ||
"state_id" => nil, | ||
"state_name" => nil | ||
) | ||
end | ||
|
||
|
@@ -79,7 +175,14 @@ module Spree::Api | |
code: "spree123", | ||
name: "Hack0rz", | ||
url: "spree123.example.com", | ||
mail_from_address: "[email protected]" | ||
mail_from_address: "[email protected]", | ||
legal_name: 'ABC Corp', | ||
address1: "123 Main St", | ||
city: 'San Francisco', | ||
country_id: country.id, | ||
state_id: state.id, | ||
phone: "123-456-7890", | ||
zipcode: "12345" | ||
} | ||
post spree.api_stores_path, params: { store: store_hash } | ||
expect(response.status).to eq(201) | ||
|
@@ -89,13 +192,34 @@ module Spree::Api | |
store_hash = { | ||
url: "spree123.example.com", | ||
mail_from_address: "[email protected]", | ||
bcc_email: "[email protected]" | ||
bcc_email: "[email protected]", | ||
legal_name: 'XYZ Corp', | ||
description: "Leading provider of high-quality tech accessories, offering the latest gadgets, peripherals, and electronics to enhance your digital lifestyle.", | ||
tax_id: "TX-987654321", | ||
vat_id: "VAT-123456789", | ||
address1: "123 Innovation Drive", | ||
address2: "Suite 456", | ||
city: "New York", | ||
country_id: country.id, | ||
state_id: state.id, | ||
contact_phone: "123-456-7888", | ||
zipcode: "10001" | ||
} | ||
put spree.api_store_path(store), params: { store: store_hash } | ||
expect(response.status).to eq(200) | ||
expect(store.reload.url).to eql "spree123.example.com" | ||
expect(store.reload.mail_from_address).to eql "[email protected]" | ||
expect(store.reload.bcc_email).to eql "[email protected]" | ||
expect(store.reload.legal_name).to eql "XYZ Corp" | ||
expect(store.reload.tax_id).to eql "TX-987654321" | ||
expect(store.reload.vat_id).to eql "VAT-123456789" | ||
expect(store.reload.address1).to eql "123 Innovation Drive" | ||
expect(store.reload.address2).to eql "Suite 456" | ||
expect(store.reload.city).to eql "New York" | ||
expect(store.reload.country_id).to eql country.id | ||
expect(store.reload.state_id).to eql state.id | ||
expect(store.reload.contact_phone).to eql "123-456-7888" | ||
expect(store.reload.zipcode).to eql "10001" | ||
end | ||
|
||
context "deleting a store" do | ||
|
65 changes: 65 additions & 0 deletions
65
backend/app/views/spree/admin/stores/_address_form.html.erb
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,65 @@ | ||
|
||
<% s_or_b = type.chars.first %> | ||
<hr> | ||
|
||
<div class="row" id="<%= type %>" data-hook="address_fields"> | ||
<div class="col-12 col-md-6"> | ||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :legal_name %> | ||
<%= f.text_field :legal_name, class: 'fullwidth' %> | ||
</div> | ||
|
||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :address1 %> | ||
<%= f.text_field :address1, class: 'fullwidth' %> | ||
</div> | ||
|
||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :address2 %> | ||
<%= f.text_field :address2, class: 'fullwidth' %> | ||
</div> | ||
|
||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :contact_phone %> | ||
<%= f.phone_field :contact_phone, class: 'fullwidth' %> | ||
</div> | ||
</div> | ||
|
||
<div class="col-12 col-md-6"> | ||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :city %> | ||
<%= f.text_field :city, class: 'fullwidth' %> | ||
</div> | ||
|
||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :zipcode %> | ||
<%= f.text_field :zipcode, class: 'fullwidth' %> | ||
</div> | ||
|
||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :country_id, Spree::Country.model_name.human %> | ||
<span id="<%= s_or_b %>country"> | ||
<%= f.collection_select :country_id, available_countries, :id, :name, { include_blank: true }, {class: 'custom-select fullwidth js-country_id'} %> | ||
</span> | ||
</div> | ||
|
||
<div class="field <%= "#{type}-row" %>"> | ||
<%= f.label :state_id, Spree::State.model_name.human %> | ||
<span id="<%= s_or_b %>state"> | ||
<%= f.hidden_field :state_name, value: nil %> | ||
<% states = f.object.country.try(:states).nil? ? [] : f.object.country.states %> | ||
<%= f.text_field :state_name, | ||
style: "display: #{states.empty? ? 'block' : 'none' };", | ||
disabled: !states.empty?, class: 'fullwidth state_name js-state_name' %> | ||
<%= f.hidden_field :state_id, value: nil %> | ||
<%= f.collection_select :state_id, | ||
states.sort, | ||
:id, :name, | ||
{ include_blank: true }, | ||
{ class: 'custom-select fullwidth js-state_id', | ||
style: "display: #{states.empty? ? 'none' : 'block' };", | ||
disabled: states.empty? } %> | ||
</span> | ||
</div> | ||
</div> | ||
</div> |
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
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
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
19 changes: 19 additions & 0 deletions
19
core/db/migrate/20250202173007_add_store_attributes_to_spree_stores.rb
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,19 @@ | ||
class AddStoreAttributesToSpreeStores < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :spree_stores, :legal_name, :string | ||
add_column :spree_stores, :contact_email, :string | ||
add_column :spree_stores, :description, :text | ||
add_column :spree_stores, :vat_id, :string | ||
add_column :spree_stores, :tax_id, :string | ||
add_column :spree_stores, :address1, :string | ||
add_column :spree_stores, :address2, :string | ||
add_column :spree_stores, :city, :string | ||
add_column :spree_stores, :zipcode, :string | ||
add_column :spree_stores, :state_name, :string | ||
add_column :spree_stores, :contact_phone, :string | ||
add_column :spree_stores, :country_id, :integer | ||
add_column :spree_stores, :state_id, :integer | ||
add_index :spree_stores, :country_id | ||
add_index :spree_stores, :state_id | ||
end | ||
end |
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