Skip to content

Commit

Permalink
WIP [TASK] Readd BE actions for orders
Browse files Browse the repository at this point in the history
The way to add actions in the docheader changed
with https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.5/Deprecation-95164-ExtbackendBackendTemplateView.html
which needs adaptions.

Todo:
* Add actions for invoices and delivery
* Test actions (needs EXT:cart_pdf in v12 compatible version)
* Remove superfluous template
  `Private/Partials/Backend/Order/Show/Actions`
  • Loading branch information
rintisch committed Mar 25, 2024
1 parent ca26d68 commit 819c976
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions Classes/Controller/Backend/Order/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,33 @@
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\Cart\Controller\Backend\ActionController;
use Extcode\Cart\Domain\Model\Cart\Cart;
use Extcode\Cart\Domain\Model\Order\Item;
use Extcode\Cart\Domain\Repository\Order\ItemRepository;
use Extcode\Cart\Event\Order\NumberGeneratorEvent;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownItem;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

class OrderController extends ActionController
{
private const LANG_FILE = 'LLL:EXT:cart/Resources/Private/Language/locallang.xlf:';

protected PersistenceManager $persistenceManager;

private ModuleTemplate $moduleTemplate;
Expand Down Expand Up @@ -124,6 +132,7 @@ public function exportAction(): ResponseInterface
public function showAction(Item $orderItem): ResponseInterface
{
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$this->setShowDocHeader($orderItem);

$this->moduleTemplate->assign('settings', $this->settings);
$this->moduleTemplate->assign('orderItem', $orderItem);
Expand Down Expand Up @@ -154,7 +163,67 @@ public function showAction(Item $orderItem): ResponseInterface
return $this->moduleTemplate->renderResponse('Show');
}

public function generateNumberAction(Item $orderItem, string $numberType): void
private function setShowDocHeader(Item $orderItem)
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();

$buttons = [];

if (!$orderItem->getOrderNumber()) {
$buttons[] = [
[
'link' => $this->uriBuilder->reset()->setRequest($this->request)
->uriFor(
'generateNumber',
['orderItem' => $orderItem, 'numberType' => 'order']
),
'title' => 'tx_cart.controller.order.action.generateOrderNumber',
'icon' => 'actions-duplicates',
],

];
}
if (ExtensionManagementUtility::isLoaded('cart_pdf')) {
$buttons[] = [
'link' => $this->uriBuilder->reset()->setRequest($this->request)
->uriFor(
'create',
['orderItem' => $orderItem, 'pdfType' => 'order'],
'Backend\Order\Document'
),
'title' => 'tx_cart.controller.order.action.generateOrderDocument',
'icon' => 'actions-file-pdf',
];
}

if ($orderItem->getOrderPdfs()->current()) {
$buttons[] = [
'link' => $this->uriBuilder->reset()->setRequest($this->request)
->uriFor(
'download',
['orderItem' => $orderItem, 'pdfType' => 'order'],
'Backend\Order\Document'
),
'title' => 'tx_cart.controller.order.action.downloadOrderDocument',
'icon' => 'actions-file-t3d-download',
];
}

foreach ($buttons as $button) {
$title = $this->getLanguageService()->sL(self::LANG_FILE . $button['title']);
$icon = $this->iconFactory->getIcon($button['icon'], Icon::SIZE_SMALL);

$viewButton = $buttonBar->makeLinkButton()
->setHref($button['link'])
->setTitle($title)
->setShowLabelText(true)
->setIcon($icon);
$buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
}

}

public function generateNumberAction(Item $orderItem, string $numberType): ResponseInterface
{
$getNumber = 'get' . ucfirst($numberType) . 'Number';

Expand Down Expand Up @@ -182,7 +251,7 @@ public function generateNumberAction(Item $orderItem, string $numberType): void
$this->addFlashMessage($msg, '', ContextualFeedbackSeverity::ERROR);
}

$this->redirect('show', 'Backend\Order\Order', null, ['orderItem' => $orderItem]);
return $this->redirect('show', 'Backend\Order\Order', null, ['orderItem' => $orderItem]);
}

public function getPaymentStatus(): array
Expand Down Expand Up @@ -234,4 +303,10 @@ public function getShippingStatus(): array
}
return $shippingStatusArray;
}

protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}

0 comments on commit 819c976

Please sign in to comment.