Dekadinious
Forum Replies Created
-
Forum: Plugins
In reply to: [Mailchimp for WooCommerce] Duplicate entry for primary keyI can’t do that because our store is too large and we got problems the last time we did this. I have therefore done my own research here. I have confirmed that the database table structure is correct and just as you have programmed it to be. I have further confirmed that your hashing function works as expected, so the check for existing rows also works as expected.
The only thing I could think of is that we get a race condition where trackCart fires twice in quick succession, checks the database and sees that there is no existing records, then both function calls tries to insert into the database at the same time. This will mean that the database insert will be locked for the second call while the first is inserting. After that the second call will try to insert, and this will fail because the primary key “email” already exists.
To test this I logged
$uidandmicrotime()before and inside the if-else-block insidetrackCart()in the fileclass-mailchimp-woocommerce-service.phpat about line 875. My logs reveal that on every failed insert we have a race condition. Reinstalling the plugin will not fix that:[19-Aug-2021 08:33:43 UTC] Start: c2d22ee401b8bb66f88fbf81da045b5b 0.38921500 [19-Aug-2021 08:33:43 UTC] Start: c2d22ee401b8bb66f88fbf81da045b5b 0.39203500 [19-Aug-2021 08:33:43 UTC] Insert: c2d22ee401b8bb66f88fbf81da045b5b 0.50978500 [19-Aug-2021 08:33:43 UTC] Insert: c2d22ee401b8bb66f88fbf81da045b5b 0.50977300 [19-Aug-2021 08:33:43 UTC] WordPress database error Duplicate entry[...]This fires twice. I am not completely sure how your plugin is set up, but could it be that you fire this on every add to cart? It seems that way? So if we programatically add something to the cart based on other items that are added to the cart, this could provoke a race condition?
If so, you should do a check for this in the plugin and fix it. This is a normal need for large stores – to be able to dynamically and programatically add and remove from cart based on other items added and removed from the cart.
I am quite sure the best solution would be to do a
ON DUPLICATE KEY UPDATEquery. If you don’t want to do that for some reason, you can lock the table and unlock it like this:$wpdb->query("LOCK TABLES $table WRITE"); try { if (($saved_cart = $wpdb->get_row($sql)) && is_object($saved_cart)) { $statement = "UPDATE {$table} SET <code>cart</code> = '%s', <code>email</code> = '%s', <code>user_id</code> = %s WHERE <code>id</code> = '%s'"; $sql = $wpdb->prepare($statement, array(maybe_serialize($this->cart), $email, $user_id, $uid)); try { $wpdb->query($sql); } catch (\Exception $e) { return false; } } else { try { $wpdb->insert("{$wpdb->prefix}mailchimp_carts", array( 'id' => $uid, 'email' => $email, 'user_id' => (int) $user_id, 'cart' => maybe_serialize($this->cart), 'created_at' => gmdate('Y-m-d H:i:s', time()), )); } catch (\Exception $e) { return false; } } } finally { $wpdb->query("UNLOCK TABLES"); }Tested and works, but I am a bit concerned about the performance implications of this. Let me know if any of this will be implemented.
- This reply was modified 4 years, 10 months ago by Dekadinious.
- This reply was modified 4 years, 10 months ago by Dekadinious.
Hello!
Yes, that is what I was wondering. Is it possible to just have the cronjob skip private products when it runs? We have some situations where the stock gets refilled before products are published. We have a complex syncing system of stock between systems, and can’t always publish private products before the stock gets filled.
This is for products that previously were published. Is it possible to add this feature to the plugin?
Forum: Fixing WordPress
In reply to: Reducing space between footer images with CSSDo you have access to the source code? It seems this is built with Bootstrap, so you could change this:
<section class="widget media_image-4 widget_media_image col-md-4 col-sm-6">To this:
<section class="widget media_image-4 widget_media_image col-md-3 col-sm-6">For the four sections. Either that, or you could just override the whole style with CSS, turning the footer into a grid. This should get you started for desktop styles, but you will need to adjust somewhat, I think:
.content-info .footer-container.container .row { display: grid; grid-auto-flow: column; } .content-info .footer-container.container .row section { display: grid; width: 100%; align-content: center; }Ah, ok, great, I will look more into it! 🙂
Thanks for answering!
How about stuff like get_the_terms etc. Will those functions return all terms in the hierarchy that are parents of the bottom selected term?
You also wrote that “it can be a bad thing”. What exactly? Checking all, or just the bottom one?
Thanks again!
- This reply was modified 5 years ago by Dekadinious.
Hello and thank you!
The variable seems correct, but I still can’t remove the actions and filters the correct way for some reason. I needed to use an alternative way.
Perfect, happy to help 🙂 Then you can mark this as resolved in the sidebar menu 🙂
You probably need to log in to yoursite.com/wp-admin/ and go to Plugins in the menu, then activate them there.
Forum: Developing with WordPress
In reply to: Checking if you are “inside” specific filter or action?Yes, thank you!
I’ll use this instead of the global: https://developer.wordpress.org/reference/functions/current_filter/
I have no idea why that has not come up in any of my Google searches. I probably have omitted the word “current”.
Forum: Developing with WordPress
In reply to: Checking if you are “inside” specific filter or action?Thank you for your answer, but that is not the issue here. I am hooked into two different filters with the same function, and want to know inside that function which of the filters are running at the present moment.
Forum: Fixing WordPress
In reply to: Custom taxonomy suddenly redirects to another pageIt’s very interesting, but I have not found any reason or solution right now. The best I could do was set up an alert if the affected pages are redirected again.
Forum: Developing with WordPress
In reply to: Make Main Product Image 800 x 600It is possible, but it is a matter of asking in the support forum for your theme or the eCommerce-plugin you use on your site (probably WooCommerce?) 🙂
Forum: Fixing WordPress
In reply to: Slug Permalink possible bugYes! I just had a similar problem. Can you read my post here and confirm if it is the same issue?
https://wordpress.org/support/topic/custom-taxonomy-suddenly-redirects-to-another-page/
See also the discussion in the comments here: https://stackoverflow.com/questions/66693234/custom-taxonomy-suddenly-redirects-to-another-page
I would love your thoughts!
Maybe this should be escalated as a possible bug?
Have you manually deleted any plugins from the server? If not, I would imagine you could go back to normal mode and then just activate plugins one by one from the WordPress Dashboard.
Try fetching it again here: