(This is all for Commerce, not ubercat)

Currently, the only place I can find that adds a product & variations to mailchimp is the function:

mailchimp_ecommerce_add_product()

Which is called by:

/**
 * Implements hook_commerce_product_insert().
 */
mailchimp_ecommerce_commerce_commerce_product_insert()

Because of this, the module won't add existing products to mailchimp.

The real problem happens when updating these existing products.

mailchimp_ecommerce_update_product()

Is called from:

/**
 * Implements hook_commerce_product_update().
 */
function mailchimp_ecommerce_commerce_commerce_product_update()

Which fires every time a product is saved. So now the module is trying to update a product on Mailchimp's side, failing because it doesn't exist there, and sets a big red error message of "404 - the requested resource could not be found" which is confusing drupal admins:

mailchimp_ecommerce_log_error_message('Unable to update product: ' . $e->getMessage());

I propose two things to fix this:
First, on product_update, a check should be put in place if the product exists on Mailchimp. If it doesn't, then it should create it. This could even be done by the exception handler - if it returns a 404, it should create the product then.

Secondly, all the drupal_set_message(ERROR...) should check the log level before displaying a big red error. Everything is already logged, so why is it displaying big errors without checking if it should? Something like

if (variable_get('error_level', ERROR_REPORTING_HIDE) != ERROR_REPORTING_HIDE) {
  drupal_set_message(ERROR...)
}

Comments

mbreden created an issue. See original summary.

mbreden’s picture

This should fix the drupal_set_messages() from showing up all the time, at least.

firewaller’s picture

Working on functionality for inserting/updating all products via module install and config form to prevent such errors here: https://www.drupal.org/node/2848135#comment-12227383

firewaller’s picture

torgospizza’s picture

Perhaps this should be marked a duplicate of #2848135: Update/add new products after disabling/re-enabling module?

firewaller’s picture

Status: Active » Closed (duplicate)

@torgosPizza yes, this is now a duplicate.

kevster’s picture

Patch on #2 is broken - lines 181, 192 and 214 appear to be truncated? There may be others too.

EDIT: my bad - I just realised its just code example not the actual code that gets patched in!