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 from cart to detail view #175

Open
wants to merge 5 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
26 changes: 26 additions & 0 deletions Classes/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ public function showFormAction(Product $product = null): ResponseInterface
$product = $this->getProduct();
}

$detailLinkData = $this->getDetailLinkData($this->request);

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

$this->assignCurrencyTranslationData();
return $this->htmlResponse();
Expand Down Expand Up @@ -338,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,
];
}
}
13 changes: 13 additions & 0 deletions Classes/EventListener/Create/CreateCartProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
* LICENSE file that was distributed with this source code.
*/

use Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface;
use Extcode\Cart\Domain\Model\Cart\Product;
use Extcode\CartProducts\Event\RetrieveProductsFromRequestEvent;

class CreateCartProduct
{
public function __construct(protected DetailPageLinkFactoryInterface $detailPageLinkFactory) {}

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

View workflow job for this annotation

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

Parameter $detailPageLinkFactory of method Extcode\CartProducts\EventListener\Create\CreateCartProduct::__construct() has invalid type Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface.

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

View workflow job for this annotation

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

Property Extcode\CartProducts\EventListener\Create\CreateCartProduct::$detailPageLinkFactory has unknown class Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface as its type.

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

View workflow job for this annotation

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

Parameter $detailPageLinkFactory of method Extcode\CartProducts\EventListener\Create\CreateCartProduct::__construct() has invalid type Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface.

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

View workflow job for this annotation

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

Property Extcode\CartProducts\EventListener\Create\CreateCartProduct::$detailPageLinkFactory has unknown class Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface as its type.

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

View workflow job for this annotation

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

Parameter $detailPageLinkFactory of method Extcode\CartProducts\EventListener\Create\CreateCartProduct::__construct() has invalid type Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface.

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

View workflow job for this annotation

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

Property Extcode\CartProducts\EventListener\Create\CreateCartProduct::$detailPageLinkFactory has unknown class Extcode\Cart\Domain\Model\Cart\DetailPageLinkFactoryInterface as its type.
public function __invoke(RetrieveProductsFromRequestEvent $event): void
{
$request = $event->getRequest();
Expand Down Expand Up @@ -53,6 +55,17 @@
$cartProduct->setIsVirtualProduct(true);
}

if ($request->getArgument('detailPageUid')) {
$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',
$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().
}

$event->setCartProduct($cartProduct);
}
}
4 changes: 4 additions & 0 deletions Resources/Private/Partials/Product/CartForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +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="{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
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, detailLinkData: detailLinkData}"/>
</f:if>

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