Call a PUT Method inside a POST Route

Hey Everyonem, currently i’m trying to call a PUT Method inside a only allowed POST Controller. My plugin is just a Subscriber wich is attached to the Order Placement Event. From there i’m trying to call a Service with API PUT method to send my articles to an External System.

<?php

namespace Swag\RestApiHandling\Subscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;

use Shopware\Core\Checkout\Cart\CartEvents;

use \Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;

use Zend\EventManager\Exception\RuntimeException;

use Swag\RestApiHandling\Service\R2OService;

class CartEventSubscriber implements EventSubscriberInterface{

    /**

     * @var EntityRepositoryInterface 

    */

    private $orderRepository;

    

    /**

     * @var R2OService

     */

     

    private $r2oService;

    public function __construct(EntityRepositoryInterface $orderRepository,R2OService $r2oService){

        $this->orderRepository = $orderRepository;

        $this->r2oService = $r2oService;

    }

    public static function getSubscribedEvents(){

        return [

            CheckoutOrderPlacedEvent::class =>  [ 'cartSubmit', 1000],

        ];

    }

   /** 

    *@Route("/checkout/order", methods={"PUT","HEAD"}) (Just a test, can be ignored)

    */

    public function cartSubmit(CheckoutOrderPlacedEvent $orderPlacedEvent): JsonResponse{

        //$this->r2oService->put("dailyReport/open",[]);

        $this->r2oService->put("document/invoice/",[  stuff]   $this->r2oService->put("/dailyReport/close",[]);
       return new JsonResponse("done");
}

}

If there is no way, do you know a workaround? Any help is apreciated :slight_smile:
Kind regards

Well, the function cartSubmit, that handles the CheckoutOrderPlacedEvent event should return void. It is also not a controller, so no route annotation should be there.
I have not used R2OService, but it seems to be injected properly. So if it indeed has a method named ‚put‘, then it should get called, when cartSubmit function gets triggered. The question then is, how this method ‚put‘ precisely works. Shouldn’t it call the external server with its full path?
In any case, this is the skeleton of the checkSubmit method, that is sure to get triggered:

public function cartSubmit (CheckoutOrderPlacedEvent $event) : void
{
    //do your magic here
}

I hope this helps…

Hi thank you :slight_smile: I think it had to do with the htaccess. I due to some planing changes i end up putting it to a command plugin i already had. Now it is triggered with a cronjob :slight_smile: