Switch Currency According to customer country.

I am making a plugin which ensure currency according to country when customer logged in. Currently, I am facing an issue, I have register a subscriber and try to find “CUSTOMER_LOGIN_EVENT” but when I logged in, My plugin has not been able to trigger that event.

Can anybuddy help me on this.

 

Hello,
did you ensured that your plugin is installed and activated correctly? Try also to clear the cache after you activated your plugin. The code looks good for me. 

Best regards from Schöppingen

cool Michael Telgmann

Hello Michael,

Git Hub link

https://github.com/shakil2nd/switch-currency-plugin

Core Idea of Plugin

I need to make that plugin to switch currency according to the country when customer logged in to his/her  account. if customer logged in with the his/her default country USA so customer see defult currency dollar and if customer logged in using his/her default country Germany so customer see Euro as a default currency.

What I did

I selected to use ‘CUSTOMER_LOGIN_EVENT’ but when I logged in to my account it did not trigger that event so my function which I added on subscrivber not working. 

Kindly, also help me out how to updated and selected default currency which is on the top header section using that subscriber event when customer logged in.

Thanks,

Shakeel

 

 

Hello Shakeel,

the event name you subscribed to, was wrong. Also the typehint on your callback method. Here is the fix:

namespace Bc\BrandCrockCurrencySwitch\Subscriber;

use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MySubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return[
            CustomerLoginEvent::class => 'onAccountLoaded'
        ];
    }

    public function onAccountLoaded(CustomerLoginEvent $event)
    {
        echo 'MySubscriber.php Zeile: 21';
        dd($event);

        // ...
    }
}

In most cases we only dispatch the event object through the Symfony EventDispatcher, therefore you have to subscribe to the class name of the event. 

Best regards from Schöppingen

cool Michael Telgmann

1 „Gefällt mir“

Hi,

Need help to resolve this task.

I am trying to get address update event (When any one change his/her addresses). How can I get that event on subscriber? 

Please Help me out on this

Example (just for assumption i gave this example):

public static function getSubscribedEvents(): array {

return[CustomerAddressUpdateEvent::class => 'onCustomerAdressUpdated'];

}

Thanks,

Shakeel