Hot questions for Using Spree in email

Question:

I have implemented phone verification in my Spree Application.

So the user have to verify phone number first before placing an order, but once the user places the order as guest, the next time his email is stored and it goes straight to /checkout/address without going to /checkout/registration first.

Where can I modify this code so that guest checkout always goes to /checkout/registration first

Edit:

I checked the checkout_controller and I think I can edit the functionality using checkout#edit action.

But I am unable to find it in the gem files.


Answer:

You could create a decorator for the checkout_controller such as app/controllers/spree/checkout_controller_decorator.rb and change this method to something like this below(code for the decorator file):

module Spree
  CheckoutController.class_eval do
    def before_address
      # if the user has a default address, a callback takes care of setting
      # that; but if he doesn't, we need to build an empty one here
      if current_user.phone_number.present?
        @order.bill_address ||= Address.build_default
        @order.ship_address ||= Address.build_default if @order.checkout_steps.include?('delivery')
      else
        # some error telling that you need to fill the phone number
        redirect_to registration_path
      end
    end
  end
end

be aware that after the user is redirected you would have to deal with the redirecting back to the checkout page

You could change something on the User model also to ensure that the user has a phone number, it might conflict with the guest feature though.

Question:

I'm doing a spree 3.0 installation (ROR) and trying to use facebook oauth for authentication, but the fields sent back after a successful oauth, do NOT contain the email, which is critical to our application. here is the return from the facebook successful authentication.

#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=1442435073 token="CAAJa3dyBtY4BAJ2ZB3vrenNOFJKSMtvxYO09ZCJtEsmKNBs90q9nmUF4LIBr06xCizEAR3lwht3BwycLkVFdjlvkS1AUGpYODQHu25K0uO8XLDDPkTO0E9oPdIILsbTTOuIT7qcl8nJ6501z0dCXEi9hVNwPYqZBbGqiEhyoLyVgCNnDWdPRLBRF5xSovJdhjjCf6XC8ulJ4NnKBfM8"> extra=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash id="101230990227589" name="David Alajbbjfdjgij Bowersstein">> info=#<OmniAuth::AuthHash::InfoHash image="http://graph.facebook.com/101230990227589/picture" name="David Alajbbjfdjgij Bowersstein"> provider="facebook" uid="101230990227589"

as you can see, all i get back is the user name and their ID. Is there some setting on my facebook app that i need to check in order to get the email back? or is there a different way i'm supposed to do Oauth? I'm just using the spree_social gem which does this all internally so i've actually not written any code around this.

here is the code. copied out of the gem, i just added the logging lines to see what was coming back from facebook.

    def #{provider}
      authentication = Spree::UserAuthentication.find_by_provider_and_uid(auth_hash['provider'], auth_hash['uid'])

      if authentication.present? and authentication.try(:user).present?
        flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider'])
        sign_in_and_redirect :spree_user, authentication.user
      elsif spree_current_user
        spree_current_user.apply_omniauth(auth_hash)
        spree_current_user.save!
        flash[:notice] = I18n.t('devise.sessions.signed_in')
        redirect_back_or_default(account_url)
      else
        user = Spree::User.find_by_email(auth_hash['info']['email']) || Spree::User.new
        user.apply_omniauth(auth_hash)
        Rails.logger.debug("THE AUTO HASH")
        Rails.logger.debug(auth_hash.inspect)
        if user.save
          flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider'])
          sign_in_and_redirect :spree_user, user
        else
          session[:omniauth] = auth_hash.except('extra')
          flash[:notice] = Spree.t(:one_more_step, kind: auth_hash['provider'].capitalize)
          redirect_to new_spree_user_registration_url
          return
        end
      end

      if current_order
        user = spree_current_user || authentication.user
        current_order.associate_user!(user)
        session[:guest_token] = nil
      end
    end

Answer:

Facebook just released latest APIv2.4 that does not return email by default but we need to explicitly specify what fields to use.

Introducing Graph API v2.4

Now, on the very latest omniauth-facebook(possibly 2.1.0), "email" fields are specified by default and just works.

Fix default info_fields to 'name,email' #209

Or, you can just specify like

options['info_fields']='id,email,gender,link,locale,name,timezone,updated_time,verified';

Question:

Hello I have included given gem in my gemfile:

gem 'spree_mail_settings', github: 'spree-contrib/spree_mail_settings', branch: '3-0-stable'

and further done settings in spree-admin in configuration < Mail method Settings

When I place order it gives me error

2016-05-10T07:16:32.164733+00:00 app[web.1]: 2016-05-10T07:16:32.164734+00:00 app[web.1]: [ActiveJob] [ActionMailer::DeliveryJob] [9526835c-d5e7-4434-b716-a98b68b75da1] Performed ActionMailer::DeliveryJob from Inline(mailers) in 471.29ms 2016-05-10T07:16:32.164735+00:00 app[web.1]: Completed 500 Internal Server Error in 1395ms (ActiveRecord: 179.9ms) 2016-05-10T07:16:32.168574+00:00 app[web.1]: 2016-05-10T07:16:32.168583+00:00 app[web.1]: SocketError (getaddrinfo: Name or service not known): 2016-05-10T07:16:32.168583+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/net/smtp.rb:541:in initialize' 2016-05-10T07:16:32.168584+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/net/smtp.rb:541:inopen' 2016-05-10T07:16:32.168584+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/net/smtp.rb:541:in tcp_socket' 2016-05-10T07:16:32.168585+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/net/smtp.rb:551:inblock in do_start' 2016-05-10T07:16:32.168585+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/timeout.rb:88:in block in timeout' 2016-05-10T07:16:32.168586+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/timeout.rb:98:incall' 2016-05-10T07:16:32.168586+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/timeout.rb:98:in timeout' 2016-05-10T07:16:32.168587+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/net/smtp.rb:550:indo_start' 2016-05-10T07:16:32.168587+00:00 app[web.1]: vendor/ruby-2.2.4/lib/ruby/2.2.0/net/smtp.rb:520:in start' 2016-05-10T07:16:32.168587+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp.rb:113:indeliver!' 2016-05-10T07:16:32.168588+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/bundler/gems/spree_mail_settings-d416a1e35589/lib/spree/core/mail_method.rb:8:in `deliver!' 2016-05-10T07:16:32.168588+00:00 app[web.1]:

Please guide me why I am facing this issue and what settings are required.


Answer:

Do settings in the admin section like this;

Question:

So I know I can install the mailer gem from here:

https://guides.spreecommerce.com/user/configuring_mail_methods.html

But it clearly says that generic action mailer settings are more favourable at the top of the page.

I have installed postmark which is sending emails fine in an extension I built. However Spree does not appear to be sending emails when I create an order for a customer. How can I turn these transactional emails on without the Spree mailer gem, as I want to use postmark on its own.

Also where the hell is the listed email section from the documentation?

https://guides.spreecommerce.com/developer/deployment_tips.html

Thanks for any help!


Answer:

You can set up emails by adding the gem at https://github.com/spree-contrib/spree_mail_settings

Not sure if the message at the top of the page has been changed since this question was posted but it says to use that gem now.

Add gem 'spree_mail_settings', github: 'spree-contrib/spree_mail_settings' to you gemfile and you will get a new page in the admin settings for setting up your email

Question:

I've got Spree 3.0, rails 4.2.1, nginx, unicorn. Here is spree-related gem list

gem 'spree', github:'spree/spree', branch: '3-0-stable'
gem 'spree_i18n', github: 'spree-contrib/spree_i18n', branch: '3-0-stable'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '3-0-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
gem 'spree_static_content', github: 'spree/spree_static_content', branch: '3-0-stable'
gem "spree_product_zoom", git: "git://github.com/spree/spree_product_zoom.git", branch: '3-0-stable'

Trying to set up ActionMailer via config/environments/production.rb with YandexMail or GoogleMail. Here's about Yandex.Mail

config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.yandex.ru",
port: 465,
domain: 'mydomain',
user_name: 'myemail',
password: 'mypass',
authentication: "plain",
enable_starttls_auto: true }

And emails are not sent (during checkout/sending email order again). There are no error logs in production, however it's the "upstream timed out" error. And increasing proxy timeout didn't help. In my production logs it shows that's Ok

D, [2015-05-17T18:52:50.964229 #4836] DEBUG -- : [ActiveJob] [ActionMailer::DeliveryJob] [54f73692-30bc-4354-9a6f-bb29fe6d54e2]
Spree::OrderMailer#confirm_email: processed outbound mail in 1908.9ms

Tried to use mailcatcher with spree_mail_settings and mailcatcher with Action Mailer set up - doesn't work. Mailcatcher doesn't show any emails no matter mails are sent (both via spree admin when I press resend email or checkot and via console script).

But anyway, no matter what I do (change, fix) emails are not sent! Don't know what to do else, guys. Please, help me!


Answer:

Found the issue bymyself. Got to turn on stl, ttl

config.action_mailer.smtp_settings = {
address: "smtp.yandex.ru",
port: 465,
domain: 'mydomain',
user_name: 'myemail',
password: 'mypass',
authentication: :login,
ssl: true,
enable_starttls_auto: true,
tls: true }

I guess tutorials I saw before are old version Rails and there were no tls support in the box.