payzoffpayzoff MemberComments: 3 Received thanks: 0 Member since: January 9 edited May 10

Hi, I am trying to implement a test button as refs here https://developers.shopware.com/developers-guide/plugin-guidelines/#testing-communication-with-external-apis

Hallo, ich versuche hier einen Testknopf als Referenz zu implementieren https://developers.shopware.com/developers-guide/plugin-guidelines/#testing-communication-with-external-apis
Here is my service file
Hier ist meine Servicedatei

 

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services";
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">;

    <services>
        <service id="mytest_payment.mytest_payment_controllers_backend_mytest_payment_services" class="MytestPayment\Controllers\Backend\MytestPaymentServices">
            <argument type="service" id="http_client"/>
            <argument type="service" id="MytestPayment.logger" />
            <tag name="shopware.controller" module="backend" controller="MytestPayment\Controllers\Backend\MytestPaymentServices"/>
        </service>
    </services>

</container>

and

MytestPaymentServices.php 

 

<?php


namespace MytestPayment\Controllers\Backend;

use Monolog\Logger;
use Shopware\Components\HttpClient\HttpClientInterface;
use Shopware\Components\HttpClient\RequestException;
use Symfony\Component\HttpFoundation\Response;

 class MytestPaymentServices extends \Shopware_Controllers_Backend_ExtJs
{
    private const EXTERNAL_API_BASE_URL = 'https://www.dom.com/api';
    /**
     * @var HttpClientInterface
     */
    private $client;

    /**
     * @var Logger
     */
    private $logger;

    public function __construct(HttpClientInterface $client, Logger $logger)
    {
        $this->client = $client;
        $this->logger = $logger;

        parent::__construct();
    }

    public function testAction()
    {
        try {
            $response = $this->client->get(self::EXTERNAL_API_BASE_URL);

            if ((int) $response->getStatusCode() === Response::HTTP_OK) {
                $this->View()->assign('response', 'Success!');
            } else {
                $this->View()->assign('response', 'Oh no! Something went wrong :(');
            }
        } catch (RequestException $exception) {
            $this->logger->addError($exception->getMessage());

            $this->response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
            $this->View()->assign('response', $exception->getMessage());
        }
    }
}

but I get the following error

aber ich bekomme folgenden Fehler

Class Shopware_Controllers_Backend_MytestPaymentServices does not exist in engine/Library/Enlight/Hook/ProxyFactory.php on line 164

What do I do wrong?

Was mache ich falsch?

1 Answer

  • ShyimShyim MemberComments: 1181 Received thanks: 481 Member since: May 2015

    Place your Controller in Controller/Backend/XXXX.php

    Controllers name conflicting the other controller autoload

    Quote
    Accepted Answer
  • Accepted Answer
Sign In or Register to comment.