From c9a283687194974f91dda13fb1c7704dec1e0212 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Tue, 7 Aug 2018 12:18:36 -0300 Subject: [PATCH 01/28] add counters for resume the cron activity #361 --- Cron/Ecommerce.php | 9 ++++++++- Helper/Data.php | 28 ++++++++++++++++++++++++++++ Model/Api/Cart.php | 2 ++ Model/Api/Customer.php | 5 +++++ Model/Api/Order.php | 2 ++ Model/Api/Product.php | 2 ++ Model/Api/Subscriber.php | 5 +++++ 7 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php index 33ab0d50..9d376482 100644 --- a/Cron/Ecommerce.php +++ b/Cron/Ecommerce.php @@ -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); @@ -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) { @@ -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()); + + } } diff --git a/Helper/Data.php b/Helper/Data.php index 830fcda8..28263982 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -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 */ @@ -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; + } } diff --git a/Model/Api/Cart.php b/Model/Api/Cart.php index 758cd039..94d21b0b 100644 --- a/Model/Api/Cart.php +++ b/Model/Api/Cart.php @@ -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; @@ -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; 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 105a3e69..0d959800 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; diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 9dd3a8ee..aae1ee44 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -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"; @@ -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(); 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(); From 2c748fba0ee3ba9454c361619618a051854f0cd2 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 16 Aug 2018 12:01:13 -0300 Subject: [PATCH 02/28] closes #361 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8b8fe4d3..d5e7a925 100644 --- a/composer.json +++ b/composer.json @@ -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 From fe0431f95e0c7de231afd32603378513f9c17f8a Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 16 Aug 2018 12:02:07 -0300 Subject: [PATCH 03/28] closes #361 --- Controller/Adminhtml/Stores/Delete.php | 1 + Controller/Adminhtml/Stores/Save.php | 1 + 2 files changed, 2 insertions(+) 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]); } } From 75d570c40537e53174abc6bc5ca2e4166ca33250 Mon Sep 17 00:00:00 2001 From: Wojciech Naruniec Date: Mon, 27 Aug 2018 13:06:27 +0200 Subject: [PATCH 04/28] Move mailchimp_sales_model_service_quote_submit_after observer to frontend scope to avoid throwing cookie error on CLI --- etc/events.xml | 3 --- etc/frontend/events.xml | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 etc/frontend/events.xml 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 @@ + + + + + + From 58b1e11c624db46d2253a68fb423ec9fce8a710a Mon Sep 17 00:00:00 2001 From: gonzalo Date: Tue, 28 Aug 2018 15:04:40 -0300 Subject: [PATCH 05/28] change version to 1.0.30 --- CHANGELOG.md | 34 +++++++++++++++++++++++++++++----- composer.json | 2 +- etc/module.xml | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24c9604a..a06c3c14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,31 @@ # 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) (2018-08-27) + +[Full Changelog](https://github.com/mailchimp/mc-magento2/compare/1.0.29...1.0.30) + +**Implemented enhancements:** + +- 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:** + +- 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) +- 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) + +## [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 +48,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 +71,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/composer.json b/composer.json index d5e7a925..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", 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 @@ */ --> - + From 947514392673d977f1f00290771b9633d7543c71 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 29 Aug 2018 17:01:15 -0300 Subject: [PATCH 06/28] closes #357 --- Model/Api/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/Api/Cart.php b/Model/Api/Cart.php index 94d21b0b..926a5ffc 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()) { @@ -322,7 +322,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()) { From 0fbca0519df06991c7af2ce2a9ddc5b9ca775e63 Mon Sep 17 00:00:00 2001 From: Maxim Baibakov Date: Wed, 12 Sep 2018 11:37:54 +1000 Subject: [PATCH 07/28] Update Ecommerce.php --- Cron/Ecommerce.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php index 4b563a55..4e72be6c 100644 --- a/Cron/Ecommerce.php +++ b/Cron/Ecommerce.php @@ -170,30 +170,24 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId) $batchArray = []; $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); } From da8e08b0649e09d1701acfc7383cde4c4b8169f4 Mon Sep 17 00:00:00 2001 From: Maxim Baibakov Date: Wed, 12 Sep 2018 11:38:39 +1000 Subject: [PATCH 08/28] Update Ecommerce.php --- Cron/Ecommerce.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php index 4e72be6c..33ab0d50 100644 --- a/Cron/Ecommerce.php +++ b/Cron/Ecommerce.php @@ -173,21 +173,16 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId) $products = $this->_apiProduct->_sendProducts($storeId); $countProducts = count($products); $results = array_merge($results, $products); - $customers = $this->_apiCustomer->sendCustomers($storeId); $countCustomers = count($customers); $results = array_merge($results, $customers); - $orders = $this->_apiOrder->sendOrders($storeId); $countOrders = count($orders); $results = array_merge($results, $orders); - $carts = $this->_apiCart->createBatchJson($storeId); $results = array_merge($results, $carts); - $rules = $this->_apiPromoRules->sendRules($storeId); $results = array_merge($results, $rules); - $coupons = $this->_apiPromoCodes->sendCoupons($storeId); $results = array_merge($results, $coupons); } From 2ae0a8052d3a55f5851e1291874acb13baad1a33 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 12 Sep 2018 13:48:40 -0300 Subject: [PATCH 09/28] closes #309 --- Model/Api/Product.php | 63 ++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index aae1ee44..3a5ec387 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; @@ -117,7 +114,7 @@ public function _sendProducts($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); @@ -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); @@ -196,10 +191,10 @@ protected function _markSpecialPrices($magentoStoreId, $mailchimpStoreId) )->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,7 +246,6 @@ 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"; @@ -272,15 +266,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"]; @@ -329,7 +322,6 @@ 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(); @@ -344,7 +336,7 @@ protected function _buildProductData( $isVarient = true, $variants = null ) { - + $data = []; //data applied for both root and varient products @@ -352,8 +344,11 @@ protected function _buildProductData( $data["title"] = $product->getName(); $data["url"] = $product->getProductUrl(); if ($product->getImage()) { + //mijn aanpassing image url hier $filePath = 'catalog/product'.$product->getImage(); $data["image_url"] = $this->_helper->getBaserUrl($magentoStoreId, \Magento\Framework\UrlInterface::URL_TYPE_MEDIA).$filePath; + //$store = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore(); + //$data["image_url"] = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/cache/small_image/300x400/beff4985b56e3afdbeabfc89641a4582/' . $product->getImage(); } elseif ($this->_parentImage) { $data['image_url'] = $this->_parentImage; } else { @@ -498,7 +493,7 @@ public function sendModifiedProduct(\Magento\Sales\Model\Order $order, $mailchim } if ($productSyncData->getMailchimpSyncModified() && $productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) { - $data = array_merge($this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId),$data); + $data[] = $this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); $this->_updateProduct($mailchimpStoreId, $product->getId()); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { @@ -532,7 +527,7 @@ public function sendQuoteModifiedProduct(\Magento\Quote\Model\Quote $quote, $mai if ($productSyncData->getMailchimpSyncModified() && $productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) { - $data = array_merge($this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId),$data); + $data[] = $this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); $this->_updateProduct($mailchimpStoreId, $product->getId()); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { @@ -560,4 +555,4 @@ protected function _updateProduct($storeId, $entityId, $sync_delta=null, $sync_e $sync_modified ); } -} +} \ No newline at end of file From f65d7b2bbf05e5738e629200609b5ed8ed6cfbae Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 12 Sep 2018 13:57:07 -0300 Subject: [PATCH 10/28] closes #309 --- Model/Api/Product.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 3a5ec387..4c8a217a 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -344,11 +344,8 @@ protected function _buildProductData( $data["title"] = $product->getName(); $data["url"] = $product->getProductUrl(); if ($product->getImage()) { - //mijn aanpassing image url hier $filePath = 'catalog/product'.$product->getImage(); $data["image_url"] = $this->_helper->getBaserUrl($magentoStoreId, \Magento\Framework\UrlInterface::URL_TYPE_MEDIA).$filePath; - //$store = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore(); - //$data["image_url"] = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/cache/small_image/300x400/beff4985b56e3afdbeabfc89641a4582/' . $product->getImage(); } elseif ($this->_parentImage) { $data['image_url'] = $this->_parentImage; } else { From 25189aa6fbb0bf8ba4b0bca64dbb047846e40621 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 12 Sep 2018 14:09:11 -0300 Subject: [PATCH 11/28] closes #391 --- Model/Api/Product.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 4c8a217a..4696f178 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -356,15 +356,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) { + 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($product->getSpecialPrice()) { $data["price"] = $product->getSpecialPrice(); } else { $data["price"] = $product->getPrice(); } - } else { - $data["price"] = $product->getPrice(); } //stock From 5106f397b937abcde4e92065eeeb1f7ecc994b06 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 13 Sep 2018 11:01:23 -0300 Subject: [PATCH 12/28] closes #388 --- Model/Api/Result.php | 4 ++++ 1 file changed, 4 insertions(+) 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; From b374a06702310b65954e1fde52eb48f66158d3ff Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 13 Sep 2018 11:01:57 -0300 Subject: [PATCH 13/28] closes #393 --- Cron/Ecommerce.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php index 9d376482..991a1fff 100644 --- a/Cron/Ecommerce.php +++ b/Cron/Ecommerce.php @@ -171,19 +171,30 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId) $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); } From 5bb0365c58f6d0e17a95f9458a1143d2e8d3f4d2 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 13 Sep 2018 16:45:34 -0300 Subject: [PATCH 14/28] changelog version 1.0.30 --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a06c3c14..fe671b72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Change Log -## [1.0.30](https://github.com/mailchimp/mc-magento2/tree/1.0.30) (2018-08-27) +## [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) @@ -13,10 +14,13 @@ **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) @@ -24,6 +28,7 @@ - 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) From 6de738766bf044678ab841f34a072f79672054b3 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Tue, 18 Sep 2018 12:55:50 -0300 Subject: [PATCH 15/28] #361 --- Model/Api/Cart.php | 4 +++- Model/Api/Product.php | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Model/Api/Cart.php b/Model/Api/Cart.php index 926a5ffc..7640e499 100644 --- a/Model/Api/Cart.php +++ b/Model/Api/Cart.php @@ -305,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); /** @@ -363,7 +365,7 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $cartJson = $this->_makeCart($cart, $mailchimpStoreId, $magentoStoreId); if ($cartJson!="") { - $this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::ORD_NEW); + $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/Product.php b/Model/Api/Product.php index 4696f178..f275fde2 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -246,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"; @@ -322,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(); From 362d1ef86838c7a42296b00f4aed7619a1a83e31 Mon Sep 17 00:00:00 2001 From: Alexey Arendarenko Date: Fri, 28 Sep 2018 16:43:10 +0300 Subject: [PATCH 16/28] This fix sets price to 0 if it's NULL --- Model/Api/Product.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index f275fde2..919a4ed3 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -281,7 +281,7 @@ protected function _buildOldProductRequest( $variendata["title"] = $data["title"]; $variendata["url"] = $data["url"]; $variendata["sku"] = $data["sku"]; - $variendata["price"] = $data["price"]; + $variendata["price"] = (float)$data["price"]; $variendata["inventory_quantity"] = $data["inventory_quantity"]; $variendata["image_url"] = $data["image_url"]; $variendata["backorders"] = $data["backorders"]; @@ -376,6 +376,8 @@ protected function _buildProductData( } } + $data["price"] = (float)$data['price']; + //stock $stock = $this->_stockRegistry->getStockItem($product->getId(), $magentoStoreId); $data["inventory_quantity"] = (int)$stock->getQty(); @@ -561,4 +563,4 @@ protected function _updateProduct($storeId, $entityId, $sync_delta=null, $sync_e $sync_modified ); } -} \ No newline at end of file +} From 5fdc5c8efcd50961384153bbb696290aaa0c6114 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Fri, 28 Sep 2018 14:26:00 -0300 Subject: [PATCH 17/28] closes #404 --- Model/Api/Product.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index f275fde2..d076bd2d 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -110,7 +110,7 @@ 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. @@ -157,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' @@ -184,7 +184,7 @@ 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' From dc3a08e7cdfe9b9bda4768991ab063464b607b51 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Fri, 28 Sep 2018 16:37:47 -0300 Subject: [PATCH 18/28] closes #406 --- Model/Api/Product.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index d076bd2d..42ff7042 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -494,7 +494,10 @@ 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() && @@ -526,8 +529,10 @@ 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; } From d45d3fb82049bfa21e5e43883519466214034850 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Mon, 1 Oct 2018 12:39:57 -0300 Subject: [PATCH 19/28] closes #409 --- Model/Api/Product.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 42ff7042..51c6a7f7 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -502,11 +502,11 @@ public function sendModifiedProduct(\Magento\Sales\Model\Order $order, $mailchim } if ($productSyncData->getMailchimpSyncModified() && $productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) { - $data[] = $this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); + $data = array_merge($data, $this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId)); $this->_updateProduct($mailchimpStoreId, $product->getId()); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { - $data[] = $this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId); + $data = array_merge($data,$this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId)); $this->_updateProduct($mailchimpStoreId, $product->getId()); } } @@ -538,11 +538,11 @@ public function sendQuoteModifiedProduct(\Magento\Quote\Model\Quote $quote, $mai if ($productSyncData->getMailchimpSyncModified() && $productSyncData->getMailchimpSyncDelta() > $this->_helper->getMCMinSyncDateFlag()) { - $data[] = $this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); + $data = array_merge($data,$this->_buildOldProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId)); $this->_updateProduct($mailchimpStoreId, $product->getId()); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { - $data[] = $this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId); + $data = array_merge($data, $this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId)); $this->_updateProduct($mailchimpStoreId, $product->getId()); } } From aef490c2bc66b29297682207577e2810db43e23d Mon Sep 17 00:00:00 2001 From: gonzalo Date: Mon, 1 Oct 2018 13:32:05 -0300 Subject: [PATCH 20/28] closes #409 --- Model/Api/Product.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 51c6a7f7..ca9855f0 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -506,7 +506,7 @@ public function sendModifiedProduct(\Magento\Sales\Model\Order $order, $mailchim $this->_updateProduct($mailchimpStoreId, $product->getId()); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { - $data = array_merge($data,$this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId)); + $data[] = $this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId); $this->_updateProduct($mailchimpStoreId, $product->getId()); } } @@ -542,7 +542,7 @@ public function sendQuoteModifiedProduct(\Magento\Quote\Model\Quote $quote, $mai $this->_updateProduct($mailchimpStoreId, $product->getId()); } elseif (!$productSyncData->getMailchimpSyncDelta() || $productSyncData->getMailchimpSyncDelta() < $this->_helper->getMCMinSyncDateFlag()) { - $data = array_merge($data, $this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId)); + $data[] = $this->_buildNewProductRequest($product, $mailchimpStoreId, $magentoStoreId); $this->_updateProduct($mailchimpStoreId, $product->getId()); } } From 17ed1336367b7a41a02c53da498653dcce1e53e9 Mon Sep 17 00:00:00 2001 From: Alexey Arendarenko Date: Thu, 4 Oct 2018 17:00:53 +0300 Subject: [PATCH 21/28] Add condition to check if there is a special price (for cases when timing for special price is set but special price is NOT set) --- Model/Api/Product.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 919a4ed3..799458e0 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -281,7 +281,7 @@ protected function _buildOldProductRequest( $variendata["title"] = $data["title"]; $variendata["url"] = $data["url"]; $variendata["sku"] = $data["sku"]; - $variendata["price"] = (float)$data["price"]; + $variendata["price"] = $data["price"]; $variendata["inventory_quantity"] = $data["inventory_quantity"]; $variendata["image_url"] = $data["image_url"]; $variendata["backorders"] = $data["backorders"]; @@ -359,7 +359,7 @@ protected function _buildProductData( $data["sku"] = $product->getSku(); $today = $this->_helper->getGmtDate("Y-m-d"); try { - if ($product->getSpecialFromDate() && $product->getSpecialFromDate() <= $today) { + if ($product->getSpecialFromDate() && $product->getSpecialFromDate() <= $today && (float)$product->getSpecialPrice()) { if (!$product->getSpecialToDate() || ($product->getSpecialToDate() && $today <= $product->getSpecialToDate())) { $data["price"] = $product->getSpecialPrice(); } else { @@ -376,7 +376,7 @@ protected function _buildProductData( } } - $data["price"] = (float)$data['price']; + $data["price"] = $data['price']; //stock $stock = $this->_stockRegistry->getStockItem($product->getId(), $magentoStoreId); From a9158b8c72d0c50c5225987143d79b8e74fa2d3a Mon Sep 17 00:00:00 2001 From: Alexey Arendarenko Date: Thu, 4 Oct 2018 17:07:25 +0300 Subject: [PATCH 22/28] Code improvements Remove unused code from previous commits --- Model/Api/Product.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Model/Api/Product.php b/Model/Api/Product.php index 799458e0..3b727ec2 100644 --- a/Model/Api/Product.php +++ b/Model/Api/Product.php @@ -369,15 +369,13 @@ protected function _buildProductData( $data["price"] = $product->getPrice(); } } catch(\Exception $e) { - if($product->getSpecialPrice()) { + if((float)$product->getSpecialPrice()) { $data["price"] = $product->getSpecialPrice(); } else { $data["price"] = $product->getPrice(); } } - $data["price"] = $data['price']; - //stock $stock = $this->_stockRegistry->getStockItem($product->getId(), $magentoStoreId); $data["inventory_quantity"] = (int)$stock->getQty(); From e707866791e0848b083498b3fd3c5ec8a908e774 Mon Sep 17 00:00:00 2001 From: keller Date: Fri, 5 Oct 2018 16:27:20 -0300 Subject: [PATCH 23/28] #420 Fix filter when creating collection --- Model/Api/Order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/Api/Order.php b/Model/Api/Order.php index 566da7a8..38059ab1 100644 --- a/Model/Api/Order.php +++ b/Model/Api/Order.php @@ -526,8 +526,8 @@ 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; From 5854c1fcd8c3b2a8e3d645802475bff68637356d Mon Sep 17 00:00:00 2001 From: keller Date: Fri, 5 Oct 2018 16:29:28 -0300 Subject: [PATCH 24/28] closes #420 Initialize total order count and total spent on 0 --- Model/Api/Order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/Api/Order.php b/Model/Api/Order.php index 38059ab1..777328ce 100644 --- a/Model/Api/Order.php +++ b/Model/Api/Order.php @@ -530,8 +530,8 @@ protected function GeneratePOSTPayload(\Magento\Sales\Model\Order $order, $mailc ['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 */ From 7738a964d7004a3a9cb7951fba82fd519188c0d4 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 10 Oct 2018 12:49:55 -0300 Subject: [PATCH 25/28] add the block for the mailchimp combo #423 --- .../System/Config/Form/Field/MailchimpMap.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php 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..b197971d --- /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']; + } + 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 From 4295f3b451cdb48bf03243028b76f68da7db1129 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 10 Oct 2018 12:50:39 -0300 Subject: [PATCH 26/28] change the text field for mailchimp tag for a combo #423 --- .../System/Config/Form/Field/CustomerMap.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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 From a7f7dd138d4aae852b3d6c4537e7698e47aa5275 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 10 Oct 2018 12:51:52 -0300 Subject: [PATCH 27/28] add management for the mc combo #423 --- Helper/VarsMap.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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; } From 25bafb647e53496ac2ca48cc0ec180198b26aa52 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 10 Oct 2018 14:49:41 -0300 Subject: [PATCH 28/28] add name and type to the tag closes #423 --- Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php b/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php index b197971d..82285836 100644 --- a/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php +++ b/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php @@ -49,7 +49,7 @@ protected function _getMailchimpTags() $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']; + $ret[$item['tag']] = $item['tag'].' ('.$item['name'].' : '.$item['type'].')'; } return $ret; }