spree-contrib / spree_multi_vendor

Spree marketplace extension. Create your own marketplace on top of Spree Commerce
https://spreecommerce.org/marketplace-ecommerce/
BSD 3-Clause "New" or "Revised" License
142 stars 135 forks source link

Vendor email of order confirmations is sent twice #162

Closed giugrilli closed 3 years ago

giugrilli commented 3 years ago

When placing an order, the confirmation email is sent twice to the vendor

giugrilli commented 3 years ago

it looks like these two handlers are called twice

base.state_machine.after_transition to: :complete, do: :generate_order_commissions base.state_machine.after_transition to: :complete, do: :send_notification_mails_to_vendors

any hint?

giugrilli commented 3 years ago

Basically when the server gets started, it looks like (at least in my solution) the .prepended method inside SpreeMultiVendor::Spree::OrderDecorator gets called twice.

The state_machine has no check of duplicate methods, therefore it injects two callbacks for each ":send_notification_mails_to_vendors" and ":generate_order_commissions"

This is the reason why, when the state goes to :complete both methods are called twice!

Temporarely, as workaround, I'm forking and doing this inside SpreeMultiVendor::Spree::OrderDecorator

unless base.state_machine.callbacks.values.any?{|callback| callback.any?{|cb| cb.instance_variable_get(:@methods).include?(:generate_order_commissions)}} base.state_machine.after_transition to: :complete, do: :generate_order_commissions end

hoshinotsuyoshi commented 3 years ago

This is also happening in my environment. 🙋

I was wondering how other people were dealing with it.

I'd like to know, will it happen in a production environment? Maybe it's hard to happen if config.cache_classes = true.

zolzaya commented 3 years ago

Same for me. Any news?