shopware6shopware6-app

Ho do i get the app config data/customer data, guest or logged in, in an app script?


I try to create an app script where i need to deny the finish process of an order under defined circumstances. Therefore i need access to the date of birth from a customer and a given variable in my app config. How can i get them?

The line-items for example i get like this:

{# @var services \Shopware\Core\Framework\Script\ServiceStubs #}
{% set items = services.cart.items %}

Solution

  • You can get the customer from the SalesChannelContext, given they're logged in.

    {% if hook.salesChannelContext.customer %}
        {% set birthday = hook.salesChannelContext.customer.birthday %}
    {% endif %}
    

    Regarding your comment, the cart manipulation hook is probably what you want to use. For instance you could use the script to add errors and notifications to the cart given a condition based on the birthday.