Skip to content

Commit

Permalink
feat: Add possibility to save the cart to offcanvas cart (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: Janko <[email protected]>
  • Loading branch information
aragon999 and J4nk0123 authored Nov 1, 2024
1 parent 5d54120 commit 819dda4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@
<description>Enables the native sharing feature on supported devices.</description>
<description lang="de-DE">Aktiviert die native Teilen-Funktion auf unterstützten Endgeräten.</description>
</input-field>

<input-field type="bool">
<name>showSaveCartButtonInOffcanvas</name>
<defaultValue>false</defaultValue>
<label>Show "Save Cart" button in offcanvas cart</label>
<label lang="de-DE">"Warenkorb speichern" Button im Offcanvas-Warenkorb anzeigen</label>
</input-field>
</card>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% sw_extends '@Storefront/storefront/component/checkout/offcanvas-cart.html.twig' %}

{% block component_offcanvas_cart_actions_cart %}
{{ parent() }}

{% if config('FroshPlatformShareBasket.config.showSaveCartButtonInOffcanvas') %}
{% block frosh_share_basket_offcanvas %}
{% if page.froshShareBasketState == 'cartExists' %}
{% block frosh_share_basket_offcanvas_existing_cart %}
{% sw_include '@Storefront/storefront/utilities/frosh-share-basket.html.twig' with {
froshShareBasketUrl: page.froshShareBasketUrl,
froshShareBasketState: page.froshShareBasketState,
} %}
{% endblock %}
{% elseif page.froshShareBasketState != 'cartLoaded' %}
{% set froshBasketAjaxSubmitOptions = {
replaceSelectors: ".js-frosh-share-basket-container",
submitOnce: true,
} %}

{% block frosh_share_basket_offcanvas_form %}
<div class="js-frosh-share-basket-container" data-frosh-share-basket-buttons="true">
<form action="{{ path('frontend.frosh.share-basket.save') }}"
method="post"
class="js-frosh-share-basket-form"
data-form-ajax-submit="true"
data-form-ajax-submit-options="{{ froshBasketAjaxSubmitOptions|json_encode }}">
{% block frosh_share_basket_offcanvas_save_button %}
<button type="submit" class="btn btn-link w-100">
{{ "frosh-share-basket.saveCart"|trans }}
</button>
{% endblock %}
</form>
</div>
{% endblock %}
{% endif %}
{% endblock %}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Frosh\ShareBasket\Services\ShareBasketServiceInterface;
use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CheckoutPageSubscriber implements EventSubscriberInterface
Expand All @@ -16,10 +17,11 @@ public static function getSubscribedEvents(): array
{
return [
CheckoutCartPageLoadedEvent::class => 'onCartLoaded',
OffcanvasCartPageLoadedEvent::class => 'onCartLoaded',
];
}

public function onCartLoaded(CheckoutCartPageLoadedEvent $event): void
public function onCartLoaded(CheckoutCartPageLoadedEvent|OffcanvasCartPageLoadedEvent $event): void
{
if (!$event->getRequest()->hasSession()) {
return;
Expand Down

0 comments on commit 819dda4

Please sign in to comment.