mailchimp / mc-magento2

MailChimp for Magento 2. Syncs all data (subscriber, customers, orders, products) and enables marketing automation with email campaigns, automations, ads, postcards and more.
Open Software License 3.0
157 stars 111 forks source link

API Cart createBatchJson() never sends abandoned cart data #374

Closed portchris closed 6 years ago

portchris commented 6 years ago

Ebizmarts\MailChimp\Model\Api\Cart->createBatchJson() never sends abandoned cart data

Been trying to debug an issue where a client automation report is not populating with information. As far as I am aware, the configuration is set up correctly as the client receives subscribers almost daily. Webhook is also installed and working.

Screenshot: https://snag.gy/v8OUDl.jpg

I added appropriate logging to Cron/Ecommerce.php and Model/Api/Cart.php to see if there are actually any abandoned carts on my Magento store:

public function createBatchJson($magentoStoreId)
    {
        $allCarts = [];
        if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_ABANDONEDCART_ACTIVE, $magentoStoreId)) {
            return $allCarts;
        }

        $this->_firstDate = $this->_helper->getConfigValue(
            \Ebizmarts\MailChimp\Helper\Data::XML_ABANDONEDCART_FIRSTDATE,
            $magentoStoreId
        );
        $this->_counter = 0;
        $mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE, $magentoStoreId);

        $date = $this->_helper->getDateMicrotime();
        $this->_batchId =  \Ebizmarts\MailChimp\Helper\Data::IS_QUOTE.'_'.$date;

    // get all the carts converted in orders (must be deleted on mailchimp)
    $allCarts = array_merge($allCarts, $this->_getConvertedQuotes($mailchimpStoreId, $magentoStoreId));
    $this->_helper->log("Total of " . count($allCarts) . " orders to send in batch");

        // get all the carts modified but not converted in orders
        $allCarts = array_merge($allCarts, $this->_getModifiedQuotes($mailchimpStoreId, $magentoStoreId));
    $this->_helper->log("Total of " . count($allCarts) . " modified quotes to send in batch");

    // get new carts
        $allCarts = array_merge($allCarts, $this->_getNewQuotes($mailchimpStoreId, $magentoStoreId));
        $this->_helper->log("Found " . count($allCarts) . " abandoned carts to send.");
        return $allCarts;
    }

Results were:

[2018-08-21 17:11:14] MailChimpLogger.INFO: Total of 0 orders to send in batch
 [] []
[2018-08-21 17:11:14] MailChimpLogger.INFO: Total of 3 modified quotes to send in batch
 [] []
[2018-08-21 17:11:50] MailChimpLogger.INFO: Found 149 abandoned carts to send.

So I definitely have abandoned cart data to send, but nowhere in this method can you see any call to the API. Should the call be here, or am I missing something?

Preconditions

1. Magento CE 2.2.5 without sample data is installed.
2. mc-magento2 1.0.29 installed and correctly set up.
3. There are active quotes with email addresses in the "quote" db table.
4. Automation email report has been set up on Mailchimp side.
...

Steps to reproduce

Actual and Expected result

Automation data is sent, screenshot supplied is populated with data, automation email is sent to the customer, the customer completes checkout and empties their wallet, Marketing team take credit for a job well done.

gonzaloebiz commented 6 years ago

Hi @portchris

thanks for your feedback. Can you please share your magento configuration screen (with your api key blurred)

Thanks

portchris commented 6 years ago

Yes of course, here we are: https://snag.gy/Z5KkHz.jpg

gonzaloebiz commented 6 years ago

You already look at the cron_schedule table to see the status of the ebizmarts_ecommerce jobs? Are the status success?

portchris commented 6 years ago

Ah, interesting. I can see it says error, some with messages, others without:

*************************** 162. row ***************************
 schedule_id: 1042555
    job_code: ebizmarts_ecommerce
      status: error
    messages:  : 
  created_at: 2018-08-22 05:18:03
scheduled_at: 2018-08-22 05:20:00
 executed_at: 2018-08-22 05:20:04
 finished_at: NULL
*************************** 163. row ***************************
 schedule_id: 1042562
    job_code: ebizmarts_ecommerce
      status: error
    messages:  : 
  created_at: 2018-08-22 05:22:02
scheduled_at: 2018-08-22 05:25:00
 executed_at: 2018-08-22 05:25:04
 finished_at: NULL
*************************** 164. row ***************************
 schedule_id: 1042586
    job_code: ebizmarts_ecommerce
      status: error
    messages:  : 
  created_at: 2018-08-22 05:27:03
scheduled_at: 2018-08-22 05:30:00
 executed_at: 2018-08-22 05:30:04
 finished_at: NULL
*************************** 165. row ***************************
 schedule_id: 1042598
    job_code: ebizmarts_ecommerce
      status: error
    messages: Resource Not Found : The requested resource could not be found.
  created_at: 2018-08-22 05:33:03
scheduled_at: 2018-08-22 05:35:00
 executed_at: 2018-08-22 05:35:03
 finished_at: NULL
*************************** 166. row ***************************
 schedule_id: 1042604
    job_code: ebizmarts_ecommerce
      status: error
    messages: Resource Not Found : The requested resource could not be found.
  created_at: 2018-08-22 05:37:03
scheduled_at: 2018-08-22 05:40:00
 executed_at: 2018-08-22 05:40:04
 finished_at: NULL
*************************** 167. row ***************************
 schedule_id: 1042628
    job_code: ebizmarts_ecommerce
      status: error
    messages: Resource Not Found : The requested resource could not be found.
  created_at: 2018-08-22 05:42:02
scheduled_at: 2018-08-22 05:45:00
 executed_at: 2018-08-22 05:45:03
 finished_at: NULL
*************************** 168. row ***************************
portchris commented 6 years ago

I've been researching this issue, it looks related to #240 but we are on the latest version v1.0.29, where I see both issues #220 and #240 are resolved. Can you think of any reason this might still be appearing?

Thanks in advance for your help on this.

gonzaloebiz commented 6 years ago

@portchris try to update the ebizmarts/mailchimp-lib, the last version help us to debug

Best

portchris commented 6 years ago

Okay, updated to the latest version of ebizmarts/mailchimp-lib - 3.0.17. I've got the latest CRON errors below:

|     1068622 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:53:11 | 2018-08-28 17:55:00 | 2018-08-28 17:55:06 | NULL        |
|     1068614 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:47:15 | 2018-08-28 17:50:00 | 2018-08-28 17:50:24 | NULL        |
|     1068604 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:42:29 | 2018-08-28 17:45:00 | 2018-08-28 17:45:17 | NULL        |
|     1068576 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:37:23 | 2018-08-28 17:40:00 | 2018-08-28 17:40:17 | NULL        |
|     1068568 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:32:10 | 2018-08-28 17:35:00 | 2018-08-28 17:35:09 | NULL        |
|     1068546 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:27:09 | 2018-08-28 17:30:00 | 2018-08-28 17:30:18 | NULL        |
|     1068538 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:22:25 | 2018-08-28 17:25:00 | 2018-08-28 17:25:30 | NULL        |
|     1068531 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:18:06 | 2018-08-28 17:20:00 | 2018-08-28 17:20:12 | NULL        |
|     1068522 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:13:06 | 2018-08-28 17:15:00 | 2018-08-28 17:15:12 | NULL        |
|     1068499 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:07:14 | 2018-08-28 17:10:00 | 2018-08-28 17:10:07 | NULL        |
|     1068489 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 17:02:10 | 2018-08-28 17:05:00 | 2018-08-28 17:05:22 | NULL        |
|     1068481 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:58:12 | 2018-08-28 17:00:00 | 2018-08-28 17:00:25 | NULL        |
|     1068456 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:52:28 | 2018-08-28 16:55:00 | 2018-08-28 16:55:03 | NULL        |
|     1068446 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:47:28 | 2018-08-28 16:50:00 | 2018-08-28 16:50:30 | NULL        |
|     1068439 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:43:20 | 2018-08-28 16:45:00 | 2018-08-28 16:45:27 | NULL        |
|     1068401 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:37:07 | 2018-08-28 16:40:00 | 2018-08-28 16:40:15 | NULL        |
|     1068379 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:33:24 | 2018-08-28 16:35:00 | 2018-08-28 16:35:28 | NULL        |
|     1068371 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:27:29 | 2018-08-28 16:30:00 | 2018-08-28 16:30:27 | NULL        |
|     1068346 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:22:25 | 2018-08-28 16:25:00 | 2018-08-28 16:25:24 | NULL        |
|     1068338 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:17:21 | 2018-08-28 16:20:00 | 2018-08-28 16:20:17 | NULL        |
|     1068330 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:13:31 | 2018-08-28 16:15:00 | 2018-08-28 16:15:17 | NULL        |
|     1068324 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:08:18 | 2018-08-28 16:10:00 | 2018-08-28 16:10:30 | NULL        |
|     1068299 | ebizmarts_ecommerce | error   | Resource Not Found : The requested resource could not be found. | 2018-08-28 16:03:03 | 2018-08-28 16:05:00 | 2018-08-28 16:05:15 | NULL        |
+-------------+---------------------+---------+-----------------------------------------------------------------+---------------------+---------------------+---------------------+-------------+

Whart other kinds of debugging information can I provide you?

gonzaloebiz commented 6 years ago

3.0.17 is a really old version of ebizmarts/mailchimp-lib, please take a look at https://github.com/ebizmarts/mailchimp-lib/releases

Best

portchris commented 6 years ago

I upgraded ebizmarts/mailchimp-lib to the latest version, now I can see more useful error logging:

*************************** 168. row ***************************
 schedule_id: 1097010
    job_code: ebizmarts_ecommerce
      status: error
    messages: Resource Not Found for Api Call: https://us9.api.mailchimp.com/3.0/ecommerce/stores/316612fb9bb0e488398c6168df289538/promo-rules/60/promo-codes - The requested resource could not be found.
  created_at: 2018-09-04 01:08:17
scheduled_at: 2018-09-04 01:10:00
 executed_at: 2018-09-04 01:10:21
 finished_at: NULL
*************************** 169. row ***************************

There was a promotion blocking further processing. I removed this entry from the database:

delete from mailchimp_sync_ecommerce where related_id = 60 and mailchimp_sync_delta is null;

Since then, status = success Thanks for your help on this one. Debugging messages are much clearer!

Data is still not sending to Mailchimp, but I have started getting these errors in the log:

MailChimpLogger.INFO: MailChimp error Invalid Resource for API Call: https://us9.api.mailchimp.com/3.0/batches - The resource submitted could not be validated. For field-specific details, see the 'errors' array.

Can I ask what is the "errors" array, and where is it? Errors page in the admin is blank so I assume it is not that.

Many thanks

gonzaloebiz commented 6 years ago

Hi @portchris

you can view the errors array in the log