Skip to content

Commit

Permalink
[TASK] Adaption after split of ProductPlugin
Browse files Browse the repository at this point in the history
After the migration of switchableControllerActions
the pluginName can differ which needs to be
considered.
  • Loading branch information
rintisch committed Oct 10, 2024
1 parent fb92dff commit e079a8b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
28 changes: 25 additions & 3 deletions Classes/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,11 @@ public function showFormAction(Product $product = null): ResponseInterface
$product = $this->getProduct();
}

$frontendController = $this->request->getAttribute('frontend.controller');
$detailPageUid = $frontendController->getRequestedId();
$detailLinkData = $this->getDetailLinkData($this->request);

$this->view->assign('product', $product);
$this->view->assign('cartSettings', $this->cartConfiguration['settings']);
$this->view->assign('detailPageUid', $detailPageUid);
$this->view->assign('detailLinkData', $detailLinkData);

$this->assignCurrencyTranslationData();
return $this->htmlResponse();
Expand Down Expand Up @@ -342,4 +341,27 @@ protected function restoreSession(): void
$this->cart = $this->cartUtility->getNewCart($this->cartConfiguration);
$this->sessionHandler->writeCart($this->cartConfiguration['settings']['cart']['pid'], $this->cart);
}

private function getDetailLinkData(Request $request): array
{
$frontendController = $request->getAttribute('frontend.controller');
$requestArguments = $frontendController->getPageArguments()->getArguments();

$pluginNamespace = preg_grep('/tx_cartproducts_.*/', array_keys($requestArguments));
$pluginNamespace = array_shift($pluginNamespace);

$pluginArguments = $requestArguments[$pluginNamespace];
$controller = $pluginArguments['controller'];
$action = $pluginArguments['action'];
$pluginName = preg_replace('/tx_cartproducts_/', '', $pluginNamespace);

$detailPageUid = $frontendController->getRequestedId();

return [
'uid' => $detailPageUid,
'pluginName' => $pluginName,
'controller' => $controller,
'action' => $action,
];
}
}
5 changes: 3 additions & 2 deletions Classes/EventListener/Create/CreateCartProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public function __invoke(RetrieveProductsFromRequestEvent $event): void
$detailPageLink = $this->detailPageLinkFactory->getDetailPageLink(

Check failure on line 59 in Classes/EventListener/Create/CreateCartProduct.php

View workflow job for this annotation

GitHub Actions / code-quality (8.1, ^12.4)

Call to method getDetailPageLink() on an unknown class Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface.

Check failure on line 59 in Classes/EventListener/Create/CreateCartProduct.php

View workflow job for this annotation

GitHub Actions / code-quality (8.2, ^12.4)

Call to method getDetailPageLink() on an unknown class Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface.

Check failure on line 59 in Classes/EventListener/Create/CreateCartProduct.php

View workflow job for this annotation

GitHub Actions / code-quality (8.3, ^12.4)

Call to method getDetailPageLink() on an unknown class Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface.
(int)$request->getArgument('detailPageUid'),
'cartproducts',
'products',
'product'
$request->getArgument('detailPagePluginName'),
$request->getArgument('detailPageController'),
$request->getArgument('detailPageAction')
);
$cartProduct->setDetailPageLink($detailPageLink);

Check failure on line 66 in Classes/EventListener/Create/CreateCartProduct.php

View workflow job for this annotation

GitHub Actions / code-quality (8.1, ^12.4)

Call to an undefined method Extcode\Cart\Domain\Model\Cart\Product::setDetailPageLink().

Check failure on line 66 in Classes/EventListener/Create/CreateCartProduct.php

View workflow job for this annotation

GitHub Actions / code-quality (8.2, ^12.4)

Call to an undefined method Extcode\Cart\Domain\Model\Cart\Product::setDetailPageLink().

Check failure on line 66 in Classes/EventListener/Create/CreateCartProduct.php

View workflow job for this annotation

GitHub Actions / code-quality (8.3, ^12.4)

Call to an undefined method Extcode\Cart\Domain\Model\Cart\Product::setDetailPageLink().
}
Expand Down
5 changes: 4 additions & 1 deletion Resources/Private/Partials/Product/CartForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
additionalAttributes="{data-ajax: '{f:if(condition: \'{settings.addToCartByAjax}\', then: \'1\', else: \'0\')}', data-type: 'slot', data-id: '{slot.uid}'}">
<input type="hidden" name="tx_cart_cart[productType]" value="CartProducts">
<input type="hidden" name="tx_cart_cart[product]" value="{product.uid}">
<input type="hidden" name="tx_cart_cart[detailPageUid]" value="{detailPageUid}">
<input type="hidden" name="tx_cart_cart[detailPageUid]" value="{detailLinkData.uid}">
<input type="hidden" name="tx_cart_cart[detailPagePluginName]" value="{detailLinkData.pluginName}">
<input type="hidden" name="tx_cart_cart[detailPageController]" value="{detailLinkData.controller}">
<input type="hidden" name="tx_cart_cart[detailPageAction]" value="{detailLinkData.action}">

<input class="form-control" type="number" value="1" name="tx_cart_cart[quantity]">
<f:if condition="{product.beVariants}">
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Product/ShowForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<f:if condition="{product}">
<f:if condition="{cartSettings.cart.pid}">
<f:render partial="Product/CartForm"
arguments="{product: product, pid: cartSettings.cart.pid, detailPageUid: detailPageUid}"/>
arguments="{product: product, pid: cartSettings.cart.pid, detailLinkData: detailLinkData}"/>
</f:if>

<div id="product-price">
Expand Down

0 comments on commit e079a8b

Please sign in to comment.