Skip to content
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

Issue361 #380

Merged
merged 3 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Controller/Adminhtml/Stores/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function execute()
return $resultRedirect->setPath('mailchimp/stores');
} catch (\Mailchimp_Error $e) {
$this->messageManager->addError(__('Store could not be deleted.'.$e->getMessage()));
$this->_helper->log($e->getFriendlyMessage());
return $resultRedirect->setPath('mailchimp/stores/edit', ['id'=>$storeId]);
}
}
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Stores/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function execute()
}
} catch (\Mailchimp_Error $e) {
$this->messageManager->addErrorMessage(__('Store could not be saved.'.$e->getMessage()));
$this->_helper->log($e->getFriendlyMessage());
return $resultRedirect->setPath('mailchimp/stores/edit', ['id'=>$storeId]);
}
}
Expand Down
9 changes: 8 additions & 1 deletion Cron/Ecommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId)
$countProducts = 0;
$countOrders = 0;
$batchArray = [];
$this->_helper->resetCounters();
$results = $this->_apiSubscribers->sendSubscribers($storeId, $listId);
if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ECOMMERCE_ACTIVE, $storeId)) {
$products = $this->_apiProduct->_sendProducts($storeId);
Expand Down Expand Up @@ -206,7 +207,7 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId)
$this->_mailChimpSyncBatches->setMailchimpStoreId($mailchimpStoreId);
$this->_mailChimpSyncBatches->getResource()->save($this->_mailChimpSyncBatches);
$batchId = $batchResponse['id'];
$this->_helper->log("Sent batch $batchId");
$this->_showResume($batchId);
}
}
} catch (\Mailchimp_Error $e) {
Expand Down Expand Up @@ -260,4 +261,10 @@ protected function _ping($storeId)
}
return true;
}
protected function _showResume($batchId)
{
$this->_helper->log("Sent batch $batchId");
$this->_helper->log($this->_helper->getCounters());

}
}
28 changes: 28 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
const PLATFORM = 'Magento2';
const MAXSTORES = 200;

const SUB_MOD = "SubscriberModified";
const SUB_NEW = "SubscriberNew";
const PRO_MOD = "ProductModified";
const PRO_NEW = "ProductNew";
const CUS_MOD = "CustomerModified";
const CUS_NEW = "CustomerNew";
const ORD_MOD = "OrderModified";
const ORD_NEW = "OrderNew";
const QUO_MOD = "QuoteModified";
const QUO_NEW = "QuoteNew";

protected $counters = [];
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
Expand Down Expand Up @@ -1060,4 +1072,20 @@ public function getAllApiKeys() {
}
return $apiKeys;
}
public function modifyCounter($index, $increment=1)
{
if(array_key_exists($index,$this->counters)) {
$this->counters[$index] = $this->counters[$index] + $increment;
} else {
$this->counters[$index] = 1;
}
}
public function resetCounters()
{
$this->counters = [];
}
public function getCounters()
{
return $this->counters;
}
}
2 changes: 2 additions & 0 deletions Model/Api/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ protected function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId)
if (count($cart->getAllVisibleItems())) {
$cartJson = $this->_makeCart($cart, $mailchimpStoreId, $magentoStoreId);
if ($cartJson!="") {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::QUO_MOD);
$allCarts[$this->_counter]['method'] = 'POST';
$allCarts[$this->_counter]['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/carts';
$allCarts[$this->_counter]['operation_id'] = $this->_batchId . '_' . $cartId;
Expand Down Expand Up @@ -362,6 +363,7 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId)

$cartJson = $this->_makeCart($cart, $mailchimpStoreId, $magentoStoreId);
if ($cartJson!="") {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::ORD_NEW);
$allCarts[$this->_counter]['method'] = 'POST';
$allCarts[$this->_counter]['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/carts';
$allCarts[$this->_counter]['operation_id'] = $this->_batchId . '_' . $cartId;
Expand Down
5 changes: 5 additions & 0 deletions Model/Api/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public function sendCustomers($storeId)
$this->_helper->log('Customer: '.$customer->getId().' json encode failed');
}
if (!empty($customerJson)) {
if($item->getMailchimpSyncModified() == 1) {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::CUS_MOD);
} else {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::CUS_NEW);
}
$customerArray[$counter]['method'] = "PUT";
$customerArray[$counter]['path'] = "/ecommerce/stores/" . $mailchimpStoreId . "/customers/" . $customer->getId();
$customerArray[$counter]['operation_id'] = $this->_batchId . '_' . $customer->getId();
Expand Down
2 changes: 2 additions & 0 deletions Model/Api/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ protected function _getModifiedOrders($magentoStoreId)

$orderJson = $this->GeneratePOSTPayload($order, $mailchimpStoreId, $magentoStoreId, true);
if (!empty($orderJson)) {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::ORD_MOD);
$batchArray[$this->_counter]['method'] = "PATCH";
$batchArray[$this->_counter]['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/orders/' . $order->getIncrementId();
$batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId;
Expand Down Expand Up @@ -245,6 +246,7 @@ protected function _getNewOrders($magentoStoreId)
}
$orderJson = $this->GeneratePOSTPayload($order, $mailchimpStoreId, $magentoStoreId);
if (!empty($orderJson)) {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::ORD_NEW);
$batchArray[$this->_counter]['method'] = "POST";
$batchArray[$this->_counter]['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/orders';
$batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId;
Expand Down
2 changes: 2 additions & 0 deletions Model/Api/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ protected function _buildNewProductRequest(
$this->_helper->log("Product " . $product->getId() . " json encode failed");
return [];
}
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::PRO_NEW);
$data = [];
$data['method'] = "POST";
$data['path'] = "/ecommerce/stores/" . $mailchimpStoreId . "/products";
Expand Down Expand Up @@ -328,6 +329,7 @@ protected function _buildOldProductRequest(
$this->_helper->log("Product " . $product->getId() . " json encode failed");
return [];
}
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::PRO_MOD);
$data = [];
$data['method'] = "PATCH";
$data['path'] = "/ecommerce/stores/" . $mailchimpStoreId . "/products/".$product->getId();
Expand Down
5 changes: 5 additions & 0 deletions Model/Api/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function sendSubscribers($storeId, $listId)
$this->_helper->log($errorMessage, $storeId);
}
if (!empty($subscriberJson)) {
if($subscriber->getMailchimpSyncModified()==1) {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::SUB_MOD);
} else {
$this->_helper->modifyCounter( \Ebizmarts\MailChimp\Helper\Data::SUB_NEW);
}
$subscriberArray[$counter]['method'] = "PUT";
$subscriberArray[$counter]['path'] = "/lists/" . $listId . "/members/" . $md5HashEmail;
$subscriberArray[$counter]['operation_id'] = $batchId . '_' . $subscriber->getSubscriberId();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"forum": "http://ebizmarts.com/forums/view/6"
},
"require" : {
"ebizmarts/mailchimp-lib": ">=3.0.26"
"ebizmarts/mailchimp-lib": ">=3.0.27"
}
}