Punchout Iframe issue with Magento 2 - magento2

I am trying to integrate the punchout system with Magento 2.
Magento does not allow opening iframe due to security reasons. I have added 'x-frame-options' => '*' option to the env.php file but still not allow to open the Iframe.
Also, I have changed the below file but I did not get the exact result.
vendor\magento\framework\App\Response\HeaderProvider\XFrameOptions.php
I am getting the below response from punchout. After that I am getting a blank screen.
In the punchout response x-frame-options showing twice.
Can you guide which settings are required to open the site in the Iframe?
Thanks in advance

I found a solution:
1 - Remove the x-frame-options from the env.php
2 - Override the \Magento\Framework\App\Response\HeaderProvider\XFrameOptions.php file ( don't forget the di.xml ) and comment the content of the __construct
class XFrameOptions extends \Magento\Framework\App\Response\HeaderProvider\XFrameOptions
{
/** Deployment config key for frontend x-frame-options header value */
const DEPLOYMENT_CONFIG_X_FRAME_OPT = 'x-frame-options';
/** Always send SAMEORIGIN in backend x-frame-options header */
const BACKEND_X_FRAME_OPT = 'SAMEORIGIN';
/**
* x-frame-options Header name
*
* #var string
*/
protected $headerName = Http::HEADER_X_FRAME_OPT;
/**
* x-frame-options header value
*
* #var string
*/
protected $headerValue;
/**
* #param string $xFrameOpt
*/
public function __construct($xFrameOpt = 'SAMEORIGIN')
{
//$this->headerValue = $xFrameOpt;
}
}
I think this will work!

Related

Symfony 4 + Api platform Cannot validate values of type \"NULL\" automatically. on nativeSQL query

i have been stuck for few hours with this:
Doing a simple query on my Variation base :
$query = "UPDATE variation SET status = 'FALSE' WHERE id IN
('ba21ac3f-0e7f-4bb9-b31f-dbd49053002e','a656e102-0339-4db0-a4b1-16451c2f1d90','64da7d32-2c9f-4478-bc6d-0b7b6c07af8e','8aba2925-7017-4899-bdfa-bf341c0fccec','6d4374cb-3713-4162-be53-2232202b5809','1810057a-6157-45bf-85d5-ade282b7d807','967d7495-6e93-4530-b6d8-d23640b39226','ebdcd88f-1f58-44b6-a14d-d0db9a564671')";
$result = $this->entityManager->getConnection()->prepare($query);
$result->execute();
And using postman it's returning me :
"#context": "/contexts/Error",
"#type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Cannot validate values of type \"NULL\" automatically. Please provide a constraint."`
my variation class:
/**
* #var bool
*
* #ORM\Column(type="boolean")
*
* #Groups({"variation"})
*/
protected $status;
How comes it try to validate somethings. Ps the query is fully working ( POSTGRES - Symfony 4.2 - PHP72 )
If body content is empty in request, its possible to correct that if content type are is also empty in header request

Set content-type HTTP header for 404 page in TYPO3 9.5

I am making a webservice using TYPO3. Everything in the frontend should be JSON with HTTP header Content-Type: application/json, however I am unable to change the Content-Type header for the 404 page. Whatever I try, it's always Content-Type: text/html; charset=utf-8. How can I change this?
This is my basic page TypoScript configuration:
page = PAGE
page {
config {
disableAllHeaderCode = 1
disablePrefixComment = 1
xhtml_cleaning = 0
admPanel = 0
}
10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = MyExt
pluginName = MyPlugin
vendorName = MyVendor
}
}
The extension uses TYPO3\CMS\Extbase\Mvc\View\JsonView.
I've already tried adding the header using config.additionalHeaders.10.header = Content-Type: application/json. I've also tried setting [FE][pageNotFound_handling] to USER_FUNCTION:... and setting the headers in PHP.
I found the solution myself. From TYPO3 9.5 the default page not found handling can be overridden in the site configuration:
errorHandling:
-
errorCode: 404
errorHandler: PHP
errorPhpClassFQCN: Vendor\MyExt\PageErrorHandler\PageNotFoundHandler
And in EXT:MyExt/Classes/PageErrorHandler/PageNotFoundHandler.php:
<?php
namespace Vendor\MyExt\PageErrorHandler;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface;
/**
* Class PageNotFoundHandler
*/
class PageNotFoundHandler implements PageErrorHandlerInterface
{
/**
* Handle page error
*
* #param ServerRequestInterface $request
* #param string $message
* #param array $reasons
* #return ResponseInterface
*/
public function handlePageError(ServerRequestInterface $request, string $message, array $reasons = []): ResponseInterface
{
$response = new Response(404, ['Content-Type' => 'application/json'], '{"error":"Not found"}');
return $response;
}
}

TYPO3 8.7 Extbase generate csv-file

I try to generate a csv-file in my TYPO3 Extension. I get following error:
1225709595: The Fluid template files "" could not be loaded. (More information)
TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException thrown in file
/usr/local/www/apache24/xx/xx/vendor/typo3fluid/fluid/src/View/TemplatePaths.php in line 719.
25 TYPO3Fluid\Fluid\View\TemplatePaths::resolveFileInPaths(array, "Default", "csv")
My Controller looks like:
$icalView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$icalView->setFormat('csv');
$icalView->setTemplatePathAndFilename('typo3conf/ext/xxx/Resources/Private/Templates/Bestellung/Listbestellungen.txt');
$icalView->assign('xx', $xx);
$icalContent = $icalView->render();
I do have Subfolter "Layout" in ... Bestellung/ and I do have file Default.csv
Same code working in extension in TYPO3 7.6.x - what has changed in 8.7?
Thanks for help!
Martin
Here an snippet how I do it in 8.7 to send an eMail:
As I know you have to set the paths for Template, Layout and Partials also, before you select the template to use
/**
* configurationManager
*
* #var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
* #inject
*/
protected $configurationManager;
public function sendEmail($template,...)
{
/**
* Generate Email Body
*/
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
/** #var StandaloneView $emailView */
$emailView = $this->objectManager->get(StandaloneView::class);
$emailView->getRequest()->setControllerExtensionName($controllerExtensionName);
$emailView->getRequest()->setPluginName($pluginName);
$emailView->getRequest()->setControllerName($controllerName);
$emailView->setTemplateRootPaths($extbaseFrameworkConfiguration['view']['templateRootPaths']);
$emailView->setLayoutRootPaths($extbaseFrameworkConfiguration['view']['layoutRootPaths']);
$emailView->setPartialRootPaths($extbaseFrameworkConfiguration['view']['partialRootPaths']);
$emailView->setTemplate('Email/' . ucfirst($template));
$emailView->assignMultiple($variables);
$emailBody = $emailView->render();
}
I solved this by changing the code a little bit and now it is working:
$storage = $this->resourceFactory->getDefaultStorage();
if ($storage === NULL) {
throw new \RuntimeException('Could not get the default storage', 1475590001);
}
/** #var \TYPO3\CMS\Fluid\View\StandaloneView $icalView */
$icalView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$icalView->setFormat('csv');
$templateRootPath[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:xxx/Resources/Private/Templates/');
$layoutRootPaths[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:xxx/Resources/Private/Layouts/');
$partialRootPaths[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:xxx/Resources/Private/Partials/');
$icalView->setLayoutRootPaths($layoutRootPaths);
$icalView->setPartialRootPaths($partialRootPaths);
$icalView->setTemplatePathAndFilename('typo3conf/ext/xxx/Resources/Private/Templates/Bestellung/Listbestellungen.txt');
$icalView->assign('xxx', $xxx);
$icalContent = $icalView->render();
$tempFolder = $storage->getFolder('bestellungencsv');
$tempFile = $storage->createFile('bestellungen_'.$xxx->getUid().'.csv', $tempFolder);
$tempFile->setContents($icalContent);

Creating Routing Paths using FosRestFundle in Symfony

I am developing an Api for one of my projects in Symfony and I want create several routing paths like the following:
/api/messages/{id}
/api/messages/creator/{username}
/api/messages/receiver/{username}
My routing files are configured in this way (I will post just the info relating to the api config):
routing.yml:
NelmioApiDocBundle:
resource: "#NelmioApiDocBundle/Resources/config/routing.yml"
prefix: "/doc"
api:
type: rest
resource: "routing_api.yml"
prefix: /api
routing_api.yml:
api_message:
type: rest
resource: AppBundle\Controller\ApiMessagesController
api_chats:
type: rest
resource: AppBundle\Controller\ApiChatController
And my ApiMessagesController:
<?php
namespace AppBundle\Controller;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\View\RouteRedirectView;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
/**
* Class ApiMessagesController
* #package AppBundle\Controller
*
* #RouteResource("messages")
*/
class ApiMessagesController extends FOSRestController{
/**
* Gets an individual Message
*
* #param int $id
* #return mixed
* #throws \Doctrine\ORM\NoResultException
* #throws \Doctrine\ORM\NonUniqueResultException
*
* #ApiDoc(
* output="AppBundle\Entity\Message",
* statusCodes={
* 200 = "Returned when successful",
* 404 = "Return when not found"
* }
* )
*/
public function getAction($id){;
return $this->get('app.message.manager')->findById($id);
}
/**
* Gets all messages sent by each users
*
* #param int $id
* #return mixed
* #throws \Doctrine\ORM\NoResultException
* #throws \Doctrine\ORM\NonUniqueResultException
*
* #ApiDoc(
* output="AppBundle\Entity\Message",
* statusCodes={
* 200 = "Returned when successful",
* 404 = "Return when not found"
* }
* )
*/
public function getCreatorAction($creator){
return $this->get('app.message.manager')->findByCreator($creator);
}
}
The route /api/messages/{id} works as I expected but I am really stuck right now about how to define the route /api/messages/creator/{creator} because Nelmio is telling me that I created this route /api/messages/{creator}/creator instead of /api/messages/creator/{username}
I think that I put all info regarding to my issue, but if something is missing tell me and I will update my question. Thanks
If you're not happy with URLs FOSRest does, you can always use #Route annotation and redefine everything you need.

codeignither HMVC version 3.0.6 view not loading

The follwing below is an controller for an template i am making in codeignither HMVC. I am trying to load this template module in my task modules but for some reason it wont load in the template modules but the data loads in my task controller.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class templates extends MX_Controller
{
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see https://codeigniter.com/user_guide/general/urls.html
*/
public function one_col($data)
{
$this->load->view('one_col',$data);
}
public function two_col($data)
{
$this->load->view('two_col',$data);
}
public function admin($data)
{
$this->load->view('admin', $data);
}
public function index()
{
echo "Hello world";
}
}
this code below is my task controller and it works fine when i run it in the link http://localhost:81/hmvc/index.php/tasks however when i try to run the template view "two_col" http://localhost:81/hmvc/index.php/templates/two_col
using this code in the template
<?php $this->load->view($module.'/'.$view_file); ?>
i get this error :
task module controller below
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class tasks extends MX_Controller
{
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->model('mdl_tasks');
$data['query'] = $this->mdl_tasks->get('priority');
#$this->load->view('display', $data);
$data['view_file'] = "display";
$data['module'] = "tasks";
echo Modules::run('templates/two_col', $data);
#$this->load->module('templates');
#$this->templates->two_col($data);
}
}
echo Modules::run('templates/two_col', $data);
#$this->load->module('templates');
I'm pretty sure replacement these codes together will work.
Because php is an interpreted programming language. PHP loads every line one by one if deteced an error for ex. on 5Th line it doesnt compile the rest of lines. More information for interpreted lang. and also in your code you implementing the lib function before loading lib