Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Enable link to detail view #523

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
55 changes: 55 additions & 0 deletions Classes/Domain/Model/Cart/DetailPageLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Extcode\Cart\Domain\Model\Cart;

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

final class DetailPageLink
{
public function __construct(
protected int $pageUid,
protected string $extensionName = '',
protected string $pluginName = '',
protected string $controller = '',
protected string $action = '',
) {}

public function getPageUid(): int
{
return $this->pageUid;
}

public function getExtensionName(): string
{
return $this->extensionName;
}

public function getPluginName(): string
{
return $this->pluginName;
}

public function getController(): string
{
return $this->controller;
}
public function getAction(): string
{
return $this->action;
}

public function isActionLink(): bool
{
if ($this->pageUid && $this->extensionName && $this->pluginName && $this->controller && $this->action) {
return true;
}
return false;
}
}
28 changes: 28 additions & 0 deletions Classes/Domain/Model/Cart/DetailPageLinkFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Extcode\Cart\Domain\Model\Cart;

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

class DetailPageLinkFactory implements DetailPageLinkFactoryInterface
{
public function getDetailPageLink(
int $detailPageUid,
string $extensionName = '',
string $pluginName = '',
string $controller = '',
string $action = '',
): ?DetailPageLink {
if ($detailPageUid > 0) {
return new DetailPageLink($detailPageUid, $extensionName, $pluginName, $controller, $action);
}
return null;
}
}
23 changes: 23 additions & 0 deletions Classes/Domain/Model/Cart/DetailPageLinkFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Extcode\Cart\Domain\Model\Cart;

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

interface DetailPageLinkFactoryInterface
{
public function getDetailPageLink(
int $detailPageUid,
string $extensionName = '',
string $pluginName = '',
string $controller = '',
string $action = ''
): ?DetailPageLink;
}
12 changes: 12 additions & 0 deletions Classes/Domain/Model/Cart/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Product
*/
protected bool $handleStockInVariants = false;

protected DetailPageLink $detailPageLink;

public function __construct(
protected string $productType,
protected int $productId,
Expand Down Expand Up @@ -698,4 +700,14 @@ public function setHandleStockInVariants(bool $handleStockInVariants): void
{
$this->handleStockInVariants = $handleStockInVariants;
}

public function getDetailPageLink(): DetailPageLink
{
return $this->detailPageLink;
}

public function setDetailPageLink(DetailPageLink $detailPageLink): void
{
$this->detailPageLink = $detailPageLink;
}
}
39 changes: 37 additions & 2 deletions Resources/Private/Partials/Cart/ProductForm/ProductList.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,41 @@
xmlns:cart="http://typo3.org/ns/Extcode/Cart/ViewHelpers"
data-namespace-typo3-fluid="true">

<f:section name="detailLink">
<f:if condition="{product.detailPageLink}">
<f:then>
<f:if condition="{product.detailPageLink.actionLink}">
<f:link.action
pageUid="{product.detailPageLink.pageUid}"
extensionName="{product.detailPageLink.extensionName}"
pluginName="{product.detailPageLink.pluginName}"
controller="{product.detailPageLink.controller}"
action="{product.detailPageLink.action}"
arguments="{product: product.productId}">
{linkedTitle}
</f:link.action>
</f:if>
<f:if condition="!{product.detailPageLink.actionLink} && {product.detailPageLink.pageUid}">
<f:link.page pageUid="{product.detailPageLink.pageUid}">
{linkedTitle}
</f:link.page>
</f:if>

</f:then>
<f:else>
{linkedTitle}
</f:else>
</f:if>
</f:section>

<f:section name="withoutVariant">
<tr class="{f:if(condition: product.quantityInRange, then: '', else: 'danger')}">
<td colspan="2" class="col-md-6">
<div class="product-name">
{product.title} {f:if(condition:'{product.feVariant.value}',then:'- {product.feVariant.value}')}
<f:variable name="linkedTitle">
{product.title} {f:if(condition:'{product.feVariant.value}',then:'- {product.feVariant.value}')}
</f:variable>
<f:render section="detailLink" arguments="{product: product, linkedTitle: linkedTitle}"/>
</div>
<p>
<f:translate key="tx_cart_domain_model_order_product.sku.short"/>
Expand Down Expand Up @@ -59,7 +89,12 @@
<tr class="{f:if(condition: product.quantityInRange, then: '', else: 'danger')}">
<td class="col-md-1">&nbsp;</td>
<td class="col-md-5">
<div class="product-name">{variant.title}</div>
<div class="product-name">
<f:variable name="linkedTitle">
{variant.title}
</f:variable>
<f:render section="detailLink" arguments="{product: product, linkedTitle: linkedTitle}"/>
</div>
<p>
<f:translate key="tx_cart_domain_model_order_product.sku.short"/>
: {variant.completeSku}
Expand Down
Loading