<?php declare(strict_types=1);
namespace Ce\CustomerSubaccounts\Storefront\Controller;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use GuzzleHttp;
/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
class SubaccountController extends StorefrontController
{
/**
* @Route("/subaccount", name="frontend.subaccount.example", defaults={"csrf_protected"=false}, methods={"GET"})
*/
public function showExample(Request $request, SalesChannelContext $context): Response
{
// $clientId = 'SWIAMML6Z3BBEFBXEG5TV3VSTW';
// $clientSecret = 'OFM3SER4OVNCSWhkcDZFQ3V3cWFQa2RiNmZtRGNIeFdaNlplUFQ';
$clientId = 'SWIACTDKBLD2CULHU3BBQM5NEA';
$clientSecret = 'aDdzNEpwQUk5Vm9GdjFZaUxHalY1c0dNa0lTRFFJcEJGeG9NY2s';
// SWSCPSHKQ-Y-FZL1LFS-RM20AW
// $curl = curl_init();
// curl_setopt($curl, CURLOPT_POST, 1);
// $curlopt[CURLOPT_POSTFIELDS] = $parameters_string;
// curl_setopt_array($curl, [
// CURLOPT_URL => "http://localhost/store-api/account/register",
// CURLOPT_RETURNTRANSFER => true,
// CURLOPT_ENCODING => "",
// CURLOPT_MAXREDIRS => 10,
// CURLOPT_TIMEOUT => 30,
// CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
// CURLOPT_CUSTOMREQUEST => "POST",
// CURLOPT_POSTFIELDS => "{\n
// \"firstName\": \"Alice\",\n
// \"lastName\": \"Apple\",\n
// \"email\": \"alice.apple@example.com\",\n
// \"password\": \"ilovefruits\",\n
// \"storefrontUrl\": \"http://localhost\",\n
// \"billingAddress\": {\n
// \"street\": \"Apple Alley 42\",\n
// \"zipcode\": \"1234-5\",\n
// \"city\": \"Appleton\",\n
// \"countryId\": \"0x88d0dabde41146199a6edbe18eb57fea\"\n }\n}",
// CURLOPT_HTTPHEADER => [
// "Accept: application/json",
// "Content-Type: application/json",
// "sw-access-key: SWSCPSHKQ-Y-FZL1LFS-RM20AW",
// "sw-context-token: ".$context->getToken()
// ],
// ]);
//
// $response = curl_exec($curl);
// $err = curl_error($curl);
//
// curl_close($curl);
//
// if ($err) {
// echo "cURL Error #:" . $err;
// } else {
// echo $response;
// }
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "http://sw6afg.ce1.eu/store-api/context",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"Content-Type: application/json",
"sw-access-key: SWSCPSHKQ-Y-FZL1LFS-RM20AW"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
// echo "cURL Error #:" . $err;
} else {
// echo $response;
}
// var_dump($response);
// die();
return $this->renderStorefront('@CeCustomerSubaccounts/storefront/page/subaccount.html.twig', [
'example' => 'Subaccounts'
]);
}
}