Call external API once the stock level updated

I am going to create a plugin. This plugin will call external API once the stock level updated (i.e. decrease qty). My plugin file contains the following code. I can’t find var_dump or expected output not display. :

scheduleClearCache(ActivateContext::CACHE_LIST_DEFAULT);
    }
    public function deactivate(DeactivateContext $context)
    {
        $context->scheduleClearCache(DeactivateContext::CACHE_LIST_DEFAULT);
    }
    public function uninstall()
    {
        return true;
    }
    public function install()
    {
        # this event will be used after saving the order in the database
        return [
            'Shopware_Modules_Order_SaveOrder_ProcessDetails' => 'OnOrder_SaveOrderProcessDetails',
        ];
      
    }

    public function onOrder_SaveOrderProcessDetails(Enlight_Event_EventArgs $args)
	{
       // get SKU of Order items

       // Write here a qty you want to update on external 
       //CURL code will place here
	}
  
}

?>

 

Hello,

other than in Shopware 5 in Shopware 6 the base classes of a plugin are no longer an event subscriber automatically. You will have to add an own subscriber class and add it to your services.xml file, if you want to subscribe to an event. Please also refer to our documentation for further reads https://docs.shopware.com/en/shopware-platform-dev-en/internals/plugins/plugin-quick-start?category=shopware-platform-dev-en/internals/plugins

Best regards from Schöppingen

 Michael Telgmann

I have Shopware version 5.X

[@Michael Telgmann](http://forum.shopware.com/profile/17553/Michael Telgmann „Michael Telgmann“)‍  I have implemented as per plugin guide

I will move the thread then…

Have a look at our Shopware 5 documentation please Developing plugins

[@Michael Telgmann](http://forum.shopware.com/profile/17553/Michael Telgmann „Michael Telgmann“)‍ I have created a plugin as per above document. Plugin created and active. Show in the backend as expected. I have tried lots of way but can’t get ride out this.

 

I can’t get an event which allow me call extenal API. 

Main Plugin File 

scheduleClearCache(ActivateContext::CACHE_LIST_DEFAULT);
    }
    public function deactivate(DeactivateContext $context)
    {
        $context->scheduleClearCache(DeactivateContext::CACHE_LIST_DEFAULT);
    }
    public function uninstall()
    {
        return true;
    }
    public function install()
    {
        # this event will be used after saving the order in the database
        return [
            'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout_Finish' => 'OnOrder_SaveOrderProcessDetails'
           
        ];
      
    }

    public function onOrder_SaveOrderProcessDetails(Enlight_Event_EventArgs $args)
	{
        $basketContent = $args->getDetails();     
	    $order = $args->getSubject();
	    $orderNumber = $order->sOrderNumber;

	    var_dump ($basketContent);
	}
  
}

?>

 

Config File : 

 

            Korona Pos
             API Token
             API Token
            API Tken                        
            An API token provided by Support.

 

Have a look here: Shopware events
you have to implement the getSubscribedEvents method

Best regards from Schöppingen

cool Michael Telgmann

 public static function getSubscribedEvents(){
        return [
            'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout_Finish' => 'OnOrder_SaveOrderProcessDetails'
           
        ];

    }

You mean this??

[@Michael Telgmann](http://forum.shopware.com/profile/17553/Michael Telgmann „Michael Telgmann“)‍  Most recent as per document : 

 

scheduleClearCache(ActivateContext::CACHE_LIST_DEFAULT);
    }
    public function deactivate(DeactivateContext $context)
    {
        $context->scheduleClearCache(DeactivateContext::CACHE_LIST_DEFAULT);
    }
  
    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout_Finish' => 'OnOrder_SaveOrderProcessDetails'
           
        ];

    }

    public function onOrder_SaveOrderProcessDetails(Enlight_Event_EventArgs $args)
	{
        $basketContent = $args->getDetails();     
	    $order = $args->getSubject();
	    $orderNumber = $order->sOrderNumber;

	    var_dump ($basketContent);
	}
  
}

?>

 

yes, that should work

Ok I will review once again. Might minor mistek

@Michael Telgmann schrieb:

yes, that should work

I would like to update you. can you check the source code? Because I have check all things still no outcome

[@Michael Telgmann](http://forum.shopware.com/profile/17553/Michael Telgmann “Michael Telgmann”)‍ Is it possible to check?

is your plugin installed and activated?

Btw: Have you already seen our online trainings? https://academy.shopware.com/collections?category=english-trainings They are really helpful for beginners  Smile

Best regards from Schöppingen

cool Michael Telgmann

1 „Gefällt mir“

[@Michael Telgmann](http://forum.shopware.com/profile/17553/Michael Telgmann “Michael Telgmann”)‍ I have Hook issue which called some other place. Can you guide me I want to implement external API. I have code written in code PHP.

 

Correct place : 

public static function getSubscribedEvents()

{

return [

'Shopware_Modules_Order_SaveOrder_ProcessDetails' => 'getAccountController'

];



}

 

@Michael Telgmann schrieb:

is your plugin installed and activated?

Btw: Have you already seen our online trainings? https://academy.shopware.com/collections?category=english-trainings They are really helpful for beginners  Smile

Best regards from Schöppingen

cool Michael Telgmann

This is the same which I follow. 

Folder structure in Core PHP

Api.class.php // Contain Base class and functions

Helper.class.php // I have added some method 

index.php // Execurtable file where all include

 

require_once("KoronaApi.class.php");
require_once("KoronaHelper.class.php");

// Prepare Data Set 

$token = "Token";

// Organization which Manage warehouse and other things

$orgNo = "1";

// A SKU or Number must same as both site ecommerce and korona

$productNumber = "BLVK.Choco";

$qty = 10; // QTY you want to update Minus (-) indicate 

// An Object manage stock
$KoronaObject = new KoronaHelper();
echo $KoronaObject->StockAdjustment($token,$orgNo,$productNumber,$qty);

 

Fatal error : Class ‚SwagTest\Subscribers\Helper‘ not found in /custom/plugins/SwagTest** /Subscribers/SwagTest **Subscriber.php  on line  6

Thank you for help. [@Michael Telgmann](http://forum.shopware.com/profile/17553/Michael Telgmann “Michael Telgmann”)‍ Its solved.