-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Integrity constraint violation - Duplicate entry #411
Comments
That is clearly a Commerce error. Does it work again when you revert sprigifying the form? I'm not seeing anything immediately obvious that might cause the error. |
Ok, thanks, I just wanted to be sure that I haven't committed a basic error. Also I've made a small component to test and it all worked out fine:
Component:
Thanks for having looked into it. |
Yes, it works like it should when I revert it to normal. |
Hi @outline4 Thank you for writing into support to notify us about this one. Catching up with the comments above, am I right in understanding that when this is just a normal form without using Sprig and just using the native Commerce functionality everything works correctly? Thanks! |
A normal form works correctly. |
To be a 100% sure, I also deactivated "Language Redirector". Still: the error persists |
I think if this is the case we need to hand it back over to @bencroker to see if he can decipher what might be happening. Would be interesting to know what requests are being sent Commerce's way based on the component you came up with. |
Hi @bencroker. Are you able to test this on a commerce 5 site? |
Yes, I’ll do some testing today and let you know what I find. |
@outline4 could you please test whether this is still an issue using Sprig 3.5.2? |
I just did a test. Sprig 3.5.2 generates the same error. |
I tested your code above and it works without any issues – the product is added to the cart. Can you please test using different product and variant IDs. |
Ok, so I guess it has something to do with sites. Sites have caused other problems with craft commerce. Thanks for testing! |
Sure thing. If it turns out to be Sprig related, please let me know. |
Hi This sounds like potentially the current site is being lost during the interaction with Sprig. It could be worth trying to add Hope this helps, thanks! |
@nfourtythree you're a live saver! This did the trick! @bencroker is this the official way or a bug? |
Now I try to update the #mini-cart component, and it's failing me. In the _add_to_cart component I have this:
(I did also try I call the mini-cart component the following way:
I've temporarily hard coded the Site for debugging purposes (I tried with and without s-headers). The mini-cart component is the following:
But it's not refreshing the component. How can I debug it further? Everything is on the latest version. |
The site ID should be passed through as part of the config param. You should see it encoded in the URL, something like this: The issue with refreshing the cart component is likely related, I’d suggest figuring out the site ID issue first. FYI you can use the Twig tags Sprig provides. {% if addedToCart %}
{% do sprig.triggerRefresh('#mini-cart') %}
{% endif %} |
ok, thanks. I've added the following:
with the following output:
and for the mini-cart component:
with this output:
still: no refresh... Why is this so hard? hope I can get this sorted somehow! I love sprig! Especially for online shops! Edit: added the siteId to the component attributes |
You haven’t really changed anything. My assumption that the |
I've added the The add-to-cart is working, I get a status 200 and an output. The refresh for I have the exact same code on a commerce 4 website with only one shop and one site, and all is working out well. Adding Where would I need to put this in the Maybe you see an obvious error here |
What I meant was that the site ID should already be passed through as part of the config param. I see that it is from your previous comment. When I add a product to the cart at https://www.ingwerer.shop/de-ch/ it appears to work. It just is not refreshing the cart. Correct? Can you show me the Sprig component as it is now? |
This is the mini-cart component:
This is the add-to-cart component:
note that without so I guess something similar needs to be transmitted to refresh the #mini-cart component. |
As per the docs, can you check for success as follows? {% if sprig.isSuccess %}
{% do sprig.triggerRefresh('#mini-cart') %}
{% elseif sprig.isError %}
{{ sprig.message }}
{% endif %} |
I've added this: still the same. I was pretty sure that it already was a success since the product is added. What else could I be watching? |
I've deleted the siteId config param. I don't see a change in behaviour... I click the add-to-cart button. The success message is displayed. The product is added to the cart. I don't see a change in the mini-cart component until I manually refresh the site. |
What is the error? You may have to find it in the logs. |
the error 500 is the same as before: "Integrity constraint violation – yii\db\IntegrityException ok, we're getting somewhere! |
my guess is that you need to incorporate the s-headers within {% do sprig.triggerRefresh('#mini-cart') %} Edit: but I don't know how? |
I’ll have to look into this. This is the first report I’ve had of such an issue, so it may be specific to Commerce or to your setup. |
I am really sorry that you have to go through all of this and really glad that you are trying to help! Can I send you something per email? DB, templates, composer.json? |
There's some things that might be worthy of knowing:
this has also lead to some commerce bugs. |
I’m always happy to help, just please do keep in mind that Sprig is a free plugin. If you need me to prioritise this and have some budget for it, please get in touch at [email protected] |
Support Request
Hi, It's been a while since I've used sprig in combination with craft commerce.
I've hit a wall with the most basic action I would like to perform.
I want to make the add-to-cart button reactive.
This is the original and well working code:
so I've put this code within a component like this:
the component looks like this:
basically I've just eliminated
{{ csrfInput() }}
and{{ actionInput('commerce/cart/update-cart') }}
and added sprig and the corresponding s-actionI get an error 500 saying:
Integrity constraint violation – yii\db\IntegrityException
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '15240990b0121e9bf6812c3fbf927ccf' for key 'craft_idx_zccrurnkljlvdkbflcexnuqnhqeijrwxibox'
The SQL being executed was: INSERT INTO
craft_commerce_orders
(id
,storeId
,number
,reference
,itemTotal
,itemSubtotal
,email
,orderCompletedEmail
,isCompleted
,dateOrdered
,datePaid
,dateAuthorized
,shippingMethodHandle
,shippingMethodName
,paymentSourceId
,gatewayId
,orderStatusId
,couponCode
,total
,totalPrice
,totalPaid
,totalDiscount
,totalShippingCost
,totalTax
,totalTaxIncluded
,totalQty
,totalWeight
,currency
,lastIp
,orderLanguage
,orderSiteId
,origin
,paymentCurrency
,customerId
,registerUserOnOrderComplete
,saveBillingAddressOnOrderComplete
,saveShippingAddressOnOrderComplete
,returnUrl
,cancelUrl
,message
,paidStatus
,recalculationMode
,sourceShippingAddressId
,sourceBillingAddressId
,dateUpdated
,dateCreated
,shippingAddressId
,billingAddressId
,uid
) VALUES (969, 2, '15240990b0121e9bf6812c3fbf927ccf', NULL, '0', '0', '[email protected]', NULL, 0, NULL, NULL, NULL, 'ch', 'Spedition CH', NULL, NULL, NULL, NULL, '0', '0', '0', '0', '0', '0', '0', 0, '0', 'CHF', '169.155.235.224', 'de-CH', 1, 'web', 'CHF', 802, 0, 0, 0, NULL, NULL, NULL, 'unpaid', 'all', 828, 828, '2025-01-16 18:33:13', '2025-01-16 18:33:13', 967, 968, '896a32ce-ab07-49ab-940f-531971db7af9')What am I missing?
It could be very obvious...
Any help appreciated!
-Stefan
Systeminformationen
PHP-Version: 8.3.14
Betriebssystem: Linux 5.14.0-427.42.1.el9_4.x86_64
Datenbanktreiber & Version: MariaDB 10.11.10
Image-Treiber & Version: Imagick 3.7.0 (ImageMagick 7.1.1-39)
Craft-Version: Craft Pro 5.5.9
Yii-Version: 2.0.51
Twig-Version: v3.14.2
Guzzle-Version: 7.9.2
Plugins
Plugin Version
3.5.1
The text was updated successfully, but these errors were encountered: