Skip to content

Commit 8bf518e

Browse files
committed
[TASK] Introduce DetailPageLink object + factory
1 parent 33c37ea commit 8bf518e

File tree

5 files changed

+107
-19
lines changed

5 files changed

+107
-19
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Extcode\Cart\Domain\Model\Cart;
6+
7+
/*
8+
* This file is part of the package extcode/cart.
9+
*
10+
* For the full copyright and license information, please read the
11+
* LICENSE file that was distributed with this source code.
12+
*/
13+
14+
final class DetailPageLink
15+
{
16+
public function __construct(
17+
protected int $pageUid,
18+
protected string $extensionName = '',
19+
protected string $pluginName = '',
20+
protected string $controller = ''
21+
)
22+
{}
23+
24+
public function getPageUid(): int
25+
{
26+
return $this->pageUid;
27+
}
28+
29+
public function getExtensionName(): string
30+
{
31+
return $this->extensionName;
32+
}
33+
34+
public function getPluginName(): string
35+
{
36+
return $this->pluginName;
37+
}
38+
39+
public function getController(): string
40+
{
41+
return $this->controller;
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Extcode\Cart\Domain\Model\Cart;
6+
7+
/*
8+
* This file is part of the package extcode/cart.
9+
*
10+
* For the full copyright and license information, please read the
11+
* LICENSE file that was distributed with this source code.
12+
*/
13+
14+
class DetailPageLinkFactory implements DetailPageLinkFactoryInterface
15+
{
16+
public function getDetailPageLink(
17+
int $detailPageUid,
18+
string $extensionName = '',
19+
string $pluginName = '',
20+
string $controller = ''
21+
): ?DetailPageLink
22+
{
23+
if ($detailPageUid > 0) {
24+
return new DetailPageLink($detailPageUid, $extensionName, $pluginName, $controller);
25+
}
26+
return null;
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Extcode\Cart\Domain\Model\Cart;
6+
7+
/*
8+
* This file is part of the package extcode/cart.
9+
*
10+
* For the full copyright and license information, please read the
11+
* LICENSE file that was distributed with this source code.
12+
*/
13+
14+
interface DetailPageLinkFactoryInterface
15+
{
16+
public function getDetailPageLink(
17+
int $detailPageUid,
18+
string $extensionName = '',
19+
string $pluginName = '',
20+
string $controller = ''
21+
): ?DetailPageLink;
22+
}

Classes/Domain/Model/Cart/Product.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Product
6060
*/
6161
protected bool $handleStockInVariants = false;
6262

63-
protected array $detailPageParameter = [];
63+
protected DetailPageLink $detailPageLink;
6464

6565
public function __construct(
6666
protected string $productType,
@@ -700,18 +700,13 @@ public function setHandleStockInVariants(bool $handleStockInVariants): void
700700
$this->handleStockInVariants = $handleStockInVariants;
701701
}
702702

703-
public function getDetailPageParameter(): array
703+
public function getDetailPageLink(): DetailPageLink
704704
{
705-
return $this->detailPageParameter;
705+
return $this->detailPageLink;
706706
}
707707

708-
public function setDetailPageParameter(array $detailPageParameter): void
708+
public function setDetailPageLink(DetailPageLink $detailPageLink): void
709709
{
710-
$this->detailPageParameter = $detailPageParameter;
711-
}
712-
713-
public function addDetailPageParameter(string $key, int|string $value): void
714-
{
715-
$this->detailPageParameter[$key] = $value;
710+
$this->detailPageLink = $detailPageLink;
716711
}
717712
}

Resources/Private/Partials/Cart/ProductForm/ProductList.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<tr class="{f:if(condition: product.quantityInRange, then: '', else: 'danger')}">
77
<td colspan="2" class="col-md-6">
88
<div class="product-name">
9-
<f:if condition="{product.detailPageParameter.pageUid} && {product.detailPageParameter.extensionName}">
9+
<f:if condition="{product.detailPageLink}">
1010
<f:then>
1111
<f:link.action
12-
pageUid="{product.detailPageParameter.pageUid}"
13-
extensionName="{product.detailPageParameter.extensionName}"
14-
pluginName="{product.detailPageParameter.pluginName}"
15-
controller="{product.detailPageParameter.controller}"
12+
pageUid="{product.detailPageLink.pageUid}"
13+
extensionName="{product.detailPageLink.extensionName}"
14+
pluginName="{product.detailPageLink.pluginName}"
15+
controller="{product.detailPageLink.controller}"
1616
arguments="{product: product.productId}">
1717
{product.title} {f:if(condition:'{product.feVariant.value}',then:'- {product.feVariant.value}')}
1818
</f:link.action>
@@ -77,10 +77,10 @@
7777
<f:if condition="{product.detailPageParameter.pageUid} && {product.detailPageParameter.extensionName}">
7878
<f:then>
7979
<f:link.action
80-
pageUid="{product.detailPageParameter.pageUid}"
81-
extensionName="{product.detailPageParameter.extensionName}"
82-
pluginName="{product.detailPageParameter.pluginName}"
83-
controller="{product.detailPageParameter.controller}"
80+
pageUid="{product.detailPageLink.pageUid}"
81+
extensionName="{product.detailPageLink.extensionName}"
82+
pluginName="{product.detailPageLink.pluginName}"
83+
controller="{product.detailPageLink.controller}"
8484
arguments="{product: product.productId}">
8585
{variant.title}
8686
</f:link.action>

0 commit comments

Comments
 (0)