Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Classes/Domain/DoctrineRepository/PageRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Extcode\CartProducts\Domain\DoctrineRepository;

use Doctrine\DBAL\Exception;
use Extcode\CartProducts\Domain\Model\Product\Product;
use TYPO3\CMS\Core\Database\ConnectionPool;

final class PageRepository
{
public const TABLENAME = 'pages';

public function __construct(
private readonly ConnectionPool $connectionPool,
) {}

/**
* @return array<string,mixed>|false
* @throws Exception
*/
public function getProductPageByProduct(Product $product)
{
$queryBuilder = $this->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();
}
}
28 changes: 24 additions & 4 deletions Classes/Domain/DoctrineRepository/Product/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,43 @@
* LICENSE file that was distributed with this source code.
*/

use Doctrine\DBAL\Exception;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;

class ProductRepository
{
public const TABLENAME = 'tx_cartproducts_domain_model_product_product';

public function __construct(
private readonly ConnectionPool $connectionPool
private readonly ConnectionPool $connectionPool,
) {}

/**
* @return array<string,mixed>|false
* @throws Exception
*/
public function findProductByUid(int $uid)
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLENAME);

return $queryBuilder
->select('product.title')
->from(self::TABLENAME, 'product')
->where($queryBuilder->expr()->eq('product.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))
)
Expand All @@ -43,7 +63,7 @@ public function addQuantityToStock(int $uid, int $quantity)
$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))
)
Expand All @@ -64,7 +84,7 @@ private function getQueryBuilder(): QueryBuilder
{
return $this
->connectionPool
->getConnectionForTable('tx_cartproducts_domain_model_product_product')
->getConnectionForTable(self::TABLENAME)
->createQueryBuilder();
}
}
45 changes: 45 additions & 0 deletions Classes/Domain/Model/WatchlistItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Extcode\CartProducts\Domain\Model;

use WerkraumMedia\Watchlist\Domain\Model\Item;

final class WatchlistItem implements Item
{
private readonly string $type;

public function __construct(
private readonly int $uid,
private readonly int $detailPid,
private readonly string $title,
) {
$this->type = 'CartProducts';
}

public function getUniqueIdentifier(): string
{
return $this->type . '-' . $this->uid . '-' . $this->detailPid;
}

public function getType(): string
{
return $this->type;
}

public function getUid(): int
{
return $this->uid;
}

public function getDetailPid(): int
{
return $this->detailPid;
}

public function getTitle(): string
{
return $this->title;
}
}
46 changes: 46 additions & 0 deletions Classes/Handler/WatchlistItemHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Extcode\CartProducts\Handler;

/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\CartProducts\Domain\DoctrineRepository\Product\ProductRepository;
use Extcode\CartProducts\Domain\Model\WatchlistItem;
use WerkraumMedia\Watchlist\Domain\ItemHandlerInterface;
use WerkraumMedia\Watchlist\Domain\Model\Item;

final class WatchlistItemHandler implements ItemHandlerInterface
{
public function __construct(
private readonly ProductRepository $productRepository,
) {}

public function return(string $identifier): ?Item
{
list($uid, $detailPid) = explode('-', $identifier);

$product = $this->productRepository->findProductByUid((int)$uid);

if ($product === false) {
return null;
}

return new WatchlistItem(
(int)$uid,
(int)$detailPid,
(string)$product['title']
);
}

public function handlesType(): string
{
return 'CartProducts';
}
}
59 changes: 59 additions & 0 deletions Classes/ViewHelpers/Product/PageUidViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Extcode\CartProducts\ViewHelpers\Product;

/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\CartProducts\Domain\DoctrineRepository\PageRepository;
use Extcode\CartProducts\Domain\Model\Product\Product;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class PageUidViewHelper extends AbstractViewHelper
{
public function __construct(
private readonly PageRepository $pageRepository,
) {}

public function initializeArguments()
{
parent::initializeArguments();

$this->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;
}
}
27 changes: 27 additions & 0 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Extcode\CartProducts\Configuration;

use Extcode\CartProducts\Handler\WatchlistItemHandler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use WerkraumMedia\Watchlist\Domain\ItemHandlerRegistry;

return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder) {
if ($containerBuilder->hasDefinition(ItemHandlerRegistry::class)) {
$watchlistItemHandlerDefinition = new Definition(
WatchlistItemHandler::class
);
$watchlistItemHandlerDefinition->addTag('watchlist.itemHandler')
->setAutoconfigured(true)
->setAutowired(true);
$containerBuilder->addDefinitions(
[
WatchlistItemHandler::class => $watchlistItemHandlerDefinition,
]
);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. include:: ../../Includes.rst.txt

========================================
Feature: #262 - Add WatchlistItemHandler
========================================

See `Issue 262 <https://github.com/extcode/cart_products/issues/262>`__

Description
===========

After the release of the werkraummedia/watchlist extension for TYPO3 v12 the
WatchlistItemHandler for extcode/cart-products can be added again.
This allows products to be added to the watchlist.

.. index:: Frontend
20 changes: 20 additions & 0 deletions Documentation/Changelog/6.2/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. include:: ../../Includes.rst.txt

6.2 Changes
===========

**Table of contents**

.. contents::
:local:
:depth: 1

Features
^^^^^^^^

.. toctree::
:maxdepth: 1
:titlesonly:
:glob:

Feature-*
1 change: 1 addition & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ChangeLog
:maxdepth: 5
:titlesonly:

6.2/Index
6.1/Index
6.0/Index
5.0/Index
Expand Down
4 changes: 2 additions & 2 deletions Documentation/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Cart Products - extend EXT:cart with products
cart_products

:Package name:
extcode/cart_products
extcode/cart-products

:Version:
|release|
Expand Down Expand Up @@ -60,7 +60,7 @@ Cart Products - extend EXT:cart with products

.. card:: :ref:`Introduction <introduction>`

Introduction to the extension cart, general information.
Introduction to the extension, general information.

.. card:: :ref:`For Administrators <administrator>`

Expand Down
4 changes: 2 additions & 2 deletions Documentation/guides.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
interlink-shortcode="extcode/cart_products"
/>
<project title="Cart Products"
release="6.1.0"
version="6.1"
release="6.2.0"
version="6.2"
copyright="2018 - 2025"
/>
<inventory id="t3tsref" url="https://docs.typo3.org/typo3cms/TyposcriptReference/"/>
Expand Down
7 changes: 7 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<source>back</source>
</trans-unit>

<trans-unit id="tx_cartproducts.add_to_watchlist">
<source>add to watchlist</source>
</trans-unit>
<trans-unit id="tx_cartproducts.remove_from_watchlist">
<source>remove from watchlist</source>
</trans-unit>

<trans-unit id="tx_cartproducts.module.productController.listAction.header">
<source>Product Listing</source>
</trans-unit>
Expand Down
9 changes: 9 additions & 0 deletions Resources/Private/Partials/Product/WatchlistButtons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:cartproducts="http://typo3.org/ns/Extcode/CartProducts/ViewHelpers"
data-namespace-typo3-fluid="true">

<button data-watchlist-item="CartProducts-{product.uid}-{cartproducts:product.pageUid(product: product, settings: settings)}" class="watchlist-btn watchlist-inactive">
<span class="add-to-list"><f:translate key="tx_cartproducts.add_to_watchlist"/></span>
<span class="remove-from-list"><f:translate key="tx_cartproducts.remove_from_watchlist"/></span>
</button>
</html>
Loading