Prevent Search Engines from flooding the Encode Cache – using an XCLASS

The RealURL encode cache could get flooded with the URLs that are used by search engines like Google, Solr etc… If we know the exact parameter they use, we can prevent the flooding using this simple function given below

1.) Add this code to the file “Realurl.php” in the “Sconfig\Xclass” folder. Here “Sconfig” – is the name of our extension. “Xclass – folder may need to be created if not present”

CODE START
########################

<?php

namespace Scwebs\Sconfig\Xclass;

class Realurl extends \tx_realurl {
public function encodeSpURL(&$params) {
parent::encodeSpURL($params);
}

protected function encodeSpURL_encodeCache($urlData, $internalExtras, $setEncodedURL = ”) {
// \TYPO3\CMS\Core\Utility\GeneralUtility::devLog(‘Inside the hook now!’, ‘realurl’, 1, array($urlData));
if( isset($_GET[‘gclid’]) ){
$this->devLog(‘gclid detected. Not doing anything!’);
return ”;
}
parent::encodeSpURL_encodeCache($urlData, $internalExtras, $setEncodedURL);
}
}

########################
CODE END

2. Our Xclass needs to be registered, this can be done in the “Sconfig/ext_localconf.php” using the code below:

$GLOBALS[‘TYPO3_CONF_VARS’][‘SYS’][‘Objects’][‘tx_realurl’] = array(
‘className’ => Scwebs\\Sconfig\\Xclass\\Realurl’
);

Xclass to force the use of Additional Params in all content links

Suppose you want to add one extra parameter to typolink all over the website
Here is the steps to follow :
Step1:
Include below lines in ext_localconf.php of our extension
$GLOBALS[‘TYPO3_CONF_VARS’][‘SYS’][‘Objects’][‘TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer’] = array(
‘className’ => ‘VenderName\\ExtName\\Xclass\\ContentObjectRenderer’
);
// Also Xclass the old class name for compatibility issues (old extensions may create an instance of “tslib_cObj”)
$GLOBALS[‘TYPO3_CONF_VARS’][‘SYS’][‘Objects’][‘tslib_cObj’] = array(
‘className’ => ‘VenderName\\ExtName\\Xclass\\ContentObjectRenderer’
);

Step2:
Create File with name ContentObjectRenderer.php in Xclass Folder
<?
namespace Vendername\Extensionname\Xclass;

class ContentObjectRenderer extends \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer {

/**
* Adds customerview = 1 in url params
*/
function typoLink($linktxt, $conf) {
if($_GET[‘customerview’] == 1){
$conf[‘additionalParams’] = $conf[‘additionalParams’].’&customerview=1′;
}
$typolink = parent::typoLink($linktxt, $conf);
return $typolink;
}
}
?>

Step3:
Clear the cache and check whether xclass is included or not.
Finally reload the frontend page where all typolinks are added with custom parameter customerview

Extend Typo3 Function using Xclass in Extbase Extension

Here is the few steps on how to extend a function Using XCLASS

Step1:
Add Below code in ext_localconf.php

$GLOBALS[‘TYPO3_CONF_VARS’][‘SYS’][‘Objects’][‘tx_realurl’] = array(
‘className’ => ‘Vendername\\Extensionname\\Xclass\\Realurl’
);

Step2:
Finally Create File with name Realurl.php in Xclass Folder
<?php
namespace Vendername\Extensionname\Xclass;

class Realurl extends \tx_realurl {
public function encodeSpURL(&$params) {
// Do Your Stuff
devlog(‘ I am here.’);
parent::encodeSpURL($params);
}
}
?>

Step3:
Clear the cache and check whether xclass is included or not.

Thats it.

 

 

Epay payment gateway integration in TYPO3 extbase extension.

The process is, after booking we will create the new booking record containing booked product info like product name, its total price etc.

The booking record creation action will be like this,

public function createAction(\TYPO3\myext\Domain\Model\Packagebooking $newPackagebooking) {

//create package
$this->packagebookingRepository->add($newPackagebooking);

//get created package id
$persistenceManager = GeneralUtility::makeInstance(‘TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager’);
$persistenceManager->persistAll();
$pUidNew = $newPackagebooking->getUid();

/* Redirect to payment */
$this->redirect(‘payment’, ‘Packagebooking’ ,NULL ,array(‘packagebooking’=>$pUidNew));
}

After record creation we will redirect to payment Action.

public function paymentAction($packagebooking) {
/*
* MD5 key: mymd5key
* merchant id: 123456
*
*/

//get the booked record. $packagebooking contains the uid of the last created booking record
$packagebooking = $this->packagebookingRepository->findByUid($packagebooking);

//generate return url
$accepturl = $this->controllerContext
->getUriBuilder()->reset()
->setTargetPageUid($this->settings[‘orderConfirmationPid’])
->setNoCache(1)
->setArguments(array(
‘tx_myext_checkout’ => array(
‘orderid’ => $packagebooking->getUid(),
‘action’ => ‘paymentconfirm’,
‘controller’ => ‘Packagebooking’,
)
))->buildFrontendUri();
$accepturl = GeneralUtility::getIndpEnv(‘TYPO3_SITE_URL’).$accepturl;

//Generate javascript required for payment gateway api
$paymentwindowJs = ”;
$paymentParams = array(
‘merchantnumber’ => “123456”,
‘amount’ => $packagebooking->getTotalprice() * 100,
‘currency’ => “DKK”,
‘windowstate’=> “2”,
‘orderid’ => $packagebooking->getUid(),
‘accepturl’ => $accepturl
);
$paymentwindowJs .='<script type=”text/javascript”>’;
$paymentwindowJs .=’paymentwindow = new PaymentWindow({‘;
foreach ($paymentParams as $key => $value) {
$paymentwindowJs .= “‘” . $key . “‘: \”” . $value . “\”,\n”;
}
$paymentwindowJs .= “‘hash’:”.'”‘.md5(implode(“”, array_values($paymentParams)) . “mymd5key”).'”‘;
$paymentwindowJs .= ‘});’;
$paymentwindowJs .=’paymentwindow.append(“payment-div”);paymentwindow.open();</script>’;

$this->view->assignMultiple(
array(
‘paymentwindowJs’ => $paymentwindowJs
)
);
}

Payment action template will be like this

<f:layout name=”Default” />
<f:section name=”main”>
<h1>Payment</h1>
<div class=”thankyoumessage”>
<div id=”payment-div”></div>
</div>

<script charset=”UTF-8″ src=”https://ssl.ditonlinebetalingssystem.dk/integration/ewindow/paymentwindow.js” type=”text/javascript”></script>
<f:format.raw>{paymentwindowJs}</f:format.raw>

</f:section>

Aftere this we will proceed in payment by Epay api. After the payment has been done, we will redirec to confirmation page having confirmation plugin.

Below is the confirmation action, here we will calculate the MD5 hash from the return url and compare it with the received hash. And update the payment record accordingly.

public function paymentconfirmAction() {
$posted = GeneralUtility::_GET(‘tx_myext_checkout’);
$posted[‘txnid’] = GeneralUtility::_GET(‘txnid’);
$posted[‘ordernumber’] = GeneralUtility::_GET(‘orderid’);
$posted[‘paymenttype’] = GeneralUtility::_GET(‘paymenttype’);
$posted[‘hash’] = GeneralUtility::_GET(‘hash’);

//Check for bad hash
$params = $_GET;
$var = “”;
foreach ($params as $key => $value) {
if(is_array($value)) {
foreach ($_GET[‘tx_myext_checkout’] as $key => $value) {
$var .= $value;
}
} elseif($key != “hash”) {
$var .= $value;
}
}

$genstamp = md5($var . “mymd5key”);

if($genstamp != $_GET[“hash”]) {
$status = ‘Hash is not valid’;
} else {
//Hash is OK
$status = ‘Transaction success’;
}

$this->packagebookingRepository->updateOrderEpay($posted, $status);
$this->view->assign(‘status’, $status);
}

Hope this helps someone!

 

The default controller for extension not found.

Some time we get the error like
“The default controller for extension “extname” and plugin “Calendar” can not be determined.
Please check for TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin() in your ext_localconf.php”.

Even we have all the correct configurations in ext_localconf.php and ext_tables.php

This is what we have in ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
‘Vendor.’ . $_EXTKEY,
‘Calendar’,
array(
‘Calendar’ => ‘list, show’,
),
array(
‘Calendar’ => ”,

)
);
?>

This is what we have in ext_tables.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
‘Calendar For Dates’,
‘Calendar’
);

All the configurations are perfect but still we get the error, why?

Yes there is the reason for it. Suppose we have more than one extension, or more that one plug in in the same extension.
Other extensions or plugins might have had flexforms, and we have added that plugin and configured the flexform.
Now for the same tt_content element we have selected the plugin “Calendar”, and when we select this plugin we dont see any flexform values of
previous plugins.
But in Databse the table tt_content still stores the flexform values of old plug in and this leades to error.

Solution :
1) Go to databse and delete the flexform values for the perticular tt_content element.
or
2) Delete the old content element and add the new tt_content element.