spree_google_merchant_feed 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.md +21 -0
- data/README.md +93 -0
- data/Rakefile +21 -0
- data/app/controllers/spree/google_merchant_controller.rb +16 -0
- data/app/views/spree/google_merchant/products.xml.builder +41 -0
- data/config/routes.rb +4 -0
- data/lib/generators/spree_google_merchant/install/install_generator.rb +20 -0
- data/lib/spree_google_merchant_feed/configuration.rb +13 -0
- data/lib/spree_google_merchant_feed/engine.rb +24 -0
- data/lib/spree_google_merchant_feed/factories.rb +6 -0
- data/lib/spree_google_merchant_feed/version.rb +7 -0
- data/lib/spree_google_merchant_feed.rb +5 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f6fedad81fac72b814ef49704e3238d7757f18278c14266fc5c6b82c7d632ed0
|
4
|
+
data.tar.gz: cd6fcb8295803a8a9be6bdf6dc1df4931598b1dd5c3d70bf4360ebd2c3098dec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bfd24f144298c5026dd5aabc9cebdcca60e817815aa2ecd2d333304a833e8095d64099a15ce0f41ce574fdda1cbf4c2516ada2a080b73648c3f9ed06169c3a0
|
7
|
+
data.tar.gz: 1ab4bf7f1d16cf8e8f8316c9ae97488f06266f7d2f4c95043e133f4597a8a20f1d31a83cdf75aaab3be0f89695e460aff840addf9e76f6d4a9253cf886bc5cef
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 OlympusOne
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# SpreeGoogleMerchantFeed
|
2
|
+
|
3
|
+
This is a Google Merchant extension for [Spree Commerce](https://spreecommerce.org), an open source e-commerce platform built with Ruby on Rails. Adds the ability to provide products listings to Google Merchant Center for Spree Commerce.
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/spree_google_merchant_feed)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Add this extension to your Gemfile with this line:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
bundle add spree_google_merchant_feed
|
13
|
+
```
|
14
|
+
|
15
|
+
2. Install the migrations:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
bundle exec rake railties:install:migrations FROM=spree_google_merchant_feed
|
19
|
+
```
|
20
|
+
|
21
|
+
3. Run the migrations:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
bundle exec rails db:migrate
|
25
|
+
```
|
26
|
+
|
27
|
+
4. Restart your server
|
28
|
+
|
29
|
+
If your server was running, restart it so that it can find the assets properly.
|
30
|
+
|
31
|
+
## Developing
|
32
|
+
|
33
|
+
1. Create a dummy app
|
34
|
+
|
35
|
+
```bash
|
36
|
+
bundle update
|
37
|
+
bundle exec rake test_app
|
38
|
+
```
|
39
|
+
|
40
|
+
2. Add your new code
|
41
|
+
3. Run tests
|
42
|
+
|
43
|
+
```bash
|
44
|
+
bundle exec rspec
|
45
|
+
```
|
46
|
+
|
47
|
+
When testing your applications integration with this extension you may use it's factories.
|
48
|
+
Simply add this require statement to your spec_helper:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'spree_google_merchant_feed/factories'
|
52
|
+
```
|
53
|
+
|
54
|
+
## Releasing a new version
|
55
|
+
|
56
|
+
```shell
|
57
|
+
bundle exec gem bump -p -t
|
58
|
+
bundle exec gem release
|
59
|
+
```
|
60
|
+
|
61
|
+
For more options please see [gem-release README](https://github.com/svenfuchs/gem-release)
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
If you'd like to contribute, please take a look at the
|
66
|
+
[instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
|
67
|
+
pull request.
|
68
|
+
|
69
|
+
Copyright (c) 2025 OlympusOne, released under the MIT
|
70
|
+
|
71
|
+
## Google Merchant Center Integration
|
72
|
+
|
73
|
+
To use your Google Merchant endpoint as a data source in Google Merchant Center:
|
74
|
+
|
75
|
+
1. **Deploy your endpoint**
|
76
|
+
Ensure your authentication and data endpoints are publicly accessible and return the required data format (e.g., XML, CSV, or JSON).
|
77
|
+
For this extension, your endpoint will typically be:
|
78
|
+
`https://yoursite.com/google_merchant/products.xml`
|
79
|
+
|
80
|
+
2. **Copy your endpoint URL**
|
81
|
+
This is the URL that Google Merchant Center will fetch data from.
|
82
|
+
|
83
|
+
3. **Add as a data feed in Google Merchant Center**
|
84
|
+
- Go to [Google Merchant Center](https://merchants.google.com/).
|
85
|
+
- In the header, click **Settings & tools**.
|
86
|
+
- Select **Data sources**.
|
87
|
+
- Click **Add product source**.
|
88
|
+
- Choose **Add products from a file**.
|
89
|
+
- Enter your endpoint URL (e.g., `https://yoursite.com/google_merchant/products.xml`) as the feed source.
|
90
|
+
- Set fetch frequency and credentials if authentication is required.
|
91
|
+
|
92
|
+
4. **Test and verify**
|
93
|
+
After saving, Google will attempt to fetch your data. Check for errors and ensure your feed is processed correctly.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'spree/testing_support/extension_rake'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
|
9
|
+
task :default do
|
10
|
+
if Dir['spec/dummy'].empty?
|
11
|
+
Rake::Task[:test_app].invoke
|
12
|
+
Dir.chdir('../../')
|
13
|
+
end
|
14
|
+
Rake::Task[:spec].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generates a dummy app for testing'
|
18
|
+
task :test_app do
|
19
|
+
ENV['LIB_NAME'] = 'spree_google_merchant_feed'
|
20
|
+
Rake::Task['extension:test_app'].invoke
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
class GoogleMerchantController < StoreController
|
3
|
+
include BaseHelper
|
4
|
+
include StorefrontHelper
|
5
|
+
|
6
|
+
def products
|
7
|
+
respond_to do |format|
|
8
|
+
format.xml
|
9
|
+
format.gzip do
|
10
|
+
gz_xml = ActiveSupport::Gzip.compress(render_to_string(template: 'spree/google_merchant/products', formats: [:xml]))
|
11
|
+
send_data(gz_xml, filename: 'sitemap.xml.gz', type: 'application/x-gzip', disposition: 'inline')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
xml.instruct! :xml, version: "1.0", encoding: "UTF-8"
|
2
|
+
xml.rss version: "2.0", "xmlns:g" => "http://base.google.com/ns/1.0" do
|
3
|
+
xml.channel do
|
4
|
+
cache current_store do
|
5
|
+
xml.title current_store.name
|
6
|
+
xml.link root_url
|
7
|
+
xml.description current_store.meta_description
|
8
|
+
end
|
9
|
+
|
10
|
+
cache [storefront_products_scope, current_currency] do
|
11
|
+
storefront_products_scope.find_each do |product|
|
12
|
+
xml.item do
|
13
|
+
# Basic product data
|
14
|
+
xml.tag! "g:id", product.id
|
15
|
+
xml.tag! "g:title", product.name.truncate(150)
|
16
|
+
xml.tag! "g:description", product.storefront_description&.truncate(5000)
|
17
|
+
xml.tag! "g:link", spree_storefront_resource_url(product)
|
18
|
+
if product.default_image.present?
|
19
|
+
xml.tag! "g:image_link", spree_image_url(product.featured_image, width: 500, height: 500)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Price and availability
|
23
|
+
xml.tag! "g:availability", product.in_stock? ? "in_stock" : "out_of_stock"
|
24
|
+
xml.tag! "g:availability_date", product.available_on.strftime("%Y-%m-%dT%H:%M%z") if product.available_on?
|
25
|
+
xml.tag! "g:expiration_date", product.discontinue_on.strftime("%Y-%m-%dT%H:%M%z") if product.discontinue_on?
|
26
|
+
xml.tag! "g:price", format('%.2f', product.display_amount.to_d) + " " + current_currency
|
27
|
+
|
28
|
+
# Product category
|
29
|
+
xml.tag! "g:product_type", product_breadcrumb_taxons(product).map(&:name).join(' > ')
|
30
|
+
|
31
|
+
# Product identifiers
|
32
|
+
xml.tag! "g:brand", product.brand.name if product.brand.present?
|
33
|
+
xml.tag! "g:gtin", product.sku
|
34
|
+
|
35
|
+
# Detailed product description
|
36
|
+
xml.tag! "g:product_weight", "#{product.weight}#{product.weight_unit}" if product.weight.present?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module SpreeGoogleMerchantFeed
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :migrate, type: :boolean, default: true
|
5
|
+
|
6
|
+
def add_migrations
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_google_merchant_feed'
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_migrations
|
11
|
+
run_migrations = options[:migrate] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
12
|
+
if run_migrations
|
13
|
+
run 'bin/rails db:migrate'
|
14
|
+
else
|
15
|
+
puts 'Skipping rails db:migrate, don\'t forget to run it!'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SpreeGoogleMerchantFeed
|
2
|
+
class Configuration < Spree::Preferences::Configuration
|
3
|
+
|
4
|
+
# Some example preferences are shown below, for more information visit:
|
5
|
+
# https://docs.spreecommerce.org/developer/contributing/creating-an-extension
|
6
|
+
|
7
|
+
# preference :enabled, :boolean, default: true
|
8
|
+
# preference :dark_chocolate, :boolean, default: true
|
9
|
+
# preference :color, :string, default: 'Red'
|
10
|
+
# preference :favorite_number, :integer
|
11
|
+
# preference :supported_locales, :array, default: [:en]
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SpreeGoogleMerchantFeed
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_google_merchant_feed'
|
6
|
+
|
7
|
+
# use rspec for tests
|
8
|
+
config.generators do |g|
|
9
|
+
g.test_framework :rspec
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer 'spree_google_merchant_feed.environment', before: :load_config_initializers do |_app|
|
13
|
+
SpreeGoogleMerchantFeed::Config = SpreeGoogleMerchantFeed::Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.activate
|
17
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
18
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config.to_prepare(&method(:activate).to_proc)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
|
3
|
+
#
|
4
|
+
# Example adding this to your spec_helper will load these Factories for use:
|
5
|
+
# require 'spree_google_merchant_feed/factories'
|
6
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_google_merchant_feed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OlympusOne
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: spree
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 5.0.4
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 5.0.4
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: spree_storefront
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.0.4
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 5.0.4
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: spree_admin
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 5.0.4
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 5.0.4
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: spree_extension
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: spree_dev_tools
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
description: Adds the ability to provide products listings to Google Merchant Center
|
83
|
+
for Spree Commerce.
|
84
|
+
email: info@olympusone.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- LICENSE.md
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- app/controllers/spree/google_merchant_controller.rb
|
93
|
+
- app/views/spree/google_merchant/products.xml.builder
|
94
|
+
- config/routes.rb
|
95
|
+
- lib/generators/spree_google_merchant/install/install_generator.rb
|
96
|
+
- lib/spree_google_merchant_feed.rb
|
97
|
+
- lib/spree_google_merchant_feed/configuration.rb
|
98
|
+
- lib/spree_google_merchant_feed/engine.rb
|
99
|
+
- lib/spree_google_merchant_feed/factories.rb
|
100
|
+
- lib/spree_google_merchant_feed/version.rb
|
101
|
+
homepage: https://github.com/olympusone/spree_google_merchant_feed
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata:
|
105
|
+
bug_tracker_uri: https://github.com/olympusone/spree_google_merchant_feed/issues
|
106
|
+
changelog_uri: https://github.com/olympusone/spree_google_merchant_feed/releases/tag/v1.0.0
|
107
|
+
documentation_uri: https://github.com/olympusone/spree_google_merchant_feed
|
108
|
+
homepage_uri: https://github.com/olympusone/spree_google_merchant_feed
|
109
|
+
source_code_uri: https://github.com/olympusone/spree_google_merchant_feed/tree/v1.0.0
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements:
|
124
|
+
- none
|
125
|
+
rubygems_version: 3.6.9
|
126
|
+
specification_version: 4
|
127
|
+
summary: Spree Commerce Google Merchant Extension
|
128
|
+
test_files: []
|