From 11e6224c097f225fd0e800f5c68f39df62d7a15c Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Wed, 14 May 2025 11:52:25 +0200 Subject: [PATCH] [TASK] Add support for werkraummedia/watchlist Relates: #274 --- .../DoctrineRepository/PageRepository.php | 39 ++++++++++++ .../Product/ProductRepository.php | 25 ++++++-- Classes/Domain/Model/WatchlistItem.php | 56 ++++++++++++++++++ Classes/Domain/Model/WatchlistItemFactory.php | 57 ++++++++++++++++++ Classes/Handler/WatchlistItemHandler.php | 33 +++++++++++ .../ViewHelpers/Product/PageUidViewHelper.php | 59 +++++++++++++++++++ Configuration/Services.php | 27 +++++++++ Configuration/Services.yaml | 2 + .../Feature-274-AddWatchlistItemHandler.rst | 16 +++++ Documentation/Changelog/7.2/Index.rst | 20 +++++++ Documentation/Changelog/Index.rst | 1 + Documentation/Index.rst | 4 +- Documentation/guides.xml | 4 +- Resources/Private/Language/locallang.xlf | 7 +++ .../Partials/Product/WatchlistButtons.html | 9 +++ composer.json | 6 +- ext_emconf.php | 2 +- 17 files changed, 357 insertions(+), 10 deletions(-) create mode 100644 Classes/Domain/DoctrineRepository/PageRepository.php create mode 100644 Classes/Domain/Model/WatchlistItem.php create mode 100644 Classes/Domain/Model/WatchlistItemFactory.php create mode 100644 Classes/Handler/WatchlistItemHandler.php create mode 100644 Classes/ViewHelpers/Product/PageUidViewHelper.php create mode 100644 Configuration/Services.php create mode 100644 Documentation/Changelog/7.2/Feature-274-AddWatchlistItemHandler.rst create mode 100644 Documentation/Changelog/7.2/Index.rst create mode 100644 Resources/Private/Partials/Product/WatchlistButtons.html diff --git a/Classes/Domain/DoctrineRepository/PageRepository.php b/Classes/Domain/DoctrineRepository/PageRepository.php new file mode 100644 index 00000000..7c4f3460 --- /dev/null +++ b/Classes/Domain/DoctrineRepository/PageRepository.php @@ -0,0 +1,39 @@ +connectionPool->getQueryBuilderForTable(self::TABLENAME); + + return $queryBuilder->select('*') + ->from(self::TABLENAME) + ->where( + $queryBuilder->expr()->eq('cart_products_product', $product->getUid()) + ) + ->orderBy('sorting') + ->setMaxResults(1) + ->executeQuery() + ->fetchAssociative(); + } +} diff --git a/Classes/Domain/DoctrineRepository/Product/ProductRepository.php b/Classes/Domain/DoctrineRepository/Product/ProductRepository.php index dd84870f..842c2e8d 100644 --- a/Classes/Domain/DoctrineRepository/Product/ProductRepository.php +++ b/Classes/Domain/DoctrineRepository/Product/ProductRepository.php @@ -1,5 +1,7 @@ connectionPool->getQueryBuilderForTable(self::TABLENAME); + + return $queryBuilder + ->select('uid', 'title', 'images') + ->from(self::TABLENAME) + ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid))) + ->setMaxResults(1) + ->executeQuery() + ->fetchAssociative(); + } + public function getStock(int $uid): int { $queryBuilder = $this->getQueryBuilder(); return $queryBuilder ->select('stock') - ->from('tx_cartproducts_domain_model_product_product') + ->from(self::TABLENAME) ->where( $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) @@ -43,7 +60,7 @@ public function addQuantityToStock(int $uid, int $quantity): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->update('tx_cartproducts_domain_model_product_product') + ->update(self::TABLENAME) ->where( $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)) ) @@ -64,7 +81,7 @@ private function getQueryBuilder(): QueryBuilder { return $this ->connectionPool - ->getConnectionForTable('tx_cartproducts_domain_model_product_product') + ->getConnectionForTable(self::TABLENAME) ->createQueryBuilder(); } } diff --git a/Classes/Domain/Model/WatchlistItem.php b/Classes/Domain/Model/WatchlistItem.php new file mode 100644 index 00000000..c0f21d00 --- /dev/null +++ b/Classes/Domain/Model/WatchlistItem.php @@ -0,0 +1,56 @@ +uid . '-' . $this->detailPid; + } + + public function getType(): string + { + return self::TYPE; + } + + public function getUid(): int + { + return $this->uid; + } + + public function getDetailPid(): int + { + return $this->detailPid; + } + + public function getTitle(): string + { + return $this->title; + } + + public function getFileReference(): ?int + { + return $this->fileReference; + } +} diff --git a/Classes/Domain/Model/WatchlistItemFactory.php b/Classes/Domain/Model/WatchlistItemFactory.php new file mode 100644 index 00000000..b5850ed1 --- /dev/null +++ b/Classes/Domain/Model/WatchlistItemFactory.php @@ -0,0 +1,57 @@ +productRepository->findProductByUid((int)$uid); + + if ($product === false) { + return null; + } + + return new WatchlistItem( + (int)$uid, + (int)$detailPid, + (string)$product['title'], + $this->getFirstImageReference($product), + ); + } + + private function getFirstImageReference(array $product): ?int + { + if (is_string($product['images'] ?? null) === false || $product['images'] === '') { + return null; + } + + $images = explode(',', $product['images']); + + $image = array_pop($images); + + if (is_numeric($image) === false) { + return null; + } + + return (int)$image; + } +} diff --git a/Classes/Handler/WatchlistItemHandler.php b/Classes/Handler/WatchlistItemHandler.php new file mode 100644 index 00000000..130a3e40 --- /dev/null +++ b/Classes/Handler/WatchlistItemHandler.php @@ -0,0 +1,33 @@ +watchlistItemFactory->createFromIdentifier($identifier); + } + + public function handlesType(): string + { + return 'CartProducts'; + } +} diff --git a/Classes/ViewHelpers/Product/PageUidViewHelper.php b/Classes/ViewHelpers/Product/PageUidViewHelper.php new file mode 100644 index 00000000..33908240 --- /dev/null +++ b/Classes/ViewHelpers/Product/PageUidViewHelper.php @@ -0,0 +1,59 @@ +registerArgument( + 'product', + Product::class, + 'product', + true + ); + + $this->registerArgument( + 'settings', + 'array', + 'settings array', + true + ); + } + + public function render(): string + { + $product = $this->arguments['product']; + + $page = $this->pageRepository->getProductPageByProduct($product); + + if ($page) { + return $page['uid']; + } + if ($product->getCategory() && $product->getCategory()->getCartProductShowPid()) { + return $product->getCategory()->getCartProductShowPid(); + } + if ($this->arguments['settings']['showPageUids']) { + return $this->arguments['settings']['showPageUids']; + } + + return $GLOBALS['TSFE']->id; + } +} diff --git a/Configuration/Services.php b/Configuration/Services.php new file mode 100644 index 00000000..a6f964ba --- /dev/null +++ b/Configuration/Services.php @@ -0,0 +1,27 @@ +hasDefinition(ItemHandlerRegistry::class)) { + $watchlistItemHandlerDefinition = new Definition( + WatchlistItemHandler::class + ); + $watchlistItemHandlerDefinition->addTag('watchlist.itemHandler') + ->setAutoconfigured(true) + ->setAutowired(true); + $containerBuilder->addDefinitions( + [ + WatchlistItemHandler::class => $watchlistItemHandlerDefinition, + ] + ); + } +}; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 23122020..e22e64fd 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -6,6 +6,8 @@ services: Extcode\CartProducts\: resource: '../Classes/*' + exclude: + - '../Classes/Handler/WatchlistItemHandler.php' Extcode\CartProducts\EventListener\Create\CheckRequest: tags: diff --git a/Documentation/Changelog/7.2/Feature-274-AddWatchlistItemHandler.rst b/Documentation/Changelog/7.2/Feature-274-AddWatchlistItemHandler.rst new file mode 100644 index 00000000..a8c1d263 --- /dev/null +++ b/Documentation/Changelog/7.2/Feature-274-AddWatchlistItemHandler.rst @@ -0,0 +1,16 @@ +.. include:: ../../Includes.rst.txt + +======================================== +Feature: #274 - Add WatchlistItemHandler +======================================== + +See `Issue 274 `__ + +Description +=========== + +After the release of the werkraummedia/watchlist extension for TYPO3 v13 the +WatchlistItemHandler for extcode/cart-products can be added again. +This allows products to be added to the watchlist. + +.. index:: Frontend diff --git a/Documentation/Changelog/7.2/Index.rst b/Documentation/Changelog/7.2/Index.rst new file mode 100644 index 00000000..72342737 --- /dev/null +++ b/Documentation/Changelog/7.2/Index.rst @@ -0,0 +1,20 @@ +.. include:: ../../Includes.rst.txt + +7.2 Changes +=========== + +**Table of contents** + +.. contents:: + :local: + :depth: 1 + +Features +^^^^^^^^ + +.. toctree:: + :maxdepth: 1 + :titlesonly: + :glob: + + Feature-* diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index 9cfb0ae8..a52b3543 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -10,6 +10,7 @@ ChangeLog :maxdepth: 5 :titlesonly: + 7.2/Index 7.1/Index 7.0/Index 6.0/Index diff --git a/Documentation/Index.rst b/Documentation/Index.rst index f217053e..ca79bb59 100644 --- a/Documentation/Index.rst +++ b/Documentation/Index.rst @@ -20,7 +20,7 @@ Cart Products - extend EXT:cart with products cart_products :Package name: - extcode/cart_products + extcode/cart-products :Version: |release| @@ -60,7 +60,7 @@ Cart Products - extend EXT:cart with products .. card:: :ref:`Introduction ` - Introduction to the extension cart, general information. + Introduction to the extension, general information. .. card:: :ref:`For Administrators ` diff --git a/Documentation/guides.xml b/Documentation/guides.xml index c385dad8..5cacb857 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -11,8 +11,8 @@ interlink-shortcode="extcode/cart_products" /> diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 58725ece..0eb07597 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -57,6 +57,13 @@ back + + add to watchlist + + + remove from watchlist + + Product Listing diff --git a/Resources/Private/Partials/Product/WatchlistButtons.html b/Resources/Private/Partials/Product/WatchlistButtons.html new file mode 100644 index 00000000..e0bcd50c --- /dev/null +++ b/Resources/Private/Partials/Product/WatchlistButtons.html @@ -0,0 +1,9 @@ + + + + diff --git a/composer.json b/composer.json index 62bad8d6..f34362f5 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,8 @@ "typo3/cms-fluid-styled-content": "^13.4", "typo3/cms-install": "^13.4", "typo3/cms-reactions": "^13.4", - "typo3/testing-framework": "^8.2" + "typo3/testing-framework": "^8.2", + "werkraummedia/watchlist": "^3.0" }, "scripts": { "test:cgl": [ @@ -107,5 +108,8 @@ "@test:typoscript:lint", "@test:php" ] + }, + "suggest": { + "werkraummedia/watchlist": "^3.0" } } diff --git a/ext_emconf.php b/ext_emconf.php index 592e9a1a..e3a1b7d6 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Cart - Products', 'description' => 'Shopping Cart(s) for TYPO3 - Products', 'category' => 'plugin', - 'version' => '7.1.0', + 'version' => '7.2.0', 'state' => 'stable', 'author' => 'Daniel Gohlke', 'author_email' => 'ext@extco.de',