Skip to content

Commit

Permalink
[FEATURE] Enable link from cart to detail view
Browse files Browse the repository at this point in the history
This is a needed adaption to make it possible
that a product detail view can be linked from
the product list of the cart.

Fixes: extcode#167
  • Loading branch information
rintisch committed Jun 11, 2024
1 parent 7f8f37d commit 894ec7f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Classes/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function showAction(Product $product = null): ResponseInterface
return new ForwardResponse('list');
}


$this->view->assign('user', $GLOBALS['TSFE']->fe_user->user);
$this->view->assign('product', $product);
$this->view->assign('cartSettings', $this->cartConfiguration['settings']);
Expand All @@ -200,8 +201,12 @@ public function showFormAction(Product $product = null): ResponseInterface
$product = $this->getProduct();
}

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

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

$this->assignCurrencyTranslationData();
return $this->htmlResponse();
Expand Down
7 changes: 6 additions & 1 deletion Classes/EventListener/Create/CreateCartProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function __invoke(RetrieveProductsFromRequestEvent $event): void
$taxClasses[$productProduct->getTaxClassId()],
(int)$request->getArgument('quantity'),
$productProduct->getIsNetPrice(),
$event->getCartFeVariant()
$event->getCartFeVariant(),
$request->getArgument('detailViewParameter')
);

$cartProduct->setMaxNumberInCart($productProduct->getMaxNumberInOrder());
Expand All @@ -53,6 +54,10 @@ public function __invoke(RetrieveProductsFromRequestEvent $event): void
$cartProduct->setIsVirtualProduct(true);
}

$cartProduct->addDetailViewParameter('extensionName', 'cartproducts');
$cartProduct->addDetailViewParameter('pluginName', 'products');
$cartProduct->addDetailViewParameter('controller', 'product');

$event->setCartProduct($cartProduct);
}
}
1 change: 1 addition & 0 deletions Resources/Private/Partials/Product/CartForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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[detailViewParameter][pageUid]" value="{detailViewPageUid}">

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

<div id="product-price">
Expand All @@ -18,4 +19,4 @@
</f:if>
</f:if>
</f:section>
</html>
</html>

0 comments on commit 894ec7f

Please sign in to comment.