vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27 edited October 1

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. :

<?php

namespace SwagKorona;

use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
use Enlight\Event\SubscriberInterface;

class SwagKorona extends Plugin
{
    public function activate(ActivateContext $context)
    {
        $context->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
	}
  
}

?>

 

Comments

  • Michael TelgmannMichael Telgmann ModeratorComments: 1083 Received thanks: 304 Member since: June 2014

    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

    cool Michael Telgmann

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    I have Shopware version 5.X

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 edited October 1 Member since: September 27

    @Michael Telgmann‍  I have implemented as per plugin guide

  • Michael TelgmannMichael Telgmann ModeratorComments: 1083 Received thanks: 304 Member since: June 2014

    I will move the thread then...

    Have a look at our Shopware 5 documentation please https://developers.shopware.com/plugin-guide/

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    @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. 

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 edited October 1 Member since: September 27

    Main Plugin File 

    <?php
    
    namespace SwagKorona;
    
    use Shopware\Components\Plugin;
    use Shopware\Components\Plugin\Context\ActivateContext;
    use Shopware\Components\Plugin\Context\DeactivateContext;
    use Enlight\Event\SubscriberInterface;
    
    class SwagKorona extends Plugin
    {
        public function activate(ActivateContext $context)
        {
            $context->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 : 

     

    <?xml version="1.0" encoding="utf-8"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
            xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/5.3/engine/Shopware/Components/Plugin/schema/config.xsd">;
        <elements>
            <element required="true" type="text" scope="locale">
                <name>Korona Pos</name>
                <label lang="de"> API Token</label>
                <label lang="en"> API Token</label>
                <value>API Tken</value>                        
                <description>An API token provided by  Support.</description>
            </element>
        </elements>
    </config>

     

  • Michael TelgmannMichael Telgmann ModeratorComments: 1083 Received thanks: 304 Member since: June 2014

    Have a look here: https://developers.shopware.com/developers-guide/event-guide/#plugins-use-subscribers
    you have to implement the getSubscribedEvents method

    Best regards from Schöppingen

    cool Michael Telgmann

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 edited October 1 Member since: September 27
     public static function getSubscribedEvents(){
            return [
                'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout_Finish' => 'OnOrder_SaveOrderProcessDetails'
               
            ];
    
        }

    You mean this??

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    @Michael Telgmann‍  Most recent as per document : 

     

    <?php
    
    namespace SwagKorona;
    
    use Shopware\Components\Plugin;
    use Shopware\Components\Plugin\Context\ActivateContext;
    use Shopware\Components\Plugin\Context\DeactivateContext;
    use Enlight\Event\SubscriberInterface;
    
    class SwagKorona extends Plugin
    {
        public function activate(ActivateContext $context)
        {
            $context->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);
    	}
      
    }
    
    ?>

     

  • Michael TelgmannMichael Telgmann ModeratorComments: 1083 Received thanks: 304 Member since: June 2014

    yes, that should work

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    Ok I will review once again. Might minor mistek

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    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

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    @Michael Telgmann‍ Is it possible to check?

  • Michael TelgmannMichael Telgmann ModeratorComments: 1083 Received thanks: 304 Member since: June 2014

    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

    Thanked by 1vasims_zignuts
  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

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

     

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    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. 

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

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

     

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    Fatal error: Class 'SwagTest\Subscribers\Helper' not found in/custom/plugins/SwagTest/Subscribers/SwagTestSubscriber.php on line 6

  • vasims_zignutsvasims_zignuts MemberComments: 23 Received thanks: 0 Member since: September 27

    Thank you for help. @Michael Telgmann‍ Its solved. 

Sign In or Register to comment.