shakil2ndshakil2nd MemberComments: 2 Received thanks: 0 Member since: July 31

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.

imageimage

 

image

1 Answer

  • Michael TelgmannMichael Telgmann ModeratorComments: 1073 Received thanks: 300 edited July 31 Member since: June 2014

    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

    Quote
    Accepted Answer
    Thanked by 1shakil2nd
  • Accepted Answer

Answers

  • Michael TelgmannMichael Telgmann ModeratorComments: 1073 Received thanks: 300 Member since: June 2014

    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

  • shakil2ndshakil2nd MemberComments: 2 Received thanks: 0 Member since: July 31

    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

     

     

  • Michael TelgmannMichael Telgmann ModeratorComments: 1073 Received thanks: 300 edited July 31 Member since: June 2014

    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

    Quote
    Accepted Answer
    Thanked by 1shakil2nd
  • shakil2ndshakil2nd MemberComments: 2 Received thanks: 0 edited August 5 Member since: July 31

    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' ];
    
    }

    image

    Thanks,

    Shakeel

Sign In or Register to comment.