Poorly executed module

Created on 19 August 2025, 3 months ago

# Mailchimp E-commerce Module Issues Summary

Problem/Motivation

The Mailchimp E-commerce module for Drupal Commerce has several critical issues that prevent proper product synchronization and abandoned cart functionality:

1. **Fatal errors during product sync**: `Call to a member function get() on null` when entity references become stale
2. **Incorrect entity ID handling**: Sync operations use incorrect array functions, causing invalid entity IDs to be processed
3. **Empty product images**: Images appear as spinning placeholders because non-absolute URLs are sent to external API
4. **Broken abandoned cart emails**: Automations never trigger because entity updates are only sent during user interaction, not on a time-based schedule
5. **Duplicate entity errors**: Attempting to add existing entities results in API errors instead of graceful updates

Steps to reproduce

**Product Sync Issues:**
1. Delete some Commerce products from Drupal
2. Run product sync via admin interface
3. Observe fatal error: "Call to a member function get() on null"
4. Note only a small subset of products sync instead of the full catalog
5. Check Mailchimp - product images show as spinning placeholders

**Abandoned Cart Issues:**
1. Add items to cart with valid email address
2. Abandon cart (leave site)
3. Wait several hours
4. No abandoned cart email is sent
5. Return to cart and interact with it (add/remove/update items) - cron does NOT help
6. Abandoned cart email finally triggers when user visits cart ( dumb )

Proposed resolution

**Immediate fixes implemented:**
1. **Null guard in BatchSyncProducts**: Skip deleted products gracefully instead of fatal error
2. **Correct product ID handling**: Use `array_values($result)` in sync form to get actual entity IDs
3. **Filter invalid IDs**: Use `Product::loadMultiple()` to filter to existing products before batching
4. **Absolute image URLs**: Enhanced `getProductImageUrl()` to generate absolute file URLs for ExoAsset β†’ Media β†’ File chains
5. **Update on duplicate**: When addProduct fails with "already exists", automatically attempt updateProduct

**Long-term fixes needed:**
1. **Abandoned cart cron job**: Implement periodic cart timestamp updates in Mailchimp to trigger time-based automations
2. **Event-driven cart abandonment**: Send explicit "cart abandoned" events after periods of inactivity
3. **Proper image field configuration**: Ensure image field mapping is configured during module installation

Remaining tasks

- [ ] Implement cron-based abandoned cart timestamp refresh mechanism
- [ ] Add configuration UI for abandoned cart timing settings
- [ ] Create proper "cart abandoned" event triggers
- [ ] Add automated tests for product sync edge cases
- [ ] Improve error handling and logging throughout the module
- [ ] Document proper image field configuration requirements

User interface changes

- Enhanced product sync form to handle large catalogs without timeouts (reduced batch size)
- Improved error messaging for sync failures
- Better progress tracking during batch operations
- Configuration form should include image field mapping guidance

API changes

- Modified `ProductHandler::getProductImageUrl()` to support ExoAsset and Media entities
- Enhanced `ProductHandler::addProduct()` to fall back to updateProduct on conflicts
- Updated batch processing to filter invalid product IDs before API calls
- Improved error handling for Mailchimp API responses

Data model changes

- No database schema changes required
- Configuration changes: `mailchimp_ecommerce.settings.mailchimp_ecommerce_product_image` must be set to appropriate field name
- Batch processing now filters product IDs to ensure they reference valid Commerce products
- Cart timestamp handling needs architectural changes for proper abandonment tracking

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States thronedigital

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024