Integration

Sie können die Funktionalität anderer Extensions um den UPS-Versand erweitern, indem Sie Backend-Links zur Erstellung neuer UPS-Shipping-Einträge erstellen. Die Links, können Parameter enthalten, die den UPS-Shipping-Eintrag mit Werten voraus befüllen.

use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$returnUrl = 'Return url';
$shippingPageUid = 'Page uid des Containers mit UPS-Shipment-Einträgen';

$defVals = [];
$defVals['address_line'] = 'Beispieladresse 1';
$defVals['weight_unit'] = 'KGS';
$defVals['package_dimensions_unit'] = 'CM';

$uriParameter = [
    'returnUrl' => $returnUrl,
    'edit' => [
        'tx_ups_api_domain_model_shipping' => [
            $shippingPageUid => 'new'
        ]
    ],
    'defVals' => [
        'tx_ups_api_domain_model_shipping' => $defVals
        ]
    ];

$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uri = (string)$uriBuilder->buildUriFromRoute('record_edit', $uriParameter);

Beispiel

In diesem Beispiel wird ein Button zur Erstellung eines UPS-Shipping-Eintrags in einen Record einer anderen Extension eingebunden.

1.Erstellung eines FormElements zur darstellung des Buttons und Erstellung eines Links zur Erstellung eines UPS-Shipping-Eintrags.

<?php

namespace Vendor\Extension\Form\Element;

use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class CreateShippingButton extends AbstractFormElement
{

    public function render(): array
    {
        $shippingPageUid = $this->data['parentPageRow']['uid'];
        $returnUrl = $this->data['returnUrl'];

        $dbRow = $this->data['databaseRow'];
        // Hier werden die UPS-Shipping Felder befüllt
        // z.B.
        $defVals = [
            'address_line' => $dbRow['address']
        ];

        $uriParameter = [
            'returnUrl' => $returnUrl,
            'edit' => [
                'tx_ups_api_domain_model_shipping' => [
                    $shippingPageUid => 'new'
                ]
            ],
            'defVals' => [
                'tx_ups_api_domain_model_shipping' => $defVals
            ]
        ];

        /**@var UriBuilder $uriBuilder */
        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
        $uri = (string)$uriBuilder->buildUriFromRoute('record_edit', $uriParameter);

        $result = $this->initializeResultArray();
        $mainFieldHtml = [];
        $mainFieldHtml[] = '<div class="form-control-wrap">';
        $mainFieldHtml[] = '<div class="form-wizards-wrap">';
        $mainFieldHtml[] = '<div class="form-wizards-element">';
        $mainFieldHtml[] = '<a href="' . $uri . '" class="btn btn-default">New shipping</a>';
        $mainFieldHtml[] = '</div>';
        $mainFieldHtml[] = '</div>';
        $mainFieldHtml[] = '</div>';

        $result['html'] = implode(LF, $mainFieldHtml);
        return $result;
    }
}

2.Registrierung eines render-Typs in ext_localconf.php

$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry']['1610980654'] = [
    'nodeName' => 'createShippingButton',
    'priority' => 40,
    'class' => \Vendor\Extension\Form\Element\CreateShippingButton::class,
];

3.Hinzufügen des Buttons zum TCA in Configuration/TCA/Overrides/tx_extension_domain_model_tablename.php

<?php
defined('TYPO3_MODE') or die();

$extKey = 'extension';
$table = 'tx_extension_domain_model_tablename';
$lll = 'LLL:EXT:' . $extKey . '/Resources/Private/Language/locallang_db.xlf:' . $table;

if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('ups_api')){

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
        'tx_extension_domain_model_tablename',
        [
            'create_shipping' => [
                'label' => $lll . '.createShipping',
                'config' => [
                    'type' => 'none',
                    'renderType' => 'createShippingButton'
                ]
            ]
        ]
    );
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
        'tx_extension_domain_model_tablename',
        'create_shipping'
    );
}