Take action on your abandoned carts!
Add this line to your application's Gemfile:
gem 'solidus_abandoned_carts', github: 'solidusio-contrib/solidus_abandoned_carts'
Then run the following:
$ bundle install $ bundle exec rails g solidus_abandoned_carts:install
If you want to change the configuration, you can add the following to an initializer:
SolidusAbandonedCarts::Config.tap do |config| # Amount of time after which a cart is considered abandoned. config.abandoned_after = 24.hours # The states in which a cart is considered to be abandoned. config.abandoned_states = [:cart, :address, :delivery, :payment, :confirm] # Service object that will be called for abandoned carts. config.notifier_class = 'Spree::AbandonedCartNotifier' end
The last step in the installation process is to configure the
background job to run regularly. There are different ways to do this depending on the environment
your application is running in: Heroku Scheduler, cron etc.
If you're okay with the default behavior of sending an abandoned cart email, you can simply override
spree.abandoned_cart_subject translation key and the
view. The default notifier will take care of sending the email for you.
If, on the other hand, you want to use custom logic, keep reading!
You can define your own abandoned cart logic by changing the
parameter. Here's what an example notifier could look like, if you wanted to call an external API
instead of sending an email:
module AwesomeStore class AbandonedCartNotifier < Spree::AbandonedCartNotifier def call # Skip notification if this cart was already notified return if order.abandoned_cart_email_sent_at # Run your custom logic MyApiService.notify_abandoned_cart(order.email) # Mark this cart as notified order.touch :abandoned_cart_email_sent_at end end end
Run the following to automatically build a dummy app and run the tests:
$ bundle exec rake
Bug reports and pull requests are welcome on GitHub at https://github.com/solidusio-contrib/solidus_abandoned_carts.
The gem is available as open source under the terms of the MIT License.