Skip to content

Commit

Permalink
[TASK] Introduce DetailPageLink object + factory
Browse files Browse the repository at this point in the history
  • Loading branch information
rintisch committed Jun 20, 2024
1 parent 33c37ea commit 8bf518e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 19 deletions.
43 changes: 43 additions & 0 deletions Classes/Domain/Model/Cart/DetailPageLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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 = ''
)
{}

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;
}
}
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 = ''
): ?DetailPageLink
{
if ($detailPageUid > 0) {
return new DetailPageLink($detailPageUid, $extensionName, $pluginName, $controller);
}
return null;
}
}
22 changes: 22 additions & 0 deletions Classes/Domain/Model/Cart/DetailPageLinkFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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 = ''
): ?DetailPageLink;
}
15 changes: 5 additions & 10 deletions Classes/Domain/Model/Cart/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Product
*/
protected bool $handleStockInVariants = false;

protected array $detailPageParameter = [];
protected DetailPageLink $detailPageLink;

public function __construct(
protected string $productType,
Expand Down Expand Up @@ -700,18 +700,13 @@ public function setHandleStockInVariants(bool $handleStockInVariants): void
$this->handleStockInVariants = $handleStockInVariants;
}

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

public function setDetailPageParameter(array $detailPageParameter): void
public function setDetailPageLink(DetailPageLink $detailPageLink): void
{
$this->detailPageParameter = $detailPageParameter;
}

public function addDetailPageParameter(string $key, int|string $value): void
{
$this->detailPageParameter[$key] = $value;
$this->detailPageLink = $detailPageLink;
}
}
18 changes: 9 additions & 9 deletions Resources/Private/Partials/Cart/ProductForm/ProductList.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<tr class="{f:if(condition: product.quantityInRange, then: '', else: 'danger')}">
<td colspan="2" class="col-md-6">
<div class="product-name">
<f:if condition="{product.detailPageParameter.pageUid} && {product.detailPageParameter.extensionName}">
<f:if condition="{product.detailPageLink}">
<f:then>
<f:link.action
pageUid="{product.detailPageParameter.pageUid}"
extensionName="{product.detailPageParameter.extensionName}"
pluginName="{product.detailPageParameter.pluginName}"
controller="{product.detailPageParameter.controller}"
pageUid="{product.detailPageLink.pageUid}"
extensionName="{product.detailPageLink.extensionName}"
pluginName="{product.detailPageLink.pluginName}"
controller="{product.detailPageLink.controller}"
arguments="{product: product.productId}">
{product.title} {f:if(condition:'{product.feVariant.value}',then:'- {product.feVariant.value}')}
</f:link.action>
Expand Down Expand Up @@ -77,10 +77,10 @@
<f:if condition="{product.detailPageParameter.pageUid} && {product.detailPageParameter.extensionName}">
<f:then>
<f:link.action
pageUid="{product.detailPageParameter.pageUid}"
extensionName="{product.detailPageParameter.extensionName}"
pluginName="{product.detailPageParameter.pluginName}"
controller="{product.detailPageParameter.controller}"
pageUid="{product.detailPageLink.pageUid}"
extensionName="{product.detailPageLink.extensionName}"
pluginName="{product.detailPageLink.pluginName}"
controller="{product.detailPageLink.controller}"
arguments="{product: product.productId}">
{variant.title}
</f:link.action>
Expand Down

0 comments on commit 8bf518e

Please sign in to comment.