diff --git a/Block/Adminhtml/System/Config/Form/Field/CustomerMap.php b/Block/Adminhtml/System/Config/Form/Field/CustomerMap.php
index dfe8bd7c..10f02cfb 100644
--- a/Block/Adminhtml/System/Config/Form/Field/CustomerMap.php
+++ b/Block/Adminhtml/System/Config/Form/Field/CustomerMap.php
@@ -19,6 +19,7 @@ class CustomerMap extends \Magento\Config\Block\System\Config\Form\Field\FieldA
* @var VarsMap
*/
protected $_varsRenderer=null;
+ protected $_mailchimpRenderer=null;
protected function _getVarsRenderer()
{
@@ -32,10 +33,26 @@ protected function _getVarsRenderer()
}
return $this->_varsRenderer;
}
+ protected function _getMailchimpRenderer()
+ {
+ if (!$this->_mailchimpRenderer) {
+ $this->_mailchimpRenderer = $this->getLayout()->createBlock(
+ 'Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\MailchimpMap',
+ '',
+ ['data' => ['is_render_to_js_template' => true]]
+ );
+ $this->_mailchimpRenderer->setClass('mailchimp_field_select');
+ }
+ return $this->_mailchimpRenderer;
+ }
protected function _prepareToRender()
{
- $this->addColumn('mailchimp', ['label' => __('Mailchimp')]);
+// $this->addColumn('mailchimp', ['label' => __('Mailchimp')]);
+ $this->addColumn(
+ 'mailchimp_field_id',
+ ['label' => __('Mailchimp'), 'renderer' => $this->_getMailchimpRenderer()]
+ );
$this->addColumn(
'customer_field_id',
['label' => __('Magento'), 'renderer' => $this->_getVarsRenderer()]
@@ -48,6 +65,8 @@ protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
$optionExtraAttr = [];
$optionExtraAttr['option_' . $this->_getVarsRenderer()->calcOptionHash($row->getData('customer_field_id'))] =
'selected="selected"';
+ $optionExtraAttr['option_' . $this->_getMailchimpRenderer()->calcOptionHash($row->getData('mailchimp_field_id'))] =
+ 'selected="selected"';
$row->setData(
'option_extra_attrs',
$optionExtraAttr
diff --git a/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php b/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php
new file mode 100644
index 00000000..82285836
--- /dev/null
+++ b/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php
@@ -0,0 +1,75 @@
+
+ * @copyright Ebizmarts (http://ebizmarts.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @date: 10/9/18 1:17 PM
+ * @file: MailchimpMap.php
+ */
+
+namespace Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field;
+
+class MailchimpMap extends \Magento\Framework\View\Element\Html\Select
+{
+ /**
+ * @var \Ebizmarts\MailChimp\Helper\Data
+ */
+ private $_helper;
+ /**
+ * @var \Magento\Store\Model\StoreManagerInterface
+ */
+ private $_storeManager;
+
+ /**
+ * MailchimpMap constructor.
+ * @param \Magento\Framework\View\Element\Context $context
+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
+ * @param \Ebizmarts\MailChimp\Helper\Data $helper
+ * @param array $data
+ */
+ public function __construct(
+ \Magento\Framework\View\Element\Context $context,
+ \Magento\Store\Model\StoreManagerInterface $storeManager,
+ \Ebizmarts\MailChimp\Helper\Data $helper,
+ array $data=[]
+ )
+ {
+ parent::__construct($context, $data);
+ $this->_helper = $helper;
+ $this->_storeManager = $storeManager;
+ }
+
+ protected function _getMailchimpTags()
+ {
+ $ret = [];
+ $api = $this->_helper->getApi($this->_storeManager->getStore()->getId());
+ $merge = $api->lists->mergeFields->getAll($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_LIST));
+ foreach($merge['merge_fields'] as $item) {
+ $ret[$item['tag']] = $item['tag'].' ('.$item['name'].' : '.$item['type'].')';
+ }
+ return $ret;
+ }
+ public function setInputName($value)
+ {
+ return $this->setName($value);
+ }
+
+ /**
+ * Render block HTML
+ *
+ * @return string
+ */
+ public function _toHtml()
+ {
+ if (!$this->getOptions()) {
+ foreach ($this->_getMailchimpTags() as $attId => $attLabel) {
+ $this->addOption($attId, addslashes($attLabel));
+ }
+ }
+ return parent::_toHtml();
+ }
+}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24c9604a..fe671b72 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,36 @@
# Change Log
-## [1.0.29](https://github.com/mailchimp/mc-magento2/tree/1.0.29) (2018-05-31)
+## [1.0.30](https://github.com/mailchimp/mc-magento2/tree/1.0.30)
+
+[Full Changelog](https://github.com/mailchimp/mc-magento2/compare/1.0.29...1.0.30)
+
+**Implemented enhancements:**
+
+- Adding extra logging on import parts of the Cronjob [\#393](https://github.com/mailchimp/mc-magento2/issues/393)
+- Add an option to choose between send MailChimp or Magento mails [\#372](https://github.com/mailchimp/mc-magento2/issues/372)
+- Log batch totals for each run [\#361](https://github.com/mailchimp/mc-magento2/issues/361)
+- Add debug information [\#359](https://github.com/mailchimp/mc-magento2/issues/359)
+- High CPU load when API not available [\#325](https://github.com/mailchimp/mc-magento2/issues/325)
+**Fixed bugs:**
+
+- Special prices management in Magento Enterprise [\#391](https://github.com/mailchimp/mc-magento2/issues/391)
+- Failed to open stream: No such file or directory [\#388](https://github.com/mailchimp/mc-magento2/issues/388)
+- MailChimp breaks order processing when it's done through CLI [\#378](https://github.com/mailchimp/mc-magento2/issues/378)
+- Promo rules are not updated [\#370](https://github.com/mailchimp/mc-magento2/issues/370)
+- Error in the configuration when selecting other website than default [\#368](https://github.com/mailchimp/mc-magento2/issues/368)
+- Orders not synced when products in the order not already synced [\#366](https://github.com/mailchimp/mc-magento2/issues/366)
+- Wrong website set on customer [\#357](https://github.com/mailchimp/mc-magento2/issues/357)
+- Issue with coupons for free shipping [\#355](https://github.com/mailchimp/mc-magento2/issues/355)
+- Error downloading response from error grid when batch not exist [\#351](https://github.com/mailchimp/mc-magento2/issues/351)
+- Unable to set custom Env.php API Credentials [\#345](https://github.com/mailchimp/mc-magento2/issues/345)
+- Disabled in Admin Panel Mailchimp block Magento default newsletter flow. [\#339](https://github.com/mailchimp/mc-magento2/issues/339)
+- Webhook processing fails when list id does not match any list configured in Magento [\#337](https://github.com/mailchimp/mc-magento2/issues/337)
+- Sending modified products in order or cart [\#335](https://github.com/mailchimp/mc-magento2/issues/335)
+- Base table or view not found Magento 2.2.4 [\#321](https://github.com/mailchimp/mc-magento2/issues/321)
+- Unknown column 'at\_special\_from\_date\_default.value' in 'on clause' [\#309](https://github.com/mailchimp/mc-magento2/issues/309)
+
+## [1.0.29](https://github.com/mailchimp/mc-magento2/tree/1.0.29) (2018-05-31)
[Full Changelog](https://github.com/mailchimp/mc-magento2/compare/1.0.28...1.0.29)
**Implemented enhancements:**
@@ -24,7 +53,11 @@
- Bad registers are generated in mailchimp\_sync\_ecommerce table [\#267](https://github.com/mailchimp/mc-magento2/issues/267)
- PHP warning in Helper/Data.php line 340 [\#266](https://github.com/mailchimp/mc-magento2/issues/266)
- Subscriber fields not updated when Ecommerce Data not enabled [\#258](https://github.com/mailchimp/mc-magento2/issues/258)
+- The instest groups are not reloaded when the list changes [\#257](https://github.com/mailchimp/mc-magento2/issues/257)
+- The user can select non existing group in admin [\#256](https://github.com/mailchimp/mc-magento2/issues/256)
+- Don't process stores with no mailchimp store [\#255](https://github.com/mailchimp/mc-magento2/issues/255)
- Error when attempting to edit a customer from the backend [\#240](https://github.com/mailchimp/mc-magento2/issues/240)
+- 2.2 Error Importing Configuration [\#223](https://github.com/mailchimp/mc-magento2/issues/223)
- No Abandoned Cart Data Sent [\#220](https://github.com/mailchimp/mc-magento2/issues/220)
- Magento 2.2.1: Changes like "unsubscribe" and "delete" to subscribers in Magento backend aren't synched [\#147](https://github.com/mailchimp/mc-magento2/issues/147)
- Change cron group id to 'mailchimp'. [\#282](https://github.com/mailchimp/mc-magento2/pull/282) ([jhruehl](https://github.com/jhruehl))
@@ -43,10 +76,6 @@
**Fixed bugs:**
-- The instest groups are not reloaded when the list changes [\#257](https://github.com/mailchimp/mc-magento2/issues/257)
-- The user can select non existing group in admin [\#256](https://github.com/mailchimp/mc-magento2/issues/256)
-- Don't process stores with no mailchimp store [\#255](https://github.com/mailchimp/mc-magento2/issues/255)
-- 2.2 Error Importing Configuration [\#223](https://github.com/mailchimp/mc-magento2/issues/223)
- Wrong product marked as modified in ecommerce table [\#253](https://github.com/mailchimp/mc-magento2/issues/253)
- Don't delete the batch\_id when modify a register [\#246](https://github.com/mailchimp/mc-magento2/issues/246)
- Invalid argument supplied for foreach\(\) [\#243](https://github.com/mailchimp/mc-magento2/issues/243)
diff --git a/Controller/Adminhtml/Stores/Delete.php b/Controller/Adminhtml/Stores/Delete.php
index 5fbdbe89..e24d6d3d 100644
--- a/Controller/Adminhtml/Stores/Delete.php
+++ b/Controller/Adminhtml/Stores/Delete.php
@@ -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]);
}
}
diff --git a/Controller/Adminhtml/Stores/Save.php b/Controller/Adminhtml/Stores/Save.php
index 60bbf656..fa9e7581 100644
--- a/Controller/Adminhtml/Stores/Save.php
+++ b/Controller/Adminhtml/Stores/Save.php
@@ -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]);
}
}
diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php
index 4b563a55..991a1fff 100644
--- a/Cron/Ecommerce.php
+++ b/Cron/Ecommerce.php
@@ -168,31 +168,32 @@ 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)) {
$this->_helper->log('Generate Products payload');
$products = $this->_apiProduct->_sendProducts($storeId);
$countProducts = count($products);
$results = array_merge($results, $products);
-
+
$this->_helper->log('Generate Customers payload');
$customers = $this->_apiCustomer->sendCustomers($storeId);
$countCustomers = count($customers);
$results = array_merge($results, $customers);
-
+
$this->_helper->log('Generate Orders payload');
$orders = $this->_apiOrder->sendOrders($storeId);
$countOrders = count($orders);
$results = array_merge($results, $orders);
-
+
$this->_helper->log('Generate Carts payload');
$carts = $this->_apiCart->createBatchJson($storeId);
$results = array_merge($results, $carts);
-
+
$this->_helper->log('Generate Rules payload');
$rules = $this->_apiPromoRules->sendRules($storeId);
$results = array_merge($results, $rules);
-
+
$this->_helper->log('Generate Coupons payload');
$coupons = $this->_apiPromoCodes->sendCoupons($storeId);
$results = array_merge($results, $coupons);
@@ -217,7 +218,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) {
@@ -271,4 +272,10 @@ protected function _ping($storeId)
}
return true;
}
+ protected function _showResume($batchId)
+ {
+ $this->_helper->log("Sent batch $batchId");
+ $this->_helper->log($this->_helper->getCounters());
+
+ }
}
diff --git a/Helper/Data.php b/Helper/Data.php
index fba8bba0..931ea1ee 100644
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -60,6 +60,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
*/
@@ -1061,4 +1073,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;
+ }
}
diff --git a/Helper/VarsMap.php b/Helper/VarsMap.php
index b5c2e811..793a909f 100644
--- a/Helper/VarsMap.php
+++ b/Helper/VarsMap.php
@@ -63,7 +63,7 @@ protected function isEncodedArrayFieldValue($value)
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('customer_field_id', $row)
- || !array_key_exists('mailchimp', $row)
+ || !array_key_exists('mailchimp_field_id', $row)
) {
return false;
}
@@ -77,13 +77,13 @@ protected function decodeArrayFieldValue(array $value)
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('customer_field_id', $row)
- || !array_key_exists('mailchimp', $row)
+ || !array_key_exists('mailchimp_field_id', $row)
) {
continue;
}
- $groupId = $row['customer_field_id'];
- $qty = $row['mailchimp'];
- $result[$groupId] = $qty;
+ $customer_field_id = $row['customer_field_id'];
+ $mailchimp_field_id = $row['mailchimp_field_id'];
+ $result[$customer_field_id] = $mailchimp_field_id;
}
return $result;
}
@@ -114,7 +114,7 @@ protected function encodeArrayFieldValue(array $value)
$result = [];
foreach ($value as $customerFieldId => $mailchimpName) {
$resultId = $this->mathRandom->getUniqueHash('_');
- $result[$resultId] = ['mailchimp' => $mailchimpName ,'customer_field_id' => $customerFieldId];
+ $result[$resultId] = ['mailchimp_field_id' => $mailchimpName ,'customer_field_id' => $customerFieldId];
}
return $result;
}
diff --git a/Model/Api/Cart.php b/Model/Api/Cart.php
index 758cd039..7640e499 100644
--- a/Model/Api/Cart.php
+++ b/Model/Api/Cart.php
@@ -218,7 +218,7 @@ protected function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId)
* @var $customer \Magento\Customer\Model\Customer
*/
$customer = $this->_customerFactory->create();
- $customer->setWebsiteId($magentoStoreId);
+ $customer->setWebsiteId($this->_helper->getWebsiteId($magentoStoreId));
$customer->loadByEmail($cart->getCustomerEmail());
if ($customer->getEmail() != $cart->getCustomerEmail()) {
@@ -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;
@@ -304,6 +305,8 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId)
);
// be sure that the quotes are already in mailchimp and not deleted
$newCarts->getSelect()->where("m4m.mailchimp_sync_delta IS NULL");
+
+
// limit the collection
$newCarts->getSelect()->limit(self::BATCH_LIMIT);
/**
@@ -321,7 +324,7 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId)
continue;
}
$customer = $this->_customerFactory->create();
- $customer->setWebsiteId($magentoStoreId);
+ $customer->setWebsiteId($this->_helper->getWebsiteId($magentoStoreId));
$customer->loadByEmail($cart->getCustomerEmail());
if ($customer->getEmail() != $cart->getCustomerEmail()) {
@@ -362,6 +365,7 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId)
$cartJson = $this->_makeCart($cart, $mailchimpStoreId, $magentoStoreId);
if ($cartJson!="") {
+ $this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::QUO_NEW);
$allCarts[$this->_counter]['method'] = 'POST';
$allCarts[$this->_counter]['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/carts';
$allCarts[$this->_counter]['operation_id'] = $this->_batchId . '_' . $cartId;
diff --git a/Model/Api/Customer.php b/Model/Api/Customer.php
index 882d8468..3011dde7 100644
--- a/Model/Api/Customer.php
+++ b/Model/Api/Customer.php
@@ -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();
diff --git a/Model/Api/Order.php b/Model/Api/Order.php
index 04ed90ac..777328ce 100644
--- a/Model/Api/Order.php
+++ b/Model/Api/Order.php
@@ -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;
@@ -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;
@@ -524,12 +526,12 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc
//customer orders data
$orderCollection = $this->_orderCollectionFactory->create();
$orderCollection->addFieldToFilter('state', [
- ['neq',\Magento\Sales\Model\Order::STATE_CANCELED],
- ['neq',\Magento\Sales\Model\Order::STATE_CLOSED]])
+ ['neq' => \Magento\Sales\Model\Order::STATE_CANCELED],
+ ['neq' => \Magento\Sales\Model\Order::STATE_CLOSED]])
->addAttributeToFilter('customer_email', ['eq' => $order->getCustomerEmail()]);
- $totalOrders = 1;
- $totalAmountSpent = (int)$order->getGrandTotal();
+ $totalOrders = 0;
+ $totalAmountSpent = 0;
/**
* @var $customerOrder \Magento\Sales\Model\Order
*/
diff --git a/Model/Api/Product.php b/Model/Api/Product.php
index 9dd3a8ee..1e9b0a39 100644
--- a/Model/Api/Product.php
+++ b/Model/Api/Product.php
@@ -1,25 +1,22 @@
- * @copyright Ebizmarts (http://ebizmarts.com)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * @date: 10/10/16 5:22 PM
- * @file: Product.php
- */
+mc-magento2 Magento Component
+@category Ebizmarts
+@Package mc-magento2
+@author Ebizmarts Team info@ebizmarts.com
+@copyright Ebizmarts (http://ebizmarts.com)
+@license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+@Date: 10/10/16 5:22 PM
+@file: Product.php
+ */
namespace Ebizmarts\MailChimp\Model\Api;
-
-
class Product
{
- const DOWNLOADABLE = 'downloadable';
- const PRODUCTIMAGE = 'product_small_image';
- const MAX = 100;
+ const DOWNLOADABLE = 'downloadable';
+ const PRODUCTIMAGE = 'product_small_image';
+ const MAX = 100;
protected $_parentImage = null;
protected $_childtUrl = null;
@@ -93,7 +90,7 @@ public function __construct(
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollection,
\Magento\Catalog\Model\Product\Option $option
) {
-
+
$this->_productRepository = $productRepository;
$this->_helper = $helper;
$this->_productCollection = $productCollection;
@@ -113,11 +110,11 @@ public function _sendProducts($magentoStoreId)
$mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE, $magentoStoreId);
$this->_markSpecialPrices($magentoStoreId,$mailchimpStoreId);
$collection = $this->_getCollection();
- $collection->setStoreId($magentoStoreId);
+ $collection->addStoreFilter($magentoStoreId);
$collection->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = e.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT.
- "' and m4m.mailchimp_store_id = '".$mailchimpStoreId."'",
+ "' and m4m.mailchimp_store_id = '".$mailchimpStoreId."'",
['m4m.*']
);
$collection->getSelect()->where("m4m.mailchimp_sync_delta IS null OR (m4m.mailchimp_sync_delta > '".$this->_helper->getMCMinSyncDateFlag().
@@ -128,8 +125,6 @@ public function _sendProducts($magentoStoreId)
* @var $product \Magento\Catalog\Model\Product
*/
$product = $this->_productRepository->get($item->getSku());
-// $productSyncData = $this->_chimpSyncEcommerce->getByStoreIdType($mailchimpStoreId,$product->getId(),
-// \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT);
if ($item->getMailchimpSyncModified() && $item->getMailchimpSyncDelta() &&
$item->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) {
$batchArray = array_merge($this->_buildOldProductRequest($product,$this->_batchId,$mailchimpStoreId, $magentoStoreId),$batchArray);
@@ -162,7 +157,7 @@ protected function _markSpecialPrices($magentoStoreId, $mailchimpStoreId)
* get the products with current special price that are not synced and mark it as modified
*/
$collection = $this->_getCollection();
- $collection->setStoreId($magentoStoreId);
+ $collection->addStoreFilter($magentoStoreId);
$collection->addAttributeToFilter(
'special_price',
['gt'=>0], 'left'
@@ -180,7 +175,7 @@ protected function _markSpecialPrices($magentoStoreId, $mailchimpStoreId)
)],]], 'left'
);
$collection->getSelect()->joinLeft(['mc' => $collection->getTable('mailchimp_sync_ecommerce')],
- "mc.type = 'PRO' AND mc.related_id = e.entity_id AND mc.mailchimp_sync_modified = 0 ".$collection->getConnection()->quoteInto(" AND mc.mailchimp_store_id = ?",$mailchimpStoreId) ." and mc.mailchimp_sync_delta < (IF(at_special_from_date.value_id > 0, at_special_from_date.value, at_special_from_date_default.value))");
+ "mc.type = 'PRO' AND mc.related_id = e.entity_id AND mc.mailchimp_sync_modified = 0 ".$collection->getConnection()->quoteInto(" AND mc.mailchimp_store_id = ?",$mailchimpStoreId) ." and mc.mailchimp_sync_delta < at_special_from_date.value");
$collection->getSelect()->where('mc.mailchimp_sync_delta is not null');
foreach ($collection as $item) {
$this->_updateProduct($mailchimpStoreId, $item->getEntityId(),null,null, 1);
@@ -189,17 +184,17 @@ protected function _markSpecialPrices($magentoStoreId, $mailchimpStoreId)
* get the products that was synced when it have special price and have no more special price
*/
$collection2 = $this->_getCollection();
- $collection2->setStoreId($magentoStoreId);
+ $collection2->addStoreFilter($magentoStoreId);
$collection2->addAttributeToFilter(
'special_price',
['gt'=>0], 'left'
)->addAttributeToFilter(
'special_to_date', ['or' => [ 0 => ['date' => true,
'to' => date('Y-m-d',time()).' 00:00:00'],
- ]], 'left'
+ ]], 'left'
);
$collection2->getSelect()->joinLeft(['mc' => $collection2->getTable('mailchimp_sync_ecommerce')],
- "mc.type = 'PRO' and mc.related_id = e.entity_id and mc.mailchimp_sync_modified = 0 ".$collection->getConnection()->quoteInto(" AND mc.mailchimp_store_id = ?",$mailchimpStoreId) ." and mc.mailchimp_sync_delta < (IF(at_special_to_date.value_id > 0, at_special_to_date.value, at_special_to_date_default.value))",[]);
+ "mc.type = 'PRO' and mc.related_id = e.entity_id and mc.mailchimp_sync_modified = 0 ".$collection->getConnection()->quoteInto(" AND mc.mailchimp_store_id = ?",$mailchimpStoreId) ." and mc.mailchimp_sync_delta < at_special_to_date.value",[]);
$collection2->getSelect()->where('mc.mailchimp_sync_delta is not null');
foreach ($collection2 as $item) {
$this->_updateProduct($mailchimpStoreId, $item->getEntityId(),null,null, 1);
@@ -218,7 +213,7 @@ protected function _buildNewProductRequest(
$mailchimpStoreId,
$magentoStoreId
) {
-
+
$variantProducts = [];
switch ($product->getTypeId()) {
case \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE:
@@ -251,6 +246,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";
@@ -271,15 +267,14 @@ protected function _buildOldProductRequest(
$product->getTypeId() == "downloadable") {
$data = $this-> _buildProductData($product, $magentoStoreId);
$variantProducts [] = $product;
-
-// $parentIds = $product->getTypeInstance()->getParentIdsByChild($product->getId());
- $parentIds = $this->_configurable->getParentIdsByChild($product->getId());
+ // $parentIds = $product->getTypeInstance()->getParentIdsByChild($product->getId());
+ $parentIds = $this->_configurable->getParentIdsByChild($product->getId());
//add or update variant
foreach ($parentIds as $parentId) {
$productSync = $this->_chimpSyncEcommerce->create()->getByStoreIdType($mailchimpStoreId,
- $parentId,
- \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT);
+ $parentId,
+ \Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT);
if($productSync->getMailchimpSyncDelta()) {
$variendata = [];
$variendata["id"] = $data["id"];
@@ -328,6 +323,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();
@@ -342,7 +338,7 @@ protected function _buildProductData(
$isVarient = true,
$variants = null
) {
-
+
$data = [];
//data applied for both root and varient products
@@ -362,15 +358,22 @@ protected function _buildProductData(
//this is for a varient product
$data["sku"] = $product->getSku();
$today = $this->_helper->getGmtDate("Y-m-d");
- if($product->getSpecialFromDate() && $product->getSpecialFromDate() <= $today)
- {
- if(!$product->getSpecialToDate() || ($product->getSpecialToDate() && $today <= $product->getSpecialToDate())) {
+ try {
+ if ($product->getSpecialFromDate() && $product->getSpecialFromDate() <= $today && (float)$product->getSpecialPrice()) {
+ if (!$product->getSpecialToDate() || ($product->getSpecialToDate() && $today <= $product->getSpecialToDate())) {
+ $data["price"] = $product->getSpecialPrice();
+ } else {
+ $data["price"] = $product->getPrice();
+ }
+ } else {
+ $data["price"] = $product->getPrice();
+ }
+ } catch(\Exception $e) {
+ if((float)$product->getSpecialPrice()) {
$data["price"] = $product->getSpecialPrice();
} else {
$data["price"] = $product->getPrice();
}
- } else {
- $data["price"] = $product->getPrice();
}
//stock
@@ -491,12 +494,15 @@ public function sendModifiedProduct(\Magento\Sales\Model\Order $order, $mailchim
$product->getId(),
\Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT
);
- if ($product->getId()!=$item->getProductId() || $product->getTypeId()=='bundle' || $product->getTypeId()=='grouped') {
+ if ($product->getId()!=$item->getProductId() || (
+ $product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE &&
+ $product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL &&
+ $product->getTypeId() != "downloadable")) {
continue;
}
if ($productSyncData->getMailchimpSyncModified() &&
$productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) {
- $data = array_merge($this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId),$data);
+ $data = array_merge($data, $this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId));
$this->_updateProduct($mailchimpStoreId, $product->getId());
} elseif (!$productSyncData->getMailchimpSyncDelta() ||
$productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) {
@@ -523,14 +529,16 @@ public function sendQuoteModifiedProduct(\Magento\Quote\Model\Quote $quote, $mai
$product->getId(),
\Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT
);
-
- if ($product->getId()!=$item->getProductId() || $product->getTypeId()=='bundle' || $product->getTypeId()=='grouped') {
+ if ($product->getId()!=$item->getProductId() || (
+ $product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE &&
+ $product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL &&
+ $product->getTypeId() != "downloadable")) {
continue;
}
if ($productSyncData->getMailchimpSyncModified() &&
$productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) {
- $data = array_merge($this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId),$data);
+ $data = array_merge($data,$this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId));
$this->_updateProduct($mailchimpStoreId, $product->getId());
} elseif (!$productSyncData->getMailchimpSyncDelta() ||
$productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) {
diff --git a/Model/Api/Result.php b/Model/Api/Result.php
index 0f4b1ffa..1a6d9baf 100644
--- a/Model/Api/Result.php
+++ b/Model/Api/Result.php
@@ -95,6 +95,10 @@ public function getBatchResponse($batchId, $storeId = null)
$response = $api->batchOperation->status($batchId);
if (isset($response['status']) && $response['status'] == 'finished') {
+ // Create temporary directory, if that does not exist
+ if (!is_dir($baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR)) {
+ mkdir($baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR);
+ }
// get the tar.gz file with the results
$fileUrl = urldecode($response['response_body_url']);
$fileName = $baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . self::MAILCHIMP_TEMP_DIR . DIRECTORY_SEPARATOR . $batchId;
diff --git a/Model/Api/Subscriber.php b/Model/Api/Subscriber.php
index d0f638a7..9b77bd22 100644
--- a/Model/Api/Subscriber.php
+++ b/Model/Api/Subscriber.php
@@ -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();
diff --git a/composer.json b/composer.json
index 8b8fe4d3..8c55ec20 100644
--- a/composer.json
+++ b/composer.json
@@ -6,7 +6,7 @@
},
"description": "Connect MailChimp with Magento",
"type": "magento2-module",
- "version": "1.0.29",
+ "version": "1.0.30",
"authors": [
{
"name": "Ebizmarts Corp",
@@ -24,6 +24,6 @@
"forum": "http://ebizmarts.com/forums/view/6"
},
"require" : {
- "ebizmarts/mailchimp-lib": ">=3.0.26"
+ "ebizmarts/mailchimp-lib": ">=3.0.27"
}
}
\ No newline at end of file
diff --git a/etc/events.xml b/etc/events.xml
index bc7d78ef..37067863 100644
--- a/etc/events.xml
+++ b/etc/events.xml
@@ -14,9 +14,6 @@
-
-
-
diff --git a/etc/frontend/events.xml b/etc/frontend/events.xml
new file mode 100644
index 00000000..adb3a9bc
--- /dev/null
+++ b/etc/frontend/events.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/etc/module.xml b/etc/module.xml
index 32d7dca1..630a324c 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -11,7 +11,7 @@
*/
-->
-
+