Skip to content
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

feat(GoogleMerchant): Allow to load products via scope. #26

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Jul 9, 2024

Currently all products are loaded from the database during application boot, because we yield the block when we
register a feed
.

This is far from ideal! Especially if you want to boot the app to prepare specs or build assets on heroku or in a docker container.

I think we can agree that accessing the database during app boot is generally a bad idea.

Current fix

One could prevent accessing the database by using this little hack

feed.generator = ->(output) {
  SolidusFeeds::Generators::GoogleMerchant.new(
    Spree::Product.available,
    host: Spree::Store.default.url
  ).call(output)
}

but this does not feel quite right.

Proposed fix

Instead let's allow to pass a product_scope instead of products. By using available as default scope we do what most stores want anyway.

So, it now gets as simple as

SolidusFeeds::Generators::GoogleMerchant.new(
  host: "www.example.com", # You should pass this instead of using
  # the Spree::Store.current, which as well accesses the database
)

or pass your custom scope

SolidusFeeds::Generators::GoogleMerchant.new(
  product_scope: :solidus_mugs,
  host: "www.example.com"
)

@tvdeyen tvdeyen requested a review from a team July 9, 2024 16:38
tvdeyen added 2 commits July 9, 2024 18:40
Currently all products are loaded from the database during
application boot. This is not ideal, especially if you
want to boot the app to prepare specs or build assets on
heroku or in a docker container. Let's agree that accessing the
database during app boot is generally a bad idea.

You can now pass a `product_scope` instead of passing products.
Default scope is `available` (which is what most stores want anyway).

So, it now gets as simple as

    SolidusFeeds::Generators::GoogleMerchant.new(
      host: "www.example.com", # You should pass this instead of using
      # the Spree::Store.current, which as well accesses the database
    )

or

    SolidusFeeds::Generators::GoogleMerchant.new(
      product_scope: :solidus_mugs,
      host: "www.example.com"
    )
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tvdeyen tvdeyen merged commit bb091ae into master Jul 9, 2024
5 checks passed
@tvdeyen tvdeyen deleted the product-scope branch July 9, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants