# Call external API once the stock level updated

**URL:** <https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092>\
**Category:** International (English Only)\
**Tags:** programming\
**Created:** [1. Oktober 2019 um 13:28 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092 "2019-10-01T13:28:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 13:28 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/1 "2019-10-01T13:28:34Z")

</div>

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
	}
  
}

?>

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [1. Oktober 2019 um 13:36 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/2 "2019-10-01T13:36:17Z")

</div>

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&nbsp;[https://docs.shopware.com/en/shopware-platform-dev-en/internals/plugins/plugin-quick-start?category=shopware-platform-dev-en/internals/plugins](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

&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 13:37 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/3 "2019-10-01T13:37:02Z")

</div>

I have Shopware version 5.X

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 13:38 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/4 "2019-10-01T13:38:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [1. Oktober 2019 um 13:38 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/5 "2019-10-01T13:38:53Z")

</div>

I will move the thread then…

Have a look at our Shopware 5 documentation please&nbsp;[Developing plugins](https://developers.shopware.com/plugin-guide/)

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 13:44 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/6 "2019-10-01T13:44:35Z")

</div>

[@Michael Telgmann]([http://forum.shopware.com/profile/17553/Michael](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.

&nbsp;

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

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 13:46 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/7 "2019-10-01T13:46:18Z")

</div>

Main Plugin File&nbsp;

```
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);
	}
  
}

?>

```

&nbsp;

**Config File :&nbsp;**

&nbsp;

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

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [1. Oktober 2019 um 13:46 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/8 "2019-10-01T13:46:55Z")

</div>

Have a look here:&nbsp;[Shopware events](https://developers.shopware.com/developers-guide/event-guide/#plugins-use-subscribers)  
you have to implement the getSubscribedEvents method

Best regards from Schöppingen

![cool](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 13:48 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/9 "2019-10-01T13:48:16Z")

</div>

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

    }

```

You mean this??

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 13:54 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/10 "2019-10-01T13:54:29Z")

</div>

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

&nbsp;

```
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);
	}
  
}

?>

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [1. Oktober 2019 um 14:04 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/11 "2019-10-01T14:04:22Z")

</div>

yes, that should work

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 14:09 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/12 "2019-10-01T14:09:59Z")

</div>

Ok I will review once again. Might minor mistek

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 14:32 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/13 "2019-10-01T14:32:06Z")

</div>

> [@Michael Telgmann schrieb:](https://forum.shopware.com/profile/17553/Michael%20Telgmann "Michael%20Telgmann")

yes, that should work

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

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [1. Oktober 2019 um 14:39 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/14 "2019-10-01T14:39:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [2. Oktober 2019 um 07:12 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/15 "2019-10-02T07:12:09Z")

</div>

is your plugin installed and activated?

Btw: Have you already seen our online trainings?&nbsp;[https://academy.shopware.com/collections?category=english-trainings](https://academy.shopware.com/collections?category=english-trainings) They are really helpful for beginners&nbsp; ![Smile](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/smile.png "Smile")

Best regards from Schöppingen

![cool](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [2. Oktober 2019 um 07:43 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/16 "2019-10-02T07:43:50Z")

</div>

[@Michael Telgmann]([http://forum.shopware.com/profile/17553/Michael](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.

&nbsp;

Correct place :&nbsp;

```
public static function getSubscribedEvents()

{

return [

'Shopware_Modules_Order_SaveOrder_ProcessDetails' => 'getAccountController'

];

}

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [2. Oktober 2019 um 07:46 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/17 "2019-10-02T07:46:14Z")

</div>

> [@Michael Telgmann schrieb:](https://forum.shopware.com/profile/17553/Michael%20Telgmann "Michael%20Telgmann")
> 
> is your plugin installed and activated?
> 
> Btw: Have you already seen our online trainings?&nbsp;[https://academy.shopware.com/collections?category=english-trainings](https://academy.shopware.com/collections?category=english-trainings) They are really helpful for beginners&nbsp; ![Smile](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/bac5f5766b6a20565a8fb995345b4e41d24daac0.png "Smile")
> 
> Best regards from Schöppingen
> 
> ![cool](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "cool")&nbsp;Michael Telgmann

This is the same which I follow.&nbsp;

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [2. Oktober 2019 um 07:53 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/18 "2019-10-02T07:53:58Z")

</div>

**Folder structure in Core PHP**

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

Helper.class.php // I have added some method&nbsp;

index.php // Execurtable file where all include

&nbsp;

```
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);

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [2. Oktober 2019 um 08:29 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/19 "2019-10-02T08:29:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)\
**Post date:** [3. Oktober 2019 um 07:01 UTC](https://forum.shopware.com/t/call-external-api-once-the-stock-level-updated/62092/20 "2019-10-03T07:01:19Z")

</div>

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