FosterCommerce / klaviyoconnect

A plugin for Craft CMS. Grow your ecommerce business with smarter email automations.
https://klaviyoconnect.fostercommerce.com/
Other
10 stars 10 forks source link

Guest or logged out error #126

Closed daniellelecomte closed 4 months ago

daniellelecomte commented 4 months ago

Hey y'all - I am seeing this error on a Craft 4 site: Craft 4.8.0, Commerce 4.5.4, Klaviyo 5.0.8, PHP 8.2

When I try to finish checkout as a guest, I am greeted with "You must identify a user by email or ID."

Screenshot: https://d.pr/i/hhYCYr

Works just fine when a user is logged in!

We're basically just capturing the subscriber when they place an order.

<form method="post" action="">
    {{ csrfInput() }}
    {{ redirectInput('/checkout/order?number={number}') }}
    {{ hiddenInput('cancelUrl', '/checkout/payment'|hash) }}
    {{ hiddenInput('orderEmail', cart.email) }}

    {# Klaviyo fields #}
    {{ hiddenInput('action', '/klaviyoconnect/api/track') }}
    {{ hiddenInput('confirmOptIn', '0') }}
    {{ hiddenInput('forward', '/commerce/payments/pay') }}

    <div class="mt-4">
        {% namespace cart.gateway.handle|commercePaymentFormNamespace %}
            {{ cart.gateway.getPaymentFormHtml({})|raw }}
        {% endnamespace %}
    </div>

    <div class="py-4">
        <label class="text-lg-2">
            {{ hiddenInput('list', null) }}
            <input type="checkbox" id="subscribe" name="list" value="{{ klaviyo.klaviyoList.id ?? '' }}" checked />
            Subscribe to our newsletter
        </label>
    </div>

    {% include '_components/shared/recaptcha' with { action: 'checkout' } %}

    <button class="btn mt-4 g-recaptcha" data-sitekey="{{ getenv('RECAPTCHA_SITE_KEY') }}" type="submit">Place Order</button>
</form>

Any insight? Thanks!

Related to Issue #1

johnnynotsolucky commented 4 months ago

Hi @daniellelecomte, the track action expects the email field to be named "email", could you try using that as the name of the input instead and see if it resolves your issue?

-    {{ hiddenInput('orderEmail', cart.email) }}
+    {{ hiddenInput('email', cart.email) }}
daniellelecomte commented 4 months ago

Hi @johnnynotsolucky - that did the trick - thank you for the speedy reply! 🙏🏼