From 265b7c5325d7ad6bfd67adbef29ed5a9d4eb3bf5 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Thu, 5 Sep 2019 09:51:57 -0300 Subject: [PATCH 001/160] Warnings in tests fixed --- .../Ebizmarts/MailChimp/Helper/DataTest.php | 22 +++++++++---------- .../MailChimp/Model/Api/OrdersTest.php | 6 ++--- .../MailChimp/Model/Api/ProductsTest.php | 4 ++-- .../Adminhtml/EcommerceControllerTest.php | 6 ++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php index 10a3238dc..7b2ecc957 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php @@ -1920,11 +1920,11 @@ public function testCreateMergeFields() 's:7:"magento";s:1:"5";}}'; $mapFieldsUnserialized = array( - "_1468601283719_719", array("mailchimp", "WEBSITE", "magento", "1"), "_1468609069544_544", - array("mailchimp", "STOREID", "magento", "2"), "_1469026825907_907", - array("mailchimp", "STORENAME", "magento", "3"), - "_1469027411717_717", array("mailchimp","PREFIX","magento", "4"), "_1469027418285_285", - array("mailchimp", "FNAME", "magento", "5") + "_1468601283719_719" => array("mailchimp" => "WEBSITE", "magento" => "1"), + "_1468609069544_544" => array("mailchimp" => "STOREID", "magento"=> "2"), + "_1469026825907_907" => array("mailchimp" => "STORENAME", "magento" => "3"), + "_1469027411717_717" => array("mailchimp" => "PREFIX","magento" => "4"), + "_1469027418285_285" => array("mailchimp" => "FNAME", "magento" => "5") ); $arrayMergeFieldsGetAll = array @@ -2037,15 +2037,15 @@ public function testCreateMergeFields() ->with($listId, null, null, 50) ->willReturn($arrayMergeFieldsGetAll); - $times = 10; + $times = 5; $helperDataMock->expects($this->exactly($times))->method('_createCustomFieldTypes') ->withConsecutive( - array($mapFieldsUnserialized), array($mapFieldsUnserialized), - array($mapFieldsUnserialized), array($mapFieldsUnserialized), - array($mapFieldsUnserialized), array($mapFieldsUnserialized), - array($mapFieldsUnserialized), array($mapFieldsUnserialized), - array($mapFieldsUnserialized), array($mapFieldsUnserialized) + array($mapFieldsUnserialized), + array($mapFieldsUnserialized), + array($mapFieldsUnserialized), + array($mapFieldsUnserialized), + array($mapFieldsUnserialized) ); $helperDataMock->createMergeFields($scopeId, $scope); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php index f09019e12..922979fcc 100755 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php @@ -170,7 +170,7 @@ public function testGeneratePOSTPayload() $currentDate = date("yyyy-mm-dd"); $lines['itemsCount'] = 9; - $lines[0] = array( + $lines['lines'][] = array( "id" => 1, "product_id" => 2, "product_variant_id" => 2, @@ -192,7 +192,7 @@ public function testGeneratePOSTPayload() $data['processed_at_foreign'] = $currentDate; $data['updated_at_foreign'] = $currentDate; $data['cancelled_at_foreign'] = $currentDate; - $data['lines'] = null; + $data['lines'] = $lines['lines']; $data['customer'] = array( 'id' => '66ceb8736aefb347ac63da0d588b29a6', 'email_address' => 'test@ebizmarts.com', @@ -235,7 +235,7 @@ public function testGeneratePOSTPayload() $helperMock->expects($this->exactly(2)) ->method('setCurrentStore') - ->withConsecutive($magentoStoreId, $oldStore); + ->withConsecutive(array($magentoStoreId), array($oldStore)); $orderMock = $this->getMockBuilder(Mage_Sales_Model_Order::class) ->disableOriginalConstructor() diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index 55f2d74c9..b2e059dad 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -126,8 +126,8 @@ public function testCreateBatchJson() $helperMock->expects($this->exactly(2)) ->method('setCurrentStore') ->withConsecutive( - $magentoStoreId, - $oldStore + array($magentoStoreId), + array($oldStore) ); $helperMock->expects($this->once()) diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/EcommerceControllerTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/EcommerceControllerTest.php index d51c4c28c..bb0449224 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/EcommerceControllerTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/EcommerceControllerTest.php @@ -146,9 +146,9 @@ public function testResendEcommerceDataAction() $requestMock->expects($this->exactly(3)) ->method('getParam') ->withConsecutive( - $paramFilters, - 'scope', - 'scope_id' + array($paramFilters), + array('scope'), + array('scope_id') ) ->willReturnOnConsecutiveCalls( $filter, From 48626c3013d77f9662f205fe2f2ac158bbb41610 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Thu, 5 Sep 2019 09:59:10 -0300 Subject: [PATCH 002/160] First version of parent class SyncItem --- .../MailChimp/Model/Api/SyncItem.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php new file mode 100755 index 000000000..764187e8a --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -0,0 +1,87 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class Ebizmarts_MailChimp_Model_Api_SyncItem +{ + /** + * @param $cartId + * @param $mailchimpStoreId + * @param null $syncDelta + * @param null $syncError + * @param int $syncModified + * @param null $syncedFlag + * @param null $syncDeleted + * @param null $token + * @param bool $saveOnlyIfExists + * @param bool $allowBatchRemoval + */ + protected function _updateSyncData( + $cartId, + $mailchimpStoreId, + $syncDelta = null, + $syncError = null, + $syncModified = 0, + $syncedFlag = null, + $syncDeleted = null, + $token = null, + $saveOnlyIfExists = false, + $allowBatchRemoval = true + ) { + $helper = $this->getHelper(); + $helper->saveEcommerceSyncData( + $cartId, + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + $mailchimpStoreId, + $syncDelta, + $syncError, + $syncModified, + $syncDeleted, + $token, + $syncedFlag, + $saveOnlyIfExists, + null, + $allowBatchRemoval + ); + } + + /** + * @return Ebizmarts_MailChimp_Helper_Data + */ + protected function getHelper() + { + return Mage::helper('mailchimp'); + } + + /** + * @return Ebizmarts_MailChimp_Helper_Date + */ + protected function getDateHelper() + { + return Mage::helper('mailchimp/date'); + } + + /** + * @return mixed + */ + public function getMailchimpEcommerceDataTableName() + { + return Mage::getSingleton('core/resource')->getTableName('mailchimp/ecommercesyncdata'); + } + + /** + * @param $magentoStoreId + * @return mixed + */ + public function getWebSiteIdFromMagentoStoreId($magentoStoreId) + { + return Mage::getModel('core/store')->load($magentoStoreId)->getWebsiteId(); + } +} From 2abf90d5d0a8b462a8725e20961c6cde1edf43be Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Thu, 5 Sep 2019 15:40:23 -0300 Subject: [PATCH 003/160] Api Products now using parent class and tests fixed --- .../MailChimp/Model/Api/Products.php | 178 +++++++++--------- .../MailChimp/Model/Api/SyncItem.php | 37 +++- .../MailChimp/Model/Api/ProductsTest.php | 102 ++++++---- 3 files changed, 185 insertions(+), 132 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 17cdf3ebf..b473621a1 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -9,7 +9,7 @@ * @copyright Ebizmarts (http://ebizmarts.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Ebizmarts_MailChimp_Model_Api_Products +class Ebizmarts_MailChimp_Model_Api_Products extends Ebizmarts_MailChimp_Model_Api_SyncItem { const PRODUCT_IS_ENABLED = 1; const PRODUCT_IS_DISABLED = 2; @@ -25,11 +25,6 @@ class Ebizmarts_MailChimp_Model_Api_Products */ protected $_productTypeConfigurable; - /** - * @var Ebizmarts_MailChimp_Helper_Data - */ - protected $_mailchimpHelper; - protected $_mailchimpDateHelper; protected $_visibilityOptions; protected $_productTypeConfigurableResource; public static $noChildrenIds = array(0 => array()); @@ -38,12 +33,12 @@ class Ebizmarts_MailChimp_Model_Api_Products public function __construct() { + parent::__construct(); + $this->_productTypeConfigurable = Mage::getModel('catalog/product_type_configurable'); $this->_productTypeConfigurableResource = Mage::getResourceSingleton( 'catalog/product_type_configurable' ); - $this->_mailchimpHelper = Mage::helper('mailchimp'); - $this->_mailchimpDateHelper = Mage::helper('mailchimp/date'); $this->_visibilityOptions = Mage::getModel('catalog/product_visibility')->getOptionArray(); } @@ -56,8 +51,8 @@ public function __construct() */ public function createBatchJson($mailchimpStoreId, $magentoStoreId) { - $helper = $this->getMailChimpHelper(); - $dateHelper = $this->getMailChimpDateHelper(); + $helper = $this->getHelper(); + $dateHelper = $this->getDateHelper(); $oldStore = $helper->getCurrentStoreId(); $helper->setCurrentStore($magentoStoreId); @@ -96,7 +91,11 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $buildUpdateOperations, $batchArray ); - $this->_updateSyncData($productId, $mailchimpStoreId); + $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $productId, + $mailchimpStoreId + ); } $counter = count($batchArray); @@ -122,9 +121,14 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) } //update product delta - $this->_updateSyncData($productId, $mailchimpStoreId); + $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $productId, + $mailchimpStoreId + ); } else { $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, $dateHelper->formatDate(null, 'Y-m-d H:i:s'), @@ -165,6 +169,7 @@ public function createDeletedProductsBatchJson($mailchimpStoreId, $magentoStoreI } $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $product->getId(), $mailchimpStoreId, null, @@ -224,19 +229,21 @@ protected function _buildNewProductRequest($product, $batchId, $mailchimpStoreId if ($body === false) { //json encode failed $jsonErrorMsg = json_last_error_msg(); - $this->getMailChimpHelper()->logError( + $this->getHelper()->logError( "Product " . $product->getId() . " json encode failed (".$jsonErrorMsg.")" ); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $product->getId(), $mailchimpStoreId, - $this->getMailChimpDateHelper()->getCurrentDateTime(), + $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMsg, 0, null, null, + null, false, -1 ); @@ -275,7 +282,7 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor $parentIds = $this->_productTypeConfigurableResource->getParentIdsByChild($product->getId()); foreach ($parentIds as $parentId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $productSyncDataItem = $helper->getEcommerceSyncDataItem( $parentId, Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, @@ -293,18 +300,20 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor $body = json_encode($bodyData, JSON_HEX_APOS | JSON_HEX_QUOT); if ($body === false) { $jsonErrorMsg = json_last_error_msg(); - $this->getMailChimpHelper()->logError( + $this->getHelper()->logError( "Product " . $parent->getId() . " json encode failed (".$jsonErrorMsg.")" ); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parent->getId(), $mailchimpStoreId, - $this->getMailChimpDateHelper()->getCurrentDateTime(), + $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMsg, 0, null, null, + null, false, -1 ); @@ -334,24 +343,26 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor $body = json_encode($bodyData, JSON_HEX_APOS | JSON_HEX_QUOT); if ($body === false) { //json encode failed - $this->getMailChimpHelper()->logError( + $this->getHelper()->logError( "Product " . $product->getId() . " json encode failed (".json_last_error_msg().")" ); $jsonErrorMsg = json_last_error_msg(); - $this->getMailChimpHelper()->logError( + $this->getHelper()->logError( "Product " . $product->getId() . " json encode failed (".$jsonErrorMsg.")" ); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $product->getId(), $mailchimpStoreId, - $this->getMailChimpDateHelper()->getCurrentDateTime(), + $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMsg, 0, null, null, + null, false, -1 ); @@ -383,7 +394,7 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru $data = array(); $productId = $product->getId(); - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $rc = $helper->getProductResourceModel(); //data applied for both root and varient products $data["id"] = $productId; @@ -489,6 +500,7 @@ public function update($productId, $mailchimpStoreId) $parentIdArray = $this->getAllParentIds($productId); foreach ($parentIdArray as $parentId) { $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentId, $mailchimpStoreId, null, @@ -496,12 +508,14 @@ public function update($productId, $mailchimpStoreId) 1, 0, null, + null, true, false ); } $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, null, @@ -509,6 +523,7 @@ public function update($productId, $mailchimpStoreId) 1, 0, null, + null, true, false ); @@ -523,6 +538,7 @@ public function update($productId, $mailchimpStoreId) public function updateDisabledProducts($productId, $mailchimpStoreId) { $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, null, @@ -530,6 +546,7 @@ public function updateDisabledProducts($productId, $mailchimpStoreId) 0, 1, null, + null, false, false ); @@ -548,8 +565,8 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $data = array(); $batchId = $this->makeBatchId($magentoStoreId); $items = $order->getAllVisibleItems(); - $helper = $this->getMailChimpHelper(); - $dateHelper = $this->getMailChimpDateHelper(); + $helper = $this->getHelper(); + $dateHelper = $this->getDateHelper(); $syncDateFlag = $helper->getEcommMinSyncDateFlag($mailchimpStoreId, $magentoStoreId); foreach ($items as $item) { $itemProductId = $item->getProductId(); @@ -566,6 +583,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) ) { if ($productId) { $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, $dateHelper->formatDate(null, 'Y-m-d H:i:s'), @@ -597,7 +615,11 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $buildUpdateOperations, $data ); - $this->_updateSyncData($productId, $mailchimpStoreId); + $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $productId, + $mailchimpStoreId + ); } } elseif (!$syncDelta || $syncDelta < $syncDateFlag || !$isProductEnabled) { $bodyData = $this->_buildNewProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); @@ -606,7 +628,11 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $data[] = $bodyData; // avoid update for disabled products to prevent send the product as modified if ($isProductEnabled) { - $this->_updateSyncData($productId, $mailchimpStoreId); + $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $productId, + $mailchimpStoreId + ); } } } @@ -628,32 +654,32 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) * @param bool $saveOnlyIfexists * @param bool $allowBatchRemoval */ - protected function _updateSyncData( - $productId, - $mailchimpStoreId, - $syncDelta = null, - $syncError = null, - $syncModified = 0, - $syncDeleted = null, - $syncedFlag = null, - $saveOnlyIfexists = false, - $allowBatchRemoval = true - ) { - $this->getMailChimpHelper()->saveEcommerceSyncData( - $productId, - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, - $mailchimpStoreId, - $syncDelta, - $syncError, - $syncModified, - $syncDeleted, - null, - $syncedFlag, - $saveOnlyIfexists, - null, - $allowBatchRemoval - ); - } +// protected function _updateSyncData( +// $productId, +// $mailchimpStoreId, +// $syncDelta = null, +// $syncError = null, +// $syncModified = 0, +// $syncDeleted = null, +// $syncedFlag = null, +// $saveOnlyIfexists = false, +// $allowBatchRemoval = true +// ) { +// $this->getHelper()->saveEcommerceSyncData( +// $productId, +// Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, +// $mailchimpStoreId, +// $syncDelta, +// $syncError, +// $syncModified, +// $syncDeleted, +// null, +// $syncedFlag, +// $saveOnlyIfexists, +// null, +// $allowBatchRemoval +// ); +// } /** * @param $magentoStoreId @@ -662,7 +688,7 @@ protected function _updateSyncData( public function makeBatchId($magentoStoreId) { $batchId = 'storeid-' . $magentoStoreId . '_' . Ebizmarts_MailChimp_Model_Config::IS_PRODUCT; - $batchId .= '_' . $this->getMailChimpDateHelper()->getDateMicrotime(); + $batchId .= '_' . $this->getDateHelper()->getDateMicrotime(); return $batchId; } @@ -682,7 +708,7 @@ public function makeProductsNotSentCollection($magentoStoreId, $isParentProduct } $collection->addStoreFilter($magentoStoreId); - $this->_mailchimpHelper->addResendFilter( + $this->getHelper()->addResendFilter( $collection, $magentoStoreId, Ebizmarts_MailChimp_Model_Config::IS_PRODUCT @@ -702,7 +728,7 @@ public function makeProductsNotSentCollection($magentoStoreId, $isParentProduct */ protected function getBatchLimitFromConfig() { - $helper = $this->_mailchimpHelper; + $helper = $this->getHelper; return $helper->getProductAmountLimit(); } @@ -726,7 +752,7 @@ public function getSyncDataTableName() */ protected function shouldSendProductUpdate($mailchimpStoreId, $magentoStoreId, $product) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $resendTurn = $helper->getResendTurn($magentoStoreId); return !$resendTurn && $product->getMailchimpSyncModified() @@ -900,22 +926,6 @@ protected function getChildrenIdsForConfigurable($product) return $this->_productTypeConfigurable->getChildrenIds($product->getId()); } - /** - * @return Ebizmarts_MailChimp_Helper_Data - */ - protected function getMailChimpHelper() - { - return $this->_mailchimpHelper; - } - - /** - * @return Ebizmarts_MailChimp_Helper_Date - */ - protected function getMailChimpDateHelper() - { - return $this->_mailchimpDateHelper; - } - /** * This function will perform the join of the collection with the table * mailchimp_ecommerce_sync_data when the programcreates the batch json @@ -1001,7 +1011,7 @@ protected function buildMailchimpDataWhere($collection) */ public function getNotVisibleProductUrl($childId, $magentoStoreId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $parentId = null; if (!$this->_parentId) { $parentId = $this->getParentId($childId); @@ -1067,7 +1077,7 @@ public function getParentImageUrl($childId, $magentoStoreId) } if ($parentId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $imageUrl = $helper->getImageUrlById($parentId, $magentoStoreId); } @@ -1172,10 +1182,10 @@ protected function getProductWithAttributesById($magentoStoreId, $parentId) */ protected function getMailChimpImageUrl($product, $magentoStoreId) { - $imageUrl = $this->getMailChimpHelper() + $imageUrl = $this->getHelper() ->getMailChimpProductImageUrl( $this->_parentImageUrl, - $this->getMailChimpHelper()->getImageUrlById( + $this->getHelper()->getImageUrlById( $product->getId(), $magentoStoreId ) @@ -1225,7 +1235,7 @@ protected function currentProductIsVisible() */ protected function getProductPrice($product, $magentoStoreId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $rc = $helper->getProductResourceModel(); $price = $this->getMailchimpFinalPrice($product, $magentoStoreId); return $price; @@ -1310,7 +1320,7 @@ protected function getVisibility($visibility) */ protected function getMailchimpFinalPrice($product, $magentoStoreId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $price = Mage::helper('tax') ->getPrice( $product, @@ -1321,14 +1331,6 @@ protected function getMailchimpFinalPrice($product, $magentoStoreId) return $price; } - /** - * @return Mage_Core_Model_Resource - */ - public function getCoreResource() - { - return Mage::getSingleton('core/resource'); - } - /** * Sync to mailchimp the special price of the products * @@ -1354,7 +1356,7 @@ public function _markSpecialPrices($mailchimpStoreId, $magentoStoreId) 'left' )->addAttributeToFilter( 'special_from_date', - array('lteq' => $this->getMailChimpDateHelper()->formatDate() . " 23:59:59"), + array('lteq' => $this->getDateHelper()->formatDate() . " 23:59:59"), 'left' )->addAttributeToFilter( 'special_from_date', @@ -1365,7 +1367,7 @@ public function _markSpecialPrices($mailchimpStoreId, $magentoStoreId) $whereCondition = $connection->quoteInto( 'm4m.mailchimp_sync_delta IS NOT NULL ' . 'AND m4m.mailchimp_sync_delta < ?', - $this->getMailChimpDateHelper()->formatDate() . " 00:00:00" + $this->getDateHelper()->formatDate() . " 00:00:00" ); $collection->getSelect()->where($whereCondition); @@ -1386,7 +1388,7 @@ public function _markSpecialPrices($mailchimpStoreId, $magentoStoreId) 'left' )->addAttributeToFilter( 'special_to_date', - array('lt' => $this->getMailChimpDateHelper()->formatDate() . " 00:00:00"), + array('lt' => $this->getDateHelper()->formatDate() . " 00:00:00"), 'left' )->addAttributeToFilter( 'special_to_date', diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 764187e8a..8b1077262 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -11,6 +11,22 @@ */ class Ebizmarts_MailChimp_Model_Api_SyncItem { + /** + * @var Ebizmarts_MailChimp_Helper_Data + */ + protected $_mailchimpHelper; + + /** + * @var Ebizmarts_MailChimp_Helper_Date + */ + protected $_mailchimpDateHelper; + + public function __construct() + { + $this->_mailchimpHelper = Mage::helper('mailchimp'); + $this->_mailchimpDateHelper = Mage::helper('mailchimp/date'); + } + /** * @param $cartId * @param $mailchimpStoreId @@ -24,21 +40,22 @@ class Ebizmarts_MailChimp_Model_Api_SyncItem * @param bool $allowBatchRemoval */ protected function _updateSyncData( - $cartId, + $type, + $id, $mailchimpStoreId, $syncDelta = null, $syncError = null, $syncModified = 0, - $syncedFlag = null, $syncDeleted = null, + $syncedFlag = null, $token = null, $saveOnlyIfExists = false, $allowBatchRemoval = true ) { $helper = $this->getHelper(); $helper->saveEcommerceSyncData( - $cartId, - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + $id, + $type, $mailchimpStoreId, $syncDelta, $syncError, @@ -57,7 +74,7 @@ protected function _updateSyncData( */ protected function getHelper() { - return Mage::helper('mailchimp'); + return $this->_mailchimpHelper; } /** @@ -65,7 +82,7 @@ protected function getHelper() */ protected function getDateHelper() { - return Mage::helper('mailchimp/date'); + return $this->_mailchimpDateHelper; } /** @@ -84,4 +101,12 @@ public function getWebSiteIdFromMagentoStoreId($magentoStoreId) { return Mage::getModel('core/store')->load($magentoStoreId)->getWebsiteId(); } + + /** + * @return Mage_Core_Model_Resource + */ + public function getCoreResource() + { + return Mage::getSingleton('core/resource'); + } } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index b2e059dad..61c5d5c4f 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -46,11 +46,7 @@ public function testCreateBatchJson() $productMock = $this->getMockBuilder(Mage_Catalog_Model_Product::class) ->disableOriginalConstructor() - ->setMethods( - array( - "getId" - ) - ) + ->setMethods(array('getId')) ->getMock(); $productCollection = $this->getMockBuilder(Mage_Catalog_Model_Resource_Product_Collection::class) @@ -62,7 +58,7 @@ public function testCreateBatchJson() array('makeBatchId', 'makeProductsNotSentCollection', 'joinMailchimpSyncData', 'shouldSendProductUpdate', 'getChildrenIdsForConfigurable', 'getMailChimpHelper', 'isProductFlatTableEnabled', '_buildNewProductRequest', - '_updateSyncData', '_markSpecialPrices') + '_updateSyncData', '_markSpecialPrices', 'getHelper') ) ->getMock(); @@ -81,7 +77,7 @@ public function testCreateBatchJson() ->getMock(); $productsApiMock->expects($this->once())->method("isProductFlatTableEnabled")->willReturn(false); - $productsApiMock->expects($this->once())->method("getMailChimpHelper")->willReturn($helperMock); + $productsApiMock->expects($this->once())->method("getHelper")->willReturn($helperMock); $productMock->expects($this->once())->method("getId")->willReturn($productId); @@ -117,7 +113,10 @@ public function testCreateBatchJson() ->method('_buildNewProductRequest') ->with($productMock, self::BATCH_ID, $mailchimpStoreId, $magentoStoreId) ->willReturn($productData); - $productsApiMock->expects($this->once())->method('_updateSyncData')->with($productId, $mailchimpStoreId); + $productsApiMock + ->expects($this->once()) + ->method('_updateSyncData') + ->with(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId); $helperMock->expects($this->once()) ->method('getCurrentStoreId') @@ -198,7 +197,7 @@ public function testGetNotVisibleProductUrl() $url = 'url/path'; $productsApiMock = $this->_productsApiMock - ->setMethods(array('getMailChimpHelper', 'getParentId', 'getProductWithAttributesById', 'getUrlByPath')) + ->setMethods(array('getHelper', 'getParentId', 'getProductWithAttributesById', 'getUrlByPath')) ->getMock(); $mailChimpHelperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -215,7 +214,7 @@ public function testGetNotVisibleProductUrl() ->disableOriginalConstructor() ->getMock(); - $productsApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($mailChimpHelperMock); + $productsApiMock->expects($this->once())->method('getHelper')->willReturn($mailChimpHelperMock); $productsApiMock->expects($this->once())->method('getParentId')->with($childId)->willReturn($parentId); $productsApiMock ->expects($this->once()) @@ -257,7 +256,7 @@ public function testGetParentImageUrl() $imageUrl = 'imageUrl'; $productsApiMock = $this->_productsApiMock - ->setMethods(array('getMailChimpHelper', 'getParentId')) + ->setMethods(array('getParentId', 'getHelper')) ->getMock(); $mailChimpHelperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -266,7 +265,7 @@ public function testGetParentImageUrl() ->getMock(); $productsApiMock->expects($this->once())->method('getParentId')->with($childId)->willReturn($parentId); - $productsApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($mailChimpHelperMock); + $productsApiMock->expects($this->once())->method('getHelper')->willReturn($mailChimpHelperMock); $mailChimpHelperMock ->expects($this->once()) @@ -387,9 +386,9 @@ public function testSendModifiedProduct() $productsApiMock = $this->_productsApiMock ->setMethods( - array('makeBatchId', '_updateSyncData', 'loadProductById', 'getMailChimpHelper', - 'isGroupedProduct', 'isBundleProduct', '_buildUpdateProductRequest', - '_buildNewProductRequest', 'isProductEnabled', 'getMailChimpDateHelper' + array('makeBatchId', '_updateSyncData', 'loadProductById', 'isGroupedProduct', + 'isBundleProduct', '_buildUpdateProductRequest', '_buildNewProductRequest', + 'isProductEnabled', 'getHelper', 'getDateHelper' ) ) ->getMock(); @@ -462,8 +461,8 @@ public function testSendModifiedProduct() $newProductId ); - $productsApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($helperMock); - $productsApiMock->expects($this->once())->method('getMailChimpDateHelper')->willReturn($dateHelperMock); + $productsApiMock->expects($this->once())->method('getHelper')->willReturn($helperMock); + $productsApiMock->expects($this->once())->method('getDateHelper')->willReturn($dateHelperMock); $productsApiMock->expects($this->exactly(2)) ->method('isProductEnabled') @@ -532,11 +531,14 @@ public function testSendModifiedProduct() ->with($productMock, $batchId, $mailchimpStoreId, $magentoStoreId) ->willReturn(array()); - $productsApiMock->expects($this->exactly(3))->method('_updateSyncData')->withConsecutive( - array($groupedProductId, $mailchimpStoreId), - array($oldProductId, $mailchimpStoreId), - array($newProductId, $mailchimpStoreId) - ); + $productsApiMock + ->expects($this->exactly(3)) + ->method('_updateSyncData') + ->withConsecutive( + array(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $groupedProductId, $mailchimpStoreId), + array(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $oldProductId, $mailchimpStoreId), + array(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $newProductId, $mailchimpStoreId) + ); $return = $productsApiMock->sendModifiedProduct($orderMock, $mailchimpStoreId, $magentoStoreId); } @@ -677,6 +679,7 @@ public function testCreateDeletedProductsBatchJson() ->expects($this->once()) ->method('_updateSyncData') ->with( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productMock->getId(), $mailchimpStoreId, null, @@ -741,15 +744,42 @@ public function testUpdate() $productsApiMock->expects($this->exactly(9)) ->method('_updateSyncData') ->withConsecutive( - array($parentIdArray[0], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($parentIdArray[1], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($parentIdArray[2], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($parentIdArray[3], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($parentIdArray[4], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($parentIdArray[5], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($parentIdArray[6], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($parentIdArray[7], $mailchimpStoreId, null, null, 1, null, null, true, false), - array($productId, $mailchimpStoreId, null, null, 1, null, null, true, false) + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[0], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[1], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[2], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[3], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[4], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[5], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[6], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $parentIdArray[7], $mailchimpStoreId, null, null, 1, null, null, null, true, false + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $productId, $mailchimpStoreId, null, null, 1, null, null, null, true, false + ) ); $productsApiMock->update($productId, $mailchimpStoreId); @@ -763,11 +793,7 @@ public function testMarkSpecialPrices() $dateToday = '2019-07-25'; $helperDateMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Date::class) - ->setMethods( - array( - 'formatDate' - ) - ) + ->setMethods(array('formatDate')) ->getMock(); $timeZone = Mage::app()->getStore()->getConfig('general/locale/timezone'); @@ -790,7 +816,7 @@ public function testMarkSpecialPrices() array( 'getCoreResource', 'getProductResourceCollection', 'getSelect', 'update', 'joinMailchimpSyncDataForSpecialPrices', - 'getMailChimpDateHelper' + 'getDateHelper' ) ) ->getMock(); @@ -814,7 +840,7 @@ public function testMarkSpecialPrices() $productsApiMock ->expects($this->exactly(3)) - ->method('getMailChimpDateHelper') + ->method('getDateHelper') ->willReturn($helperDateMock); $helperDateMock From 919543e2f4ebe3e7f5d9d1fb85a2d12ffa0c2558 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Thu, 5 Sep 2019 15:41:16 -0300 Subject: [PATCH 004/160] Commented Code removed --- .../MailChimp/Model/Api/Products.php | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index b473621a1..2867079f0 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -641,46 +641,6 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) return $data; } - /** - * update product sync data - * - * @param $productId - * @param $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncDeleted - * @param int|null $syncedFlag - * @param bool $saveOnlyIfexists - * @param bool $allowBatchRemoval - */ -// protected function _updateSyncData( -// $productId, -// $mailchimpStoreId, -// $syncDelta = null, -// $syncError = null, -// $syncModified = 0, -// $syncDeleted = null, -// $syncedFlag = null, -// $saveOnlyIfexists = false, -// $allowBatchRemoval = true -// ) { -// $this->getHelper()->saveEcommerceSyncData( -// $productId, -// Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, -// $mailchimpStoreId, -// $syncDelta, -// $syncError, -// $syncModified, -// $syncDeleted, -// null, -// $syncedFlag, -// $saveOnlyIfexists, -// null, -// $allowBatchRemoval -// ); -// } - /** * @param $magentoStoreId * @return string From 4df95f33cef62c6d3a9648037a9ddc1bc981995b Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 10:11:26 -0300 Subject: [PATCH 005/160] Api Carts now using parent class and tests fixed --- .../Ebizmarts/MailChimp/Model/Api/Carts.php | 114 +++++++----------- .../MailChimp/Model/Api/CartsTest.php | 54 ++++++--- 2 files changed, 81 insertions(+), 87 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index 0dfe2f2c1..d356f6e36 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -9,7 +9,7 @@ * @copyright Ebizmarts (http://ebizmarts.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Ebizmarts_MailChimp_Model_Api_Carts +class Ebizmarts_MailChimp_Model_Api_Carts extends Ebizmarts_MailChimp_Model_Api_SyncItem { const BATCH_LIMIT = 100; @@ -20,6 +20,11 @@ class Ebizmarts_MailChimp_Model_Api_Carts protected $_api = null; protected $_token = null; + public function __construct() + { + parent::__construct(); + } + /** * @param $mailchimpStoreId * @param $magentoStoreId @@ -108,13 +113,14 @@ public function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $alreadySentCartId, $mailchimpStoreId, null, null, 0, - null, - 1 + 1, + null ); $this->setCounter($this->getCounter() + 1); } @@ -127,13 +133,14 @@ public function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $cartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, null, 0, - null, - 1 + 1, + null ); $this->setCounter($this->getCounter() + 1); } @@ -202,13 +209,14 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $alreadySentCartId, $mailchimpStoreId, null, null, 0, - null, - 1 + 1, + null ); $this->setCounter($this->getCounter() + 1); } @@ -219,7 +227,7 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) // avoid carts abandoned as guests when customer email associated to a registered customer. if (!$cart->getCustomerId() && $customer->getEmail() == $cart->getCustomerEmail()) { - $this->_updateSyncData($cartId, $mailchimpStoreId); + $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId); continue; } @@ -238,6 +246,7 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['body'] = $cartJson; $this->setCounter($this->getCounter() + 1); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -250,12 +259,20 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) } else { $error = $helper->__('There is not supported products in this cart.'); - $this->_updateSyncData($cartId, $mailchimpStoreId, null, $error, 0); + $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + $cartId, + $mailchimpStoreId, + null, + $error, + 0 + ); } } else { $jsonErrorMessage = json_last_error_msg(); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -319,7 +336,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $orderCollection->addFieldToFilter('main_table.updated_at', array('from' => $cart->getUpdatedAt())); //if cart is empty or customer has an order made after the abandonment skip current cart. if (empty($cart->getAllVisibleItems()) || $orderCollection->getSize()) { - $this->_updateSyncData($cartId, $mailchimpStoreId); + $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId); continue; } @@ -345,13 +362,14 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $alreadySentCartId, $mailchimpStoreId, null, null, 0, - null, - 1 + 1, + null ); $this->setCounter($this->getCounter() + 1); } @@ -361,7 +379,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) // don't send the carts for guest customers who are registered if (!$cart->getCustomerId() && $customer->getEmail() == $cart->getCustomerEmail()) { - $this->_updateSyncData($cartId, $mailchimpStoreId); + $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId); continue; } @@ -380,6 +398,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['body'] = $cartJson; $this->setCounter($this->getCounter() + 1); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -392,14 +411,20 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) } else { $error = $helper->__('There is not supported products in this cart.'); $this->_updateSyncData( - $cartId, $mailchimpStoreId, $dateHelper->getCurrentDateTime(), - $error, 0 + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + $cartId, + $mailchimpStoreId, + $dateHelper->getCurrentDateTime(), + $error, + 0 ); } } else { $jsonErrorMessage = json_last_error_msg(); $this->_updateSyncData( - $cartId, $mailchimpStoreId, + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + $cartId, + $mailchimpStoreId, $dateHelper->getCurrentDateTime(), $jsonErrorMessage, 0, @@ -676,47 +701,6 @@ protected function _addBillingAddress($address, $billingAddress) return $address; } - /** - * @param $cartId - * @param $mailchimpStoreId - * @param null $syncDelta - * @param null $syncError - * @param int $syncModified - * @param null $syncedFlag - * @param null $syncDeleted - * @param null $token - * @param bool $saveOnlyIfExists - * @param bool $allowBatchRemoval - */ - protected function _updateSyncData( - $cartId, - $mailchimpStoreId, - $syncDelta = null, - $syncError = null, - $syncModified = 0, - $syncedFlag = null, - $syncDeleted = null, - $token = null, - $saveOnlyIfExists = false, - $allowBatchRemoval = true - ) { - $helper = $this->getHelper(); - $helper->saveEcommerceSyncData( - $cartId, - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, - $mailchimpStoreId, - $syncDelta, - $syncError, - $syncModified, - $syncDeleted, - $token, - $syncedFlag, - $saveOnlyIfExists, - null, - $allowBatchRemoval - ); - } - /** * @param $mailchimpStoreId * @param $magentoStoreId @@ -734,22 +718,6 @@ public function addProductNotSentData($mailchimpStoreId, $magentoStoreId, $cart, return $allCarts; } - /** - * @return Ebizmarts_MailChimp_Helper_Data - */ - protected function getHelper() - { - return Mage::helper('mailchimp'); - } - - /** - * @return Ebizmarts_MailChimp_Helper_Date - */ - protected function getDateHelper() - { - return Mage::helper('mailchimp/date'); - } - /** * @param $newCarts * @param $mailchimpStoreId diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php index e33c1e653..340faf227 100755 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php @@ -194,14 +194,16 @@ public function testGetConvertedQuotes() ->method('_updateSyncData') ->withConsecutive( array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, - null, null, null, null, 1 + null, null, null, 1, null ), array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID, - null, null, null, null, 1 + null, null, null, 1, null ) ); $cartsApiMock->expects($this->exactly(2)) @@ -375,8 +377,14 @@ public function testGetModifiedQuotes() $cartsApiMock->expects($this->exactly(2)) ->method('_updateSyncData') ->withConsecutive( - array(self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, 1), - array(self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token) + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token + ) ); $cartsApiMock->expects($this->exactly(2)) ->method('setCounter') @@ -509,7 +517,7 @@ public function testGetModifiedQuotesGuestCustomer() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getCustomerModel') ->willReturn($customerModelMock); @@ -685,8 +693,14 @@ public function testGetModifiedQuotesEmptyJson() $cartsApiMock->expects($this->exactly(2)) ->method('_updateSyncData') ->withConsecutive( - array(self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, 1), - array(self::CART_ID, self::MAILCHIMP_STORE_ID) + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::CART_ID, self::MAILCHIMP_STORE_ID + ) ); $cartsApiMock->expects($this->once()) ->method('setCounter') @@ -879,8 +893,14 @@ public function testGetNewQuotesNewQuote() $cartsApiMock->expects($this->exactly(2)) ->method('_updateSyncData') ->withConsecutive( - array(self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, 1), - array(self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token) + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token + ) ); $cartsApiMock->expects($this->once()) ->method('getCustomerModel') @@ -1077,7 +1097,7 @@ public function testGetNewQuotesIsOrder() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getOrderCollection') ->willReturn($orderCollectionMock); @@ -1202,7 +1222,7 @@ public function testGetNewQuotesEmpty() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getOrderCollection') ->willReturn($orderCollectionMock); @@ -1335,7 +1355,7 @@ public function testGetNewQuotesGuestCustomer() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getCustomerModel') ->willReturn($customerModelMock); @@ -1529,8 +1549,14 @@ public function testGetNewQuotesEmptyJson() $cartsApiMock->expects($this->exactly(2)) ->method('_updateSyncData') ->withConsecutive( - array(self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, 1), - array(self::CART_ID, self::MAILCHIMP_STORE_ID) + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null + ), + array( + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + self::CART_ID, self::MAILCHIMP_STORE_ID + ) ); $cartsApiMock->expects($this->once()) ->method('getCustomerModel') From e3aac5a2857f2e725ea404d5810370035ec8537e Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Fri, 6 Sep 2019 10:24:23 -0300 Subject: [PATCH 006/160] Using Varien_Http_Adapter_Curl methods, instead using discouraged curl_exec function. --- .../Ebizmarts/MailChimp/Helper/Curl.php | 44 ++++++++++++++++ .../Ebizmarts/MailChimp/Helper/Data.php | 6 +-- .../Ebizmarts/MailChimp/Model/Api/Batches.php | 39 ++++++++++++--- lib/Ebizmarts/MailChimp.php | 50 +++++++++---------- 4 files changed, 104 insertions(+), 35 deletions(-) create mode 100644 app/code/community/Ebizmarts/MailChimp/Helper/Curl.php diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Curl.php b/app/code/community/Ebizmarts/MailChimp/Helper/Curl.php new file mode 100644 index 000000000..0052b43cf --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Curl.php @@ -0,0 +1,44 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 9/5/19 3:55 PM + * @file: Curl.php + */ + +class Ebizmarts_MailChimp_Helper_Curl extends Mage_Core_Helper_Abstract +{ + /** + * @param array $options + * @return array An array with... + */ + public function curlExec($options = array()) + { + $url = isset($options[CURLOPT_URL]) ? $options[CURLOPT_URL] : false; + $method = isset($options[CURLOPT_CUSTOMREQUEST]) ? $options[CURLOPT_CUSTOMREQUEST] : false; + $userAgent = isset($options[CURLOPT_USERAGENT]) ? $options[CURLOPT_USERAGENT] : Zend_Http_Client::HTTP_1; + $headers = isset($options[CURLOPT_HTTPHEADER]) ? $options[CURLOPT_HTTPHEADER] : array(); + $body = isset($options[CURLOPT_POSTFIELDS]) ? $options[CURLOPT_POSTFIELDS] : ''; + + if($url === false) + return array(); + + $curl = new Varien_Http_Adapter_Curl(); + $curl->setOptions($options); + $curl->write($method, $url, $userAgent, $headers, $body); + $response = $curl->read(); + $responseBody = $response === false ? '' : Zend_Http_Response::extractBody($response); + $curlError = $response === false ? $curl->getError() : ''; + $info = $curl->getInfo(); + $curl->close(); + + return array('response' => $responseBody, 'error' => $curlError, 'info' => $info); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index f4d1f09f5..11a7e2858 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -4866,15 +4866,15 @@ public function modifyCounterDataSentToMailchimp($index, $hasError = false, $inc if ($hasError === true) { $count = isset($counterGetResponsesBatchAtIndex[self::DATA_NOT_SENT_TO_MAILCHIMP]) ? $counterGetResponsesBatchAtIndex[self::DATA_NOT_SENT_TO_MAILCHIMP] - : $increment; + : 0; $statusChanged = self::DATA_NOT_SENT_TO_MAILCHIMP; } else { $count = isset($counterGetResponsesBatchAtIndex[self::DATA_SENT_TO_MAILCHIMP]) ? $counterGetResponsesBatchAtIndex[self::DATA_SENT_TO_MAILCHIMP] - : $increment; + : 0; } - $this->setCountersDataSentToMailchimp($index, $statusChanged, $count); + $this->setCountersDataSentToMailchimp($index, $statusChanged, $count + $increment); } public function resetCountersDataSentToMailchimp() diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index a6e32fa0e..e3db8fb3f 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -23,6 +23,11 @@ class Ebizmarts_MailChimp_Model_Api_Batches */ protected $_mailchimpDateHelper; + /** + * @var Ebizmarts_MailChimp_Helper_Curl + */ + protected $_mailchimpCurlHelper; + /** * @var Ebizmarts_MailChimp_Model_Api_Customers */ @@ -62,6 +67,8 @@ public function __construct() { $this->_mailchimpHelper = Mage::helper('mailchimp'); $this->_mailchimpDateHelper = Mage::helper('mailchimp/date'); + $this->_mailchimpCurlHelper = Mage::helper('mailchimp/curl'); + $this->_apiCustomers = Mage::getModel('mailchimp/api_customers'); $this->_apiProducts = Mage::getModel('mailchimp/api_products'); $this->_apiCarts = Mage::getModel('mailchimp/api_carts'); @@ -79,6 +86,14 @@ protected function getHelper() return $this->_mailchimpHelper; } + /** + * @return Ebizmarts_MailChimp_Helper_Curl + */ + protected function getMailchimpCurlHelper() + { + return $this->_mailchimpCurlHelper; + } + /** * @return Ebizmarts_MailChimp_Helper_Date */ @@ -310,6 +325,7 @@ public function _sendEcommerceBatch($magentoStoreId) $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); try { $this->deleteUnsentItems(); + if ($helper->isEcomSyncDataEnabled($magentoStoreId)) { $helper->resetCountersSentPerBatch(); $batchArray = array(); @@ -336,6 +352,7 @@ public function _sendEcommerceBatch($magentoStoreId) $ordersArray = $apiOrders->createBatchJson($mailchimpStoreId, $magentoStoreId); $orderAmount = count($ordersArray); $batchArray['operations'] = array_merge($batchArray['operations'], $ordersArray); + if ($helper->getPromoConfig($magentoStoreId) == self::SEND_PROMO_ENABLED) { //promo rule operations $helper->logBatchStatus('Generate Promo Rules Payload'); @@ -596,6 +613,7 @@ protected function _sendSubscriberBatches() public function sendStoreSubscriberBatch($storeId, $limit) { $helper = $this->getHelper(); + try { if ($helper->isSubscriptionEnabled($storeId)) { $helper->resetCountersSubscribers(); @@ -657,32 +675,39 @@ public function getBatchResponse($batchId, $magentoStoreId) { $helper = $this->getHelper(); $files = array(); + try { $baseDir = $this->getMagentoBaseDir(); $api = $helper->getApi($magentoStoreId); + if ($api) { // check the status of the job $response = $api->batchOperation->status($batchId); + if (isset($response['status']) && $response['status'] == 'finished') { // get the tar.gz file with the results $fileUrl = urldecode($response['response_body_url']); $fileName = $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId . '.tar.gz'; $fd = fopen($fileName, 'w'); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $fileUrl); - curl_setopt($ch, CURLOPT_FILE, $fd); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // this will follow redirects - $r = curl_exec($ch); + $curlOptions = array( + CURLOPT_URL => $fileUrl, + CURLOPT_FILE => $fd, + CURLOPT_FOLLOWLOCATION => true, // this will follow redirects + ); - curl_close($ch); + $curlHelper = $this->getMailchimpCurlHelper(); + $curlResults = $curlHelper->curlExec($curlOptions); + $r = $curlResults['response']; fclose($fd); mkdir( $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId, 0750, true ); + $archive = new Mage_Archive(); + if (file_exists($fileName)) { $files = $this->_unpackBatchFile($files, $batchId, $archive, $fileName, $baseDir); } @@ -1165,7 +1190,7 @@ protected function _showResumeEcommerce($batchId, $storeId) $helper = $this->getHelper(); $countersSentPerBatch = $helper->getCountersSentPerBatch(); - if (!empty($countersSentPerBatch) || $helper->getCountersSentPerBatch() != null) { + if (!empty($countersSentPerBatch) || $countersSentPerBatch != null) { $helper->logBatchStatus("Sent batch $batchId for store $storeId"); $helper->logBatchQuantity($helper->getCountersSentPerBatch()); } else { diff --git a/lib/Ebizmarts/MailChimp.php b/lib/Ebizmarts/MailChimp.php index 73dcc0667..dcc59dfeb 100755 --- a/lib/Ebizmarts/MailChimp.php +++ b/lib/Ebizmarts/MailChimp.php @@ -203,7 +203,7 @@ class Ebizmarts_MailChimp public $templates; protected $_apiKey; - protected $_ch; + protected $curlOptions = array(); protected $_root = 'https://api.mailchimp.com/3.0'; protected $_debug = false; @@ -239,24 +239,21 @@ public function __construct($apiKey = null, $opts = array(), $userAgent = null) $this->_debug = true; } - - $this->_ch = curl_init(); - if (isset($opts['CURLOPT_FOLLOWLOCATION']) && $opts['CURLOPT_FOLLOWLOCATION'] === true) { - curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, true); + $this->curlOptions[CURLOPT_FOLLOWLOCATION] = true; } if ($userAgent) { - curl_setopt($this->_ch, CURLOPT_USERAGENT, $userAgent); + $this->curlOptions[CURLOPT_USERAGENT] = $userAgent; } else { - curl_setopt($this->_ch, CURLOPT_USERAGENT, 'Ebizmart-MailChimp-PHP/3.0.0'); + $this->curlOptions[CURLOPT_USERAGENT] = 'Ebizmart-MailChimp-PHP/3.0.0'; } - curl_setopt($this->_ch, CURLOPT_HEADER, false); - curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($this->_ch, CURLOPT_CONNECTTIMEOUT, $opts['timeout']); - curl_setopt($this->_ch, CURLOPT_TIMEOUT, $opts['timeout']); - curl_setopt($this->_ch, CURLOPT_USERPWD, "noname:" . $this->_apiKey); + $this->curlOptions[CURLOPT_HEADER] = false; + $this->curlOptions[CURLOPT_RETURNTRANSFER] = true; + $this->curlOptions[CURLOPT_CONNECTTIMEOUT] = $opts['timeout']; + $this->curlOptions[CURLOPT_TIMEOUT] = $opts['timeout']; + $this->curlOptions[CURLOPT_USERPWD] = "noname:" . $this->_apiKey; $this->root = new MailChimp_Root($this); $this->authorizedApps = new MailChimp_AuthorizedApps($this); @@ -376,31 +373,35 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ $headers[] = 'Accept-Language: ' . $paramsOrig['language']; } - $ch = $this->_ch; if ($hasParams && $method != Ebizmarts_MailChimp::GET) { - curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + $this->curlOptions[CURLOPT_POSTFIELDS] = $params; } else { - curl_setopt($ch, CURLOPT_POSTFIELDS, null); + $this->curlOptions[CURLOPT_POSTFIELDS] = null; + if ($hasParams) { $_params = http_build_query($params); $url .= '?' . $_params; } } - curl_setopt($ch, CURLOPT_URL, $this->_root . $url); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_VERBOSE, $this->_debug); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + $this->curlOptions[CURLOPT_URL] = $this->_root . $url; + $this->curlOptions[CURLOPT_HTTPHEADER] = $headers; + $this->curlOptions[CURLOPT_VERBOSE] = $this->_debug; + $this->curlOptions[CURLOPT_CUSTOMREQUEST] = $method; - $responseBody = curl_exec($ch); - - $info = curl_getinfo($ch); + /** + * @var $curlHelper Ebizmarts_MailChimp_Helper_Curl + */ + $curlHelper = Mage::helper('mailchimp/curl'); + $curlResult = $curlHelper->curlExec($this->curlOptions); + $responseBody = $curlResult['response']; + $info = $curlResult['info']; + $curlError = $curlResult['error']; $result = json_decode($responseBody, true); - $curlError = curl_error($ch); if (!empty($curlError)) { - throw new MailChimp_HttpError($url, $method, $params, '', "API call to $url failed: " . curl_error($ch)); + throw new MailChimp_HttpError($url, $method, $params, '', "API call to $url failed: " . $curlError); } if (floor($info['http_code'] / 100) >= 4) { @@ -408,7 +409,6 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ $detail = array_key_exists('detail', $result) ? $result['detail'] : ''; $errors = array_key_exists('errors', $result) ? $result['errors'] : null; $title = array_key_exists('title', $result) ? $result['title'] : ''; - throw new MailChimp_HttpError($this->_root . $url, $method, $params, $title, $detail, $errors); } else { throw new MailChimp_HttpError($this->_root . $url, $method, $params, $result); From 17deaf459f2e3ed37517627d729478376ff9dea1 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 11:00:49 -0300 Subject: [PATCH 007/160] Api Customers now using parent class and tests fixed --- .../MailChimp/Model/Api/Customers.php | 135 ++++++------------ .../MailChimp/Model/Api/CustomersTest.php | 29 +++- 2 files changed, 66 insertions(+), 98 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index dc6bb10cf..edc422993 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -10,15 +10,10 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Ebizmarts_MailChimp_Model_Api_Customers +class Ebizmarts_MailChimp_Model_Api_Customers extends Ebizmarts_MailChimp_Model_Api_SyncItem { const BATCH_LIMIT = 100; - - /** - * @var Ebizmarts_MailChimp_Helper_Data - */ - protected $_mailchimpHelper; - protected $_mailchimpDateHelper; + protected $_optInConfiguration; protected $_optInStatusForStore; protected $_locale; @@ -29,8 +24,8 @@ class Ebizmarts_MailChimp_Model_Api_Customers public function __construct() { - $this->_mailchimpHelper = $this->makeHelper(); - $this->_mailchimpDateHelper = $this->makeDateHelper(); + parent::__construct(); + $this->_optInConfiguration = array(); $this->_locale = Mage::app()->getLocale(); $this->_directoryRegionModel = Mage::getModel('directory/region'); @@ -88,7 +83,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) { $this->setMailchimpStoreId($mailchimpStoreId); $this->setMagentoStoreId($magentoStoreId); - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $customersCollection = array(); $customerIds = $this->getCustomersToSync(); @@ -122,7 +117,14 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $customerArray[$counter] = $this->makePutBatchStructure($customerJson, $customer); $this->_updateSyncData( - $customer->getId(), $mailchimpStoreId, null, null, 0, null + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, + $customer->getId(), + $mailchimpStoreId, + null, + null, + 0, + null, + null ); $counter++; @@ -144,19 +146,26 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) } } else { $this->_updateSyncData( - $customer->getId(), $mailchimpStoreId, - $this->getMailChimpDateHelper()->getCurrentDateTime(), 'Customer with no data', 0 + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, + $customer->getId(), + $mailchimpStoreId, + $this->getDateHelper()->getCurrentDateTime(), + 'Customer with no data', + 0 ); } } else { $jsonErrorMessage = $this->logCouldNotEncodeCustomerError($customer); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, $customer->getId(), $mailchimpStoreId, - $this->getMailChimpDateHelper()->getCurrentDateTime(), + $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMessage, 0, null, + null, + null, false, -1 ); @@ -310,8 +319,20 @@ protected function getCountryNameByCode($countryCode) */ public function update($customerId, $storeId) { - $mailchimpStoreId = $this->_mailchimpHelper->getMCStoreId($storeId); - $this->_updateSyncData($customerId, $mailchimpStoreId, null, null, 1, null, true, false); + $mailchimpStoreId = $this->getHelper()->getMCStoreId($storeId); + $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, + $customerId, + $mailchimpStoreId, + null, + null, + 1, + null, + null, + null, + true, + false + ); } /** @@ -338,44 +359,6 @@ protected function getOptInConfiguration($magentoStoreId) return $this->_optInConfiguration[$magentoStoreId]; } - /** - * update customer sync data - * - * @param int $customerId - * @param string $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncedFlag - * @param bool $saveOnlyIfexists - * @param bool $allowBatchRemoval - */ - protected function _updateSyncData( - $customerId, - $mailchimpStoreId, - $syncDelta = null, - $syncError = null, - $syncModified = 0, - $syncedFlag = null, - $saveOnlyIfexists = false, - $allowBatchRemoval = true - ) { - $this->_mailchimpHelper->saveEcommerceSyncData( - $customerId, - Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, - $mailchimpStoreId, - $syncDelta, - $syncError, - $syncModified, - null, - null, - $syncedFlag, - $saveOnlyIfexists, - null, - $allowBatchRemoval - ); - } - /** * @return void */ @@ -383,7 +366,7 @@ protected function makeBatchId() { $this->_batchId = "storeid-{$this->getBatchMagentoStoreId()}_"; $this->_batchId .= Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER . '_'; - $this->_batchId .= $this->_mailchimpDateHelper->getDateMicrotime(); + $this->_batchId .= $this->getDateHelper()->getDateMicrotime(); } /** @@ -435,7 +418,7 @@ public function getSyncDataTableName() */ protected function isEcommerceCustomerOptInConfigEnabled($magentoStoreId) { - $configValue = $this->_mailchimpHelper->getConfigValueForScope( + $configValue = $this->getHelper()->getConfigValueForScope( Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CUSTOMERS_OPTIN, $magentoStoreId ); @@ -459,7 +442,7 @@ protected function checkEcommerceOptInConfigAndUpdateStorage($magentoStoreId) */ protected function getBatchLimitFromConfig() { - $helper = $this->_mailchimpHelper; + $helper = $this->getHelper(); return $helper->getCustomerAmountLimit(); } @@ -497,7 +480,7 @@ protected function getCustomerLastname($customer) protected function logCouldNotEncodeCustomerError($customer) { $jsonErrorMessage = json_last_error_msg(); - $this->_mailchimpHelper->logError( + $this->getHelper()->logError( "Customer " . $customer->getId() . " json encode failed (".$jsonErrorMessage.") on store " . $this->getBatchMagentoStoreId() ); @@ -510,11 +493,11 @@ protected function logCouldNotEncodeCustomerError($customer) */ protected function logCouldNotEncodeMailchimpTags($customer, $mailchimpTags) { - $this->_mailchimpHelper->logError( + $this->getHelper()->logError( "MailChimp tags encode failed, Customer " . $customer->getId() . " on store " . $this->getBatchMagentoStoreId()." mergeFields:" ); - $this->_mailchimpHelper->logError($mailchimpTags); + $this->getHelper()->logError($mailchimpTags); } /** @@ -584,38 +567,6 @@ protected function getSubscriberModel() return $subscriber; } - /** - * @return Ebizmarts_MailChimp_Helper_Data - */ - protected function makeHelper() - { - return Mage::helper('mailchimp'); - } - - /** - * @return Ebizmarts_MailChimp_Helper_Data - */ - protected function getMailChimpHelper() - { - return $this->_mailchimpHelper; - } - - /** - * @return Ebizmarts_MailChimp_Helper_Date - */ - protected function makeDateHelper() - { - return Mage::helper('mailchimp/date'); - } - - /** - * @return Ebizmarts_MailChimp_Helper_Date - */ - protected function getMailChimpDateHelper() - { - return $this->_mailchimpDateHelper; - } - /** * @param $customer * @param $listId diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php index 6ea852727..ed6aefc06 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php @@ -120,7 +120,7 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() 'getOptIn', 'getOptInStatusForStore', 'getBatchMagentoStoreId', '_buildCustomerData', 'makePutBatchStructure', '_updateSyncData', 'setMailchimpStoreId', 'setMagentoStoreId', - 'getCustomerResourceCollection', 'getSubscriberModel', 'getMailChimpHelper', + 'getCustomerResourceCollection', 'getSubscriberModel', 'getHelper', 'isSubscribed', 'makePatchBatchStructure', 'incrementCounterSentPerBatch','sendMailchimpTags' ) ) @@ -152,7 +152,7 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() $customerArray = array($customerMock); - $this->_customersApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($helperMock); + $this->_customersApiMock->expects($this->once())->method('getHelper')->willReturn($helperMock); $this->_customersApiMock->expects($this->once())->method('setMailchimpStoreId')->with($mailchimpStoreId); $this->_customersApiMock->expects($this->once())->method('setMagentoStoreId')->with($storeId); $this->_customersApiMock->expects($this->once()) @@ -211,7 +211,16 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() $this->_customersApiMock ->expects($this->once()) ->method('_updateSyncData') - ->with($customerId, $mailchimpStoreId, null, null, 0, null) + ->with( + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, + $customerId, + $mailchimpStoreId, + null, + null, + 0, + null, + null + ) ->willReturnSelf(); $helperMock->expects($this->once()) @@ -305,7 +314,7 @@ public function testCreateBatchJsonOptInTrueCustomerNotSubscribed() 'getOptIn', 'getOptInStatusForStore', 'getBatchMagentoStoreId', '_buildCustomerData', 'makePutBatchStructure', '_updateSyncData', 'setMailchimpStoreId', 'setMagentoStoreId', - 'getCustomerResourceCollection', 'getSubscriberModel', 'getMailChimpHelper', + 'getCustomerResourceCollection', 'getSubscriberModel', 'getHelper', 'isSubscribed', 'makePatchBatchStructure', 'incrementCounterSentPerBatch', 'makeMailchimpTagsBatchStructure' ) @@ -339,7 +348,7 @@ public function testCreateBatchJsonOptInTrueCustomerNotSubscribed() $customerArray = array($customerMock); - $this->_customersApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($helperMock); + $this->_customersApiMock->expects($this->once())->method('getHelper')->willReturn($helperMock); $this->_customersApiMock->expects($this->once())->method('setMailchimpStoreId')->with($mailchimpStoreId); $this->_customersApiMock->expects($this->once())->method('setMagentoStoreId')->with($storeId); $this->_customersApiMock->expects($this->once()) @@ -398,7 +407,15 @@ public function testCreateBatchJsonOptInTrueCustomerNotSubscribed() $this->_customersApiMock ->expects($this->once()) ->method('_updateSyncData') - ->with($customerId, $mailchimpStoreId, null, null, 0, null) + ->with( + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, + $customerId, $mailchimpStoreId, + null, + null, + 0, + null, + null + ) ->willReturnSelf(); $helperMock->expects($this->once()) From 96cbfc416f0af967263740ec1b9546571cc8a66f Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 11:36:31 -0300 Subject: [PATCH 008/160] Api Orders now using parent class --- .../Ebizmarts/MailChimp/Model/Api/Orders.php | 83 ++++++------------- 1 file changed, 25 insertions(+), 58 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 6af6e227d..42b320d99 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -9,7 +9,7 @@ * @copyright Ebizmarts (http://ebizmarts.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Ebizmarts_MailChimp_Model_Api_Orders +class Ebizmarts_MailChimp_Model_Api_Orders extends Ebizmarts_MailChimp_Model_Api_SyncItem { const BATCH_LIMIT = 50; @@ -29,6 +29,11 @@ class Ebizmarts_MailChimp_Model_Api_Orders protected $_api = null; protected $_listsCampaignIds = array(); + public function __construct() + { + parent::__construct(); + } + /** * Set the request for orders to be created on MailChimp * @@ -107,16 +112,18 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) $batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId; $batchArray[$this->_counter]['body'] = $orderJson; //update order delta - $this->_updateSyncData($orderId, $mailchimpStoreId); + $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId); $this->_counter++; } else { $error = $helper->__('Something went wrong when retrieving product information.'); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, 0, + null, 0 ); continue; @@ -126,12 +133,15 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $jsonErrorMsg, 0, + null, 0, + null, false, -1 ); @@ -189,16 +199,18 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) $batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId; $batchArray[$this->_counter]['body'] = $orderJson; //update order delta - $this->_updateSyncData($orderId, $mailchimpStoreId); + $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId); $this->_counter++; } else { $error = $helper->__('Something went wrong when retrieving product information.'); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, 0, + null, 0 ); continue; @@ -208,12 +220,15 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $jsonErrorMsg, 0, + null, 0, + null, false, -1 ); @@ -669,57 +684,21 @@ public function update($orderId, $magentoStoreId) if ($helper->isEcomSyncDataEnabled($magentoStoreId)) { $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, null, null, 1, null, + null, + null, true, false ); } } - /** - * update customer sync data - * - * @param int $orderId - * @param string $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncedFlag - * @param bool $saveOnlyIfexists - * @param bool $allowBatchRemoval - */ - protected function _updateSyncData( - $orderId, - $mailchimpStoreId, - $syncDelta = null, - $syncError = null, - $syncModified = 0, - $syncedFlag = null, - $saveOnlyIfexists = false, - $allowBatchRemoval = true - ) { - $helper = $this->getHelper(); - $helper->saveEcommerceSyncData( - $orderId, - Ebizmarts_MailChimp_Model_Config::IS_ORDER, - $mailchimpStoreId, - $syncDelta, - $syncError, - $syncModified, - null, - null, - $syncedFlag, - $saveOnlyIfexists, - null, - $allowBatchRemoval - ); - } - /** * Replace all orders with old id with the increment id on MailChimp. * @@ -790,11 +769,13 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS 'Something went wrong when retrieving product information during migration from 1.1.6.' ); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, 0, + null, 0 ); continue; @@ -802,11 +783,13 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS } else { $error = $helper->__("Json error during migration from 1.1.6"); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, 0, + null, 0 ); continue; @@ -843,22 +826,6 @@ public function addProductNotSentData($mailchimpStoreId, $magentoStoreId, $order return $batchArray; } - /** - * @return Ebizmarts_MailChimp_Helper_Data - */ - protected function getHelper() - { - return Mage::helper('mailchimp'); - } - - /** - * @return Ebizmarts_MailChimp_Helper_Date - */ - protected function getDateHelper() - { - return Mage::helper('mailchimp/date'); - } - /** * @param $newOrders * @param $mailchimpStoreId From ecf88aada53092358b6d520847bfbe74940c152c Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 12:00:36 -0300 Subject: [PATCH 009/160] Api PromoCodes now using parent class and tests fixed --- .../MailChimp/Model/Api/PromoCodes.php | 75 +++++++------------ .../MailChimp/Model/Api/SyncItem.php | 5 +- .../MailChimp/Model/Api/PromoCodesTest.php | 12 +-- 3 files changed, 38 insertions(+), 54 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index 9d8aec2a3..c4eb1c11d 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -9,7 +9,7 @@ * @copyright Ebizmarts (http://ebizmarts.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Ebizmarts_MailChimp_Model_Api_PromoCodes +class Ebizmarts_MailChimp_Model_Api_PromoCodes extends Ebizmarts_MailChimp_Model_Api_SyncItem { const BATCH_LIMIT = 50; const TYPE_FIXED = 'fixed'; @@ -19,8 +19,6 @@ class Ebizmarts_MailChimp_Model_Api_PromoCodes const TARGET_SHIPPING = 'shipping'; protected $_batchId; - protected $_mailchimpHelper; - protected $_mailchimpDateHelper; /** * @var Ebizmarts_MailChimp_Model_Api_PromoRules */ @@ -28,8 +26,7 @@ class Ebizmarts_MailChimp_Model_Api_PromoCodes public function __construct() { - $this->_mailchimpHelper = Mage::helper('mailchimp'); - $this->_mailchimpDateHelper = Mage::helper('mailchimp/date'); + parent::__construct(); } /** @@ -43,7 +40,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $this->_batchId = 'storeid-' . $magentoStoreId . '_' . Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE . '_' - . Mage::helper('mailchimp/date')->getDateMicrotime(); + . $this->getDateHelper()->getDateMicrotime(); $batchArray = array_merge($batchArray, $this->_getDeletedPromoCodes($mailchimpStoreId)); $batchArray = array_merge($batchArray, $this->_getNewPromoCodes($mailchimpStoreId, $magentoStoreId)); @@ -84,8 +81,8 @@ protected function _getDeletedPromoCodes($mailchimpStoreId) protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) { $batchArray = array(); - $helper = $this->getMailChimpHelper(); - $dateHelper = $this->getMailChimpDateHelper(); + $helper = $this->getHelper(); + $dateHelper = $this->getDateHelper(); $newPromoCodes = $this->makePromoCodesCollection($magentoStoreId); $this->joinMailchimpSyncDataWithoutWhere($newPromoCodes, $mailchimpStoreId); @@ -106,7 +103,7 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) $codeId = $promoCode->getCouponId(); $ruleId = $promoCode->getRuleId(); try { - $promoRuleSyncData = $this->getMailChimpHelper()->getEcommerceSyncDataItem( + $promoRuleSyncData = $this->getHelper()->getEcommerceSyncDataItem( $ruleId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $mailchimpStoreId @@ -147,18 +144,21 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) $batchArray[$counter]['body'] = $promoCodeJson; $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, null, null, 0, null, + null, $promoCode->getToken() ); $counter++; } else { $error = $helper->__('Something went wrong when retrieving the information.'); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -170,6 +170,7 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) $jsonErrorMsg = json_last_error_msg(); $helper->logError("Promo code" . $codeId . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -177,9 +178,10 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) 0, null, null, - false, null, - -1 + false, + -1, + null ); } } catch (Exception $e) { @@ -213,7 +215,7 @@ protected function getPromoCodeResourceCollection() */ public function makePromoCodesCollection($magentoStoreId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); /** * @var Mage_SalesRule_Model_Resource_Coupon_Collection $collection */ @@ -290,18 +292,20 @@ public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId * @param bool $allowBatchRemoval */ protected function _updateSyncData( + $type, // NEW $codeId, $mailchimpStoreId, $syncDelta = null, $syncError = null, $syncModified = 0, $syncDeleted = null, + $syncedFlag = null, // NEW $token = null, $saveOnlyIfexists = false, - $deletedRelatedId = null, - $allowBatchRemoval = true + $allowBatchRemoval = true, + $deletedRelatedId = null ) { - $this->getMailChimpHelper()->saveEcommerceSyncData( + $this->getHelper()->saveEcommerceSyncData( $codeId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $mailchimpStoreId, @@ -330,22 +334,6 @@ protected function generateCodeData($promoCode, $magentoStoreId) return $data; } - /** - * @return Ebizmarts_MailChimp_Helper_Data - */ - protected function getMailChimpHelper() - { - return $this->_mailchimpHelper; - } - - /** - * @return Ebizmarts_MailChimp_Helper_Date - */ - protected function getMailChimpDateHelper() - { - return $this->_mailchimpDateHelper; - } - protected function addWebsiteColumn($collection) { $websiteTableName = $this->getCoreResource()->getTableName('salesrule/website'); @@ -426,7 +414,7 @@ public function markAsDeleted($codeId, $promoRuleId) */ protected function _setDeleted($codeId, $promoRuleId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $promoCodes = $helper->getAllEcommerceSyncDataItemsPerId( $codeId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE @@ -434,6 +422,7 @@ protected function _setDeleted($codeId, $promoRuleId) foreach ($promoCodes as $promoCode) { $mailchimpStoreId = $promoCode->getMailchimpStoreId(); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, null, @@ -441,9 +430,10 @@ protected function _setDeleted($codeId, $promoRuleId) 0, 1, null, + null, true, - $promoRuleId, - false + false, + $promoRuleId ); } } @@ -456,7 +446,7 @@ public function deletePromoCodesSyncDataByRule($promoRule) { $promoCodeIds = $this->getPromoCodesForRule($promoRule->getRelatedId()); foreach ($promoCodeIds as $promoCodeId) { - $promoCodeSyncDataItems = $this->getMailChimpHelper()->getAllEcommerceSyncDataItemsPerId( + $promoCodeSyncDataItems = $this->getHelper()->getAllEcommerceSyncDataItemsPerId( $promoCodeId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE ); @@ -472,7 +462,7 @@ public function deletePromoCodesSyncDataByRule($promoRule) */ public function deletePromoCodeSyncData($promoCodeId, $mailchimpStoreId) { - $promoCodeSyncDataItem = $this->getMailChimpHelper()->getEcommerceSyncDataItem( + $promoCodeSyncDataItem = $this->getHelper()->getEcommerceSyncDataItem( $promoCodeId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $mailchimpStoreId @@ -487,7 +477,7 @@ public function deletePromoCodeSyncData($promoCodeId, $mailchimpStoreId) protected function getPromoCodesForRule($promoRuleId) { $promoCodes = array(); - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $promoRules = $helper->getAllEcommerceSyncDataItemsPerId( $promoRuleId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE @@ -529,23 +519,16 @@ protected function getPromoRuleIdByCouponId($promoCodeId) */ protected function setCodeWithParentError($mailchimpStoreId, $ruleId, $codeId) { - $dateHelper = $this->getMailChimpDateHelper(); + $dateHelper = $this->getDateHelper(); $error = Mage::helper('mailchimp')->__( 'Parent rule with id ' . $ruleId . ' has not been correctly sent.' ); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error ); } - - /** - * @return Mage_Core_Model_Abstract - */ - protected function getCoreResource() - { - return Mage::getSingleton('core/resource'); - } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 8b1077262..6044562ae 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -50,7 +50,8 @@ protected function _updateSyncData( $syncedFlag = null, $token = null, $saveOnlyIfExists = false, - $allowBatchRemoval = true + $allowBatchRemoval = true, + $deletedRelatedId = null ) { $helper = $this->getHelper(); $helper->saveEcommerceSyncData( @@ -64,7 +65,7 @@ protected function _updateSyncData( $token, $syncedFlag, $saveOnlyIfExists, - null, + $deletedRelatedId, $allowBatchRemoval ); } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php index 9370fc804..08db963d5 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php @@ -56,7 +56,7 @@ public function testMakePromoCodesCollection() ->setMethods( array( 'getPromoCodeResourceCollection', 'addWebsiteColumn', - 'joinPromoRuleData', 'getMailChimpHelper' + 'joinPromoRuleData', 'getHelper' ) ) ->getMock(); @@ -70,7 +70,7 @@ public function testMakePromoCodesCollection() ->setMethods(array('addResendFilter')) ->getMock(); - $promoCodesApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($mailChimpHelperMock); + $promoCodesApiMock->expects($this->once())->method('getHelper')->willReturn($mailChimpHelperMock); $promoCodesApiMock ->expects($this->once()) @@ -130,7 +130,7 @@ public function testDeletePromoCodesSyncDataByRule() $syncDataItems = array(); $promoCodesApiMock = $this->_promoCodesApiMock - ->setMethods(array('getPromoCodesForRule', 'getMailChimpHelper')) + ->setMethods(array('getPromoCodesForRule', 'getHelper')) ->getMock(); $promoRuleMock = $this->getMockBuilder(Mage_SalesRule_Model_Rule::class) @@ -161,7 +161,7 @@ public function testDeletePromoCodesSyncDataByRule() ->method('getPromoCodesForRule') ->with($promoRuleId) ->willReturn($promoCodesIds); - $promoCodesApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($mailChimpHelperMock); + $promoCodesApiMock->expects($this->once())->method('getHelper')->willReturn($mailChimpHelperMock); $mailChimpHelperMock ->expects($this->once()) @@ -182,7 +182,7 @@ public function testDeletePromoCodesSyncDataByRule() public function testDeletePromoCodeSyncData() { $promoCodesApiMock = $this->_promoCodesApiMock - ->setMethods(array('getMailChimpHelper')) + ->setMethods(array('getHelper')) ->getMock(); $mailChimpHelperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -195,7 +195,7 @@ public function testDeletePromoCodeSyncData() ->setMethods(array('delete')) ->getMock(); - $promoCodesApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($mailChimpHelperMock); + $promoCodesApiMock->expects($this->once())->method('getHelper')->willReturn($mailChimpHelperMock); $mailChimpHelperMock ->expects($this->once()) From 5e98d75ff4314c7f08f6bc0eeada8d1373ac130b Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Fri, 6 Sep 2019 13:34:00 -0300 Subject: [PATCH 010/160] Using methods for accessing and modifying the curlOptions class attribute. --- lib/Ebizmarts/MailChimp.php | 67 ++++++++++++++++++++------ lib/Mandrill/Mandrill.php | 96 ++++++++++++++++++++++++++++--------- 2 files changed, 126 insertions(+), 37 deletions(-) diff --git a/lib/Ebizmarts/MailChimp.php b/lib/Ebizmarts/MailChimp.php index dcc59dfeb..83b10609d 100755 --- a/lib/Ebizmarts/MailChimp.php +++ b/lib/Ebizmarts/MailChimp.php @@ -239,21 +239,24 @@ public function __construct($apiKey = null, $opts = array(), $userAgent = null) $this->_debug = true; } + $curlOptions = array(); + if (isset($opts['CURLOPT_FOLLOWLOCATION']) && $opts['CURLOPT_FOLLOWLOCATION'] === true) { - $this->curlOptions[CURLOPT_FOLLOWLOCATION] = true; + $curlOptions[CURLOPT_FOLLOWLOCATION] = true; } if ($userAgent) { - $this->curlOptions[CURLOPT_USERAGENT] = $userAgent; + $curlOptions[CURLOPT_USERAGENT] = $userAgent; } else { - $this->curlOptions[CURLOPT_USERAGENT] = 'Ebizmart-MailChimp-PHP/3.0.0'; + $curlOptions[CURLOPT_USERAGENT] = 'Ebizmart-MailChimp-PHP/3.0.0'; } - $this->curlOptions[CURLOPT_HEADER] = false; - $this->curlOptions[CURLOPT_RETURNTRANSFER] = true; - $this->curlOptions[CURLOPT_CONNECTTIMEOUT] = $opts['timeout']; - $this->curlOptions[CURLOPT_TIMEOUT] = $opts['timeout']; - $this->curlOptions[CURLOPT_USERPWD] = "noname:" . $this->_apiKey; + $curlOptions[CURLOPT_HEADER] = false; + $curlOptions[CURLOPT_RETURNTRANSFER] = true; + $curlOptions[CURLOPT_CONNECTTIMEOUT] = $opts['timeout']; + $curlOptions[CURLOPT_TIMEOUT] = $opts['timeout']; + $curlOptions[CURLOPT_USERPWD] = "noname:" . $this->_apiKey; + $this->setCurlOptionsAddOptions($curlOptions); $this->root = new MailChimp_Root($this); $this->authorizedApps = new MailChimp_AuthorizedApps($this); @@ -373,10 +376,12 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ $headers[] = 'Accept-Language: ' . $paramsOrig['language']; } + $curlOptions = array(); + if ($hasParams && $method != Ebizmarts_MailChimp::GET) { - $this->curlOptions[CURLOPT_POSTFIELDS] = $params; + $curlOptions[CURLOPT_POSTFIELDS] = $params; } else { - $this->curlOptions[CURLOPT_POSTFIELDS] = null; + $curlOptions[CURLOPT_POSTFIELDS] = null; if ($hasParams) { $_params = http_build_query($params); @@ -384,15 +389,16 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ } } - $this->curlOptions[CURLOPT_URL] = $this->_root . $url; - $this->curlOptions[CURLOPT_HTTPHEADER] = $headers; - $this->curlOptions[CURLOPT_VERBOSE] = $this->_debug; - $this->curlOptions[CURLOPT_CUSTOMREQUEST] = $method; + $curlOptions[CURLOPT_URL] = $this->_root . $url; + $curlOptions[CURLOPT_HTTPHEADER] = $headers; + $curlOptions[CURLOPT_VERBOSE] = $this->_debug; + $curlOptions[CURLOPT_CUSTOMREQUEST] = $method; /** * @var $curlHelper Ebizmarts_MailChimp_Helper_Curl */ $curlHelper = Mage::helper('mailchimp/curl'); + $this->setCurlOptionsAddOptions($curlOptions); $curlResult = $curlHelper->curlExec($this->curlOptions); $responseBody = $curlResult['response']; @@ -417,4 +423,37 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ return $result; } + + /** + * @return array + */ + public function getCurlOptions() + { + return $this->curlOptions; + } + + /** + * @param array $curlOptions + */ + protected function setCurlOptions($curlOptions) + { + $this->curlOptions = $curlOptions; + } + + /** + * @param $index + * @param $value + */ + protected function setCurlOptionsIndexValue($index, $value) + { + $this->curlOptions[$index] = $value; + } + + /** + * @param array $curlOptions + */ + protected function setCurlOptionsAddOptions($curlOptions = array()) + { + $this->curlOptions += $curlOptions; + } } diff --git a/lib/Mandrill/Mandrill.php b/lib/Mandrill/Mandrill.php index 3e8f0ac47..40fb9f3f0 100755 --- a/lib/Mandrill/Mandrill.php +++ b/lib/Mandrill/Mandrill.php @@ -39,7 +39,7 @@ class Mandrill_Mandrill { public $apikey; - public $ch; + protected $curlOptions; public $root = 'https://mandrillapp.com/api/1.0'; public $debug = false; @@ -91,17 +91,21 @@ public function __construct($apikey = null) $this->apikey = $apikey; - $this->ch = curl_init(); - curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mandrill-PHP/1.0.53'); - curl_setopt($this->ch, CURLOPT_POST, true); + $curlOptions = array( + CURLOPT_USERAGENT => 'Mandrill-PHP/1.0.53', + CURLOPT_POST => true + ); + if (!ini_get('open_basedir')) { - curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); + $curlOptions[CURLOPT_FOLLOWLOCATION] = true; } - curl_setopt($this->ch, CURLOPT_HEADER, false); - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30); - curl_setopt($this->ch, CURLOPT_TIMEOUT, 600); + $curlOptions[CURLOPT_HEADER] = false; + $curlOptions[CURLOPT_RETURNTRANSFER] = true; + $curlOptions[CURLOPT_CONNECTTIMEOUT] = 30; + $curlOptions[CURLOPT_TIMEOUT] = 600; + + $this->setCurlOptionsAddOptions($curlOptions); $this->root = rtrim($this->root, '/') . '/'; @@ -124,30 +128,39 @@ public function __construct($apikey = null) public function __destruct() { - curl_close($this->ch); + $this->curlOptions = array(); } public function call($url, $params) { $params['key'] = $this->apikey; $params = json_encode($params); - $ch = $this->ch; - curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json'); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); - curl_setopt($ch, CURLOPT_POSTFIELDS, $params); - curl_setopt($ch, CURLOPT_VERBOSE, $this->debug); + $curlOptions = array(); + $curlOptions[CURLOPT_URL] = $this->root . $url . '.json'; + $curlOptions[CURLOPT_HTTPHEADER] = array('Content-Type: application/json'); + $curlOptions[CURLOPT_POSTFIELDS] = $params; + $curlOptions[CURLOPT_VERBOSE] = $this->debug; $start = microtime(true); $this->log('Call to ' . $this->root . $url . '.json: ' . $params); + if ($this->debug) { $curl_buffer = fopen('php://memory', 'w+'); - curl_setopt($ch, CURLOPT_STDERR, $curl_buffer); + $curlOptions[CURLOPT_STDERR] = $curl_buffer; } - $response_body = curl_exec($ch); - $info = curl_getinfo($ch); + /** + * @var $curlHelper Ebizmarts_MailChimp_Helper_Curl + */ + $curlHelper = Mage::helper('mailchimp/curl'); + $this->setCurlOptionsAddOptions($curlOptions); + $curlFullResponse = $curlHelper->curlExec($this->curlOptions); + $info = $curlFullResponse['info']; + $responseBody = $curlFullResponse['response']; + $curlError = $curlFullResponse['error']; $time = microtime(true) - $start; + if ($this->debug) { rewind($curl_buffer); $this->log(stream_get_contents($curl_buffer)); @@ -155,15 +168,18 @@ public function call($url, $params) } $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms'); - $this->log('Got response: ' . $response_body); + $this->log('Got response: ' . $responseBody); - if (curl_error($ch)) { - throw new Mandrill_HttpError("API call to $url failed: " . curl_error($ch)); + if (!empty($curlError)) { + throw new Mandrill_HttpError("API call to $url failed: " . $curlError); } - $result = json_decode($response_body, true); + $result = json_decode($responseBody, true); + if ($result === null) { - throw new Mandrill_Error('We were unable to decode the JSON response from the Mandrill API: ' . $response_body); + throw new Mandrill_Error( + 'We were unable to decode the JSON response from the Mandrill API: ' . $responseBody + ); } try { @@ -180,6 +196,7 @@ public function call($url, $params) public function readConfigs() { $paths = array('~/.mandrill.key', '/etc/mandrill.key'); + foreach ($paths as $path) { if (file_exists($path)) { $apikey = trim(file_get_contents($path)); @@ -208,4 +225,37 @@ public function log($msg) error_log($msg); } } + + /** + * @return array + */ + protected function getCurlOptions() + { + return $this->curlOptions; + } + + /** + * @param array $curlOptions + */ + protected function setCurlOptions($curlOptions) + { + $this->curlOptions = $curlOptions; + } + + /** + * @param $index + * @param $value + */ + protected function setCurlOptionsIndexValue($index, $value) + { + $this->curlOptions[$index] = $value; + } + + /** + * @param array $curlOptions + */ + protected function setCurlOptionsAddOptions($curlOptions = array()) + { + $this->curlOptions += $curlOptions; + } } From b6cc1ade79078226d6484df54cee6f26c5bdb76d Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 13:58:00 -0300 Subject: [PATCH 011/160] Api PromoRules now using parent class and tests fixed --- .../MailChimp/Model/Api/PromoRules.php | 100 ++++-------------- .../MailChimp/Model/Api/PromoRulesTest.php | 18 ++-- 2 files changed, 29 insertions(+), 89 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index 3ff05e956..adbdefc4f 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -9,7 +9,7 @@ * @copyright Ebizmarts (http://ebizmarts.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Ebizmarts_MailChimp_Model_Api_PromoRules +class Ebizmarts_MailChimp_Model_Api_PromoRules extends Ebizmarts_MailChimp_Model_Api_SyncItem { const BATCH_LIMIT = 50; const TYPE_FIXED = 'fixed'; @@ -19,14 +19,7 @@ class Ebizmarts_MailChimp_Model_Api_PromoRules const TARGET_SHIPPING = 'shipping'; protected $_batchId; - /** - * @var Ebizmarts_MailChimp_Helper_Data - */ - protected $_mailchimpHelper; - /** - * @var Ebizmarts_MailChimp_Helper_Date - */ - protected $_mailchimpDateHelper; + /** * @var Ebizmarts_MailChimp_Model_Api_PromoCodes */ @@ -34,8 +27,7 @@ class Ebizmarts_MailChimp_Model_Api_PromoRules public function __construct() { - $this->_mailchimpHelper = Mage::helper('mailchimp'); - $this->_mailchimpDateHelper = Mage::helper('mailchimp/date'); + parent::__construct(); $this->_promoCodes = Mage::getModel('mailchimp/api_promoCodes'); } @@ -50,7 +42,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $this->_batchId = 'storeid-' . $magentoStoreId . '_' . Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE . '_' - . $this->getMailChimpDateHelper()->getDateMicrotime(); + . $this->getDateHelper()->getDateMicrotime(); $batchArray = array_merge($batchArray, $this->_getModifiedAndDeletedPromoRules($mailchimpStoreId)); return $batchArray; @@ -90,8 +82,8 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) { $promoData = array(); $promoRule = $this->getPromoRule($ruleId); - $helper = $this->getMailChimpHelper(); - $dateHelper = $this->getMailChimpDateHelper(); + $helper = $this->getHelper(); + $dateHelper = $this->getDateHelper(); try { $ruleData = $this->generateRuleData($promoRule); $promoRuleJson = json_encode($ruleData); @@ -106,7 +98,7 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) . $dateHelper->getDateMicrotime() . '_' . $ruleId; $promoData['body'] = $promoRuleJson; //update promo rule delta - $this->_updateSyncData($ruleId, $mailchimpStoreId); + $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId); } else { $error = $promoRule->getMailchimpSyncError(); if (!$error) { @@ -114,6 +106,7 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) } $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -125,12 +118,15 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) $helper->logError("Promo rule " . $ruleId . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), $jsonErrorMsg, 0, null, + null, + null, false, -1 ); @@ -230,51 +226,13 @@ public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId ); } - /** - * update promo rule sync data - * - * @param int $ruleId - * @param string $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncDeleted - * @param bool $saveOnlyIfexists - * @param bool $allowBatchRemoval - */ - protected function _updateSyncData( - $ruleId, - $mailchimpStoreId, - $syncDelta = null, - $syncError = null, - $syncModified = 0, - $syncDeleted = null, - $saveOnlyIfexists = false, - $allowBatchRemoval = true - ) { - $this->getMailChimpHelper()->saveEcommerceSyncData( - $ruleId, - Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, - $mailchimpStoreId, - $syncDelta, - $syncError, - $syncModified, - $syncDeleted, - null, - null, - $saveOnlyIfexists, - null, - $allowBatchRemoval - ); - } - /** * @param $ruleId * @param $mailchimpStoreId */ protected function deletePromoRuleSyncData($ruleId, $mailchimpStoreId) { - $ruleSyncDataItem = $this->getMailChimpHelper()->getEcommerceSyncDataItem( + $ruleSyncDataItem = $this->getHelper()->getEcommerceSyncDataItem( $ruleId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $mailchimpStoreId @@ -329,22 +287,6 @@ protected function generateRuleData($promoRule) return $data; } - /** - * @return Ebizmarts_MailChimp_Helper_Data - */ - protected function getMailChimpHelper() - { - return $this->_mailchimpHelper; - } - - /** - * @return Ebizmarts_MailChimp_Helper_Date - */ - protected function getMailChimpDateHelper() - { - return $this->_mailchimpDateHelper; - } - /** * @param $promoAction * @return string|null @@ -398,7 +340,7 @@ public function update($ruleId) */ protected function _setModified($ruleId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $promoRules = $helper->getAllEcommerceSyncDataItemsPerId( $ruleId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE @@ -406,12 +348,15 @@ protected function _setModified($ruleId) foreach ($promoRules as $promoRule) { $mailchimpStoreId = $promoRule->getMailchimpStoreId(); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, null, null, 1, null, + null, + null, true, false ); @@ -431,7 +376,7 @@ public function markAsDeleted($ruleId) */ protected function _setDeleted($ruleId) { - $helper = $this->getMailChimpHelper(); + $helper = $this->getHelper(); $promoRules = $helper->getAllEcommerceSyncDataItemsPerId( $ruleId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE @@ -439,12 +384,15 @@ protected function _setDeleted($ruleId) foreach ($promoRules as $promoRule) { $mailchimpStoreId = $promoRule->getMailchimpStoreId(); $this->_updateSyncData( + Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, null, null, 0, 1, + null, + null, true, false ); @@ -484,14 +432,6 @@ protected function getWebsiteIdByStoreId($magentoStoreId) return Mage::getModel('core/store')->load($magentoStoreId)->getWebsiteId(); } - /** - * @return Mage_Core_Model_Abstract - */ - protected function getCoreResource() - { - return Mage::getSingleton('core/resource'); - } - /** * @param $data * @return bool diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php index 114220fb4..321e5c9d7 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php @@ -37,7 +37,7 @@ public function testCreateBatchJson() ); $promoRulesApiMock = $this->_promoRulesApiMock - ->setMethods(array('getMailChimpDateHelper', '_getModifiedAndDeletedPromoRules')) + ->setMethods(array('getDateHelper', '_getModifiedAndDeletedPromoRules')) ->getMock(); $mailChimpDateHelperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Date::class) @@ -47,7 +47,7 @@ public function testCreateBatchJson() $promoRulesApiMock ->expects($this->once()) - ->method('getMailChimpDateHelper') + ->method('getDateHelper') ->willReturn($mailChimpDateHelperMock); $mailChimpDateHelperMock ->expects($this->once()) @@ -79,9 +79,9 @@ public function testGetNewPromoRuleWithOutError($promoRuleData) $promoRulesApiMock = $this->_promoRulesApiMock ->disableOriginalConstructor() ->setMethods( - array('getPromoRule', 'getMailChimpHelper', '_updateSyncData', 'getMailChimpDiscountAmount', + array('getPromoRule', 'getHelper', '_updateSyncData', 'getMailChimpDiscountAmount', 'getMailChimpType', 'getMailChimpTarget', 'ruleIsNotCompatible', 'ruleHasMissingInformation', - 'getMailchimpDateHelper') + 'getDateHelper') ) ->getMock(); @@ -108,7 +108,7 @@ public function testGetNewPromoRuleWithOutError($promoRuleData) $promoRulesApiMock ->expects($this->once()) - ->method('getMailChimpDateHelper') + ->method('getDateHelper') ->willReturn($mailChimpDateHelperMock); $promoRulesApiMock ->expects($this->once()) @@ -228,8 +228,8 @@ public function testGetNewPromoRuleWithError($promoRuleData) ->disableOriginalConstructor() ->setMethods( array( - 'getPromoRule', '_updateSyncData', 'getMailChimpHelper', - 'getMailChimpDiscountAmount', 'getMailChimpType', 'getMailchimpDateHelper', + 'getPromoRule', '_updateSyncData', 'getHelper', + 'getMailChimpDiscountAmount', 'getMailChimpType', 'getDateHelper', 'getMailChimpTarget', 'ruleIsNotCompatible', 'ruleHasMissingInformation' ) ) @@ -257,11 +257,11 @@ public function testGetNewPromoRuleWithError($promoRuleData) $promoRulesApiMock ->expects($this->once()) - ->method('getMailChimpHelper') + ->method('getHelper') ->willReturn($mailChimpHelperMock); $promoRulesApiMock ->expects($this->once()) - ->method('getMailChimpDateHelper') + ->method('getDateHelper') ->willReturn($mailChimpDateHelperMock); $promoRulesApiMock ->expects($this->once()) From b48917135c08b7052fc168aa8f9cfe34b44b6df9 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Fri, 6 Sep 2019 14:06:19 -0300 Subject: [PATCH 012/160] Initializing curlOptions as an array(). --- lib/Mandrill/Mandrill.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Mandrill/Mandrill.php b/lib/Mandrill/Mandrill.php index 40fb9f3f0..732cb3d9e 100755 --- a/lib/Mandrill/Mandrill.php +++ b/lib/Mandrill/Mandrill.php @@ -39,7 +39,7 @@ class Mandrill_Mandrill { public $apikey; - protected $curlOptions; + protected $curlOptions = array(); public $root = 'https://mandrillapp.com/api/1.0'; public $debug = false; From bfc197506b07390687b671c06327c424035aad09 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 15:21:06 -0300 Subject: [PATCH 013/160] GetTableName and other methods unified in parent class --- .../Ebizmarts/MailChimp/Model/Api/Carts.php | 8 ---- .../MailChimp/Model/Api/Customers.php | 13 +----- .../Ebizmarts/MailChimp/Model/Api/Orders.php | 6 +-- .../MailChimp/Model/Api/Products.php | 15 +------ .../MailChimp/Model/Api/PromoCodes.php | 12 +----- .../MailChimp/Model/Api/PromoRules.php | 12 +----- .../MailChimp/Model/Api/SyncItem.php | 3 +- .../MailChimp/Model/Api/PromoCodesTest.php | 21 ---------- .../MailChimp/Model/Api/PromoRulesTest.php | 21 ---------- .../MailChimp/Model/Api/SyncItemTest.php | 42 +++++++++++++++++++ 10 files changed, 52 insertions(+), 101 deletions(-) create mode 100644 dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/SyncItemTest.php diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index d356f6e36..a44c6ff0d 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -733,14 +733,6 @@ public function joinMailchimpSyncDataWithoutWhere($newCarts, $mailchimpStoreId) ); } - /** - * @return mixed - */ - public function getMailchimpEcommerceDataTableName() - { - return Mage::getSingleton('core/resource')->getTableName('mailchimp/ecommercesyncdata'); - } - /** * @return Mage_Sales_Model_Resource_Quote_Collection */ diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index edc422993..eb6b60087 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -400,17 +400,6 @@ protected function joinMailchimpSyncData($collection) $collection->getSelect()->where("m4m.mailchimp_sync_delta IS null OR m4m.mailchimp_sync_modified = 1"); } - /** - * @return string - */ - public function getSyncDataTableName() - { - $mailchimpTableName = Mage::getSingleton('core/resource') - ->getTableName('mailchimp/ecommercesyncdata'); - - return $mailchimpTableName; - } - /** * @param $magentoStoreId * @return bool @@ -527,7 +516,7 @@ public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId } $joinCondition = "m4m.related_id = e.entity_id AND m4m.type = '%s' AND m4m.mailchimp_store_id = '%s'"; - $mailchimpTableName = $this->getSyncDataTableName(); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $collection->getSelect()->joinLeft( array("m4m" => $mailchimpTableName), diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 42b320d99..6730a6284 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -75,7 +75,7 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) { $helper = $this->getHelper(); $dateHelper = $this->getDateHelper(); - $mailchimpTableName = Mage::getSingleton('core/resource')->getTableName('mailchimp/ecommercesyncdata'); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $batchArray = array(); $modifiedOrders = $this->getResourceModelOrderCollection(); // select orders for the current Magento store id @@ -721,7 +721,7 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS $magentoStoreId, 'stores' ); - $mailchimpTableName = Mage::getSingleton('core/resource')->getTableName('mailchimp/ecommercesyncdata'); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $batchArray = array(); $config = array(); $orderCollection = $this->getResourceModelOrderCollection(); @@ -832,7 +832,7 @@ public function addProductNotSentData($mailchimpStoreId, $magentoStoreId, $order */ public function joinMailchimpSyncDataWithoutWhere($newOrders, $mailchimpStoreId) { - $mailchimpTableName = Mage::getSingleton('core/resource')->getTableName('mailchimp/ecommercesyncdata'); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $newOrders->getSelect()->joinLeft( array('m4m' => $mailchimpTableName), "m4m.related_id = main_table.entity_id AND m4m.type = '" diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 2867079f0..8771e5711 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -692,17 +692,6 @@ protected function getBatchLimitFromConfig() return $helper->getProductAmountLimit(); } - /** - * @return string - */ - public function getSyncDataTableName() - { - $mailchimpTableName = Mage::getSingleton('core/resource') - ->getTableName('mailchimp/ecommercesyncdata'); - - return $mailchimpTableName; - } - /** * @param $mailchimpStoreId * @param $magentoStoreId @@ -941,7 +930,7 @@ protected function builMailchimpDataJoinForSpecialPrices() */ protected function executeMailchimpDataJoin($collection, $mailchimpStoreId, $joinCondition) { - $mailchimpTableName = $this->getSyncDataTableName(); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $collection->getSelect()->joinLeft( array("m4m" => $mailchimpTableName), sprintf($joinCondition, Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId), @@ -1244,7 +1233,7 @@ protected function loadProductById($productId) */ protected function joinMailchimpSyncDataDeleted($mailchimpStoreId, $deletedProducts) { - $mailchimpTableName = $this->getSyncDataTableName(); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $deletedProducts->getSelect()->joinLeft( array('m4m' => $mailchimpTableName), "m4m.related_id = e.entity_id AND m4m.type = '" . Ebizmarts_MailChimp_Model_Config::IS_PRODUCT diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index c4eb1c11d..509e079f3 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -246,16 +246,6 @@ protected function makeDeletedPromoCodesCollection($mailchimpStoreId) return $deletedPromoCodes; } - /** - * @return string - */ - public function getSyncDataTableName() - { - $mailchimpTableName = $this->getCoreResource()->getTableName('mailchimp/ecommercesyncdata'); - - return $mailchimpTableName; - } - /** * @param $collection * @param $mailchimpStoreId @@ -263,7 +253,7 @@ public function getSyncDataTableName() public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId) { $joinCondition = "m4m.related_id = main_table.coupon_id AND m4m.type = '%s' AND m4m.mailchimp_store_id = '%s'"; - $mailchimpTableName = $this->getSyncDataTableName(); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $collection->getSelect()->joinLeft( array("m4m" => $mailchimpTableName), sprintf($joinCondition, Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $mailchimpStoreId), diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index adbdefc4f..b43541c8f 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -195,16 +195,6 @@ protected function makeModifiedAndDeletedPromoRulesCollection($mailchimpStoreId) return $deletedPromoRules; } - /** - * @return string - */ - public function getSyncDataTableName() - { - $mailchimpTableName = $this->getCoreResource()->getTableName('mailchimp/ecommercesyncdata'); - - return $mailchimpTableName; - } - /** * @param $collection * @param $mailchimpStoreId @@ -212,7 +202,7 @@ public function getSyncDataTableName() public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId) { $joinCondition = "m4m.related_id = main_table.rule_id AND m4m.type = '%s' AND m4m.mailchimp_store_id = '%s'"; - $mailchimpTableName = $this->getSyncDataTableName(); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $collection->getSelect()->joinLeft( array("m4m" => $mailchimpTableName), sprintf($joinCondition, Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $mailchimpStoreId), diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 6044562ae..4d6334cba 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -91,7 +91,8 @@ protected function getDateHelper() */ public function getMailchimpEcommerceDataTableName() { - return Mage::getSingleton('core/resource')->getTableName('mailchimp/ecommercesyncdata'); + return $this->getCoreResource() + ->getTableName('mailchimp/ecommercesyncdata'); } /** diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php index 08db963d5..d747e8503 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoCodesTest.php @@ -90,27 +90,6 @@ public function testMakePromoCodesCollection() $this->assertContains(Mage_SalesRule_Model_Resource_Coupon_Collection::class, get_class($return)); } - public function testGetSyncDataTableName() - { - $promoCodesApiMock = $this->_promoCodesApiMock - ->setMethods(array('getCoreResource')) - ->getMock(); - - $coreResourceMock = $this->getMockBuilder(Mage_Core_Model_Resource::class) - ->setMethods(array('getTableName')) - ->getMock(); - - $promoCodesApiMock->expects($this->once())->method('getCoreResource')->willReturn($coreResourceMock); - - $coreResourceMock - ->expects($this->once()) - ->method('getTableName') - ->with('mailchimp/ecommercesyncdata') - ->willReturn('mailchimp_ecommerce_sync_data'); - - $promoCodesApiMock->getSyncDataTableName(); - } - public function testMarkAsDeleted() { $promoRuleId = 1; diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php index 321e5c9d7..c9ea9c6b6 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php @@ -379,27 +379,6 @@ public function testMakePromoRulesCollection() $this->assertContains(Mage_SalesRule_Model_Resource_Rule_Collection::class, get_class($return)); } - public function testGetSyncDataTableName() - { - $promoRulesApiMock = $this->_promoRulesApiMock - ->setMethods(array('getCoreResource')) - ->getMock(); - - $coreResourceMock = $this->getMockBuilder(Mage_Core_Model_Resource::class) - ->setMethods(array('getTableName')) - ->getMock(); - - $promoRulesApiMock->expects($this->once())->method('getCoreResource')->willReturn($coreResourceMock); - - $coreResourceMock - ->expects($this->once()) - ->method('getTableName') - ->with('mailchimp/ecommercesyncdata') - ->willReturn('mailchimp_ecommerce_sync_data'); - - $promoRulesApiMock->getSyncDataTableName(); - } - public function testUpdate() { $promoRulesApiMock = $this->_promoRulesApiMock diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/SyncItemTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/SyncItemTest.php new file mode 100644 index 000000000..cce1a3b69 --- /dev/null +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/SyncItemTest.php @@ -0,0 +1,42 @@ +_syncItemApiMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_SyncItem::class); + } + + public function tearDown() + { + $this->_syncItemApiMock = null; + } + + public function testGetSyncDataTableName() + { + $_syncItemApiMock = $this->_syncItemApiMock + ->setMethods(array('getCoreResource')) + ->getMock(); + + $coreResourceMock = $this->getMockBuilder(Mage_Core_Model_Resource::class) + ->setMethods(array('getTableName')) + ->getMock(); + + $_syncItemApiMock->expects($this->once())->method('getCoreResource')->willReturn($coreResourceMock); + + $coreResourceMock + ->expects($this->once()) + ->method('getTableName') + ->with('mailchimp/ecommercesyncdata') + ->willReturn('mailchimp_ecommerce_sync_data'); + + $_syncItemApiMock->getMailchimpEcommerceDataTableName(); + } +} From 8c46fbee16e4c5127450afb12249925a5dfa80d7 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 15:38:42 -0300 Subject: [PATCH 014/160] whitespaces fix --- app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php | 2 +- app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index eb6b60087..f6b59fa6e 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -13,7 +13,7 @@ class Ebizmarts_MailChimp_Model_Api_Customers extends Ebizmarts_MailChimp_Model_Api_SyncItem { const BATCH_LIMIT = 100; - + protected $_optInConfiguration; protected $_optInStatusForStore; protected $_locale; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index b43541c8f..05b29dd4a 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -19,7 +19,7 @@ class Ebizmarts_MailChimp_Model_Api_PromoRules extends Ebizmarts_MailChimp_Model const TARGET_SHIPPING = 'shipping'; protected $_batchId; - + /** * @var Ebizmarts_MailChimp_Model_Api_PromoCodes */ From d8d10bef77a1d1c08cbd24f6111fe5a5c9ffe971 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Fri, 6 Sep 2019 15:47:28 -0300 Subject: [PATCH 015/160] whitespaces fix --- app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index f6b59fa6e..84f9cf9c8 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -25,7 +25,7 @@ class Ebizmarts_MailChimp_Model_Api_Customers extends Ebizmarts_MailChimp_Model_ public function __construct() { parent::__construct(); - + $this->_optInConfiguration = array(); $this->_locale = Mage::app()->getLocale(); $this->_directoryRegionModel = Mage::getModel('directory/region'); From 4ce7ed7026fc8a73c02c396a438425292e27a9e9 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 10:16:52 -0300 Subject: [PATCH 016/160] Typos error fixed --- app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php | 2 +- app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index 84f9cf9c8..b7aa84f6b 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -389,7 +389,7 @@ protected function joinDefaultBillingAddress($collection) protected function joinMailchimpSyncData($collection) { $joinCondition = "m4m.related_id = e.entity_id AND m4m.type = '%s' AND m4m.mailchimp_store_id = '%s'"; - $mailchimpTableName = $this->getSyncdataTableName(); + $mailchimpTableName = $this->getMailchimpEcommerceDataTableName(); $collection->getSelect()->joinLeft( array("m4m" => $mailchimpTableName), diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 8771e5711..242800766 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -688,7 +688,7 @@ public function makeProductsNotSentCollection($magentoStoreId, $isParentProduct */ protected function getBatchLimitFromConfig() { - $helper = $this->getHelper; + $helper = $this->getHelper(); return $helper->getProductAmountLimit(); } From eeb8c6ea6a6d935515ea77f93f174d0b6860e004 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 11:30:47 -0300 Subject: [PATCH 017/160] adding constant class return method --- .../community/Ebizmarts/MailChimp/Model/Api/Carts.php | 8 ++++++++ .../community/Ebizmarts/MailChimp/Model/Api/Customers.php | 8 ++++++++ .../community/Ebizmarts/MailChimp/Model/Api/Orders.php | 8 ++++++++ .../community/Ebizmarts/MailChimp/Model/Api/Products.php | 8 ++++++++ .../Ebizmarts/MailChimp/Model/Api/PromoCodes.php | 8 ++++++++ .../Ebizmarts/MailChimp/Model/Api/PromoRules.php | 8 ++++++++ 6 files changed, 48 insertions(+) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index 4ac24a244..125c2de80 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -873,4 +873,12 @@ protected function getApiProducts() { return Mage::getModel('mailchimp/api_products'); } + + /** + * @return string + */ + protected function getClassConstant() + { + return Ebizmarts_MailChimp_Model_Config::IS_QUOTE; + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index b7aa84f6b..fa86db39d 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -702,4 +702,12 @@ protected function sendMailchimpTags( return array($customerArray, $counter); } + /** + * @return string + */ + protected function getClassConstant() + { + return Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER; + } + } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 6730a6284..56e11309e 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -1063,4 +1063,12 @@ protected function getSubscriberModel() { return Mage::getModel('newsletter/subscriber'); } + + /** + * @return string + */ + protected function getClassConstant() + { + return Ebizmarts_MailChimp_Model_Config::IS_ORDER; + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 242800766..0679de9b7 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -1373,4 +1373,12 @@ protected function getCatalogProductStatusModel() { return Mage::getModel('catalog/product_status'); } + + /** + * @return string + */ + protected function getClassConstant() + { + return Ebizmarts_MailChimp_Model_Config::IS_PRODUCT; + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index 509e079f3..103598d27 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -521,4 +521,12 @@ protected function setCodeWithParentError($mailchimpStoreId, $ruleId, $codeId) $error ); } + + /** + * @return string + */ + protected function getClassConstant() + { + return Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE; + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index 05b29dd4a..0b99b3a6b 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -455,4 +455,12 @@ protected function ruleHasMissingInformation($data) return $hasMissingInformation; } + + /** + * @return string + */ + protected function getClassConstant() + { + return Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE; + } } From 83c0b89f497dc73d1717d5dda8bfe017ddbfef2f Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 11:46:13 -0300 Subject: [PATCH 018/160] UpdateSyncData method with dynamic type in Carts --- .../Ebizmarts/MailChimp/Model/Api/Carts.php | 16 ++----- .../MailChimp/Model/Api/SyncItem.php | 46 ++++++++++++------- .../MailChimp/Model/Api/CartsTest.php | 18 ++------ 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index 125c2de80..43f2a2075 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -113,7 +113,6 @@ public function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $alreadySentCartId, $mailchimpStoreId, null, @@ -133,7 +132,6 @@ public function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $cartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -209,7 +207,6 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $alreadySentCartId, $mailchimpStoreId, null, @@ -227,7 +224,7 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) // avoid carts abandoned as guests when customer email associated to a registered customer. if (!$cart->getCustomerId() && $customer->getEmail() == $cart->getCustomerEmail()) { - $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId); + $this->_updateSyncData($cartId, $mailchimpStoreId); continue; } @@ -246,7 +243,6 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['body'] = $cartJson; $this->setCounter($this->getCounter() + 1); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -260,7 +256,6 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) $error = $helper->__('There is not supported products in this cart.'); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -272,7 +267,6 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) $jsonErrorMessage = json_last_error_msg(); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -338,7 +332,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $allVisibleItems = $cart->getAllVisibleItems(); if (empty($allVisibleItems) || $orderCollection->getSize()) { - $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId); + $this->_updateSyncData($cartId, $mailchimpStoreId); continue; } @@ -364,7 +358,6 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $alreadySentCartId, $mailchimpStoreId, null, @@ -381,7 +374,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) // don't send the carts for guest customers who are registered if (!$cart->getCustomerId() && $customer->getEmail() == $cart->getCustomerEmail()) { - $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId); + $this->_updateSyncData($cartId, $mailchimpStoreId); continue; } @@ -400,7 +393,6 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['body'] = $cartJson; $this->setCounter($this->getCounter() + 1); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, null, @@ -413,7 +405,6 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) } else { $error = $helper->__('There is not supported products in this cart.'); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, $dateHelper->getCurrentDateTime(), @@ -424,7 +415,6 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) } else { $jsonErrorMessage = json_last_error_msg(); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, $cartId, $mailchimpStoreId, $dateHelper->getCurrentDateTime(), diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 4d6334cba..7386eb6d7 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -28,7 +28,7 @@ public function __construct() } /** - * @param $cartId + * @param $id * @param $mailchimpStoreId * @param null $syncDelta * @param null $syncError @@ -38,9 +38,9 @@ public function __construct() * @param null $token * @param bool $saveOnlyIfExists * @param bool $allowBatchRemoval + * @param int $deletedRelatedId */ protected function _updateSyncData( - $type, $id, $mailchimpStoreId, $syncDelta = null, @@ -53,21 +53,25 @@ protected function _updateSyncData( $allowBatchRemoval = true, $deletedRelatedId = null ) { - $helper = $this->getHelper(); - $helper->saveEcommerceSyncData( - $id, - $type, - $mailchimpStoreId, - $syncDelta, - $syncError, - $syncModified, - $syncDeleted, - $token, - $syncedFlag, - $saveOnlyIfExists, - $deletedRelatedId, - $allowBatchRemoval - ); + $type = $this->getClassConstant(); + + if (!empty($type)) { + $helper = $this->getHelper(); + $helper->saveEcommerceSyncData( + $id, + $type, + $mailchimpStoreId, + $syncDelta, + $syncError, + $syncModified, + $syncDeleted, + $token, + $syncedFlag, + $saveOnlyIfExists, + $deletedRelatedId, + $allowBatchRemoval + ); + } } /** @@ -111,4 +115,12 @@ public function getCoreResource() { return Mage::getSingleton('core/resource'); } + + /** + * @return string + */ + protected function getClassConstant() + { + return null; + } } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php index 340faf227..21f5925b8 100755 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php @@ -194,13 +194,11 @@ public function testGetConvertedQuotes() ->method('_updateSyncData') ->withConsecutive( array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null ), array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null @@ -378,11 +376,9 @@ public function testGetModifiedQuotes() ->method('_updateSyncData') ->withConsecutive( array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null ), array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token ) ); @@ -517,7 +513,7 @@ public function testGetModifiedQuotesGuestCustomer() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getCustomerModel') ->willReturn($customerModelMock); @@ -694,11 +690,9 @@ public function testGetModifiedQuotesEmptyJson() ->method('_updateSyncData') ->withConsecutive( array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null ), array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID ) ); @@ -894,11 +888,9 @@ public function testGetNewQuotesNewQuote() ->method('_updateSyncData') ->withConsecutive( array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null ), array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token ) ); @@ -1097,7 +1089,7 @@ public function testGetNewQuotesIsOrder() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getOrderCollection') ->willReturn($orderCollectionMock); @@ -1222,7 +1214,7 @@ public function testGetNewQuotesEmpty() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getOrderCollection') ->willReturn($orderCollectionMock); @@ -1355,7 +1347,7 @@ public function testGetNewQuotesGuestCustomer() ->willReturn(self::BATCH_LIMIT_FROM_CONFIG); $cartsApiMock->expects($this->once()) ->method('_updateSyncData') - ->with(Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID); + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('getCustomerModel') ->willReturn($customerModelMock); @@ -1550,11 +1542,9 @@ public function testGetNewQuotesEmptyJson() ->method('_updateSyncData') ->withConsecutive( array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null ), array( - Ebizmarts_MailChimp_Model_Config::IS_QUOTE, self::CART_ID, self::MAILCHIMP_STORE_ID ) ); From bda964c3a308f6c72ef5aecb432748131050bb9e Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 11:49:06 -0300 Subject: [PATCH 019/160] UpdateSyncData method with dynamic type in Customers --- .../community/Ebizmarts/MailChimp/Model/Api/Customers.php | 4 ---- .../tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php | 2 -- 2 files changed, 6 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index fa86db39d..a493a56de 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -117,7 +117,6 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $customerArray[$counter] = $this->makePutBatchStructure($customerJson, $customer); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, $customer->getId(), $mailchimpStoreId, null, @@ -146,7 +145,6 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) } } else { $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, $customer->getId(), $mailchimpStoreId, $this->getDateHelper()->getCurrentDateTime(), @@ -157,7 +155,6 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) } else { $jsonErrorMessage = $this->logCouldNotEncodeCustomerError($customer); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, $customer->getId(), $mailchimpStoreId, $this->getDateHelper()->getCurrentDateTime(), @@ -321,7 +318,6 @@ public function update($customerId, $storeId) { $mailchimpStoreId = $this->getHelper()->getMCStoreId($storeId); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, $customerId, $mailchimpStoreId, null, diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php index ed6aefc06..76ea91b8d 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php @@ -212,7 +212,6 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() ->expects($this->once()) ->method('_updateSyncData') ->with( - Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, $customerId, $mailchimpStoreId, null, @@ -408,7 +407,6 @@ public function testCreateBatchJsonOptInTrueCustomerNotSubscribed() ->expects($this->once()) ->method('_updateSyncData') ->with( - Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, $customerId, $mailchimpStoreId, null, null, From c5bb8f9db21ec8073d70425ecdc59e5372fe42fd Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 11:51:10 -0300 Subject: [PATCH 020/160] UpdateSyncData method with dynamic type in Orders --- .../Ebizmarts/MailChimp/Model/Api/Orders.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 56e11309e..4c5b8bdb0 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -112,12 +112,11 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) $batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId; $batchArray[$this->_counter]['body'] = $orderJson; //update order delta - $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId); + $this->_updateSyncData($orderId, $mailchimpStoreId); $this->_counter++; } else { $error = $helper->__('Something went wrong when retrieving product information.'); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -133,7 +132,6 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -199,12 +197,11 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) $batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId; $batchArray[$this->_counter]['body'] = $orderJson; //update order delta - $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId); + $this->_updateSyncData($orderId, $mailchimpStoreId); $this->_counter++; } else { $error = $helper->__('Something went wrong when retrieving product information.'); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -220,7 +217,6 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -684,7 +680,6 @@ public function update($orderId, $magentoStoreId) if ($helper->isEcomSyncDataEnabled($magentoStoreId)) { $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, null, @@ -769,7 +764,6 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS 'Something went wrong when retrieving product information during migration from 1.1.6.' ); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -783,7 +777,6 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS } else { $error = $helper->__("Json error during migration from 1.1.6"); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_ORDER, $orderId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), From d480a6d46b742c0481b10a4ed10d58f0ef77242c Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 12:57:25 -0300 Subject: [PATCH 021/160] UpdateSyncData method with dynamic type in Products --- .../Ebizmarts/MailChimp/Model/Api/Products.php | 13 ------------- .../MailChimp/Model/Api/ProductsTest.php | 18 ++++-------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 0679de9b7..ebc32c504 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -92,7 +92,6 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $batchArray ); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId ); @@ -122,13 +121,11 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) //update product delta $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId ); } else { $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, $dateHelper->formatDate(null, 'Y-m-d H:i:s'), @@ -169,7 +166,6 @@ public function createDeletedProductsBatchJson($mailchimpStoreId, $magentoStoreI } $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $product->getId(), $mailchimpStoreId, null, @@ -235,7 +231,6 @@ protected function _buildNewProductRequest($product, $batchId, $mailchimpStoreId ); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $product->getId(), $mailchimpStoreId, $this->getDateHelper()->getCurrentDateTime(), @@ -305,7 +300,6 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor . " json encode failed (".$jsonErrorMsg.")" ); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parent->getId(), $mailchimpStoreId, $this->getDateHelper()->getCurrentDateTime(), @@ -354,7 +348,6 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor . " json encode failed (".$jsonErrorMsg.")" ); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $product->getId(), $mailchimpStoreId, $this->getDateHelper()->getCurrentDateTime(), @@ -500,7 +493,6 @@ public function update($productId, $mailchimpStoreId) $parentIdArray = $this->getAllParentIds($productId); foreach ($parentIdArray as $parentId) { $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentId, $mailchimpStoreId, null, @@ -515,7 +507,6 @@ public function update($productId, $mailchimpStoreId) } $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, null, @@ -538,7 +529,6 @@ public function update($productId, $mailchimpStoreId) public function updateDisabledProducts($productId, $mailchimpStoreId) { $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, null, @@ -583,7 +573,6 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) ) { if ($productId) { $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, $dateHelper->formatDate(null, 'Y-m-d H:i:s'), @@ -616,7 +605,6 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $data ); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId ); @@ -629,7 +617,6 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) // avoid update for disabled products to prevent send the product as modified if ($isProductEnabled) { $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId ); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index 61c5d5c4f..af17da580 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -116,7 +116,7 @@ public function testCreateBatchJson() $productsApiMock ->expects($this->once()) ->method('_updateSyncData') - ->with(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId); + ->with($productId, $mailchimpStoreId); $helperMock->expects($this->once()) ->method('getCurrentStoreId') @@ -535,9 +535,9 @@ public function testSendModifiedProduct() ->expects($this->exactly(3)) ->method('_updateSyncData') ->withConsecutive( - array(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $groupedProductId, $mailchimpStoreId), - array(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $oldProductId, $mailchimpStoreId), - array(Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $newProductId, $mailchimpStoreId) + array($groupedProductId, $mailchimpStoreId), + array($oldProductId, $mailchimpStoreId), + array($newProductId, $mailchimpStoreId) ); $return = $productsApiMock->sendModifiedProduct($orderMock, $mailchimpStoreId, $magentoStoreId); @@ -679,7 +679,6 @@ public function testCreateDeletedProductsBatchJson() ->expects($this->once()) ->method('_updateSyncData') ->with( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productMock->getId(), $mailchimpStoreId, null, @@ -745,39 +744,30 @@ public function testUpdate() ->method('_updateSyncData') ->withConsecutive( array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[0], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[1], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[2], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[3], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[4], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[5], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[6], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $parentIdArray[7], $mailchimpStoreId, null, null, 1, null, null, null, true, false ), array( - Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $productId, $mailchimpStoreId, null, null, 1, null, null, null, true, false ) ); From a5e5f0e13c9e880286e459cd57431d594c1c1853 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 13:01:09 -0300 Subject: [PATCH 022/160] UpdateSyncData method with dynamic type in PromoCodes --- .../MailChimp/Model/Api/PromoCodes.php | 49 ------------------- 1 file changed, 49 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index 103598d27..f29fbb6a1 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -144,7 +144,6 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) $batchArray[$counter]['body'] = $promoCodeJson; $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, null, @@ -158,7 +157,6 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) } else { $error = $helper->__('Something went wrong when retrieving the information.'); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -170,7 +168,6 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) $jsonErrorMsg = json_last_error_msg(); $helper->logError("Promo code" . $codeId . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -267,50 +264,6 @@ public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId ); } - /** - * update product sync data - * - * @param $codeId - * @param $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncDeleted - * @param int|null $token - * @param bool $saveOnlyIfexists - * @param null $deletedRelatedId - * @param bool $allowBatchRemoval - */ - protected function _updateSyncData( - $type, // NEW - $codeId, - $mailchimpStoreId, - $syncDelta = null, - $syncError = null, - $syncModified = 0, - $syncDeleted = null, - $syncedFlag = null, // NEW - $token = null, - $saveOnlyIfexists = false, - $allowBatchRemoval = true, - $deletedRelatedId = null - ) { - $this->getHelper()->saveEcommerceSyncData( - $codeId, - Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, - $mailchimpStoreId, - $syncDelta, - $syncError, - $syncModified, - $syncDeleted, - $token, - null, - $saveOnlyIfexists, - $deletedRelatedId, - $allowBatchRemoval - ); - } - protected function generateCodeData($promoCode, $magentoStoreId) { $data = array(); @@ -412,7 +365,6 @@ protected function _setDeleted($codeId, $promoRuleId) foreach ($promoCodes as $promoCode) { $mailchimpStoreId = $promoCode->getMailchimpStoreId(); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, null, @@ -514,7 +466,6 @@ protected function setCodeWithParentError($mailchimpStoreId, $ruleId, $codeId) 'Parent rule with id ' . $ruleId . ' has not been correctly sent.' ); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, $codeId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), From 058ce95a7d052e2b29755d9756619eb6f68706ea Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 9 Sep 2019 13:03:21 -0300 Subject: [PATCH 023/160] UpdateSyncData method with dynamic type in PromoRules --- .../community/Ebizmarts/MailChimp/Model/Api/PromoRules.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index 0b99b3a6b..5fa2c5269 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -98,7 +98,7 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) . $dateHelper->getDateMicrotime() . '_' . $ruleId; $promoData['body'] = $promoRuleJson; //update promo rule delta - $this->_updateSyncData(Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId); + $this->_updateSyncData($ruleId, $mailchimpStoreId); } else { $error = $promoRule->getMailchimpSyncError(); if (!$error) { @@ -106,7 +106,6 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) } $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -118,7 +117,6 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) $helper->logError("Promo rule " . $ruleId . " json encode failed (".$jsonErrorMsg.")"); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, $dateHelper->formatDate(null, "Y-m-d H:i:s"), @@ -338,7 +336,6 @@ protected function _setModified($ruleId) foreach ($promoRules as $promoRule) { $mailchimpStoreId = $promoRule->getMailchimpStoreId(); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, null, @@ -374,7 +371,6 @@ protected function _setDeleted($ruleId) foreach ($promoRules as $promoRule) { $mailchimpStoreId = $promoRule->getMailchimpStoreId(); $this->_updateSyncData( - Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $ruleId, $mailchimpStoreId, null, From 6417f1bec6ce86c31d681e541e7c0c68387d0706 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 9 Sep 2019 17:53:42 -0300 Subject: [PATCH 024/160] Creating new Helper: Ebizmarts_MailChimp_Helper_File at File.php. Replacing mkdir(), unlink(), file_exists by the equivalents available in Varien_Io_File class. Segmenting a long (longer than 120 chars) Regular expression for validating email into two segments: user and domain. Avoiding the use of count($emailArray) inside a loop. Adding getMailchimpFileHelper() function in order to get easily the new File Helper. --- .../Adminhtml/Mailchimpstores/Edit/Form.php | 3 +- .../Ebizmarts/MailChimp/Helper/Data.php | 24 ++-- .../Ebizmarts/MailChimp/Helper/File.php | 104 ++++++++++++++++++ .../Ebizmarts/MailChimp/Model/Api/Batches.php | 89 +++++++++------ .../Ebizmarts/MailChimp/Model/Email/Queue.php | 9 +- .../MailChimp/Model/Email/Template.php | 2 +- .../Adminhtml/MailchimperrorsController.php | 10 +- .../mailchimp/popup/emailcatcher.phtml | 8 +- .../MailChimp/Model/Api/OrdersTest.php | 2 +- lib/Ebizmarts/MailChimp.php | 14 +-- 10 files changed, 203 insertions(+), 62 deletions(-) create mode 100644 app/code/community/Ebizmarts/MailChimp/Helper/File.php diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimpstores/Edit/Form.php b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimpstores/Edit/Form.php index c6facfddf..bf8ea5ae3 100644 --- a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimpstores/Edit/Form.php +++ b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimpstores/Edit/Form.php @@ -56,9 +56,8 @@ protected function _prepareForm() $prefix = ''; $storeId = $s->getStoreId(); - if(!$helper->ping($storeId)) { + if(!$helper->ping($storeId)) $prefix = '[Invalid]: '; - } $apikey = $helper->getApiKey($storeId); diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 11a7e2858..f60ee4705 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -48,7 +48,7 @@ class Ebizmarts_MailChimp_Helper_Data extends Mage_Core_Helper_Abstract * * @var array */ - public static $MAILCHIMP_LANGUAGES = array( + public static $mailchimpLanguages = array( 'en', // English 'ar', // Arabic 'af', // Afrikaans @@ -1038,15 +1038,16 @@ public function logRequest($message, $batchId = null) Mage::log($message, null, 'MailChimp_Failing_Requests.log', true); } elseif ($logRequestEnabled) { $logDir = Mage::getBaseDir('var') . DS . 'log'; + $fileHelper = $this->getFileHelper(); - if (!file_exists($logDir)) { - mkdir($logDir, 0750); + if (!$fileHelper->fileExists($logDir, false)) { + $fileHelper->mkDir($logDir, 0750); } $logDir .= DS . 'MailChimp_Requests'; - if (!file_exists($logDir)) { - mkdir($logDir, 0750); + if (!$fileHelper->fileExists($logDir, false)) { + $fileHelper->mkDir($logDir, 0750); } $fileName = $logDir . DS . $batchId . '.Request.log'; @@ -4182,11 +4183,12 @@ protected function _langToMCLanguage($languageCode = '') { $mailchimpLanguage = ''; - if (in_array($languageCode, self::$MAILCHIMP_LANGUAGES)) { + if (in_array($languageCode, self::$mailchimpLanguages)) { $mailchimpLanguage = $languageCode; } else { $langIso = substr($languageCode, 0, 2); - if (in_array($langIso, self::$MAILCHIMP_LANGUAGES)) { + + if (in_array($langIso, self::$mailchimpLanguages)) { $mailchimpLanguage = $langIso; } } @@ -5081,4 +5083,12 @@ public function ping($storeId) return true; } + + /** + * @return Ebizmarts_MailChimp_Helper_File + */ + protected function getFileHelper() + { + return Mage::helper('mailchimp/helper'); + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/File.php b/app/code/community/Ebizmarts/MailChimp/Helper/File.php new file mode 100644 index 000000000..31718d23c --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Helper/File.php @@ -0,0 +1,104 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 9/5/19 3:55 PM + * @file: Curl.php + */ + +class Ebizmarts_MailChimp_Helper_File extends Mage_Core_Helper_Abstract +{ + /** + * @var $_ioFile Varien_Io_File + */ + protected $_ioFile; + + public function __construct() + { + $this->_ioFile = new Varien_Io_File(); + } + + /** + * @return Varien_Io_File + */ + public function getIoFile() + { + return $this->_ioFile; + } + + /** + * @param string $file + * @return string + */ + public function dirName($file = '.') + { + return $this->_ioFile->dirname($file); + } + + /** + * @param $dir + * @param int $mode + * @param bool $recursive + * @return bool + */ + public function mkDir($dir, $mode = 0777, $recursive = true) + { + return $this->_ioFile->mkdir($dir, $mode, $recursive); + } + + /** + * @param $directory + * @param bool $recursive + * @return bool + */ + public function rmDir($directory, $recursive = false) + { + return $this->_ioFile->rmdir($directory, $recursive); + } + + /** + * @param $filename + * @param $src + * @param null $mode + * @return bool|int + */ + public function write($filename, $src, $mode = null) + { + return $this->_ioFile->write($filename, $src, $mode); + } + + /** + * @param $file + * @param bool $onlyFile + * @return bool + */ + public function fileExists($file, $onlyFile = true) + { + return $this->_ioFile->fileExists($file, $onlyFile); + } + + /** + * @param $filename + * @return bool + */ + public function unlink($filename) + { + return $this->rm($filename); + } + + /** + * @param $filename + * @return bool + */ + public function rm($filename) + { + return $this->_ioFile->rm($filename); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index e3db8fb3f..8a9f303b0 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -197,7 +197,8 @@ public function getMagentoBaseDir() */ public function batchDirExists($baseDir, $batchId) { - return is_dir($baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId); + return $this->getMailchimpFileHelper() + ->fileExists($baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId, false); } /** @@ -207,7 +208,8 @@ public function batchDirExists($baseDir, $batchId) */ public function removeBatchDir($baseDir, $batchId) { - return rmdir($baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId); + return $this->getMailchimpFileHelper() + ->rmDir($baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId); } /** @@ -258,8 +260,8 @@ public function handleSubscriberBatches() /** * Get results of batch operations sent to MailChimp. * - * @param $magentoStoreId - * @param bool $isEcommerceData + * @param $magentoStoreId + * @param bool $isEcommerceData * @throws Mage_Core_Exception */ public function _getResults( @@ -417,7 +419,7 @@ protected function _processBatchOperations($batchArray, $mailchimpStoreId, $mage $batchJson = json_encode($batchArray); if ($batchJson === false) { - $helper->logRequest('Json encode error '.json_last_error_msg()); + $helper->logRequest('Json encode error ' . json_last_error_msg()); } elseif (empty($batchJson)) { $helper->logRequest('An empty operation was detected'); } else { @@ -630,8 +632,9 @@ public function sendStoreSubscriberBatch($storeId, $limit) if (!empty($batchArray['operations'])) { $batchJson = json_encode($batchArray); + if ($batchJson === false) { - $helper->logRequest('Json encode error '.json_last_error_msg()); + $helper->logRequest('Json encode error ' . json_last_error_msg()); } elseif ($batchJson == '') { $helper->logRequest('An empty operation was detected'); } else { @@ -647,6 +650,7 @@ public function sendStoreSubscriberBatch($storeId, $limit) ->setStatus($batchResponse['status']); $batch->save(); $this->_showResumeSubscriber($batchResponse['id'], $storeId); + return array($batchResponse, $limit); } catch (Ebizmarts_MailChimp_Helper_Data_ApiKeyException $e) { $helper->logError($e->getMessage()); @@ -674,6 +678,7 @@ public function sendStoreSubscriberBatch($storeId, $limit) public function getBatchResponse($batchId, $magentoStoreId) { $helper = $this->getHelper(); + $fileHelper = $this->getMailchimpFileHelper(); $files = array(); try { @@ -700,7 +705,7 @@ public function getBatchResponse($batchId, $magentoStoreId) $curlResults = $curlHelper->curlExec($curlOptions); $r = $curlResults['response']; fclose($fd); - mkdir( + $fileHelper->mkDir( $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId, 0750, true @@ -708,7 +713,7 @@ public function getBatchResponse($batchId, $magentoStoreId) $archive = new Mage_Archive(); - if (file_exists($fileName)) { + if ($fileHelper->fileExists($fileName)) { $files = $this->_unpackBatchFile($files, $batchId, $archive, $fileName, $baseDir); } } @@ -738,23 +743,26 @@ public function getBatchResponse($batchId, $magentoStoreId) */ protected function _unpackBatchFile($files, $batchId, $archive, $fileName, $baseDir) { - $archive->unpack($fileName, $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId); + $path = $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId; + $archive->unpack($fileName, $path); $archive->unpack( - $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId . '/' . $batchId . '.tar', - $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId + $path . '/' . $batchId . '.tar', + $path ); - $dir = scandir($baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId); - foreach ($dir as $d) { - $name = pathinfo($d); - if ($name['extension'] == 'json') { - $files[] = $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId . '/' . $d; - } + + $fileHelper = $this->getMailchimpFileHelper(); + $dirItems = new DirectoryIterator($path); + + foreach ($dirItems as $index => $dirItem) { + if ($dirItem->isFile() && $dirItem->getExtension() == 'json') + $files[] = $path . '/' . $dirItem->getBasename(); } - unlink( - $baseDir . DS . 'var' . DS . 'mailchimp' . DS . $batchId . '/' . $batchId . '.tar' + $fileHelper->rm( + $path . '/' . $batchId . '.tar' ); - unlink($fileName); + + $fileHelper->rm($fileName); return $files; } @@ -770,6 +778,7 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, { $helper = $this->getHelper(); $helper->resetCountersDataSentToMailchimp(); + $fileHelper = $this->getMailchimpFileHelper(); foreach ($files as $file) { $items = json_decode(file_get_contents($file)); @@ -848,7 +857,7 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, } } - unlink($file); + $fileHelper->rm($file); } $this->_showResumeDataSentToMailchimp($magentoStoreId); @@ -933,8 +942,8 @@ public function replaceAllOrders($initialTime, $magentoStoreId) if (!empty($batchArray['operations'])) { $batchJson = json_encode($batchArray); - if ($batchJson === false ) { - $helper->logRequest('Json encode error: '.json_last_error_msg()); + if ($batchJson === false) { + $helper->logRequest('Json encode error: ' . json_last_error_msg()); } elseif ($batchJson == '') { $helper->logRequest('An empty operation was detected'); } else { @@ -965,16 +974,16 @@ public function replaceAllOrders($initialTime, $magentoStoreId) } /** - * @param $itemId - * @param $itemType - * @param $mailchimpStoreId - * @param null $syncDelta - * @param null $syncError - * @param int $syncModified - * @param null $syncDeleted - * @param null $token - * @param null $syncedFlag - * @param bool $saveOnlyIfexists + * @param $itemId + * @param $itemType + * @param $mailchimpStoreId + * @param null $syncDelta + * @param null $syncError + * @param int $syncModified + * @param null $syncDeleted + * @param null $token + * @param null $syncedFlag + * @param bool $saveOnlyIfexists */ protected function saveSyncData( $itemId, @@ -1274,12 +1283,20 @@ protected function isFirstArrival(Varien_Object $syncDataItem) */ protected function enableMergeFieldsSending($type, Varien_Object $syncDataItem) { - $syncModified = 0 ; - if ($type == Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER - && $this->isFirstArrival($syncDataItem)) { + $syncModified = 0; + + if ($type == Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER && $this->isFirstArrival($syncDataItem)) { $syncModified = 1; } return $syncModified; } + + /** + * @return Ebizmarts_MailChimp_Helper_File + */ + protected function getMailchimpFileHelper() + { + return Mage::helper('mailchimp/file'); + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php b/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php index bc73a2d0f..e4be22b35 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php @@ -24,16 +24,16 @@ public function send() $mageMCDateHelper = Mage::helper('mailchimp/date'); /** - * @var $collection Mage_Core_Model_Resource_Email_Queue_Collection -*/ + * @var $collection Mage_Core_Model_Resource_Email_Queue_Collection + */ $collection = Mage::getResourceModel('core/email_queue_collection') ->addOnlyForSendingFilter() ->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN) ->setCurPage(1) ->load(); /** - * @var $message Mage_Core_Model_Email_Queue -*/ + * @var $message Mage_Core_Model_Email_Queue + */ foreach ($collection as $message) { if ($message->getId()) { if ($message->getEntityType() == 'order') { @@ -56,6 +56,7 @@ public function send() } } else { $parameters = new Varien_Object($message->getMessageParameters()); + if ($parameters->getReturnPathEmail() !== null) { $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail()); Zend_Mail::setDefaultTransport($mailTransport); diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Email/Template.php b/app/code/community/Ebizmarts/MailChimp/Model/Email/Template.php index 222f8b799..39cff3ebe 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Email/Template.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Email/Template.php @@ -176,7 +176,7 @@ protected function _getEmailFrom($mail) if (isset($sender['domain'])) { $emailArray = explode('@', $fromEmail); - if (count($emailArray) > 1 && $emailArray[1] == $sender['domain']) { + if (isset($emailArray[1]) && $emailArray[1] == $sender['domain']) { $senderExists = true; } } diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php index 74df0c9c4..5b5ea51f9 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php @@ -136,6 +136,14 @@ protected function getFileContent($file) */ protected function unlink($file) { - unlink($file); + return $this->getFileHelper()->unlink($file); + } + + /** + * @return Ebizmarts_MailChimp_Helper_File + */ + protected function getFileHelper() + { + return Mage::helper('mailchimp/file'); } } diff --git a/app/design/frontend/base/default/template/ebizmarts/mailchimp/popup/emailcatcher.phtml b/app/design/frontend/base/default/template/ebizmarts/mailchimp/popup/emailcatcher.phtml index 369c92b64..99f0ce906 100755 --- a/app/design/frontend/base/default/template/ebizmarts/mailchimp/popup/emailcatcher.phtml +++ b/app/design/frontend/base/default/template/ebizmarts/mailchimp/popup/emailcatcher.phtml @@ -59,7 +59,7 @@ }); var cookieStored = emailCookieExists(); if (!cookieStored && $('popupDialog') == undefined) { - var popupWidth = + var popupWidth =; jsQuoteEscape( json_decode( @@ -70,7 +70,7 @@ ) )); ?>*window.innerWidth/100; - var popupHeight = + var popupHeight =; jsQuoteEscape( json_decode( @@ -219,7 +219,9 @@ } function validateEmail(email) { - var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + var user = '([^<>()[\\]\\\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\"]+)*)|(\\".+\\")'; + var domain = '(\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})'; + var re = new RegExp('ˆ' + user + '@' + domain + '$'); return re.test(email); } function emailCookieExists() { diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php index f09019e12..c48e2280a 100755 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php @@ -167,7 +167,7 @@ public function testGeneratePOSTPayload() $customerEmail = 'test@ebizmarts.com'; $customerFirstName = 'testFirstName'; $billingAddressStreet = array('billingAddress1', 'billingAddress2'); - $currentDate = date("yyyy-mm-dd"); + $currentDate = Mage::getSingleton('core/date'); $lines['itemsCount'] = 9; $lines[0] = array( diff --git a/lib/Ebizmarts/MailChimp.php b/lib/Ebizmarts/MailChimp.php index 83b10609d..6d2c157cb 100755 --- a/lib/Ebizmarts/MailChimp.php +++ b/lib/Ebizmarts/MailChimp.php @@ -203,7 +203,7 @@ class Ebizmarts_MailChimp public $templates; protected $_apiKey; - protected $curlOptions = array(); + protected $_curlOptions = array(); protected $_root = 'https://api.mailchimp.com/3.0'; protected $_debug = false; @@ -399,7 +399,7 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ */ $curlHelper = Mage::helper('mailchimp/curl'); $this->setCurlOptionsAddOptions($curlOptions); - $curlResult = $curlHelper->curlExec($this->curlOptions); + $curlResult = $curlHelper->curlExec($this->_curlOptions); $responseBody = $curlResult['response']; $info = $curlResult['info']; @@ -429,15 +429,15 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ */ public function getCurlOptions() { - return $this->curlOptions; + return $this->_curlOptions; } /** - * @param array $curlOptions + * @param array $_curlOptions */ protected function setCurlOptions($curlOptions) { - $this->curlOptions = $curlOptions; + $this->_curlOptions = $curlOptions; } /** @@ -446,7 +446,7 @@ protected function setCurlOptions($curlOptions) */ protected function setCurlOptionsIndexValue($index, $value) { - $this->curlOptions[$index] = $value; + $this->_curlOptions[$index] = $value; } /** @@ -454,6 +454,6 @@ protected function setCurlOptionsIndexValue($index, $value) */ protected function setCurlOptionsAddOptions($curlOptions = array()) { - $this->curlOptions += $curlOptions; + $this->_curlOptions += $curlOptions; } } From 2ee0858d77b3a5ad1292865ec007a6f4e1a82a14 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 10 Sep 2019 14:01:21 -0300 Subject: [PATCH 025/160] Replacing file_get_contents buy equivalent in Varien_Io_File class. --- .../Ebizmarts/MailChimp/Model/Api/Batches.php | 3 +- .../Adminhtml/MailchimperrorsController.php | 3 +- lib/Mandrill/Mandrill.php | 42 ++++++++++++------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index 8a9f303b0..b81ccfbde 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -781,7 +781,8 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, $fileHelper = $this->getMailchimpFileHelper(); foreach ($files as $file) { - $items = json_decode(file_get_contents($file)); + $fileContent = $fileHelper->read($file); + $items = json_decode($fileContent); if ($items !== false) { foreach ($items as $item) { diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php index 5b5ea51f9..45a9eec8f 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php @@ -128,7 +128,8 @@ protected function getApiBatches() */ protected function getFileContent($file) { - return json_decode(file_get_contents($file)); + $fileContent = $this->getFileHelper()->read($file); + return json_decode($fileContent); } /** diff --git a/lib/Mandrill/Mandrill.php b/lib/Mandrill/Mandrill.php index 732cb3d9e..6f92eae8f 100755 --- a/lib/Mandrill/Mandrill.php +++ b/lib/Mandrill/Mandrill.php @@ -39,11 +39,11 @@ class Mandrill_Mandrill { public $apikey; - protected $curlOptions = array(); + protected $_curlOptions = array(); public $root = 'https://mandrillapp.com/api/1.0'; public $debug = false; - public static $error_map = array( + public static $errorMap = array( "ValidationError" => "Mandrill_ValidationError", "Invalid_Key" => "Mandrill_Invalid_Key", "PaymentRequired" => "Mandrill_PaymentRequired", @@ -128,7 +128,7 @@ public function __construct($apikey = null) public function __destruct() { - $this->curlOptions = array(); + $this->_curlOptions = array(); } public function call($url, $params) @@ -146,8 +146,8 @@ public function call($url, $params) $this->log('Call to ' . $this->root . $url . '.json: ' . $params); if ($this->debug) { - $curl_buffer = fopen('php://memory', 'w+'); - $curlOptions[CURLOPT_STDERR] = $curl_buffer; + $curlBuffer = fopen('php://memory', 'w+'); + $curlOptions[CURLOPT_STDERR] = $curlBuffer; } /** @@ -155,16 +155,16 @@ public function call($url, $params) */ $curlHelper = Mage::helper('mailchimp/curl'); $this->setCurlOptionsAddOptions($curlOptions); - $curlFullResponse = $curlHelper->curlExec($this->curlOptions); + $curlFullResponse = $curlHelper->curlExec($this->_curlOptions); $info = $curlFullResponse['info']; $responseBody = $curlFullResponse['response']; $curlError = $curlFullResponse['error']; $time = microtime(true) - $start; if ($this->debug) { - rewind($curl_buffer); - $this->log(stream_get_contents($curl_buffer)); - fclose($curl_buffer); + rewind($curlBuffer); + $this->log(stream_get_contents($curlBuffer)); + fclose($curlBuffer); } $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms'); @@ -196,10 +196,12 @@ public function call($url, $params) public function readConfigs() { $paths = array('~/.mandrill.key', '/etc/mandrill.key'); + $fileHelper = $this->getFileHelper(); foreach ($paths as $path) { - if (file_exists($path)) { - $apikey = trim(file_get_contents($path)); + if ($fileHelper->fileExists($path)) { + $apikey = trim($fileHelper->read($path)); + if ($apikey) { return $apikey; } @@ -215,7 +217,7 @@ public function castError($result) throw new Mandrill_Error('We received an unexpected error: ' . json_encode($result)); } - $class = (isset(self::$error_map[$result['name']])) ? self::$error_map[$result['name']] : 'Mandrill_Error'; + $class = (isset(self::$errorMap[$result['name']])) ? self::$errorMap[$result['name']] : 'Mandrill_Error'; return new $class($result['message'], $result['code']); } @@ -231,7 +233,7 @@ public function log($msg) */ protected function getCurlOptions() { - return $this->curlOptions; + return $this->_curlOptions; } /** @@ -239,7 +241,7 @@ protected function getCurlOptions() */ protected function setCurlOptions($curlOptions) { - $this->curlOptions = $curlOptions; + $this->_curlOptions = $curlOptions; } /** @@ -248,7 +250,7 @@ protected function setCurlOptions($curlOptions) */ protected function setCurlOptionsIndexValue($index, $value) { - $this->curlOptions[$index] = $value; + $this->_curlOptions[$index] = $value; } /** @@ -256,6 +258,14 @@ protected function setCurlOptionsIndexValue($index, $value) */ protected function setCurlOptionsAddOptions($curlOptions = array()) { - $this->curlOptions += $curlOptions; + $this->_curlOptions += $curlOptions; + } + + /** + * @return Ebizmarts_MailChimp_Helper_File + */ + protected function getFileHelper() + { + return Mage::helper('mailchimp/file'); } } From c82e7b6e561d2f8c16cf2508ad1e1245361cd1fb Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 10 Sep 2019 14:44:20 -0300 Subject: [PATCH 026/160] Replacing Collection->getFirstItem() by Collection->setPageSize(1); --- .../Ebizmarts/MailChimp/Helper/Data.php | 43 ++++++++----------- .../MailChimp/Model/Api/Subscribers.php | 7 ++- .../Model/Api/Subscribers/MailchimpTags.php | 2 +- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index f60ee4705..f7e29eb7e 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -1267,11 +1267,10 @@ protected function getLastCustomerSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER)) - ->setOrder('related_id', 'DESC') - ->setPageSize(1); + ->setOrder('related_id', 'DESC'); if ($syncDataCollection->getSize()) { - $customerSyncData = $syncDataCollection->getFirstItem(); + $customerSyncData = $syncDataCollection->setPageSize(1); $lastCustomerSent = $customerSyncData->getRelatedId(); } @@ -1290,11 +1289,10 @@ protected function getLastProductSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_PRODUCT)) - ->setOrder('related_id', 'DESC') - ->setPageSize(1); + ->setOrder('related_id', 'DESC'); if ($syncDataCollection->getSize()) { - $productSyncData = $syncDataCollection->getFirstItem(); + $productSyncData = $syncDataCollection->setPageSize(1); $lastProductSent = $productSyncData->getRelatedId(); } @@ -1313,11 +1311,10 @@ protected function getLastOrderSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_ORDER)) - ->setOrder('related_id', 'DESC') - ->setPageSize(1); + ->setOrder('related_id', 'DESC'); if ($syncDataCollection->getSize()) { - $orderSyncData = $syncDataCollection->getFirstItem(); + $orderSyncData = $syncDataCollection->setPageSize(1); $lastOrderSent = $orderSyncData->getRelatedId(); } @@ -1336,11 +1333,10 @@ protected function getLastCartSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_QUOTE)) - ->setOrder('related_id', 'DESC') - ->setPageSize(1); + ->setOrder('related_id', 'DESC'); if ($syncDataCollection->getSize()) { - $cartSyncData = $syncDataCollection->getFirstItem(); + $cartSyncData = $syncDataCollection->setPageSize(1); $lastCartSent = $cartSyncData->getRelatedId(); } @@ -1359,11 +1355,10 @@ protected function getLastPromoCodeSent($scopeId, $scope) $syncDataCollection = Mage::getResourceModel('mailchimp/ecommercesyncdata_collection') ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE)) - ->setOrder('related_id', 'DESC') - ->setPageSize(1); + ->setOrder('related_id', 'DESC'); if ($syncDataCollection->getSize()) { - $promoCodeSyncData = $syncDataCollection->getFirstItem(); + $promoCodeSyncData = $syncDataCollection->setPageSize(1); $lastPromoCodeSent = $promoCodeSyncData->getRelatedId(); } @@ -1634,11 +1629,10 @@ public function getEcommerceSyncDataItem($itemId, $itemType, $mailchimpStoreId) ->addFieldToFilter('related_id', array('eq' => $itemId)) ->addFieldToFilter('type', array('eq' => $itemType)) ->addFieldToFilter('mailchimp_store_id', array('eq' => $mailchimpStoreId)) - ->setCurPage(1) - ->setPageSize(1); + ->setCurPage(1); if ($collection->getSize()) { - $ecommerceSyndDataItem = $collection->getFirstItem(); + $ecommerceSyndDataItem = $collection->setPageSize(1); } else { $ecommerceSyndDataItem = $this->getModelMailchimpEcommerceSyncData() ->setData("related_id", $itemId) @@ -2670,10 +2664,11 @@ public function delete116MigrationConfigData() protected function _migrateFrom1164($initialTime) { $dateHelper = $this->getDateHelper(); + if (!$dateHelper->timePassed($initialTime)) { - $write_connection = $this->getCoreResource()->getConnection('core_write'); + $writeConnection = $this->getCoreResource()->getConnection('core_write'); $resource = Mage::getResourceModel('mailchimp/ecommercesyncdata'); - $write_connection->update($resource->getMainTable(), array('batch_id' => '1'), "batch_id = 0"); + $writeConnection->update($resource->getMainTable(), array('batch_id' => '1'), "batch_id = 0"); $arrayMigrationConfigData = array('115' => false, '116' => false, '1164' => true); $this->handleDeleteMigrationConfigData($arrayMigrationConfigData); } @@ -2765,7 +2760,7 @@ public function loadListSubscriber($listId, $email) $subscriber = Mage::getModel('newsletter/subscriber')->getCollection() ->addFieldToFilter('store_id', array('in' => $storeIds)) ->addFieldToFilter('subscriber_email', $email) - ->getFirstItem(); + ->setPageSize(1); if (!$subscriber->getId()) { /** @@ -2811,7 +2806,7 @@ public function loadListCustomer($listId, $email) $customer = Mage::getResourceModel('customer/customer_collection') ->addFieldToFilter('store_id', array('in' => $storeIds)) ->addFieldToFilter('email', array('eq' => $email)) - ->getFirstItem(); + ->setPageSize(1); if ($customer->getId()) { $customer = Mage::getModel('customer/customer')->load($customer->getId()); } else { @@ -3096,7 +3091,7 @@ public function getScopeByMailChimpStoreId($mailChimpStoreId) ->addFieldToFilter('path', array('eq' => Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID)) ->addFieldToFilter('value', array('eq' => $mailChimpStoreId)); if ($collection->getSize()) { - $configEntry = $collection->getFirstItem(); + $configEntry = $collection->setPageSize(1); $mailchimpScope = array('scope' => $configEntry->getScope(), 'scope_id' => $configEntry->getScopeId()); } @@ -3117,7 +3112,7 @@ public function getFirstScopeFromConfig($path, $value) ->addFieldToFilter('path', array('eq' => $path)) ->addFieldToFilter('value', array('eq' => $value)); if ($collection->getSize()) { - $configEntry = $collection->getFirstItem(); + $configEntry = $collection->setPageSize(1); $mailchimpScope = array('scope' => $configEntry->getScope(), 'scope_id' => $configEntry->getScopeId()); } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php index fcc3e5a08..1bde5de7b 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php @@ -102,7 +102,7 @@ public function createBatchJson($listId, $storeId, $limit) ) ); $collection->addFieldToFilter('mailchimp_sync_error', array('eq' => '')); - $collection->getSelect()->limit($limit); + $collection->setPageSize(1); $date = $dateHelper->getDateMicrotime(); $batchId = 'storeid-'.$this->getStoreId(). '_' .Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER . '_'.$date; $counter = 0; @@ -547,11 +547,10 @@ protected function getSubscriberSyncDataItem($itemId, $magentoStoreId) $collection = Mage::getResourceModel('newsletter/subscriber_collection') ->addFieldToFilter('subscriber_id', array('eq' => $itemId)) ->addFieldToFilter('store_id', array('eq' => $magentoStoreId)) - ->setCurPage(1) - ->setPageSize(1); + ->setCurPage(1); if ($collection->getSize()) { - $subscriberSyncDataItem = $collection->getFirstItem(); + $subscriberSyncDataItem = $collection->setPageSize(1); } return $subscriberSyncDataItem; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php index 4e9fc2301..dff7f9c7e 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php @@ -592,7 +592,7 @@ protected function getLastOrderByEmail() $helper = $this->getMailchimpHelper(); $orderCollection = $helper->getOrderCollectionByCustomerEmail($this->getSubscriber()->getSubscriberEmail()); if ($this->isNotEmptyOrderCollection($orderCollection)) { - $lastOrder = $orderCollection->setOrder('created_at', 'DESC')->getFirstItem(); + $lastOrder = $orderCollection->setOrder('created_at', 'DESC')->setPageSize(1); $this->setLastOrder($lastOrder); } } From 778d4f3e93b9902736460290dac6ec989e6106c1 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Tue, 10 Sep 2019 15:32:49 -0300 Subject: [PATCH 027/160] Added method to log in log files and mailchimp error table --- .../MailChimp/Model/Api/SyncItem.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 7386eb6d7..602363651 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -74,6 +74,79 @@ protected function _updateSyncData( } } + /** + * @param $error + * @param null $mailchimpStoreId + * @param string $type + * @param null $title + * @param null $status + * @param null $originalId + * @param int $batchId + * @param null $storeId + * @param null $regType + */ + protected function logSyncError( + $error, + $mailchimpStoreId = null, + $type = 'magento_side_error', + $title = null, + $status = null, + $originalId = null, + $batchId = -1, + $storeId = null, + $regType = null + ) { + $this->getHelper()->logError($error); + + try { + $this->_logMailchimpError( + $error, $mailchimpStoreId, $type, $title, + $status, $originalId, $batchId, $storeId, $regType + ); + } catch (Exception $e) { + $this->getHelper()->logError($e->getMessage()); + } + } + + /** + * @param $error + * @param $mailchimpStoreId + * @param $type + * @param $title + * @param $status + * @param $originalId + * @param $batchId + * @param $storeId + * @param $regType + * + * @throws Exception + */ + protected function _logMailchimpError( + $error, + $mailchimpStoreId, + $type, + $title, + $status, + $originalId, + $batchId, + $storeId, + $regType + ) { + $mailchimpErrors = Mage::getModel('mailchimp/mailchimperrors'); + + $mailchimpErrors->setType($type); + $mailchimpErrors->setTitle($title); + $mailchimpErrors->setStatus($status); + $mailchimpErrors->setErrors($error); + $mailchimpErrors->setRegtype($regType); + $mailchimpErrors->setOriginalId($originalId); + $mailchimpErrors->setBatchId($batchId); + $mailchimpErrors->setStoreId($storeId); + $mailchimpErrors->setMailchimpStoreId($mailchimpStoreId); + + $mailchimpErrors->save(); + } + /** * @return Ebizmarts_MailChimp_Helper_Data */ From 0d3bbf959dd2c411937583a5b6cf8353c5cde1c4 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 10 Sep 2019 16:12:57 -0300 Subject: [PATCH 028/160] Replacing file_put_contents by equivalent in Varien_Io_File class. Replacing getFirstItem by getLastItem(). --- .../Ebizmarts/MailChimp/Helper/Data.php | 43 +++++++++++-------- .../Ebizmarts/MailChimp/Helper/File.php | 10 +++++ .../MailChimp/Model/Api/Subscribers.php | 7 +-- .../Model/Api/Subscribers/MailchimpTags.php | 4 +- .../mailchimp_setup/mysql4-install-0.0.1.php | 6 ++- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index f7e29eb7e..1161f4ec2 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -1052,7 +1052,7 @@ public function logRequest($message, $batchId = null) $fileName = $logDir . DS . $batchId . '.Request.log'; $oldPermission = umask(0033); - file_put_contents($fileName, $message); + $fileHelper->filePutContent($fileName, $message); umask($oldPermission); } } @@ -1267,10 +1267,11 @@ protected function getLastCustomerSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER)) - ->setOrder('related_id', 'DESC'); + ->setOrder('related_id', 'DESC') + ->setPageSize(1); if ($syncDataCollection->getSize()) { - $customerSyncData = $syncDataCollection->setPageSize(1); + $customerSyncData = $syncDataCollection->getLastItem(); $lastCustomerSent = $customerSyncData->getRelatedId(); } @@ -1289,10 +1290,11 @@ protected function getLastProductSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_PRODUCT)) - ->setOrder('related_id', 'DESC'); + ->setOrder('related_id', 'DESC') + ->setPageSize(1); if ($syncDataCollection->getSize()) { - $productSyncData = $syncDataCollection->setPageSize(1); + $productSyncData = $syncDataCollection->getLastItem(); $lastProductSent = $productSyncData->getRelatedId(); } @@ -1311,10 +1313,11 @@ protected function getLastOrderSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_ORDER)) - ->setOrder('related_id', 'DESC'); + ->setOrder('related_id', 'DESC') + ->setPageSize(1); if ($syncDataCollection->getSize()) { - $orderSyncData = $syncDataCollection->setPageSize(1); + $orderSyncData = $syncDataCollection->getLastItem(); $lastOrderSent = $orderSyncData->getRelatedId(); } @@ -1333,10 +1336,11 @@ protected function getLastCartSent($scopeId, $scope) $syncDataCollection = $this->getModelMailchimpEcommerceSyncData()->getCollection() ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_QUOTE)) - ->setOrder('related_id', 'DESC'); + ->setOrder('related_id', 'DESC') + ->setPageSize(1); if ($syncDataCollection->getSize()) { - $cartSyncData = $syncDataCollection->setPageSize(1); + $cartSyncData = $syncDataCollection->getLastItem(); $lastCartSent = $cartSyncData->getRelatedId(); } @@ -1355,10 +1359,11 @@ protected function getLastPromoCodeSent($scopeId, $scope) $syncDataCollection = Mage::getResourceModel('mailchimp/ecommercesyncdata_collection') ->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId)) ->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE)) - ->setOrder('related_id', 'DESC'); + ->setOrder('related_id', 'DESC') + ->setPageSize(1); if ($syncDataCollection->getSize()) { - $promoCodeSyncData = $syncDataCollection->setPageSize(1); + $promoCodeSyncData = $syncDataCollection->getLastItem(); $lastPromoCodeSent = $promoCodeSyncData->getRelatedId(); } @@ -1629,10 +1634,11 @@ public function getEcommerceSyncDataItem($itemId, $itemType, $mailchimpStoreId) ->addFieldToFilter('related_id', array('eq' => $itemId)) ->addFieldToFilter('type', array('eq' => $itemType)) ->addFieldToFilter('mailchimp_store_id', array('eq' => $mailchimpStoreId)) - ->setCurPage(1); + ->setCurPage(1) + ->setPageSize(1); if ($collection->getSize()) { - $ecommerceSyndDataItem = $collection->setPageSize(1); + $ecommerceSyndDataItem = $collection->getLastItem(); } else { $ecommerceSyndDataItem = $this->getModelMailchimpEcommerceSyncData() ->setData("related_id", $itemId) @@ -2760,7 +2766,7 @@ public function loadListSubscriber($listId, $email) $subscriber = Mage::getModel('newsletter/subscriber')->getCollection() ->addFieldToFilter('store_id', array('in' => $storeIds)) ->addFieldToFilter('subscriber_email', $email) - ->setPageSize(1); + ->setPageSize(1, 1)->getLastItem(); if (!$subscriber->getId()) { /** @@ -2806,7 +2812,8 @@ public function loadListCustomer($listId, $email) $customer = Mage::getResourceModel('customer/customer_collection') ->addFieldToFilter('store_id', array('in' => $storeIds)) ->addFieldToFilter('email', array('eq' => $email)) - ->setPageSize(1); + ->setPageSize(1, 1)->getLastItem(); + if ($customer->getId()) { $customer = Mage::getModel('customer/customer')->load($customer->getId()); } else { @@ -3090,8 +3097,9 @@ public function getScopeByMailChimpStoreId($mailChimpStoreId) $collection = Mage::getResourceModel('core/config_data_collection') ->addFieldToFilter('path', array('eq' => Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID)) ->addFieldToFilter('value', array('eq' => $mailChimpStoreId)); + if ($collection->getSize()) { - $configEntry = $collection->setPageSize(1); + $configEntry = $collection->setPageSize(1, 1)->getLastItem(); $mailchimpScope = array('scope' => $configEntry->getScope(), 'scope_id' => $configEntry->getScopeId()); } @@ -3111,8 +3119,9 @@ public function getFirstScopeFromConfig($path, $value) $collection = Mage::getResourceModel('core/config_data_collection') ->addFieldToFilter('path', array('eq' => $path)) ->addFieldToFilter('value', array('eq' => $value)); + if ($collection->getSize()) { - $configEntry = $collection->setPageSize(1); + $configEntry = $collection->setPageSize(1, 1)->getLastItem(); $mailchimpScope = array('scope' => $configEntry->getScope(), 'scope_id' => $configEntry->getScopeId()); } diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/File.php b/app/code/community/Ebizmarts/MailChimp/Helper/File.php index 31718d23c..f1f1bf8ee 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/File.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/File.php @@ -101,4 +101,14 @@ public function rm($filename) { return $this->_ioFile->rm($filename); } + + /** + * @param $filename + * @param $content + * @return int + */ + public function filePutContent($filename, $content) + { + return $this->_ioFile->filePutContent($filename, $content); + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php index 1bde5de7b..78bfbbcfc 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php @@ -102,7 +102,7 @@ public function createBatchJson($listId, $storeId, $limit) ) ); $collection->addFieldToFilter('mailchimp_sync_error', array('eq' => '')); - $collection->setPageSize(1); + $collection->getSelect()->limit($limit); $date = $dateHelper->getDateMicrotime(); $batchId = 'storeid-'.$this->getStoreId(). '_' .Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER . '_'.$date; $counter = 0; @@ -547,10 +547,11 @@ protected function getSubscriberSyncDataItem($itemId, $magentoStoreId) $collection = Mage::getResourceModel('newsletter/subscriber_collection') ->addFieldToFilter('subscriber_id', array('eq' => $itemId)) ->addFieldToFilter('store_id', array('eq' => $magentoStoreId)) - ->setCurPage(1); + ->setCurPage(1) + ->setPageSize(1); if ($collection->getSize()) { - $subscriberSyncDataItem = $collection->setPageSize(1); + $subscriberSyncDataItem = $collection->getLastItem(); } return $subscriberSyncDataItem; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php index dff7f9c7e..7c41b40b9 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php @@ -588,11 +588,13 @@ protected function addCompany($customAtt, $customer, $key) protected function getLastOrderByEmail() { $lastOrder = $this->getLastOrder(); + if ($lastOrder === null) { $helper = $this->getMailchimpHelper(); $orderCollection = $helper->getOrderCollectionByCustomerEmail($this->getSubscriber()->getSubscriberEmail()); + if ($this->isNotEmptyOrderCollection($orderCollection)) { - $lastOrder = $orderCollection->setOrder('created_at', 'DESC')->setPageSize(1); + $lastOrder = $orderCollection->setOrder('created_at', 'DESC')->setPageSize(1, 1)->getLastItem(); $this->setLastOrder($lastOrder); } } diff --git a/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-install-0.0.1.php b/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-install-0.0.1.php index bfe48ab44..a38e0b464 100755 --- a/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-install-0.0.1.php +++ b/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-install-0.0.1.php @@ -31,7 +31,11 @@ $baseDir = Mage::getBaseDir(); try { - mkdir($baseDir . DS . 'var' . DS . 'mailchimp'); + /** + * @var $fileHelper Ebizmarts_MailChimp_Helper_File + */ + $fileHelper = Mage::helper('mailchimp/file'); + $fileHelper->mkDir($baseDir . DS . 'var' . DS . 'mailchimp'); } catch (Exception $e) { Mage::log($e->getMessage(), null, 'MailChimp_Errors.log', true); } From d4875b0be495da407c0f6dac26b4841ca902b535 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 10 Sep 2019 17:34:50 -0300 Subject: [PATCH 029/160] Replacing: "return Mage::helper('mailchimp/helper');" by return "Mage::helper('mailchimp/file');" at getFileHelper() method in Ebizmarts_MailChimp_Helper_Data class in Data.php file. . --- app/code/community/Ebizmarts/MailChimp/Helper/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 1161f4ec2..840367fea 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -5093,6 +5093,6 @@ public function ping($storeId) */ protected function getFileHelper() { - return Mage::helper('mailchimp/helper'); + return Mage::helper('mailchimp/file'); } } From 2292c8f803c6c3dae975dddcc42acab6a392cf1c Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Wed, 11 Sep 2019 13:36:27 -0300 Subject: [PATCH 030/160] Error logging method added and implemented in sync items classes --- .../Ebizmarts/MailChimp/Model/Api/Carts.php | 12 +++++- .../MailChimp/Model/Api/Customers.php | 11 ++--- .../Ebizmarts/MailChimp/Model/Api/Orders.php | 43 +++++++++++++++---- .../MailChimp/Model/Api/Products.php | 30 +++++++------ .../MailChimp/Model/Api/PromoCodes.php | 19 ++++++-- .../MailChimp/Model/Api/PromoRules.php | 12 +++++- .../MailChimp/Model/Api/SyncItem.php | 6 +-- 7 files changed, 98 insertions(+), 35 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index 43f2a2075..2dc4d5b00 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -280,7 +280,11 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) ); //json encode failed - $helper->logError("Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")"); + $this->logSyncError( + "Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")", + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + $mailchimpStoreId + ); } $this->setToken(null); @@ -427,7 +431,11 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) -1 ); //json encode failed - $helper->logError("Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")"); + $this->logSyncError( + "Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")", + Ebizmarts_MailChimp_Model_Config::IS_QUOTE, + $mailchimpStoreId + ); } $this->setToken(null); diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index a493a56de..7889b6816 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -465,9 +465,10 @@ protected function getCustomerLastname($customer) protected function logCouldNotEncodeCustomerError($customer) { $jsonErrorMessage = json_last_error_msg(); - $this->getHelper()->logError( + $this->logSyncError( "Customer " . $customer->getId() . " json encode failed (".$jsonErrorMessage.") on store " - . $this->getBatchMagentoStoreId() + . $this->getBatchMagentoStoreId(), + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER ); return $jsonErrorMessage; } @@ -478,11 +479,11 @@ protected function logCouldNotEncodeCustomerError($customer) */ protected function logCouldNotEncodeMailchimpTags($customer, $mailchimpTags) { - $this->getHelper()->logError( + $this->logSyncError( "MailChimp tags encode failed, Customer " . $customer->getId() . " on store " . - $this->getBatchMagentoStoreId()." mergeFields:" + $this->getBatchMagentoStoreId()." mergeFields: " . $mailchimpTags, + Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER ); - $this->getHelper()->logError($mailchimpTags); } /** diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 4c5b8bdb0..cabcc59bd 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -128,8 +128,11 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) continue; } } else { - $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); + $jsonErrorMsg = json_last_error_msg();$this->logSyncError( + "Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")", + Ebizmarts_MailChimp_Model_Config::IS_ORDER, + $mailchimpStoreId, $magentoStoreId + ); $this->_updateSyncData( $orderId, @@ -145,7 +148,11 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) ); } } catch (Exception $e) { - $helper->logError($e->getMessage()); + $this->logSyncError( + $e->getMessage(), + Ebizmarts_MailChimp_Model_Config::IS_ORDER, + $mailchimpStoreId, $magentoStoreId + ); } } @@ -214,7 +221,11 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) } } else { $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); + $this->logSyncError( + "Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")", + Ebizmarts_MailChimp_Model_Config::IS_ORDER, + $mailchimpStoreId, $magentoStoreId + ); $this->_updateSyncData( $orderId, @@ -230,7 +241,11 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) ); } } catch (Exception $e) { - $helper->logError($e->getMessage()); + $this->logSyncError( + $e->getMessage(), + Ebizmarts_MailChimp_Model_Config::IS_ORDER, + $mailchimpStoreId, $magentoStoreId + ); } } @@ -1028,13 +1043,25 @@ public function shouldSendCampaignId($mailchimpCampaignId, $magentoStoreId) } } catch (Ebizmarts_MailChimp_Helper_Data_ApiKeyException $e) { $this->_listsCampaignIds[$apiKey][$listId][$mailchimpCampaignId] = $isCampaingFromCurrentList = true; - $helper->logError($e->getMessage()); + $this->logSyncError( + $e->getMessage(), + Ebizmarts_MailChimp_Model_Config::IS_ORDER, + null, $magentoStoreId + ); } catch (MailChimp_Error $e) { $this->_listsCampaignIds[$apiKey][$listId][$mailchimpCampaignId] = $isCampaingFromCurrentList = false; - $helper->logError($e->getFriendlyMessage()); + $this->logSyncError( + $e->getFriendlyMessage(), + Ebizmarts_MailChimp_Model_Config::IS_ORDER, + null, $magentoStoreId + ); } catch (Exception $e) { $this->_listsCampaignIds[$apiKey][$listId][$mailchimpCampaignId] = $isCampaingFromCurrentList = true; - $helper->logError($e->getMessage()); + $this->logSyncError( + $e->getMessage(), + Ebizmarts_MailChimp_Model_Config::IS_ORDER, + null, $magentoStoreId + ); } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index ebc32c504..96e078b27 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -225,9 +225,10 @@ protected function _buildNewProductRequest($product, $batchId, $mailchimpStoreId if ($body === false) { //json encode failed $jsonErrorMsg = json_last_error_msg(); - $this->getHelper()->logError( - "Product " . $product->getId() - . " json encode failed (".$jsonErrorMsg.")" + $this->logSyncError( + "Product " . $product->getId() . " json encode failed (".$jsonErrorMsg.")", + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $mailchimpStoreId, $magentoStoreId ); $this->_updateSyncData( @@ -295,10 +296,12 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor $body = json_encode($bodyData, JSON_HEX_APOS | JSON_HEX_QUOT); if ($body === false) { $jsonErrorMsg = json_last_error_msg(); - $this->getHelper()->logError( - "Product " . $parent->getId() - . " json encode failed (".$jsonErrorMsg.")" + $this->logSyncError( + "Product " . $parent->getId() . " json encode failed (".$jsonErrorMsg.")", + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + $mailchimpStoreId, $magentoStoreId ); + $this->_updateSyncData( $parent->getId(), $mailchimpStoreId, @@ -337,16 +340,19 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor $body = json_encode($bodyData, JSON_HEX_APOS | JSON_HEX_QUOT); if ($body === false) { //json encode failed - $this->getHelper()->logError( - "Product " . $product->getId() - . " json encode failed (".json_last_error_msg().")" + $this->logSyncError( + "Product " . $product->getId() . " json encode failed (".json_last_error_msg().")", + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + null, $magentoStoreId ); $jsonErrorMsg = json_last_error_msg(); - $this->getHelper()->logError( - "Product " . $product->getId() - . " json encode failed (".$jsonErrorMsg.")" + $this->logSyncError( + "Product " . $product->getId() . " json encode failed (".$jsonErrorMsg.")", + Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, + null, $magentoStoreId ); + $this->_updateSyncData( $product->getId(), $mailchimpStoreId, diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index f29fbb6a1..d15a03b05 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -166,7 +166,12 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) } } else { $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Promo code" . $codeId . " json encode failed (".$jsonErrorMsg.")"); + $this->logSyncError( + "Promo code" . $codeId . " json encode failed (".$jsonErrorMsg.")", + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, + $mailchimpStoreId, $magentoStoreId + ); + $this->_updateSyncData( $codeId, $mailchimpStoreId, @@ -182,7 +187,11 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) ); } } catch (Exception $e) { - $helper->logError($e->getMessage()); + $this->logSyncError( + $e->getMessage(), + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, + $mailchimpStoreId, $magentoStoreId + ); } } @@ -436,7 +445,11 @@ protected function getPromoCodesForRule($promoRuleId) $this->deletePromoCodeSyncData($promoCode['id'], $mailchimpStoreId); } } catch (MailChimp_Error $e) { - $helper->logError($e->getFriendlyMessage()); + $this->logSyncError( + $e->getFriendlyMessage(), + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE, + $mailchimpStoreId + ); } } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index 5fa2c5269..00bb02704 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -114,7 +114,11 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) } } else { $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Promo rule " . $ruleId . " json encode failed (".$jsonErrorMsg.")"); + $this->logSyncError( + "Promo rule " . $ruleId . " json encode failed (".$jsonErrorMsg.")", + Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, + $mailchimpStoreId, $magentoStoreId + ); $this->_updateSyncData( $ruleId, @@ -130,7 +134,11 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) ); } } catch (Exception $e) { - $helper->logError($e->getMessage()); + $this->logSyncError( + $e->getMessage(), + Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, + $mailchimpStoreId, $magentoStoreId + ); } return $promoData; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 602363651..c4dcceb36 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -87,14 +87,14 @@ protected function _updateSyncData( */ protected function logSyncError( $error, + $regType = null, $mailchimpStoreId = null, + $storeId = null, $type = 'magento_side_error', $title = null, $status = null, $originalId = null, - $batchId = -1, - $storeId = null, - $regType = null + $batchId = -1 ) { $this->getHelper()->logError($error); From 7be06dee646aa4f0e3d5c6622b081417c4bb7af0 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Wed, 11 Sep 2019 15:13:22 -0300 Subject: [PATCH 031/160] Logging errors in updateSyncData method --- .../community/Ebizmarts/MailChimp/Model/Api/SyncItem.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index c4dcceb36..1a91c4471 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -55,6 +55,14 @@ protected function _updateSyncData( ) { $type = $this->getClassConstant(); + if ($syncError !== null) { + $this->logSyncError( + "Update Sync Data error: " . $syncError, + $type, + $mailchimpStoreId + ); + } + if (!empty($type)) { $helper = $this->getHelper(); $helper->saveEcommerceSyncData( From df7849db36fe66a11ca31eed7831680653ad73c0 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Wed, 11 Sep 2019 16:34:47 -0300 Subject: [PATCH 032/160] Removing the phpcs warning: "Possible slow SQL method 'Looks like your Mailchimp store was deleted. Please create a new one and associate ' detected." due to the word 'like' in the string: 'Looks like your Mailchimp store was deleted. Please create a new one and associate ' --- .../MailChimp/Model/System/Config/Source/Account.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php index 813f1978b..18c539e5e 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php @@ -80,8 +80,8 @@ public function __construct($params) } catch (MailChimp_Error $e) { if ($helper->isEcomSyncDataEnabled($scopeArray['scope_id'], $scopeArray['scope'])) { $message = $helper->__( - 'Looks like your Mailchimp store was deleted. Please create a new one and associate ' - . 'it in order to get your Ecommerce data synced.' + 'It seems your Mailchimp store was deleted. ' + . 'Please create a new one and associate it in order to get your Ecommerce data synced.' ); Mage::getSingleton('adminhtml/session')->addWarning($message); } From c6e714ffc4909883bd751205f0e65bf275d536b2 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 16 Sep 2019 11:44:04 -0300 Subject: [PATCH 033/160] Added methods to manage syncItems in Ecommerce table --- .../MailChimp/Model/Api/SyncItem.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 7386eb6d7..646ab2f24 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -74,6 +74,60 @@ protected function _updateSyncData( } } + protected function addSyncDataError( + $id, + $mailchimpStoreId, + $error, + $token = null, + $saveOnlyIfExists = false, + $syncDelta = null + ) { + $this->_updateSyncData( + $id, + $mailchimpStoreId, + $syncDelta, + $error, + 0, + null, + null, + $token, + $saveOnlyIfExists, + -1 + ); + } + + protected function addSyncData($id, $mailchimpStoreId) + { + $this->_updateSyncData($id, $mailchimpStoreId); + } + + protected function addSyncDataToken($id, $mailchimpStoreId, $token) + { + $this->_updateSyncData( + $id, + $mailchimpStoreId, + null, + null, + 0, + null, + null, + $token + ); + } + + protected function markSyncDataAsDeleted($id, $mailchimpStoreId) + { + $this->_updateSyncData( + $id, + $mailchimpStoreId, + null, + null, + 0, + 1, + null + ); + } + /** * @return Ebizmarts_MailChimp_Helper_Data */ From 98a373b6c0013582f8f727c94d553e7c2eb10fd6 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 16 Sep 2019 11:45:02 -0300 Subject: [PATCH 034/160] Carts now using new methods and Tests fixed --- .../Ebizmarts/MailChimp/Model/Api/Carts.php | 114 ++++-------------- .../MailChimp/Model/Api/CartsTest.php | 50 ++++---- 2 files changed, 54 insertions(+), 110 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index 43f2a2075..0fd4357a6 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -112,15 +112,8 @@ public function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) . $alreadySentCartId; $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; - $this->_updateSyncData( - $alreadySentCartId, - $mailchimpStoreId, - null, - null, - 0, - 1, - null - ); + + $this->markSyncDataAsDeleted($alreadySentCartId, $mailchimpStoreId); $this->setCounter($this->getCounter() + 1); } } @@ -131,15 +124,8 @@ public function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/carts/' . $cartId; $allCarts[$counter]['operation_id'] = $batchId . '_' . $cartId; $allCarts[$counter]['body'] = ''; - $this->_updateSyncData( - $cartId, - $mailchimpStoreId, - null, - null, - 0, - 1, - null - ); + + $this->markSyncDataAsDeleted($cartId, $mailchimpStoreId); $this->setCounter($this->getCounter() + 1); } @@ -206,15 +192,8 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) . $alreadySentCartId; $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; - $this->_updateSyncData( - $alreadySentCartId, - $mailchimpStoreId, - null, - null, - 0, - 1, - null - ); + + $this->markSyncDataAsDeleted($cartId, $mailchimpStoreId); $this->setCounter($this->getCounter() + 1); } } @@ -224,7 +203,7 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) // avoid carts abandoned as guests when customer email associated to a registered customer. if (!$cart->getCustomerId() && $customer->getEmail() == $cart->getCustomerEmail()) { - $this->_updateSyncData($cartId, $mailchimpStoreId); + $this->addSyncData($cartId, $mailchimpStoreId); continue; } @@ -242,42 +221,16 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $cartId; $allCarts[$counter]['body'] = $cartJson; $this->setCounter($this->getCounter() + 1); - $this->_updateSyncData( - $cartId, - $mailchimpStoreId, - null, - null, - 0, - null, - null, - $this->getToken() - ); + + $this->addSyncDataToken($cartId, $mailchimpStoreId, $this->getToken()); } else { $error = $helper->__('There is not supported products in this cart.'); - $this->_updateSyncData( - $cartId, - $mailchimpStoreId, - null, - $error, - 0 - ); + $this->addSyncDataError($cartId, $mailchimpStoreId, $error); } } else { $jsonErrorMessage = json_last_error_msg(); - - $this->_updateSyncData( - $cartId, - $mailchimpStoreId, - null, - $jsonErrorMessage, - 0, - null, - null, - $this->getToken(), - false, - -1 - ); + $this->addSyncDataError($cartId, $mailchimpStoreId, $jsonErrorMessage, $this->getToken()); //json encode failed $helper->logError("Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")"); @@ -332,7 +285,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $allVisibleItems = $cart->getAllVisibleItems(); if (empty($allVisibleItems) || $orderCollection->getSize()) { - $this->_updateSyncData($cartId, $mailchimpStoreId); + $this->addSyncData($cartId, $mailchimpStoreId); continue; } @@ -357,15 +310,8 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) . $alreadySentCartId; $allCarts[$counter]['operation_id'] = $batchId . '_' . $alreadySentCartId; $allCarts[$counter]['body'] = ''; - $this->_updateSyncData( - $alreadySentCartId, - $mailchimpStoreId, - null, - null, - 0, - 1, - null - ); + + $this->markSyncDataAsDeleted($alreadySentCartId, $mailchimpStoreId); $this->setCounter($this->getCounter() + 1); } @@ -374,7 +320,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) // don't send the carts for guest customers who are registered if (!$cart->getCustomerId() && $customer->getEmail() == $cart->getCustomerEmail()) { - $this->_updateSyncData($cartId, $mailchimpStoreId); + $this->addSyncData($cartId, $mailchimpStoreId); continue; } @@ -392,40 +338,32 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) $allCarts[$counter]['operation_id'] = $batchId . '_' . $cartId; $allCarts[$counter]['body'] = $cartJson; $this->setCounter($this->getCounter() + 1); - $this->_updateSyncData( - $cartId, - $mailchimpStoreId, - null, - null, - 0, - null, - null, - $this->getToken() - ); + + $this->addSyncDataToken($cartId, $mailchimpStoreId, $this->getToken()); } else { $error = $helper->__('There is not supported products in this cart.'); - $this->_updateSyncData( + + $this->addSyncDataError( $cartId, $mailchimpStoreId, - $dateHelper->getCurrentDateTime(), $error, - 0 + null, + false, + $dateHelper->getCurrentDateTime() ); } } else { $jsonErrorMessage = json_last_error_msg(); - $this->_updateSyncData( + + $this->addSyncDataError( $cartId, $mailchimpStoreId, - $dateHelper->getCurrentDateTime(), $jsonErrorMessage, - 0, - null, - null, null, false, - -1 + $dateHelper->getCurrentDateTime() ); + //json encode failed $helper->logError("Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")"); } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php index 21f5925b8..ed44b49f0 100755 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CartsTest.php @@ -300,7 +300,9 @@ public function testGetModifiedQuotes() 'getCounter', '_makeCart', 'getAllCartsByEmail', - 'addProductNotSentData' + 'addProductNotSentData', + 'addSyncDataToken', + 'markSyncDataAsDeleted' ) ) ->getMock(); @@ -372,16 +374,22 @@ public function testGetModifiedQuotes() self::COUNTER, self::COUNTER ); - $cartsApiMock->expects($this->exactly(2)) - ->method('_updateSyncData') - ->withConsecutive( - array( - self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null - ), - array( - self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token - ) - ); + $cartsApiMock->expects($this->once()) + ->method('markSyncDataAsDeleted') + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); + $cartsApiMock->expects($this->once()) + ->method('addSyncDataToken') + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID, $token); +// $cartsApiMock->expects($this->exactly(2)) +// ->method('_updateSyncData') +// ->withConsecutive( +// array( +// self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null +// ), +// array( +// self::CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, null, null, $token +// ) +// ); $cartsApiMock->expects($this->exactly(2)) ->method('setCounter') ->withConsecutive( @@ -619,7 +627,9 @@ public function testGetModifiedQuotesEmptyJson() 'getCounter', '_makeCart', 'getAllCartsByEmail', - 'addProductNotSentData' + 'addProductNotSentData', + 'markSyncDataAsDeleted', + 'addSyncDataError' ) ) ->getMock(); @@ -686,16 +696,12 @@ public function testGetModifiedQuotesEmptyJson() self::COUNTER, self::COUNTER ); - $cartsApiMock->expects($this->exactly(2)) - ->method('_updateSyncData') - ->withConsecutive( - array( - self::ALREADY_SENT_CART_ID, self::MAILCHIMP_STORE_ID, null, null, null, 1, null - ), - array( - self::CART_ID, self::MAILCHIMP_STORE_ID - ) - ); + $cartsApiMock->expects($this->once()) + ->method('markSyncDataAsDeleted') + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); + $cartsApiMock->expects($this->once()) + ->method('addSyncDataError') + ->with(self::CART_ID, self::MAILCHIMP_STORE_ID); $cartsApiMock->expects($this->once()) ->method('setCounter') ->with(self::COUNTER + 1); From 393f0cffcc482409f62bd11f5e5203cadc2ff149 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 16 Sep 2019 14:26:28 -0300 Subject: [PATCH 035/160] Customers and Orders now using new methods and new method to mark modified added --- .../MailChimp/Model/Api/Customers.php | 38 +++-------- .../Ebizmarts/MailChimp/Model/Api/Orders.php | 63 +++++++------------ .../MailChimp/Model/Api/SyncItem.php | 14 ++++- 3 files changed, 41 insertions(+), 74 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index a493a56de..0ad296e65 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -116,15 +116,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) ); $customerArray[$counter] = $this->makePutBatchStructure($customerJson, $customer); - $this->_updateSyncData( - $customer->getId(), - $mailchimpStoreId, - null, - null, - 0, - null, - null - ); + $this->addSyncData($customer->getId(), $mailchimpStoreId); $counter++; if (!$isSubscribed) { @@ -144,27 +136,24 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) } } } else { - $this->_updateSyncData( + $this->addSyncDataError( $customer->getId(), $mailchimpStoreId, - $this->getDateHelper()->getCurrentDateTime(), 'Customer with no data', - 0 + null, + false, + $this->getDateHelper()->getCurrentDateTime() ); } } else { $jsonErrorMessage = $this->logCouldNotEncodeCustomerError($customer); - $this->_updateSyncData( + $this->addSyncDataError( $customer->getId(), $mailchimpStoreId, - $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMessage, - 0, - null, - null, null, false, - -1 + $this->getDateHelper()->getCurrentDateTime() ); } } @@ -317,18 +306,7 @@ protected function getCountryNameByCode($countryCode) public function update($customerId, $storeId) { $mailchimpStoreId = $this->getHelper()->getMCStoreId($storeId); - $this->_updateSyncData( - $customerId, - $mailchimpStoreId, - null, - null, - 1, - null, - null, - null, - true, - false - ); + $this->markSyncDataAsModified($customerId, $mailchimpStoreId); } /** diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 4c5b8bdb0..f81d1df98 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -112,18 +112,18 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) $batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId; $batchArray[$this->_counter]['body'] = $orderJson; //update order delta - $this->_updateSyncData($orderId, $mailchimpStoreId); + $this->addSyncData($orderId, $mailchimpStoreId); $this->_counter++; } else { $error = $helper->__('Something went wrong when retrieving product information.'); - $this->_updateSyncData( + + $this->addSyncDataError( $orderId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, - 0, null, - 0 + false, + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); continue; } @@ -131,17 +131,13 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) $jsonErrorMsg = json_last_error_msg(); $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); - $this->_updateSyncData( + $this->addSyncDataError( $orderId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $jsonErrorMsg, - 0, - null, - 0, null, false, - -1 + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); } } catch (Exception $e) { @@ -197,18 +193,18 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) $batchArray[$this->_counter]['operation_id'] = $this->_batchId . '_' . $orderId; $batchArray[$this->_counter]['body'] = $orderJson; //update order delta - $this->_updateSyncData($orderId, $mailchimpStoreId); + $this->addSyncData($orderId, $mailchimpStoreId); $this->_counter++; } else { $error = $helper->__('Something went wrong when retrieving product information.'); - $this->_updateSyncData( + + $this->addSyncDataError( $orderId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, - 0, null, - 0 + false, + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); continue; } @@ -216,17 +212,13 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) $jsonErrorMsg = json_last_error_msg(); $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); - $this->_updateSyncData( + $this->addSyncDataError( $orderId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $jsonErrorMsg, - 0, - null, - 0, null, false, - -1 + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); } } catch (Exception $e) { @@ -679,18 +671,7 @@ public function update($orderId, $magentoStoreId) $helper = $this->getHelper(); if ($helper->isEcomSyncDataEnabled($magentoStoreId)) { $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); - $this->_updateSyncData( - $orderId, - $mailchimpStoreId, - null, - null, - 1, - null, - null, - null, - true, - false - ); + $this->markSyncDataAsModified($orderId, $mailchimpStoreId); } } @@ -763,27 +744,25 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS $error = $helper->__( 'Something went wrong when retrieving product information during migration from 1.1.6.' ); - $this->_updateSyncData( + $this->addSyncDataError( $orderId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, - 0, null, - 0 + false, + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); continue; } } else { $error = $helper->__("Json error during migration from 1.1.6"); - $this->_updateSyncData( + $this->addSyncDataError( $orderId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $error, - 0, null, - 0 + false, + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); continue; } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 646ab2f24..1ba4917fe 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -115,6 +115,17 @@ protected function addSyncDataToken($id, $mailchimpStoreId, $token) ); } + protected function markSyncDataAsModified($id, $mailchimpStoreId) + { + $this->_updateSyncData( + $id, + $mailchimpStoreId, + null, + null, + 1 + ); + } + protected function markSyncDataAsDeleted($id, $mailchimpStoreId) { $this->_updateSyncData( @@ -123,8 +134,7 @@ protected function markSyncDataAsDeleted($id, $mailchimpStoreId) null, null, 0, - 1, - null + 1 ); } From dc51c9410925fd0e81f3e0db4846384b49411e77 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 16 Sep 2019 15:51:18 -0300 Subject: [PATCH 036/160] Products now using new methods and Tests fixed --- .../MailChimp/Model/Api/Products.php | 111 ++++-------------- .../MailChimp/Model/Api/ProductsTest.php | 60 ++++------ 2 files changed, 52 insertions(+), 119 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index ebc32c504..4a2a1ad59 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -91,10 +91,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $buildUpdateOperations, $batchArray ); - $this->_updateSyncData( - $productId, - $mailchimpStoreId - ); + $this->addSyncData($productId, $mailchimpStoreId); } $counter = count($batchArray); @@ -120,19 +117,15 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) } //update product delta - $this->_updateSyncData( - $productId, - $mailchimpStoreId - ); + $this->addSyncData($productId, $mailchimpStoreId); } else { - $this->_updateSyncData( + $this->addSyncDataError( $productId, $mailchimpStoreId, - $dateHelper->formatDate(null, 'Y-m-d H:i:s'), "This product type is not supported on MailChimp.", - 0, null, - 0 + false, + $dateHelper->formatDate(null, 'Y-m-d H:i:s') ); } } @@ -165,14 +158,10 @@ public function createDeletedProductsBatchJson($mailchimpStoreId, $magentoStoreI $counter++; } - $this->_updateSyncData( + $this->addSyncDataError( $product->getId(), $mailchimpStoreId, - null, - self::PRODUCT_DISABLED_IN_MAGENTO, - 0, - null, - 0 + self::PRODUCT_DISABLED_IN_MAGENTO ); } @@ -230,17 +219,13 @@ protected function _buildNewProductRequest($product, $batchId, $mailchimpStoreId . " json encode failed (".$jsonErrorMsg.")" ); - $this->_updateSyncData( + $this->addSyncDataError( $product->getId(), $mailchimpStoreId, - $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMsg, - 0, - null, null, null, - false, - -1 + $this->getDateHelper()->getCurrentDateTime() ); return false; @@ -299,18 +284,16 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor "Product " . $parent->getId() . " json encode failed (".$jsonErrorMsg.")" ); - $this->_updateSyncData( - $parent->getId(), + + $this->addSyncDataError( + $product->getId(), $mailchimpStoreId, - $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMsg, - 0, - null, null, null, - false, - -1 + $this->getDateHelper()->getCurrentDateTime() ); + return false; } @@ -347,17 +330,14 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor "Product " . $product->getId() . " json encode failed (".$jsonErrorMsg.")" ); - $this->_updateSyncData( + + $this->addSyncDataError( $product->getId(), $mailchimpStoreId, - $this->getDateHelper()->getCurrentDateTime(), $jsonErrorMsg, - 0, - null, null, null, - false, - -1 + $this->getDateHelper()->getCurrentDateTime() ); return false; @@ -492,32 +472,10 @@ public function update($productId, $mailchimpStoreId) { $parentIdArray = $this->getAllParentIds($productId); foreach ($parentIdArray as $parentId) { - $this->_updateSyncData( - $parentId, - $mailchimpStoreId, - null, - null, - 1, - 0, - null, - null, - true, - false - ); + $this->markSyncDataAsModified($parentId, $mailchimpStoreId); } - $this->_updateSyncData( - $productId, - $mailchimpStoreId, - null, - null, - 1, - 0, - null, - null, - true, - false - ); + $this->markSyncDataAsModified($productId, $mailchimpStoreId); } /** @@ -528,18 +486,7 @@ public function update($productId, $mailchimpStoreId) */ public function updateDisabledProducts($productId, $mailchimpStoreId) { - $this->_updateSyncData( - $productId, - $mailchimpStoreId, - null, - '', - 0, - 1, - null, - null, - false, - false - ); + $this->markSyncDataAsDeleted($productId, $mailchimpStoreId); } /** @@ -567,19 +514,19 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId ); + if ($productId != $itemProductId || $this->isBundleProduct($product) || $this->isGroupedProduct($product) ) { if ($productId) { - $this->_updateSyncData( + $this->addSyncDataError( $productId, $mailchimpStoreId, - $dateHelper->formatDate(null, 'Y-m-d H:i:s'), "This product type is not supported on MailChimp.", - 0, null, - 0 + null, + $dateHelper->formatDate(null, 'Y-m-d H:i:s') ); } @@ -604,10 +551,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $buildUpdateOperations, $data ); - $this->_updateSyncData( - $productId, - $mailchimpStoreId - ); + $this->addSyncData($productId, $mailchimpStoreId); } } elseif (!$syncDelta || $syncDelta < $syncDateFlag || !$isProductEnabled) { $bodyData = $this->_buildNewProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); @@ -616,10 +560,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $data[] = $bodyData; // avoid update for disabled products to prevent send the product as modified if ($isProductEnabled) { - $this->_updateSyncData( - $productId, - $mailchimpStoreId - ); + $this->addSyncData($productId, $mailchimpStoreId); } } } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index af17da580..e947be366 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -383,12 +383,13 @@ public function testSendModifiedProduct() $itemOneSyncDelta = '2018-03-14 15:03:37'; $itemTwoSyncDelta = '2018-03-14 15:03:35'; $isProductEnabled = false; + $error = "This product type is not supported on MailChimp."; $productsApiMock = $this->_productsApiMock ->setMethods( - array('makeBatchId', '_updateSyncData', 'loadProductById', 'isGroupedProduct', + array('makeBatchId', 'loadProductById', 'isGroupedProduct', 'isBundleProduct', '_buildUpdateProductRequest', '_buildNewProductRequest', - 'isProductEnabled', 'getHelper', 'getDateHelper' + 'isProductEnabled', 'getHelper', 'getDateHelper', 'addSyncData', 'addSyncDataError' ) ) ->getMock(); @@ -461,6 +462,11 @@ public function testSendModifiedProduct() $newProductId ); + $dateHelperMock->expects($this->once()) + ->method('formatDate') + ->with(null, 'Y-m-d H:i:s') + ->willReturn($ecomSyncDateFlag); + $productsApiMock->expects($this->once())->method('getHelper')->willReturn($helperMock); $productsApiMock->expects($this->once())->method('getDateHelper')->willReturn($dateHelperMock); @@ -532,10 +538,14 @@ public function testSendModifiedProduct() ->willReturn(array()); $productsApiMock - ->expects($this->exactly(3)) - ->method('_updateSyncData') + ->expects($this->once()) + ->method('addSyncDataError') + ->with($groupedProductId, $mailchimpStoreId, $error, null, null, $ecomSyncDateFlag); + + $productsApiMock + ->expects($this->exactly(2)) + ->method('addSyncData') ->withConsecutive( - array($groupedProductId, $mailchimpStoreId), array($oldProductId, $mailchimpStoreId), array($newProductId, $mailchimpStoreId) ); @@ -723,7 +733,7 @@ public function testUpdate() $mailchimpStoreId = '3ade9d9e52e35e9b18d95bdd4d9e9a44'; $productsApiMock = $this->_productsApiMock - ->setMethods(array('getAllParentIds', '_updateSyncData')) + ->setMethods(array('getAllParentIds', 'markSyncDataAsModified')) ->getMock(); $productIdArrayMock = $this->getMockBuilder(ArrayObject::class) @@ -741,35 +751,17 @@ public function testUpdate() ->willReturn(new ArrayIterator($parentIdArray)); $productsApiMock->expects($this->exactly(9)) - ->method('_updateSyncData') + ->method('markSyncDataAsModified') ->withConsecutive( - array( - $parentIdArray[0], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $parentIdArray[1], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $parentIdArray[2], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $parentIdArray[3], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $parentIdArray[4], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $parentIdArray[5], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $parentIdArray[6], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $parentIdArray[7], $mailchimpStoreId, null, null, 1, null, null, null, true, false - ), - array( - $productId, $mailchimpStoreId, null, null, 1, null, null, null, true, false - ) + array($parentIdArray[0], $mailchimpStoreId), + array($parentIdArray[1], $mailchimpStoreId), + array($parentIdArray[2], $mailchimpStoreId), + array($parentIdArray[3], $mailchimpStoreId), + array($parentIdArray[4], $mailchimpStoreId), + array($parentIdArray[5], $mailchimpStoreId), + array($parentIdArray[6], $mailchimpStoreId), + array($parentIdArray[7], $mailchimpStoreId), + array($productId, $mailchimpStoreId) ); $productsApiMock->update($productId, $mailchimpStoreId); From c3c12e9500212cd4d62bd7d9e8642d4c18610fb1 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 16 Sep 2019 16:20:16 -0300 Subject: [PATCH 037/160] Removing all uses of GENERAL_ECOMMMINSYNCDATEFLAG variable. And hence delete the method: getEcommMinSyncDateFlag() and its uses. Adding "break" loop control in getIfConfigExistsForScope() method, in order of stop iteration through the collection when condition is satisfied. Modifying ProductsTest.php --- .../Ebizmarts/MailChimp/Helper/Data.php | 60 +--------- .../Ebizmarts/MailChimp/Model/Api/Batches.php | 55 ++++----- .../MailChimp/Model/Api/Products.php | 27 ++--- .../MailChimp/Model/Api/PromoCodes.php | 10 +- .../Ebizmarts/MailChimp/Model/Config.php | 1 - .../Model/System/Config/Backend/Store.php | 13 +-- .../MailChimp/Model/Api/BatchesTest.php | 108 +++++++++--------- .../MailChimp/Model/Api/ProductsTest.php | 15 +-- 8 files changed, 98 insertions(+), 191 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 2ce316c87..591975ab1 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -493,11 +493,6 @@ public function deleteAllMCStoreData($mailchimpStoreId) 'default', 0 ); - $config->deleteConfig( - Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG . "_$mailchimpStoreId", - 'default', - 0 - ); $config->deleteConfig( Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL . "_$mailchimpStoreId", 'default', @@ -681,60 +676,6 @@ public function getMCIsSyncing($mailchimpStoreId, $scopeId = 0, $scope = 'stores return ($syncingFlag !== null) ? $syncingFlag : $oldSyncingFlag; } - /** - * Minimum date for which ecommerce data needs to be uploaded. - * If data was saved in the old way get it from the scope and update it to the new way. - * - * @param $mailchimpStoreId - * @param $scopeId - * @param null $scope - * @return mixed|null - * @throws Mage_Core_Exception - */ - public function getEcommMinSyncDateFlag($mailchimpStoreId, $scopeId, $scope = null) - { - $oldEcommMinsyncDateFlag = $this->getConfigValueForScope( - Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG, - $scopeId, - $scope - ); - $ecommMinsyncDateFlag = $this->getConfigValueForScope( - Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG . "_$mailchimpStoreId", - 0, - 'stores' - ); - - //Save old value in new place. - if ($ecommMinsyncDateFlag === null && $this->validateDate($oldEcommMinsyncDateFlag)) { - $configValue = array( - array( - Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG . "_$mailchimpStoreId", - $oldEcommMinsyncDateFlag - ) - ); - $this->saveMailchimpConfig($configValue, 0, 'default'); - } - - //Delete old entry if exists particularly in this scope. - if ($oldEcommMinsyncDateFlag !== null - && $this->getIfConfigExistsForScope( - Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG, - $scopeId, - $scope - ) - ) { - $config = $this->getConfig(); - $config->deleteConfig( - Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG, - $scope, - $scopeId - ); - $config->cleanCache(); - } - - return ($ecommMinsyncDateFlag !== null) ? $ecommMinsyncDateFlag : $oldEcommMinsyncDateFlag; - } - /** * Get if logs are enabled. * Logs can only be enabled in default scope. @@ -3051,6 +2992,7 @@ public function getIfConfigExistsForScope($configPath, $scopeId, $scope = 'store foreach ($collection as $config) { if ($config->getValue() !== null) { $configAssociatedToScope = true; + break; } } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index cff1d7168..b2ef4bd4b 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -243,16 +243,15 @@ public function handleSubscriberBatches() /** * Get results of batch operations sent to MailChimp. * - * @param $magentoStoreId - * @param bool $isEcommerceData + * @param $magentoStoreId + * @param bool $isEcommerceData * @throws Mage_Core_Exception */ public function _getResults( $magentoStoreId, $isEcommerceData = true, $status = Ebizmarts_MailChimp_Helper_Data::BATCH_PENDING - ) - { + ) { $helper = $this->getHelper(); $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); $collection = $this->getSyncBatchesModel()->getCollection() @@ -433,21 +432,13 @@ protected function _updateSyncingFlag( $orderAmount, $mailchimpStoreId, $magentoStoreId - ) - { + ) { $helper = $this->getHelper(); $dateHelper = $this->getDateHelper(); $itemAmount = ($customerAmount + $productAmount + $orderAmount); $syncingFlag = $helper->getMCIsSyncing($mailchimpStoreId, $magentoStoreId); - if ($this->shouldFlagAsSyncing( - $magentoStoreId, - $syncingFlag, - $itemAmount, - $helper, - $mailchimpStoreId - ) - ) { + if ($this->shouldFlagAsSyncing($syncingFlag, $itemAmount, $helper)) { //Set is syncing per scope in 1 until sync finishes. $configValue = array( array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", 1) @@ -942,16 +933,16 @@ public function replaceAllOrders($initialTime, $magentoStoreId) } /** - * @param $itemId - * @param $itemType - * @param $mailchimpStoreId - * @param null $syncDelta - * @param null $syncError - * @param int $syncModified - * @param null $syncDeleted - * @param null $token - * @param null $syncedFlag - * @param bool $saveOnlyIfexists + * @param $itemId + * @param $itemType + * @param $mailchimpStoreId + * @param null $syncDelta + * @param null $syncError + * @param int $syncModified + * @param null $syncDeleted + * @param null $token + * @param null $syncedFlag + * @param bool $saveOnlyIfExists */ protected function saveSyncData( $itemId, @@ -963,9 +954,8 @@ protected function saveSyncData( $syncDeleted = null, $token = null, $syncedFlag = null, - $saveOnlyIfexists = false - ) - { + $saveOnlyIfExists = false + ) { $helper = $this->getHelper(); if ($itemType == Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER) { $helper->updateSubscriberSyndData($itemId, $syncDelta, $syncError, 0, null); @@ -980,7 +970,7 @@ protected function saveSyncData( $syncDeleted, $token, $syncedFlag, - $saveOnlyIfexists, + $saveOnlyIfExists, null, false ); @@ -1121,19 +1111,14 @@ protected function setItemAsModified($helper, $mailchimpStoreId, $id, $type) } /** - * @param $magentoStoreId * @param $syncingFlag * @param $itemAmount * @param $helper - * @param $mailchimpStoreId * @return bool */ - protected function shouldFlagAsSyncing($magentoStoreId, $syncingFlag, $itemAmount, $helper, $mailchimpStoreId) + protected function shouldFlagAsSyncing($syncingFlag, $itemAmount, $helper) { - return $syncingFlag === null - && $itemAmount !== 0 - || $helper->validateDate($syncingFlag) - && $syncingFlag < $helper->getEcommMinSyncDateFlag($mailchimpStoreId, $magentoStoreId); + return $syncingFlag === null && $itemAmount !== 0 || $helper->validateDate($syncingFlag); } /** diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 0a1fbf4bb..04e2f4b87 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -550,7 +550,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $items = $order->getAllVisibleItems(); $helper = $this->getMailChimpHelper(); $dateHelper = $this->getMailChimpDateHelper(); - $syncDateFlag = $helper->getEcommMinSyncDateFlag($mailchimpStoreId, $magentoStoreId); + foreach ($items as $item) { $itemProductId = $item->getProductId(); $product = $this->loadProductById($itemProductId); @@ -560,6 +560,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId ); + if ($productId != $itemProductId || $this->isBundleProduct($product) || $this->isGroupedProduct($product) @@ -580,10 +581,10 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) } $syncModified = $productSyncData->getMailchimpSyncModified(); - $syncDelta = $productSyncData->getMailchimpSyncDelta(); + $productSyncDelta = $productSyncData->getMailchimpSyncDelta(); $isProductEnabled = $this->isProductEnabled($productId, $magentoStoreId); - if ($syncModified && $syncDelta > $syncDateFlag && $isProductEnabled) { + if ($syncModified && $isProductEnabled) { $buildUpdateOperations = $this->_buildUpdateProductRequest( $product, $batchId, @@ -599,7 +600,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) ); $this->_updateSyncData($productId, $mailchimpStoreId); } - } elseif (!$syncDelta || $syncDelta < $syncDateFlag || !$isProductEnabled) { + } elseif (!$productSyncDelta || !$isProductEnabled) { $bodyData = $this->_buildNewProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); if ($bodyData !== false) { @@ -618,15 +619,15 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) /** * update product sync data * - * @param $productId - * @param $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncDeleted - * @param int|null $syncedFlag - * @param bool $saveOnlyIfexists - * @param bool $allowBatchRemoval + * @param $productId + * @param $mailchimpStoreId + * @param int|null $syncDelta + * @param int|null $syncError + * @param int|null $syncModified + * @param int|null $syncDeleted + * @param int|null $syncedFlag + * @param bool $saveOnlyIfexists + * @param bool $allowBatchRemoval */ protected function _updateSyncData( $productId, diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index 9d8aec2a3..b14421b75 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -102,25 +102,25 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) // limit the collection $newPromoCodes->getSelect()->limit($this->getBatchLimitFromConfig()); $counter = 0; + foreach ($newPromoCodes as $promoCode) { $codeId = $promoCode->getCouponId(); $ruleId = $promoCode->getRuleId(); + try { $promoRuleSyncData = $this->getMailChimpHelper()->getEcommerceSyncDataItem( $ruleId, Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE, $mailchimpStoreId ); - if (!$promoRuleSyncData->getId() - || $promoRuleSyncData->getMailchimpSyncDelta() < $helper->getEcommMinSyncDateFlag( - $mailchimpStoreId, $magentoStoreId - ) - ) { + + if (!$promoRuleSyncData->getId()) { $promoRuleMailchimpData = $this->getApiPromoRules()->getNewPromoRule( $ruleId, $mailchimpStoreId, $magentoStoreId ); + if (!empty($promoRuleMailchimpData)) { $batchArray[$counter] = $promoRuleMailchimpData; $counter++; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Config.php b/app/code/community/Ebizmarts/MailChimp/Model/Config.php index d5081bb98..d045a8d31 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Config.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Config.php @@ -21,7 +21,6 @@ class Ebizmarts_MailChimp_Model_Config const GENERAL_CHECKOUT_SUBSCRIBE = 'mailchimp/general/checkout_subscribe'; const GENERAL_MCSTOREID = 'mailchimp/general/storeid'; const GENERAL_MCISSYNCING = 'mailchimp/general/is_syicing'; - const GENERAL_ECOMMMINSYNCDATEFLAG = 'mailchimp/general/mcminsyncdateflag'; const GENERAL_SUBMINSYNCDATEFLAG = 'mailchimp/general/subminsyncdateflag'; const GENERAL_TWO_WAY_SYNC = 'mailchimp/general/webhook_active'; const GENERAL_UNSUBSCRIBE = 'mailchimp/general/webhook_delete'; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php index d1b1d215a..183b91e8d 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php @@ -26,21 +26,12 @@ protected function _afterSave() : null; $oldMailchimpStoreId = $helper->getMCStoreId($scopeId, $scope); $isSyncing = $helper->getMCIsSyncing($newMailchimpStoreId, $scopeId, $scope); - $ecommMinSyncDate = $helper->getEcommMinSyncDateFlag($newMailchimpStoreId, $scopeId, $scope); $helper->cancelAllPendingBatches($oldMailchimpStoreId); $helper->restoreAllCanceledBatches($newMailchimpStoreId); + if ($this->isValueChanged() && $this->getValue()) { - $helper->deletePreviousConfiguredMCStoreLocalData($oldMailchimpStoreId, $scopeId, $scope); - if ($ecommMinSyncDate === null) { - $configValues = array( - array( - Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG."_$newMailchimpStoreId", - $dateHelper->formatDate(null, "Y-m-d H:i:s") - ) - ); - $helper->saveMailchimpConfig($configValues, 0, 'default'); - } + $helper->deletePreviousConfiguredMCStoreLocalData($oldMailchimpStoreId, $scopeId, $scope); if ($isSyncing === null) { $configValues = array( diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php index 4395c33a3..aff6d5483 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php @@ -348,7 +348,6 @@ public function testSendEcommerceBatch($data) $mailchimpStoreId = 'ef3bf57fb9bd695a02b7f7c7fb0d2db5'; $magentoStoreId = 1; $syncingFlag = '2018-02-01 00:00:00'; - $ecomSyncDateFlag = '2018-02-02 00:00:00'; $configValue = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", 1)); $sendPromo = $data['sendPromo']; $batchArray = array(); @@ -387,7 +386,7 @@ public function testSendEcommerceBatch($data) $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() ->setMethods( - array('getMCStoreId', 'getEcommMinSyncDateFlag', 'isEcomSyncDataEnabled', + array('getMCStoreId', 'isEcomSyncDataEnabled', 'getApi', 'getMCIsSyncing', 'logRequest', 'validateDate', 'saveMailchimpConfig', 'getPromoConfig') ) @@ -536,17 +535,12 @@ public function testSendEcommerceBatch($data) ->with($mailchimpStoreId, $magentoStoreId) ->willReturn($syncingFlag); $helperMock->expects($this->once())->method('validateDate')->with($syncingFlag)->willReturn(true); - $helperMock - ->expects($this->once()) - ->method('getEcommMinSyncDateFlag') - ->with($mailchimpStoreId, $magentoStoreId) - ->willReturn($ecomSyncDateFlag); + $helperMock ->expects($this->once()) ->method('saveMailchimpConfig') ->with($configValue, $magentoStoreId, 'stores'); - $apiBatchesMock->_sendEcommerceBatch($magentoStoreId); } @@ -556,51 +550,54 @@ public function sendEcommerceBatchDataProvider() $batchArray = array(); return array( - array(array('sendPromo' => 0, - 'customerArray' => $batchArray['operations'] = $this->getCustomerArray(), - 'productsArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getProductArray() - ), - 'cartsArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getCartArray() - ), - 'ordersArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getOrderArray() - ), - 'deletedProductsArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getDeletedProductArray() - ), - 'batchArray' => $batchArray['operations'])), - array(array('sendPromo' => 1, - 'customerArray' => $batchArray['operations'] = $this->getCustomerArray(), - 'productsArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getProductArray() - ), - 'cartsArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], $this->getCartArray() - ), - 'ordersArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getOrderArray() - ), - 'promoRulesArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getPromoRuleArray() - ), - 'promoCodesArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getPromoCodeArray() - ), - 'deletedProductsArray' => $batchArray['operations'] = array_merge( - $batchArray['operations'], - $this->getDeletedProductArray() - ), - 'batchArray' => $batchArray['operations'])), + array( + array( + 'sendPromo' => 0, + 'customerArray' => $batchArray['operations'] = $this->getCustomerArray(), + 'productsArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getProductArray() + ), + 'cartsArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getCartArray() + ), + 'ordersArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getOrderArray() + ), + 'deletedProductsArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getDeletedProductArray() + ), + 'batchArray' => $batchArray['operations'])), + array( + array('sendPromo' => 1, + 'customerArray' => $batchArray['operations'] = $this->getCustomerArray(), + 'productsArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getProductArray() + ), + 'cartsArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], $this->getCartArray() + ), + 'ordersArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getOrderArray() + ), + 'promoRulesArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getPromoRuleArray() + ), + 'promoCodesArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getPromoCodeArray() + ), + 'deletedProductsArray' => $batchArray['operations'] = array_merge( + $batchArray['operations'], + $this->getDeletedProductArray() + ), + 'batchArray' => $batchArray['operations'])), ); } @@ -618,7 +615,7 @@ public function testGetResults() ->disableOriginalConstructor() ->setMethods( array('getHelper', 'getSyncBatchesModel', 'getMagentoBaseDir', 'getBatchResponse', - 'processEachResponseFile', 'batchDirExists', 'removeBatchDir') + 'processEachResponseFile', 'batchDirExists', 'removeBatchDir') ) ->getMock(); @@ -822,8 +819,7 @@ public function testHandleSyncingValue() $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() ->setMethods( - array('isEcomSyncDataEnabled', 'getApi', - 'saveMailchimpConfig', 'getDateSyncFinishByMailChimpStoreId') + array('isEcomSyncDataEnabled', 'getApi', 'saveMailchimpConfig', 'getDateSyncFinishByMailChimpStoreId') ) ->getMock(); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index 55f2d74c9..37618aca2 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -380,10 +380,8 @@ public function testSendModifiedProduct() $oldProductId = 2; $newProductId = 3; $batchId = 'storeid-1_PRO_2018-03-15-19-16-36-84319400_'; - $ecomSyncDateFlag = '2018-03-14 15:03:36'; $itemOneSyncDelta = '2018-03-14 15:03:37'; $itemTwoSyncDelta = '2018-03-14 15:03:35'; - $isProductEnabled = false; $productsApiMock = $this->_productsApiMock ->setMethods( @@ -421,7 +419,7 @@ public function testSendModifiedProduct() $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() - ->setMethods(array('getEcommerceSyncDataItem', 'getEcommMinSyncDateFlag')) + ->setMethods(array('getEcommerceSyncDataItem')) ->getMock(); $dateHelperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Date::class) @@ -472,14 +470,9 @@ public function testSendModifiedProduct() array($newProductId) )->willReturnOnConsecutiveCalls( true, - true + false ); - $helperMock - ->expects($this->once()) - ->method('getEcommMinSyncDateFlag') - ->with($mailchimpStoreId, $magentoStoreId) - ->willReturn($ecomSyncDateFlag); $helperMock->expects($this->exactly(3))->method('getEcommerceSyncDataItem')->withConsecutive( array($groupedProductId, Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId), array($oldProductId, Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId), @@ -532,13 +525,13 @@ public function testSendModifiedProduct() ->with($productMock, $batchId, $mailchimpStoreId, $magentoStoreId) ->willReturn(array()); - $productsApiMock->expects($this->exactly(3))->method('_updateSyncData')->withConsecutive( + $productsApiMock->expects($this->exactly(2))->method('_updateSyncData')->withConsecutive( array($groupedProductId, $mailchimpStoreId), array($oldProductId, $mailchimpStoreId), array($newProductId, $mailchimpStoreId) ); - $return = $productsApiMock->sendModifiedProduct($orderMock, $mailchimpStoreId, $magentoStoreId); + return $productsApiMock->sendModifiedProduct($orderMock, $mailchimpStoreId, $magentoStoreId); } /** From 5c9fb8233394a48aa207ca6723a0e50827c15109 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Tue, 17 Sep 2019 13:25:05 -0300 Subject: [PATCH 038/160] Promo Codes and Rules now using new methods and new method to add DeletedRelatedId added --- .../MailChimp/Model/Api/PromoCodes.php | 50 ++++++------------- .../MailChimp/Model/Api/PromoRules.php | 44 ++++------------ .../MailChimp/Model/Api/SyncItem.php | 17 +++++++ 3 files changed, 41 insertions(+), 70 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index f29fbb6a1..db47ad9af 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -143,42 +143,30 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) $batchArray[$counter]['operation_id'] = $this->_batchId . '_' . $codeId; $batchArray[$counter]['body'] = $promoCodeJson; - $this->_updateSyncData( - $codeId, - $mailchimpStoreId, - null, - null, - 0, - null, - null, - $promoCode->getToken() - ); + $this->addSyncDataToken($codeId, $mailchimpStoreId, $promoCode->getToken()); $counter++; } else { $error = $helper->__('Something went wrong when retrieving the information.'); - $this->_updateSyncData( + $this->addSyncDataError( $codeId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), - $error + $error, + null, + false, + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); continue; } } else { $jsonErrorMsg = json_last_error_msg(); $helper->logError("Promo code" . $codeId . " json encode failed (".$jsonErrorMsg.")"); - $this->_updateSyncData( + $this->addSyncDataError( $codeId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $jsonErrorMsg, - 0, - null, - null, null, false, - -1, - null + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); } } catch (Exception $e) { @@ -364,19 +352,7 @@ protected function _setDeleted($codeId, $promoRuleId) ); foreach ($promoCodes as $promoCode) { $mailchimpStoreId = $promoCode->getMailchimpStoreId(); - $this->_updateSyncData( - $codeId, - $mailchimpStoreId, - null, - null, - 0, - 1, - null, - null, - true, - false, - $promoRuleId - ); + $this->addDeletedRelatedId($codeId, $mailchimpStoreId, $promoRuleId); } } @@ -465,11 +441,13 @@ protected function setCodeWithParentError($mailchimpStoreId, $ruleId, $codeId) $error = Mage::helper('mailchimp')->__( 'Parent rule with id ' . $ruleId . ' has not been correctly sent.' ); - $this->_updateSyncData( + $this->addSyncDataError( $codeId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), - $error + $error, + null, + false, + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index 5fa2c5269..ed8f4f9f4 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -98,35 +98,33 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) . $dateHelper->getDateMicrotime() . '_' . $ruleId; $promoData['body'] = $promoRuleJson; //update promo rule delta - $this->_updateSyncData($ruleId, $mailchimpStoreId); + $this->addSyncData($ruleId, $mailchimpStoreId); } else { $error = $promoRule->getMailchimpSyncError(); if (!$error) { $error = $helper->__('Something went wrong when retrieving the information.'); } - $this->_updateSyncData( + $this->addSyncDataError( $ruleId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), - $error + $error, + null, + false, + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); } } else { $jsonErrorMsg = json_last_error_msg(); $helper->logError("Promo rule " . $ruleId . " json encode failed (".$jsonErrorMsg.")"); - $this->_updateSyncData( + $this->addSyncDataError( $ruleId, $mailchimpStoreId, - $dateHelper->formatDate(null, "Y-m-d H:i:s"), $jsonErrorMsg, - 0, - null, - null, null, false, - -1 + $dateHelper->formatDate(null, "Y-m-d H:i:s") ); } } catch (Exception $e) { @@ -335,18 +333,7 @@ protected function _setModified($ruleId) ); foreach ($promoRules as $promoRule) { $mailchimpStoreId = $promoRule->getMailchimpStoreId(); - $this->_updateSyncData( - $ruleId, - $mailchimpStoreId, - null, - null, - 1, - null, - null, - null, - true, - false - ); + $this->markSyncDataAsModified($ruleId, $mailchimpStoreId); } } @@ -370,18 +357,7 @@ protected function _setDeleted($ruleId) ); foreach ($promoRules as $promoRule) { $mailchimpStoreId = $promoRule->getMailchimpStoreId(); - $this->_updateSyncData( - $ruleId, - $mailchimpStoreId, - null, - null, - 0, - 1, - null, - null, - true, - false - ); + $this->markSyncDataAsDeleted($ruleId, $mailchimpStoreId); } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php index 1ba4917fe..e21e4787a 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/SyncItem.php @@ -74,6 +74,23 @@ protected function _updateSyncData( } } + protected function addDeletedRelatedId($id, $mailchimpStoreId, $relatedId) + { + $this->_updateSyncData( + $id, + $mailchimpStoreId, + null, + null, + 0, + 1, + null, + null, + true, + false, + $relatedId + ); + } + protected function addSyncDataError( $id, $mailchimpStoreId, From bc36bad493389a8a5e6cdf1393609b84fce4b4de Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 17 Sep 2019 16:39:42 -0300 Subject: [PATCH 039/160] Matching urls like: {base_url}/?mc_cid={campaign_id} {base_url}?mc_cid={campaign_id} {base_url}?utm_source=mailchimp&mc_cid={campaign_id} --- js/ebizmarts/mailchimp/campaignCatcher.js | 92 ++++++++++++++++------- 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/js/ebizmarts/mailchimp/campaignCatcher.js b/js/ebizmarts/mailchimp/campaignCatcher.js index 2f5f3a4e9..507630a97 100755 --- a/js/ebizmarts/mailchimp/campaignCatcher.js +++ b/js/ebizmarts/mailchimp/campaignCatcher.js @@ -1,49 +1,87 @@ function getCampaign() { - var urlparams = location.search.substr(1).split('&'); - var params = new Array(); - var mc_cid = null; - var campaign = null; - var isMailchimp = false; - var mc_eid = null; - for (var i = 0; i < urlparams.length; i++) { - var param = urlparams[i].split('='); - var key = param[0]; - var val = param[1]; - if (key && val) { - params[key] = val; + let urlparams = location.search.substr(1).split('&'); + let params = []; + let mc_cid = null; + let campaign = null; + let isMailchimp = false; + let mc_eid = null; + let paramsLength = urlparams.length; + + if (paramsLength > 0) { + for (let i = 0; i < paramsLength; i++) { + let param = urlparams[i].split('='); + let key = param[0]; + let val = param[1]; + + if (key && val) { + params[key] = val; + } else { + continue; + } + + if (key === 'utm_source') { + let reg = /^mailchimp$/; + + if (reg.exec(val)) { + isMailchimp = true; + } + } + + if (key === 'mc_cid') { + mc_cid = val; + } + + if (key === 'utm_campaign') { + let campaignArray = val.split("-"); + let campaignValue = campaignArray[0]; + + if (campaignValue.length === 10) { + campaign = campaignValue; + } + } + + if (key === 'mc_eid') { + mc_eid = val; + } } - if (key == 'utm_source') { - var reg = /^mailchimp$/; - if (reg.exec(val)) { + } else { + urlparams = location.pathname.split('/'); + let utmIndex = $.inArray('utm_source', urlparams); + let mccidIndex = $.inArray('mc_cid', urlparams); + + if (utmIndex !== -1) { + let value = urlparams[utmIndex + 1]; + let reg = /^mailchimp$/; + + if (reg.exec(value)) { isMailchimp = true; } - } - if (key == 'mc_cid') { - mc_cid = val; - } - if (key == 'utm_campaign') { - var campaignArray = val.split("-"); - var campaignValue = campaignArray[0]; - if (campaignValue.length == 10) { - campaign = campaignValue; + } else { + if (mccidIndex !== -1) { + mc_cid = urlparams[mccidIndex + 1]; } } - if (key == 'mc_eid') { - mc_eid = val; + if (mc_cid && !isMailchimp) { + } } + if (mc_cid) { + Mage.Cookies.clear('mailchimp_campaign_id'); Mage.Cookies.set('mailchimp_campaign_id', mc_cid); } else { if (campaign) { + Mage.Cookies.clear('mailchimp_campaign_id'); Mage.Cookies.set('mailchimp_campaign_id', campaign); } } - var landingPage = Mage.Cookies.get('mailchimp_landing_page'); + let landingPage = Mage.Cookies.get('mailchimp_landing_page'); + if (!landingPage) { Mage.Cookies.set('mailchimp_landing_page', location); } + if (mc_eid) { Mage.Cookies.set('mailchimp_email_id', mc_eid); } From 9c0e3d0a30ced3e0a2b1eb8fd9f892d2c86d0a63 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Wed, 18 Sep 2019 10:40:56 -0300 Subject: [PATCH 040/160] Reverting changes in PHPUnit autoload --- dev/tests/mailchimp/autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/mailchimp/autoload.php b/dev/tests/mailchimp/autoload.php index 0e477642e..23bfc89a5 100644 --- a/dev/tests/mailchimp/autoload.php +++ b/dev/tests/mailchimp/autoload.php @@ -2,7 +2,7 @@ $magentoRoot = getenv('MAGENTO_ROOT'); if (empty($magentoRoot)) { - $magentoRoot = realpath(dirname(dirname(dirname(dirname(dirname(__DIR__)))))); + $magentoRoot = realpath(dirname(dirname(dirname(__DIR__)))); } define('MAGENTO_ROOT', $magentoRoot); From eac9e34da724b85341495d57b40d66f5b33a1e1f Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Wed, 18 Sep 2019 16:32:53 -0300 Subject: [PATCH 041/160] Checking that is_syncing flag status. If not syncing, then the all the carts are sent. --- .../Ebizmarts/MailChimp/Model/Api/Batches.php | 35 ++++++++++--------- .../MailChimp/Model/Api/Customers.php | 3 +- .../MailChimp/Model/Api/BatchesTest.php | 18 +++++----- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index cff1d7168..62ed7095f 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -251,8 +251,7 @@ public function _getResults( $magentoStoreId, $isEcommerceData = true, $status = Ebizmarts_MailChimp_Helper_Data::BATCH_PENDING - ) - { + ) { $helper = $this->getHelper(); $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); $collection = $this->getSyncBatchesModel()->getCollection() @@ -311,6 +310,7 @@ public function _sendEcommerceBatch($magentoStoreId) $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); try { $this->deleteUnsentItems(); + if ($helper->isEcomSyncDataEnabled($magentoStoreId)) { $helper->resetCountersSentPerBatch(); $batchArray = array(); @@ -326,17 +326,22 @@ public function _sendEcommerceBatch($magentoStoreId) $productsArray = $apiProducts->createBatchJson($mailchimpStoreId, $magentoStoreId); $productAmount = count($productsArray); $batchArray['operations'] = array_merge($batchArray['operations'], $productsArray); + //cart operations - $helper->logBatchStatus('Generate Carts Payload'); - $apiCarts = $this->getApiCarts(); - $cartsArray = $apiCarts->createBatchJson($mailchimpStoreId, $magentoStoreId); - $batchArray['operations'] = array_merge($batchArray['operations'], $cartsArray); - //order operations - $helper->logBatchStatus('Generate Orders Payload'); - $apiOrders = $this->getApiOrders(); - $ordersArray = $apiOrders->createBatchJson($mailchimpStoreId, $magentoStoreId); - $orderAmount = count($ordersArray); - $batchArray['operations'] = array_merge($batchArray['operations'], $ordersArray); + if ($helper->getMCIsSyncing($mailchimpStoreId)) { + $helper->logBatchStatus('No Carts will be synced until the store is completely synced'); + } else { + $helper->logBatchStatus('Generate Carts Payload'); + $apiCarts = $this->getApiCarts(); + $cartsArray = $apiCarts->createBatchJson($mailchimpStoreId, $magentoStoreId); + $batchArray['operations'] = array_merge($batchArray['operations'], $cartsArray);//order operations + $helper->logBatchStatus('Generate Orders Payload'); + $apiOrders = $this->getApiOrders(); + $ordersArray = $apiOrders->createBatchJson($mailchimpStoreId, $magentoStoreId); + $orderAmount = count($ordersArray); + $batchArray['operations'] = array_merge($batchArray['operations'], $ordersArray); + } + if ($helper->getPromoConfig($magentoStoreId) == self::SEND_PROMO_ENABLED) { //promo rule operations $helper->logBatchStatus('Generate Promo Rules Payload'); @@ -433,8 +438,7 @@ protected function _updateSyncingFlag( $orderAmount, $mailchimpStoreId, $magentoStoreId - ) - { + ) { $helper = $this->getHelper(); $dateHelper = $this->getDateHelper(); $itemAmount = ($customerAmount + $productAmount + $orderAmount); @@ -964,8 +968,7 @@ protected function saveSyncData( $token = null, $syncedFlag = null, $saveOnlyIfexists = false - ) - { + ) { $helper = $this->getHelper(); if ($itemType == Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER) { $helper->updateSubscriberSyndData($itemId, $syncDelta, $syncError, 0, null); diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index dc6bb10cf..e3a5da85c 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -749,8 +749,7 @@ protected function sendMailchimpTags( $magentoStoreId, $subscriber, $customer, - $listId, - $counter + $listId ); if ($batchData !== null) { diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php index 4395c33a3..ac8e31dca 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php @@ -353,6 +353,7 @@ public function testSendEcommerceBatch($data) $sendPromo = $data['sendPromo']; $batchArray = array(); $batchArray['operations'] = $data['batchArray']; + $isSyncyng = null; $customerArray = $this->getCustomerArray(); @@ -380,7 +381,7 @@ public function testSendEcommerceBatch($data) array('getHelper', 'getApiCustomers', 'getApiProducts', 'getApiCarts', 'getApiOrders', 'deleteUnsentItems', 'markItemsAsSent', 'getApiPromoRules', 'getApiPromoCodes', - 'getSyncBatchesModel', '_showResumeEcommerce') + 'getSyncBatchesModel') ) ->getMock(); @@ -440,7 +441,7 @@ public function testSendEcommerceBatch($data) ->setMethods(array('setStoreId', 'setBatchId', 'setStatus', 'save')) ->getMock(); - $apiBatchesMock->expects($this->exactly(3))->method('getHelper')->willReturn($helperMock); + $apiBatchesMock->expects($this->exactly(4))->method('getHelper')->willReturn($helperMock); $helperMock ->expects($this->once()) ->method('getMCStoreId') @@ -449,8 +450,6 @@ public function testSendEcommerceBatch($data) $apiBatchesMock->expects($this->once())->method('deleteUnsentItems'); - $apiBatchesMock->expects($this->once())->method('_showResumeEcommerce')->with($batchResponse['id']); - $helperMock ->expects($this->once()) ->method('isEcomSyncDataEnabled') @@ -531,10 +530,11 @@ public function testSendEcommerceBatch($data) ->with($batchResponse['id'], $mailchimpStoreId); $helperMock - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getMCIsSyncing') - ->with($mailchimpStoreId, $magentoStoreId) + ->with($mailchimpStoreId) ->willReturn($syncingFlag); + $helperMock->expects($this->once())->method('validateDate')->with($syncingFlag)->willReturn(true); $helperMock ->expects($this->once()) @@ -556,7 +556,8 @@ public function sendEcommerceBatchDataProvider() $batchArray = array(); return array( - array(array('sendPromo' => 0, + array( + array('sendPromo' => 0, 'customerArray' => $batchArray['operations'] = $this->getCustomerArray(), 'productsArray' => $batchArray['operations'] = array_merge( $batchArray['operations'], @@ -575,7 +576,8 @@ public function sendEcommerceBatchDataProvider() $this->getDeletedProductArray() ), 'batchArray' => $batchArray['operations'])), - array(array('sendPromo' => 1, + array( + array('sendPromo' => 1, 'customerArray' => $batchArray['operations'] = $this->getCustomerArray(), 'productsArray' => $batchArray['operations'] = array_merge( $batchArray['operations'], From 7202d50edbef5486eccc3d471e78075fbf0f86d2 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Wed, 18 Sep 2019 17:09:36 -0300 Subject: [PATCH 042/160] Fixing BatchesTest.php --- .../MailChimp/Model/Api/BatchesTest.php | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php index ac8e31dca..7e495ad04 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php @@ -347,13 +347,10 @@ public function testSendEcommerceBatch($data) { $mailchimpStoreId = 'ef3bf57fb9bd695a02b7f7c7fb0d2db5'; $magentoStoreId = 1; - $syncingFlag = '2018-02-01 00:00:00'; - $ecomSyncDateFlag = '2018-02-02 00:00:00'; - $configValue = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", 1)); + $syncingFlag = null; $sendPromo = $data['sendPromo']; $batchArray = array(); $batchArray['operations'] = $data['batchArray']; - $isSyncyng = null; $customerArray = $this->getCustomerArray(); @@ -388,9 +385,8 @@ public function testSendEcommerceBatch($data) $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() ->setMethods( - array('getMCStoreId', 'getEcommMinSyncDateFlag', 'isEcomSyncDataEnabled', - 'getApi', 'getMCIsSyncing', 'logRequest', 'validateDate', - 'saveMailchimpConfig', 'getPromoConfig') + array('getMCStoreId', 'isEcomSyncDataEnabled', + 'getApi', 'getMCIsSyncing', 'logRequest', 'validateDate', 'getPromoConfig') ) ->getMock(); @@ -535,18 +531,6 @@ public function testSendEcommerceBatch($data) ->with($mailchimpStoreId) ->willReturn($syncingFlag); - $helperMock->expects($this->once())->method('validateDate')->with($syncingFlag)->willReturn(true); - $helperMock - ->expects($this->once()) - ->method('getEcommMinSyncDateFlag') - ->with($mailchimpStoreId, $magentoStoreId) - ->willReturn($ecomSyncDateFlag); - $helperMock - ->expects($this->once()) - ->method('saveMailchimpConfig') - ->with($configValue, $magentoStoreId, 'stores'); - - $apiBatchesMock->_sendEcommerceBatch($magentoStoreId); } From 02d3e137c762c54a8b2bec087d8a220b2c087f7a Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Wed, 18 Sep 2019 17:56:50 -0300 Subject: [PATCH 043/160] Fixing BatchesTest.php --- .../MailChimp/Model/Api/BatchesTest.php | 43 ++----------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php index 7e495ad04..070a764f0 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php @@ -376,17 +376,14 @@ public function testSendEcommerceBatch($data) ->disableOriginalConstructor() ->setMethods( array('getHelper', 'getApiCustomers', 'getApiProducts', - 'getApiCarts', 'getApiOrders', 'deleteUnsentItems', - 'markItemsAsSent', 'getApiPromoRules', 'getApiPromoCodes', - 'getSyncBatchesModel') + 'getApiCarts', 'getApiOrders', 'deleteUnsentItems', 'getApiPromoRules', 'getApiPromoCodes') ) ->getMock(); $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() ->setMethods( - array('getMCStoreId', 'isEcomSyncDataEnabled', - 'getApi', 'getMCIsSyncing', 'logRequest', 'validateDate', 'getPromoConfig') + array('getMCStoreId', 'isEcomSyncDataEnabled', 'getMCIsSyncing', 'getPromoConfig') ) ->getMock(); @@ -422,22 +419,7 @@ public function testSendEcommerceBatch($data) ->setMethods(array('createBatchJson')) ->getMock(); - $apiMock = $this->getMockBuilder(Ebizmarts_MailChimp::class) - ->disableOriginalConstructor() - ->setMethods(array('getBatchOperation')) - ->getMock(); - - $apiBatchOperationMock = $this->getMockBuilder(MailChimp_BatchOperations::class) - ->disableOriginalConstructor() - ->setMethods(array('add')) - ->getMock(); - - $syncBatchesMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Synchbatches::class) - ->disableOriginalConstructor() - ->setMethods(array('setStoreId', 'setBatchId', 'setStatus', 'save')) - ->getMock(); - - $apiBatchesMock->expects($this->exactly(4))->method('getHelper')->willReturn($helperMock); + $apiBatchesMock->expects($this->exactly(2))->method('getHelper')->willReturn($helperMock); $helperMock ->expects($this->once()) ->method('getMCStoreId') @@ -506,27 +488,10 @@ public function testSendEcommerceBatch($data) ->with($mailchimpStoreId, $magentoStoreId) ->willReturn($promoCodesArray); - $helperMock->expects($this->once())->method('getApi')->with($magentoStoreId)->willReturn($apiMock); $helperMock->expects($this->once())->method('getPromoConfig')->with($magentoStoreId)->willReturn($sendPromo); - $apiMock->expects($this->once())->method('getBatchOperation')->willReturn($apiBatchOperationMock); - $apiBatchOperationMock->expects($this->once())->method('add')->with($batchJson)->willReturn($batchResponse); - - $helperMock->expects($this->once())->method('logRequest')->with($batchJson, $batchResponse['id']); - - $apiBatchesMock->expects($this->once())->method('getSyncBatchesModel')->willReturn($syncBatchesMock); - $syncBatchesMock->expects($this->once())->method('setStoreId')->with($mailchimpStoreId)->willReturnSelf(); - $syncBatchesMock->expects($this->once())->method('setBatchId')->with($batchResponse['id'])->willReturnSelf(); - $syncBatchesMock->expects($this->once())->method('setStatus')->with($batchResponse['status'])->willReturnSelf(); - $syncBatchesMock->expects($this->once())->method('save'); - - $apiBatchesMock - ->expects($this->once()) - ->method('markItemsAsSent') - ->with($batchResponse['id'], $mailchimpStoreId); - $helperMock - ->expects($this->exactly(2)) + ->expects($this->exactly(1)) ->method('getMCIsSyncing') ->with($mailchimpStoreId) ->willReturn($syncingFlag); From 9b0d147fb4c13233634030d85a6024dc97a2915b Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Thu, 19 Sep 2019 11:06:21 -0300 Subject: [PATCH 044/160] Fixing BatchesTest.php: adding _updateSyncingFlag() and _processBatchOperations() to the tests. --- .../MailChimp/Model/Api/BatchesTest.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php index 070a764f0..5278a2b22 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php @@ -376,7 +376,8 @@ public function testSendEcommerceBatch($data) ->disableOriginalConstructor() ->setMethods( array('getHelper', 'getApiCustomers', 'getApiProducts', - 'getApiCarts', 'getApiOrders', 'deleteUnsentItems', 'getApiPromoRules', 'getApiPromoCodes') + 'getApiCarts', 'getApiOrders', 'deleteUnsentItems', 'getApiPromoRules', 'getApiPromoCodes', + '_processBatchOperations', '_updateSyncingFlag') ) ->getMock(); @@ -419,7 +420,7 @@ public function testSendEcommerceBatch($data) ->setMethods(array('createBatchJson')) ->getMock(); - $apiBatchesMock->expects($this->exactly(2))->method('getHelper')->willReturn($helperMock); + $apiBatchesMock->expects($this->exactly(1))->method('getHelper')->willReturn($helperMock); $helperMock ->expects($this->once()) ->method('getMCStoreId') @@ -462,6 +463,7 @@ public function testSendEcommerceBatch($data) ->expects($this->once()) ->method('getApiOrders') ->willReturn($apiOrdersMock); + $apiOrdersMock ->expects($this->once()) ->method('createBatchJson') @@ -496,6 +498,19 @@ public function testSendEcommerceBatch($data) ->with($mailchimpStoreId) ->willReturn($syncingFlag); + $apiBatchesMock + ->expects($this->once()) + ->method('_processBatchOperations') + ->with($batchArray, $mailchimpStoreId, $magentoStoreId); + + $apiBatchesMock + ->expects($this->once()) + ->method('_updateSyncingFlag') + ->with( + count($customerArray), count($productsArray), + count($ordersArray), $mailchimpStoreId, $magentoStoreId + ); + $apiBatchesMock->_sendEcommerceBatch($magentoStoreId); } From 012da9091b91d3ee435cf86840c9cffc3d202fc7 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Thu, 19 Sep 2019 13:40:10 -0300 Subject: [PATCH 045/160] Cleaning cookie for 'mailchimp_campaign_id' key if url GET is not about 'mailchimp'. --- js/ebizmarts/mailchimp/campaignCatcher.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/ebizmarts/mailchimp/campaignCatcher.js b/js/ebizmarts/mailchimp/campaignCatcher.js index 507630a97..1c91bcfd0 100755 --- a/js/ebizmarts/mailchimp/campaignCatcher.js +++ b/js/ebizmarts/mailchimp/campaignCatcher.js @@ -62,8 +62,9 @@ function getCampaign() mc_cid = urlparams[mccidIndex + 1]; } } - if (mc_cid && !isMailchimp) { + if (mc_cid && !isMailchimp) { + Mage.Cookies.clear('mailchimp_campaign_id'); } } From a2acbe119c475e92585431f8101e8c7df572ffe5 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 23 Sep 2019 14:51:23 -0300 Subject: [PATCH 046/160] Camel Case variables fix --- .../Ebizmarts/MailChimp/Helper/Data.php | 10 +++--- .../Ebizmarts/MailChimp/Model/Api/Batches.php | 33 +++++++++---------- .../Adminhtml/MailchimperrorsController.php | 8 ++--- .../MailchimperrorsControllerTest.php | 8 ++--- shell/getMailchimpResponse.php | 6 ++-- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 2ce316c87..9f3e95c01 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -48,7 +48,7 @@ class Ebizmarts_MailChimp_Helper_Data extends Mage_Core_Helper_Abstract * * @var array */ - public static $MAILCHIMP_LANGUAGES = array( + public static $LANGUAGES = array( 'en', // English 'ar', // Arabic 'af', // Afrikaans @@ -2654,9 +2654,9 @@ protected function _migrateFrom1164($initialTime) { $dateHelper = $this->getDateHelper(); if (!$dateHelper->timePassed($initialTime)) { - $write_connection = $this->getCoreResource()->getConnection('core_write'); + $writeConnection = $this->getCoreResource()->getConnection('core_write'); $resource = Mage::getResourceModel('mailchimp/ecommercesyncdata'); - $write_connection->update($resource->getMainTable(), array('batch_id' => '1'), "batch_id = 0"); + $writeConnection->update($resource->getMainTable(), array('batch_id' => '1'), "batch_id = 0"); $arrayMigrationConfigData = array('115' => false, '116' => false, '1164' => true); $this->handleDeleteMigrationConfigData($arrayMigrationConfigData); } @@ -4167,11 +4167,11 @@ protected function _langToMCLanguage($languageCode = '') { $mailchimpLanguage = ''; - if (in_array($languageCode, self::$MAILCHIMP_LANGUAGES)) { + if (in_array($languageCode, self::$LANGUAGES)) { $mailchimpLanguage = $languageCode; } else { $langIso = substr($languageCode, 0, 2); - if (in_array($langIso, self::$MAILCHIMP_LANGUAGES)) { + if (in_array($langIso, self::$LANGUAGES)) { $mailchimpLanguage = $langIso; } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index cff1d7168..28252f86d 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -251,8 +251,7 @@ public function _getResults( $magentoStoreId, $isEcommerceData = true, $status = Ebizmarts_MailChimp_Helper_Data::BATCH_PENDING - ) - { + ) { $helper = $this->getHelper(); $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); $collection = $this->getSyncBatchesModel()->getCollection() @@ -433,8 +432,7 @@ protected function _updateSyncingFlag( $orderAmount, $mailchimpStoreId, $magentoStoreId - ) - { + ) { $helper = $this->getHelper(); $dateHelper = $this->getDateHelper(); $itemAmount = ($customerAmount + $productAmount + $orderAmount); @@ -749,20 +747,20 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, $helper->resetCountersDataSentToMailchimp(); foreach ($files as $file) { - $items = json_decode(file_get_contents($file)); + $items = json_decode(file_get_contents($file), true); if ($items !== false) { foreach ($items as $item) { - $line = explode('_', $item->operation_id); + $line = explode('_', $item['operation_id']); $store = explode('-', $line[0]); $type = $line[1]; $id = $line[3]; - if ($item->status_code != 200) { + if ($item['status_code'] != 200) { $mailchimpErrors = Mage::getModel('mailchimp/mailchimperrors'); //parse error - $response = json_decode($item->response); + $response = json_decode($item['response'], true); $errorDetails = $this->_processFileErrors($response); if (strstr($errorDetails, 'already exists')) { @@ -785,9 +783,9 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, true ); - $mailchimpErrors->setType($response->type); - $mailchimpErrors->setTitle($response->title); - $mailchimpErrors->setStatus($item->status_code); + $mailchimpErrors->setType($response['type']); + $mailchimpErrors->setTitle($response['title']); + $mailchimpErrors->setStatus($item['status_code']); $mailchimpErrors->setErrors($errorDetails); $mailchimpErrors->setRegtype($type); $mailchimpErrors->setOriginalId($id); @@ -865,17 +863,17 @@ protected function _processFileErrors($response) { $errorDetails = ""; - if (!empty($response->errors)) { - foreach ($response->errors as $error) { - if (isset($error->field) && isset($error->message)) { + if (!empty($response['errors'])) { + foreach ($response['errors'] as $error) { + if (isset($error['field']) && isset($error['message'])) { $errorDetails .= $errorDetails != "" ? " / " : ""; - $errorDetails .= $error->field . " : " . $error->message; + $errorDetails .= $error['field'] . " : " . $error['message']; } } } if ($errorDetails == "") { - $errorDetails = $response->detail; + $errorDetails = $response['detail']; } return $errorDetails; @@ -964,8 +962,7 @@ protected function saveSyncData( $token = null, $syncedFlag = null, $saveOnlyIfexists = false - ) - { + ) { $helper = $this->getHelper(); if ($itemType == Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER) { $helper->updateSubscriberSyndData($itemId, $syncDelta, $syncError, 0, null); diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php index 74df0c9c4..a32b564fd 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php @@ -64,9 +64,9 @@ public function downloadresponseAction() $items = $this->getFileContent($file); foreach ($items as $item) { $fileContent[] = array( - 'status_code' => $item->status_code, - 'operation_id' => $item->operation_id, - 'response' => json_decode($item->response) + 'status_code' => $item['status_code'], + 'operation_id' => $item['operation_id'], + 'response' => json_decode($item['response']) ); } @@ -128,7 +128,7 @@ protected function getApiBatches() */ protected function getFileContent($file) { - return json_decode(file_get_contents($file)); + return json_decode(file_get_contents($file), true); } /** diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php index 7ad9abb5e..caec2508f 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php @@ -31,10 +31,10 @@ public function testDownloadresponseAction() $mailchimpStoreId = 'a1s2d3f4g5h6j7k8l9n0'; $files = array('/magento/var/mailchimp/1f103d0176/c9cf317023.json'); $file = '/magento/var/mailchimp/1f103d0176/c9cf317023.json'; - $item = new stdClass(); - $item->status_code = 400; - $item->operation_id = 'storeid-1_CUS_2018-02-06-18-46-06-86970300_64'; - $item->response = '{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",' + $item = array(); + $item['status_code'] = 400; + $item['operation_id'] = 'storeid-1_CUS_2018-02-06-18-46-06-86970300_64'; + $item['response'] = '{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",' . '"title":"Invalid Resource","status":400,"detail":"The resource submitted could not be validated. ' . 'For field-specific details, see the \'errors\' array.","instance":"","errors":' . '[{"field":"email_address","message":"This email address looks fake or invalid. ' diff --git a/shell/getMailchimpResponse.php b/shell/getMailchimpResponse.php index 99aa7e3d5..54f67e018 100644 --- a/shell/getMailchimpResponse.php +++ b/shell/getMailchimpResponse.php @@ -47,9 +47,9 @@ if ($err) { printf("cURL Error #:" . $err); } else { - $jsonResponse = json_decode($response); - if ($jsonResponse->status == 'finished') { - $fileUrl = $jsonResponse->response_body_url; + $jsonResponse = json_decode($response, true); + if ($jsonResponse['status'] == 'finished') { + $fileUrl = $jsonResponse['response_body_url']; // check if the file is not expired parse_str($fileUrl, $fileParams); try { From dddcec28f5e4f517e4b586cafc568d5d13f9b7db Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 23 Sep 2019 15:26:51 -0300 Subject: [PATCH 047/160] Eesolving conflicts # Conflicts: # app/code/community/Ebizmarts/MailChimp/Helper/Data.php # app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php --- .../Ebizmarts/MailChimp/Helper/Data.php | 145 +++++++++++------- 1 file changed, 90 insertions(+), 55 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 840367fea..0dde3c9d9 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -1379,40 +1379,54 @@ protected function getLastPromoCodeSent($scopeId, $scope) */ public function createMergeFields($scopeId, $scope) { + $success = 0; $listId = $this->getGeneralList($scopeId, $scope); $maps = $this->unserialize($this->getMapFields($scopeId, $scope)); $customFieldTypes = $this->unserialize($this->getCustomMergeFieldsSerialized($scopeId, $scope)); - try { - $api = $this->getApi($scopeId, $scope); - $mailchimpFields = array(); - + if (count($maps) > 30 ) { + $success = 2; + } else { try { - $mailchimpFields = $api->getLists()->getMergeFields()->getAll($listId, null, null, 50); - } catch (MailChimp_Error $e) { - $this->logError($e->getFriendlyMessage()); - } + $api = $this->getApi($scopeId, $scope); + $mailchimpFields = array(); + + try { + $mailchimpFields = $api->getLists()->getMergeFields()->getAll( + $listId, + null, + null, + 50 + ); + } catch (MailChimp_Error $e) { + $this->logError($e->getFriendlyMessage()); + } - if (!empty($mailchimpFields)) { - foreach ($maps as $map) { - $customAtt = $map['magento']; - $chimpTag = $map['mailchimp']; - $alreadyExists = false; + if (!empty($mailchimpFields)) { + foreach ($maps as $map) { + $customAtt = $map['magento']; + $chimpTag = $map['mailchimp']; + $alreadyExists = false; - foreach ($mailchimpFields['merge_fields'] as $mailchimpField) { - if ($mailchimpField['tag'] == $chimpTag || strtoupper($chimpTag) == 'EMAIL') { - $alreadyExists = true; + foreach ($mailchimpFields['merge_fields'] as $mailchimpField) { + if ($mailchimpField['tag'] == $chimpTag || strtoupper($chimpTag) == 'EMAIL') { + $alreadyExists = true; + } } - } - if (!$alreadyExists) { - $this->_createCustomFieldTypes($customFieldTypes, $api, $customAtt, $listId, $chimpTag); + if (!$alreadyExists) { + $this->_createCustomFieldTypes($customFieldTypes, $api, $customAtt, $listId, $chimpTag); + } } + + $success = 1; } + } catch (Ebizmarts_MailChimp_Helper_Data_ApiKeyException $e) { + $this->logError($e->getMessage()); } - } catch (Ebizmarts_MailChimp_Helper_Data_ApiKeyException $e) { - $this->logError($e->getMessage()); } + + return $success; } protected function _createCustomFieldTypes($customFieldTypes, $api, $customAtt, $listId, $chimpTag) @@ -1581,40 +1595,10 @@ public function saveEcommerceSyncData( $ecommerceSyncDataItem = $this->getEcommerceSyncDataItem($itemId, $itemType, $mailchimpStoreId); if (!$saveOnlyIfexists || $ecommerceSyncDataItem->getMailchimpSyncDelta()) { - if ($syncDelta) { - $ecommerceSyncDataItem->setData("mailchimp_sync_delta", $syncDelta); - } elseif ($allowBatchRemoval === true) { - $ecommerceSyncDataItem->setData("batch_id", null); - } - - if ($allowBatchRemoval === -1) { - $ecommerceSyncDataItem->setData("batch_id", '-1'); - } - - if ($syncError) { - $ecommerceSyncDataItem->setData("mailchimp_sync_error", $syncError); - } - - //Always set modified value to 0 when saving sync delta or errors. - $ecommerceSyncDataItem->setData("mailchimp_sync_modified", $syncModified); - if ($syncDeleted !== null) { - $ecommerceSyncDataItem->setData("mailchimp_sync_deleted", $syncDeleted); - if ($itemType == Ebizmarts_MailChimp_Model_Config::IS_PRODUCT && $syncError == '') { - $ecommerceSyncDataItem->setData("mailchimp_sync_error", $syncError); - } - } - - if ($token) { - $ecommerceSyncDataItem->setData("mailchimp_token", $token); - } - - if ($deletedRelatedId) { - $ecommerceSyncDataItem->setData("deleted_related_id", $deletedRelatedId); - } - - if ($syncedFlag !== null) { - $ecommerceSyncDataItem->setData("mailchimp_synced_flag", $syncedFlag); - } + $this->setEcommerceSyncDataItemValues( + $itemType, $syncDelta, $syncError, $syncModified, $syncDeleted, + $token, $syncedFlag, $deletedRelatedId, $allowBatchRemoval, $ecommerceSyncDataItem + ); $ecommerceSyncDataItem->save(); } @@ -3678,6 +3662,7 @@ protected function isMissingProductLowerThanId($itemId, $storeId) $productCollection = Mage::getResourceModel('catalog/product_collection') ->addStoreFilter($storeId) ->addFieldToFilter('entity_id', array('lteq' => $itemId)); + $productCollection->addFinalPrice(); $apiProducts->joinQtyAndBackorders($productCollection); $apiProducts->joinMailchimpSyncData($productCollection, $mailchimpStoreId); $productCollection->getSelect()->where("m4m.mailchimp_sync_delta IS null"); @@ -5088,6 +5073,56 @@ public function ping($storeId) return true; } + /** + * @param $itemType + * @param $syncDelta + * @param $syncError + * @param $syncModified + * @param $syncDeleted + * @param $token + * @param $syncedFlag + * @param $deletedRelatedId + * @param $allowBatchRemoval + * @param Varien_Object $ecommerceSyncDataItem + */ + protected function setEcommerceSyncDataItemValues($itemType, $syncDelta, $syncError, $syncModified, $syncDeleted, $token, $syncedFlag, $deletedRelatedId, $allowBatchRemoval, Varien_Object $ecommerceSyncDataItem) + { + if ($syncDelta) { + $ecommerceSyncDataItem->setData("mailchimp_sync_delta", $syncDelta); + } elseif ($allowBatchRemoval === true) { + $ecommerceSyncDataItem->setData("batch_id", null); + } + + if ($allowBatchRemoval === -1) { + $ecommerceSyncDataItem->setData("batch_id", '-1'); + } + + if ($syncError) { + $ecommerceSyncDataItem->setData("mailchimp_sync_error", $syncError); + } + + //Always set modified value to 0 when saving sync delta or errors. + $ecommerceSyncDataItem->setData("mailchimp_sync_modified", $syncModified); + if ($syncDeleted !== null) { + $ecommerceSyncDataItem->setData("mailchimp_sync_deleted", $syncDeleted); + if ($itemType == Ebizmarts_MailChimp_Model_Config::IS_PRODUCT && $syncError == '') { + $ecommerceSyncDataItem->setData("mailchimp_sync_error", $syncError); + } + } + + if ($token) { + $ecommerceSyncDataItem->setData("mailchimp_token", $token); + } + + if ($deletedRelatedId) { + $ecommerceSyncDataItem->setData("deleted_related_id", $deletedRelatedId); + } + + if ($syncedFlag !== null) { + $ecommerceSyncDataItem->setData("mailchimp_synced_flag", $syncedFlag); + } + } + /** * @return Ebizmarts_MailChimp_Helper_File */ From 887a12fb88ad10779b8eedf30b3a2d9fbf18f548 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 24 Sep 2019 15:31:48 -0300 Subject: [PATCH 048/160] Deleting some "Lines exceeds 120 characters." issue ref. #779 --- .../community/Ebizmarts/MailChimp/Helper/Data.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 0dde3c9d9..fd2ab9998 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -5085,7 +5085,16 @@ public function ping($storeId) * @param $allowBatchRemoval * @param Varien_Object $ecommerceSyncDataItem */ - protected function setEcommerceSyncDataItemValues($itemType, $syncDelta, $syncError, $syncModified, $syncDeleted, $token, $syncedFlag, $deletedRelatedId, $allowBatchRemoval, Varien_Object $ecommerceSyncDataItem) + protected function setEcommerceSyncDataItemValues( + $itemType, $syncDelta, + $syncError, + $syncModified, + $syncDeleted, + $token, + $syncedFlag, + $deletedRelatedId, + $allowBatchRemoval, + Varien_Object $ecommerceSyncDataItem) { if ($syncDelta) { $ecommerceSyncDataItem->setData("mailchimp_sync_delta", $syncDelta); From 2db29840c52fc5d95fdaf0a70ae01f40d472c56f Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 24 Sep 2019 15:59:51 -0300 Subject: [PATCH 049/160] Arranging function params in multiple lines (one pe line). --- app/code/community/Ebizmarts/MailChimp/Helper/Data.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index fd2ab9998..30c19afd2 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -5086,7 +5086,8 @@ public function ping($storeId) * @param Varien_Object $ecommerceSyncDataItem */ protected function setEcommerceSyncDataItemValues( - $itemType, $syncDelta, + $itemType, + $syncDelta, $syncError, $syncModified, $syncDeleted, @@ -5094,8 +5095,8 @@ protected function setEcommerceSyncDataItemValues( $syncedFlag, $deletedRelatedId, $allowBatchRemoval, - Varien_Object $ecommerceSyncDataItem) - { + Varien_Object $ecommerceSyncDataItem + ){ if ($syncDelta) { $ecommerceSyncDataItem->setData("mailchimp_sync_delta", $syncDelta); } elseif ($allowBatchRemoval === true) { @@ -5112,8 +5113,10 @@ protected function setEcommerceSyncDataItemValues( //Always set modified value to 0 when saving sync delta or errors. $ecommerceSyncDataItem->setData("mailchimp_sync_modified", $syncModified); + if ($syncDeleted !== null) { $ecommerceSyncDataItem->setData("mailchimp_sync_deleted", $syncDeleted); + if ($itemType == Ebizmarts_MailChimp_Model_Config::IS_PRODUCT && $syncError == '') { $ecommerceSyncDataItem->setData("mailchimp_sync_error", $syncError); } From d66c3597d4a5cbfd59919a80242f179b92c08b49 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Wed, 25 Sep 2019 16:21:46 -0300 Subject: [PATCH 050/160] Fixing call() method. The _curlOptions class attribute was being overwritten unnecessarily. --- lib/Ebizmarts/MailChimp.php | 6 +++--- lib/Ebizmarts/MailChimp/Lists.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Ebizmarts/MailChimp.php b/lib/Ebizmarts/MailChimp.php index 6d2c157cb..1da457057 100755 --- a/lib/Ebizmarts/MailChimp.php +++ b/lib/Ebizmarts/MailChimp.php @@ -376,7 +376,7 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ $headers[] = 'Accept-Language: ' . $paramsOrig['language']; } - $curlOptions = array(); + $curlOptions = $this->_curlOptions; if ($hasParams && $method != Ebizmarts_MailChimp::GET) { $curlOptions[CURLOPT_POSTFIELDS] = $params; @@ -398,8 +398,8 @@ public function call($url, $params, $method = Ebizmarts_MailChimp::GET, $encodeJ * @var $curlHelper Ebizmarts_MailChimp_Helper_Curl */ $curlHelper = Mage::helper('mailchimp/curl'); - $this->setCurlOptionsAddOptions($curlOptions); - $curlResult = $curlHelper->curlExec($this->_curlOptions); + //$this->setCurlOptionsAddOptions($curlOptions); + $curlResult = $curlHelper->curlExec($curlOptions); $responseBody = $curlResult['response']; $info = $curlResult['info']; diff --git a/lib/Ebizmarts/MailChimp/Lists.php b/lib/Ebizmarts/MailChimp/Lists.php index 77166e234..75cd46e1e 100644 --- a/lib/Ebizmarts/MailChimp/Lists.php +++ b/lib/Ebizmarts/MailChimp/Lists.php @@ -46,7 +46,7 @@ class MailChimp_Lists extends MailChimp_Abstract */ public $mergeFields; /** - * @var MailChimp_ListsMergeFields + * @var MailChimp_ListsWebhooks */ public $webhooks; From 135d771cd8fd22ec4e5b12ee72c1c59f3be88474 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Thu, 26 Sep 2019 12:10:22 -0300 Subject: [PATCH 051/160] Adding a break statement, if a webhook is found while iterating existing webkooks on Mailchimp. --- app/code/community/Ebizmarts/MailChimp/Helper/Data.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 30c19afd2..2fd0c5ebc 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -2921,6 +2921,7 @@ public function createNewWebhook($scopeId, $scope, $listId) foreach ($response['webhooks'] as $webhook) { if ($webhook['url'] == $hookUrl) { $createWebhook = false; + break; } } } From e8e3b9797cbddef50a3346b6d80107edd2147dc5 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Thu, 26 Sep 2019 14:16:13 -0300 Subject: [PATCH 052/160] Fix saves, loadings and deletes in loops, long lines, and others MEQP --- .../Ebizmarts/MailChimp/Helper/Data.php | 104 ++++++++++++---- .../Ebizmarts/MailChimp/Model/Api/Batches.php | 112 +++++++++++++----- .../Ebizmarts/MailChimp/Model/Api/Orders.php | 24 +++- .../MailChimp/Model/Api/Products.php | 26 +++- .../Ebizmarts/MailChimp/Model/Api/Stores.php | 2 +- .../MailChimp/Model/Api/Subscribers.php | 34 ++++-- .../Ebizmarts/MailChimp/Model/Email/Queue.php | 31 +++-- .../MailChimp/Model/ProcessWebhook.php | 10 +- .../Adminhtml/MailchimpstoresController.php | 61 ++++++---- .../controllers/WebhookController.php | 2 +- 10 files changed, 299 insertions(+), 107 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 2ce316c87..ddd6d7dd2 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -1191,12 +1191,20 @@ public function handleOldErrors() $storeId = $error->getStoreId(); $mailchimpStoreId = $this->getMCStoreId($storeId); if ($mailchimpStoreId) { - $error->setMailchimpStoreId($mailchimpStoreId) - ->save(); + $this->_saveErrorItem($error, $mailchimpStoreId); } } } + /** + * @param $error + * @param $mailchimpStoreId + */ + protected function _saveErrorItem($error, $mailchimpStoreId) + { + $error->setMailchimpStoreId($mailchimpStoreId)->save(); + } + /** * @param $scopeId * @param $scope @@ -1402,23 +1410,7 @@ public function createMergeFields($scopeId, $scope) } if (!empty($mailchimpFields)) { - foreach ($maps as $map) { - $customAtt = $map['magento']; - $chimpTag = $map['mailchimp']; - $alreadyExists = false; - - foreach ($mailchimpFields['merge_fields'] as $mailchimpField) { - if ($mailchimpField['tag'] == $chimpTag || strtoupper($chimpTag) == 'EMAIL') { - $alreadyExists = true; - } - } - - if (!$alreadyExists) { - $this->_createCustomFieldTypes($customFieldTypes, $api, $customAtt, $listId, $chimpTag); - } - } - - $success = 1; + $success = $this->_mapFieldsIteration($maps, $mailchimpFields, $customFieldTypes, $api, $listId); } } catch (Ebizmarts_MailChimp_Helper_Data_ApiKeyException $e) { $this->logError($e->getMessage()); @@ -1428,6 +1420,44 @@ public function createMergeFields($scopeId, $scope) return $success; } + /** + * @param $maps + * @param $mailchimpFields + * @param $customFieldTypes + * @param $api + * @param $listId + * @return int + */ + protected function _mapFieldsIteration($maps, $mailchimpFields, $customFieldTypes, $api, $listId) + { + foreach ($maps as $map) { + $customAtt = $map['magento']; + $chimpTag = $map['mailchimp']; + $alreadyExists = false; + + foreach ($mailchimpFields['merge_fields'] as $mailchimpField) { + if ($mailchimpField['tag'] == $chimpTag || strtoupper($chimpTag) == 'EMAIL') { + $alreadyExists = true; + } + } + + if (!$alreadyExists) { + $this->_createCustomFieldTypes($customFieldTypes, $api, $customAtt, $listId, $chimpTag); + } + } + + $success = 1; + + return $success; + } + + /** + * @param $customFieldTypes + * @param $api + * @param $customAtt + * @param $listId + * @param $chimpTag + */ protected function _createCustomFieldTypes($customFieldTypes, $api, $customAtt, $listId, $chimpTag) { $created = false; @@ -2510,7 +2540,7 @@ protected function _makeForCollectionItem($collection, $mailchimpStoreId, $initi do { $collection->setCurPage($currentPage); - $collection->load(); + $this->_loadItemCollection($collection); foreach ($collection as $collectionItem) { $callback($collectionItem, $mailchimpStoreId); @@ -2532,6 +2562,14 @@ protected function _makeForCollectionItem($collection, $mailchimpStoreId, $initi return $finished; } + /** + * @param $collection + */ + protected function _loadItemCollection(&$collection) + { + $collection->load(); + } + /** * Migrate data from version 1.1.6. * @@ -2868,11 +2906,21 @@ protected function _deletedWebhooksByListId($api, $listId, $webhookUrl) $webhooks = $api->lists->webhooks->getAll($listId); foreach ($webhooks['webhooks'] as $webhook) { if (strpos($webhook['url'], $webhookUrl) !== false) { - $api->lists->webhooks->delete($listId, $webhook['id']); + $this->_deleteWebhookFromList($api->lists->webhooks, $listId, $webhook['id']); } } } + /** + * @param $apiWebhook + * @param $listId + * @param $webhookId + */ + protected function _deleteWebhookFromList($apiWebhook, $listId, $webhookId) + { + $apiWebhook->delete($listId, $webhookId); + } + /** * Returns true on successful creation, or error message if it fails */ @@ -5079,8 +5127,18 @@ public function ping($storeId) * @param $allowBatchRemoval * @param Varien_Object $ecommerceSyncDataItem */ - protected function setEcommerceSyncDataItemValues($itemType, $syncDelta, $syncError, $syncModified, $syncDeleted, $token, $syncedFlag, $deletedRelatedId, $allowBatchRemoval, Varien_Object $ecommerceSyncDataItem) - { + protected function setEcommerceSyncDataItemValues( + $itemType, + $syncDelta, + $syncError, + $syncModified, + $syncDeleted, + $token, + $syncedFlag, + $deletedRelatedId, + $allowBatchRemoval, + Varien_Object $ecommerceSyncDataItem + ) { if ($syncDelta) { $ecommerceSyncDataItem->setData("mailchimp_sync_delta", $syncDelta); } elseif ($allowBatchRemoval === true) { diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index cff1d7168..76f1fe3df 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -251,8 +251,7 @@ public function _getResults( $magentoStoreId, $isEcommerceData = true, $status = Ebizmarts_MailChimp_Helper_Data::BATCH_PENDING - ) - { + ) { $helper = $this->getHelper(); $mailchimpStoreId = $helper->getMCStoreId($magentoStoreId); $collection = $this->getSyncBatchesModel()->getCollection() @@ -273,18 +272,7 @@ public function _getResults( try { $batchId = $item->getBatchId(); $files = $this->getBatchResponse($batchId, $magentoStoreId); - - if (!empty($files)) { - if (isset($files['error'])) { - $item->setStatus('error'); - $item->save(); - $helper->logBatchStatus('There was an error getting the result '); - } else { - $this->processEachResponseFile($files, $batchId, $mailchimpStoreId, $magentoStoreId); - $item->setStatus('completed'); - $item->save(); - } - } + $this->_saveItemStatus($item, $files, $batchId, $mailchimpStoreId, $magentoStoreId); $baseDir = $this->getMagentoBaseDir(); @@ -298,6 +286,31 @@ public function _getResults( } } + /** + * @param $item + * @param $files + * @param $batchId + * @param $mailchimpStoreId + * @param $magentoStoreId + * @throws Mage_Core_Exception + */ + protected function _saveItemStatus($item, $files, $batchId, $mailchimpStoreId, $magentoStoreId) + { + $helper = $this->getHelper(); + + if (!empty($files)) { + if (isset($files['error'])) { + $item->setStatus('error'); + $item->save(); + $helper->logBatchStatus('There was an error getting the result '); + } else { + $this->processEachResponseFile($files, $batchId, $mailchimpStoreId, $magentoStoreId); + $item->setStatus('completed'); + $item->save(); + } + } + } + /** * Send Customers, Products, Orders, Carts to MailChimp store for given scope. * Return true if MailChimp store is reset in the process. @@ -433,8 +446,7 @@ protected function _updateSyncingFlag( $orderAmount, $mailchimpStoreId, $magentoStoreId - ) - { + ) { $helper = $this->getHelper(); $dateHelper = $this->getDateHelper(); $itemAmount = ($customerAmount + $productAmount + $orderAmount); @@ -759,7 +771,6 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, $id = $line[3]; if ($item->status_code != 200) { - $mailchimpErrors = Mage::getModel('mailchimp/mailchimperrors'); //parse error $response = json_decode($item->response); @@ -785,20 +796,17 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, true ); - $mailchimpErrors->setType($response->type); - $mailchimpErrors->setTitle($response->title); - $mailchimpErrors->setStatus($item->status_code); - $mailchimpErrors->setErrors($errorDetails); - $mailchimpErrors->setRegtype($type); - $mailchimpErrors->setOriginalId($id); - $mailchimpErrors->setBatchId($batchId); - $mailchimpErrors->setStoreId($store[1]); - - if ($type != Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER) { - $mailchimpErrors->setMailchimpStoreId($mailchimpStoreId); - } + $this->_saveMailchimpError( + $response, + $item, + $errorDetails, + $type, + $id, + $batchId, + $store, + $mailchimpStoreId + ); - $mailchimpErrors->save(); $helper->modifyCounterDataSentToMailchimp($type, true); $helper->logError($error); } else { @@ -831,6 +839,45 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, $this->_showResumeDataSentToMailchimp($magentoStoreId); } + /** + * @param $response + * @param $item + * @param $errorDetails + * @param $type + * @param $id + * @param $batchId + * @param $store + * @param $mailchimpStoreId + * @throws Exception + */ + protected function _saveMailchimpError( + $response, + $item, + $errorDetails, + $type, + $id, + $batchId, + $store, + $mailchimpStoreId + ) { + $mailchimpErrors = Mage::getModel('mailchimp/mailchimperrors'); + + $mailchimpErrors->setType($response->type); + $mailchimpErrors->setTitle($response->title); + $mailchimpErrors->setStatus($item->status_code); + $mailchimpErrors->setErrors($errorDetails); + $mailchimpErrors->setRegtype($type); + $mailchimpErrors->setOriginalId($id); + $mailchimpErrors->setBatchId($batchId); + $mailchimpErrors->setStoreId($store[1]); + + if ($type != Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER) { + $mailchimpErrors->setMailchimpStoreId($mailchimpStoreId); + } + + $mailchimpErrors->save(); + } + /** * @param $type * @param $mailchimpStoreId @@ -864,9 +911,10 @@ protected function _getError($type, $mailchimpStoreId, $id, $response) protected function _processFileErrors($response) { $errorDetails = ""; + $errors = $response->errors; - if (!empty($response->errors)) { - foreach ($response->errors as $error) { + if (!empty($errors)) { + foreach ($errors as $error) { if (isset($error->field) && isset($error->message)) { $errorDetails .= $errorDetails != "" ? " / " : ""; $errorDetails .= $error->field . " : " . $error->message; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 6af6e227d..6cb3e3cf8 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -91,7 +91,7 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) foreach ($modifiedOrders as $item) { try { $orderId = $item->getEntityId(); - $order = Mage::getModel('sales/order')->load($orderId); + $order = $this->_getOrderById($orderId); $incrementId = $order->getIncrementId(); //create missing products first $batchArray = $this->addProductNotSentData($mailchimpStoreId, $magentoStoreId, $order, $batchArray); @@ -174,7 +174,7 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) foreach ($newOrders as $item) { try { $orderId = $item->getEntityId(); - $order = Mage::getModel('sales/order')->load($orderId); + $order = $this->_getOrderById($orderId); //create missing products first $batchArray = $this->addProductNotSentData($mailchimpStoreId, $magentoStoreId, $order, $batchArray); @@ -226,6 +226,15 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) return $batchArray; } + /** + * @param $id + * @return Mage_Core_Model_Abstract + */ + protected function _getOrderById($id) + { + return Mage::getModel('sales/order')->load($id); + } + /** * Set all the data for each order to be sent * @@ -385,7 +394,7 @@ protected function _getPayloadDataLines($order, $mailchimpStoreId, $magentoStore if ($this->isItemConfigurable($item)) { $options = $item->getProductOptions(); $sku = $options['simple_sku']; - $variant = $this->getModelProduct()->getIdBySku($sku); + $variant = $this->_getProductIdBySku($sku); if (!$variant) { continue; @@ -983,6 +992,15 @@ protected function getModelProduct() return Mage::getModel('catalog/product'); } + /** + * @param $sku + * @return string + */ + protected function _getProductIdBySku($sku) + { + return $this->getModelProduct()->getIdBySku($sku); + } + /** * @return string */ diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 0a1fbf4bb..f9b5552c2 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -83,7 +83,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) foreach ($collection as $product) { $productId = $product->getId(); - if ($this->shouldSendProductUpdate($mailchimpStoreId, $magentoStoreId, $product)) { + if ($this->shouldSendProductUpdate($product)) { $buildUpdateOperations = $this->_buildUpdateProductRequest( $product, $batchId, @@ -99,7 +99,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $this->_updateSyncData($productId, $mailchimpStoreId); } - $counter = count($batchArray); + $counter = $this->_getBatchCounter($batchArray); continue; } else { $data = $this->_buildNewProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId); @@ -142,6 +142,15 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) return $batchArray; } + /** + * @param $batchArray + * @return int + */ + protected function _getBatchCounter($batchArray) + { + return count($batchArray); + } + /** * @param $mailchimpStoreId * @param $magentoStoreId @@ -282,7 +291,7 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor $mailchimpStoreId ); if ($productSyncDataItem->getMailchimpSyncDelta()) { - $parent = Mage::getModel('catalog/product')->load($parentId); + $parent = $this->_getParentProduct($parentId); $variantProducts = $this->makeProductChildrenArray( $product, $magentoStoreId, @@ -369,6 +378,15 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor return $operations; } + /** + * @param $id + * @return Mage_Core_Model_Abstract + */ + protected function _getParentProduct($id) + { + return Mage::getModel('catalog/product')->load($id); + } + /** * @param $product * @param $magentoStoreId @@ -724,7 +742,7 @@ public function getSyncDataTableName() * @return bool * @throws Mage_Core_Exception */ - protected function shouldSendProductUpdate($mailchimpStoreId, $magentoStoreId, $product) + protected function shouldSendProductUpdate($product) { return $product->getMailchimpSyncModified() && $product->getMailchimpSyncDelta() diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php index 4b7052a6f..e1fb50d3f 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php @@ -170,7 +170,7 @@ public function editMailChimpStore( * @param $e MailChimp_Error * @return string */ - private function getUserFriendlyMessage($e) + protected function getUserFriendlyMessage($e) { $helper = $this->makeHelper(); $errorMessage = $e->getFriendlyMessage(); diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php index fcc3e5a08..0eb81e351 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php @@ -128,12 +128,12 @@ public function createBatchJson($listId, $storeId, $limit) $subscriberArray[$counter]['operation_id'] = $batchId . '_' . $subscriber->getSubscriberId(); $subscriberArray[$counter]['body'] = $subscriberJson; - //update subscribers delta - $subscriber->setData("mailchimp_sync_delta", $this->_mcDateHelper->formatDate(null, 'Y-m-d H:i:s')); - $subscriber->setData("mailchimp_sync_error", ""); - $subscriber->setData("mailchimp_sync_modified", 0); - $subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE); - $subscriber->save(); + $this->_saveSubscriber( + $subscriber, + '', + $this->_mcDateHelper->formatDate(null, 'Y-m-d H:i:s'), + true + ); } } else { //json encode failed @@ -142,9 +142,7 @@ public function createBatchJson($listId, $storeId, $limit) . " json encode failed (".$jsonErrorMsg.")"; $helper->logError($errorMessage); - $subscriber->setData("mailchimp_sync_error", $jsonErrorMsg); - $subscriber->setData("mailchimp_sync_modified", 0); - $subscriber->save(); + $this->_saveSubscriber($subscriber, $jsonErrorMsg); } $counter++; @@ -153,6 +151,24 @@ public function createBatchJson($listId, $storeId, $limit) return $subscriberArray; } + /** + * @param $subscriber + * @param $error + * @param null $syncDelta + * @param bool $setSource + */ + protected function _saveSubscriber($subscriber, $error, $syncDelta = null, $setSource = false) + { + if ($setSource) { + $subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE); + } + + $subscriber->setData("mailchimp_sync_delta", $syncDelta); + $subscriber->setData("mailchimp_sync_error", $error); + $subscriber->setData("mailchimp_sync_modified", 0); + $subscriber->save(); + } + /** * @param $subscriber * @return array diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php b/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php index bc73a2d0f..4d426f14a 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Email/Queue.php @@ -20,9 +20,6 @@ class Ebizmarts_MailChimp_Model_Email_Queue extends Mage_Core_Model_Email_Queue */ public function send() { - $mageMCHelper = Mage::helper('mailchimp'); - $mageMCDateHelper = Mage::helper('mailchimp/date'); - /** * @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */ @@ -37,7 +34,7 @@ public function send() foreach ($collection as $message) { if ($message->getId()) { if ($message->getEntityType() == 'order') { - $order = Mage::getModel('sales/order')->load($message->getEntityId()); + $order = $this->_getOrderByEntityId($message->getEntityId()); $storeId = $order->getStoreId(); } else { //If email is not an order confirmation email, it will check if Mandrill enable in default config @@ -49,8 +46,7 @@ public function send() try { $this->_sendMandrillEnabled($message, $parameters, $storeId); - $message->setProcessedAt($mageMCDateHelper->formatDate(null, 'Y-m-d H:i:s')); - $message->save(); + $this->_saveMessage($message); } catch (Exception $e) { Mage::logException($e); } @@ -62,8 +58,7 @@ public function send() } $this->_sendMandrillNotEnabled($message, $parameters); - $message->setProcessedAt($mageMCDateHelper->formatDate(null, 'Y-m-d H:i:s')); - $message->save(); + $this->_saveMessage($message); } } } @@ -71,6 +66,26 @@ public function send() return $this; } + /** + * @param $entityId + * @return Mage_Core_Model_Abstract + */ + protected function _getOrderByEntityId($entityId) + { + return Mage::getModel('sales/order')->load($entityId); + } + + /** + * @param $message + */ + protected function _saveMessage($message) + { + $mageMCDateHelper = Mage::helper('mailchimp/date'); + + $message->setProcessedAt($mageMCDateHelper->formatDate(null, 'Y-m-d H:i:s')); + $message->save(); + } + /** * @param $message * @param $parameters diff --git a/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php b/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php index f4f95f02a..19c10fa6f 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php @@ -80,10 +80,18 @@ public function processWebhookData() } } - $webhookRequest->setProcessed(1)->save(); + $this->_saveProcessedWebhook($webhookRequest); } } + /** + * @param $webhookRequest + */ + protected function _saveProcessedWebhook($webhookRequest) + { + $webhookRequest->setProcessed(1)->save(); + } + /** * Update customer email * diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php index 7a99fbdad..a628f7140 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php @@ -184,36 +184,47 @@ protected function _loadStores() continue; } - $storeData = Mage::getModel('mailchimp/stores'); - $storeData->setApikey($apiKey) - ->setStoreid($store['id']) - ->setListid($store['list_id']) - ->setName($store['name']) - ->setPlatform($store['platform']) - ->setIsSync($store['is_syncing']) - ->setEmailAddress($store['email_address']) - ->setCurrencyCode($store['currency_code']) - ->setMoneyFormat($store['money_format']) - ->setPrimaryLocale($store['primary_locale']) - ->setTimezone($store['timezone']) - ->setPhone($store['phone']) - ->setAddressAddressOne($store['address']['address1']) - ->setAddressAddressTwo($store['address']['address2']) - ->setAddressCity($store['address']['city']) - ->setAddressProvince($store['address']['province']) - ->setAddressProvinceCode($store['address']['province_code']) - ->setAddressPostalCode($store['address']['postal_code']) - ->setAddressCountry($store['address']['country']) - ->setAddressCountryCode($store['address']['country_code']) - ->setDomain($store['domain']) - ->setMcAccountName($root['account_name']) - ->setListName(key_exists('name', $list) ? $list['name'] : '') - ->save(); + $this->_saveStoreData($apiKey, $store, $root, $list); } } } } + /** + * @param $apiKey + * @param $store + * @param $root + * @param $list + */ + protected function _saveStoreData($apiKey, $store, $root, $list) + { + $storeData = Mage::getModel('mailchimp/stores'); + $storeData->setApikey($apiKey) + ->setStoreid($store['id']) + ->setListid($store['list_id']) + ->setName($store['name']) + ->setPlatform($store['platform']) + ->setIsSync($store['is_syncing']) + ->setEmailAddress($store['email_address']) + ->setCurrencyCode($store['currency_code']) + ->setMoneyFormat($store['money_format']) + ->setPrimaryLocale($store['primary_locale']) + ->setTimezone($store['timezone']) + ->setPhone($store['phone']) + ->setAddressAddressOne($store['address']['address1']) + ->setAddressAddressTwo($store['address']['address2']) + ->setAddressCity($store['address']['city']) + ->setAddressProvince($store['address']['province']) + ->setAddressProvinceCode($store['address']['province_code']) + ->setAddressPostalCode($store['address']['postal_code']) + ->setAddressCountry($store['address']['country']) + ->setAddressCountryCode($store['address']['country_code']) + ->setDomain($store['domain']) + ->setMcAccountName($root['account_name']) + ->setListName(key_exists('name', $list) ? $list['name'] : '') + ->save(); + } + public function getstoresAction() { $helper = $this->getMailchimpHelper(); diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php b/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php index 91e9381e3..05888b126 100755 --- a/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php @@ -94,7 +94,7 @@ protected function _deleteWebhook($storeId, $listId) $webhooks = $api->lists->webhooks->getAll($listId); foreach ($webhooks['webhooks'] as $webhook) { if (strpos($webhook['url'], 'monkey/webhook') !== false) { - $api->lists->webhooks->delete($listId, $webhook['id']); + $helper->_deleteWebhookFromList($api->lists->webhooks, $listId, $webhook['id']); } } } catch (MailChimp_Error $e) { From 800782a209b479fcd6f98b0a2a2edd0f7e212027 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Thu, 26 Sep 2019 14:23:30 -0300 Subject: [PATCH 053/160] test fixed --- .../tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php | 2 +- .../tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php index 4395c33a3..855eef3a0 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php @@ -647,7 +647,7 @@ public function testGetResults() $syncBatches[] = $syncBatchesTwoMock; $apiBatchesMock - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getHelper') ->willReturnOnConsecutiveCalls($helperMock); $apiBatchesMock diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index 55f2d74c9..6b2833f3d 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -110,7 +110,7 @@ public function testCreateBatchJson() $productsApiMock ->expects($this->once()) ->method('shouldSendProductUpdate') - ->with($mailchimpStoreId, $magentoStoreId, $productMock) + ->with($productMock) ->willReturn(false); $productsApiMock ->expects($this->once()) From 72fd7fe0a7e43892774be3ae9e7fa61e6c24675b Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Thu, 26 Sep 2019 15:40:19 -0300 Subject: [PATCH 054/160] after run PHPCBF --- app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index 76f1fe3df..54b34aba7 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -771,7 +771,6 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId, $id = $line[3]; if ($item->status_code != 200) { - //parse error $response = json_decode($item->response); $errorDetails = $this->_processFileErrors($response); @@ -1012,8 +1011,7 @@ protected function saveSyncData( $token = null, $syncedFlag = null, $saveOnlyIfexists = false - ) - { + ) { $helper = $this->getHelper(); if ($itemType == Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER) { $helper->updateSubscriberSyndData($itemId, $syncDelta, $syncError, 0, null); From fd274e08ebe53f79b39adcaf192ae80558c924f5 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 30 Sep 2019 15:02:33 -0300 Subject: [PATCH 055/160] Removing unused params from shouldSendProductUpdate() method, in Products.php. Correcting ProductsTest.php on this method test. --- .../MailChimp/Model/Api/Products.php | 65 +++++++++++-------- .../MailChimp/Model/Api/ProductsTest.php | 2 +- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 0a1fbf4bb..0073b7248 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -83,7 +83,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) foreach ($collection as $product) { $productId = $product->getId(); - if ($this->shouldSendProductUpdate($mailchimpStoreId, $magentoStoreId, $product)) { + if ($this->shouldSendProductUpdate($product)) { $buildUpdateOperations = $this->_buildUpdateProductRequest( $product, $batchId, @@ -115,6 +115,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId ); + if ($dataProduct->getId()) { $helper->modifyCounterSentPerBatch(Ebizmarts_MailChimp_Helper_Data::PRO_MOD); } else { @@ -156,6 +157,7 @@ public function createDeletedProductsBatchJson($mailchimpStoreId, $magentoStoreI $batchArray = array(); $batchId = $this->makeBatchId($magentoStoreId); $counter = 0; + foreach ($deletedProducts as $product) { $data = $this->_buildDeleteProductRequest($product, $batchId, $mailchimpStoreId); @@ -208,6 +210,7 @@ protected function _buildDeleteProductRequest($product, $batchId, $mailchimpStor protected function _buildNewProductRequest($product, $batchId, $mailchimpStoreId, $magentoStoreId) { $variantProducts = array(); + if ($this->isSimpleProduct($product)) { $variantProducts[] = $product; } elseif ($this->isConfigurableProduct($product)) { @@ -219,14 +222,14 @@ protected function _buildNewProductRequest($product, $batchId, $mailchimpStoreId } $bodyData = $this->_buildProductData($product, $magentoStoreId, false, $variantProducts); - $body = json_encode($bodyData, JSON_HEX_APOS | JSON_HEX_QUOT); + if ($body === false) { //json encode failed $jsonErrorMsg = json_last_error_msg(); $this->getMailChimpHelper()->logError( "Product " . $product->getId() - . " json encode failed (".$jsonErrorMsg.")" + . " json encode failed (" . $jsonErrorMsg . ")" ); $this->_updateSyncData( @@ -281,6 +284,7 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId ); + if ($productSyncDataItem->getMailchimpSyncDelta()) { $parent = Mage::getModel('catalog/product')->load($parentId); $variantProducts = $this->makeProductChildrenArray( @@ -289,13 +293,13 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor true ); $bodyData = $this->_buildProductData($parent, $magentoStoreId, false, $variantProducts); - $body = json_encode($bodyData, JSON_HEX_APOS | JSON_HEX_QUOT); + if ($body === false) { $jsonErrorMsg = json_last_error_msg(); $this->getMailChimpHelper()->logError( "Product " . $parent->getId() - . " json encode failed (".$jsonErrorMsg.")" + . " json encode failed (" . $jsonErrorMsg . ")" ); $this->_updateSyncData( $parent->getId(), @@ -330,19 +334,19 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor } $bodyData = $this->_buildProductData($product, $magentoStoreId, false, $variantProducts); - $body = json_encode($bodyData, JSON_HEX_APOS | JSON_HEX_QUOT); + if ($body === false) { //json encode failed $this->getMailChimpHelper()->logError( "Product " . $product->getId() - . " json encode failed (".json_last_error_msg().")" + . " json encode failed (" . json_last_error_msg() . ")" ); $jsonErrorMsg = json_last_error_msg(); $this->getMailChimpHelper()->logError( "Product " . $product->getId() - . " json encode failed (".$jsonErrorMsg.")" + . " json encode failed (" . $jsonErrorMsg . ")" ); $this->_updateSyncData( $product->getId(), @@ -370,10 +374,10 @@ protected function _buildUpdateProductRequest($product, $batchId, $mailchimpStor } /** - * @param $product - * @param $magentoStoreId - * @param bool $isVariant - * @param array $variants + * @param $product + * @param $magentoStoreId + * @param bool $isVariant + * @param array $variants * @return array * @throws Mage_Core_Exception * @throws Mage_Core_Model_Store_Exception @@ -416,6 +420,7 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru $data += $this->getProductVariantData($product, $magentoStoreId); } else { $description = $rc->getAttributeRawValue($productId, 'description', $magentoStoreId); + if (is_string($description)) { $data["description"] = $description; } @@ -452,16 +457,19 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru protected function _processVariants($data, $variants, $product, $magentoStoreId) { $data["variants"] = array(); + if (isset($data["image_url"])) { $this->_parentImageUrl = $data["image_url"]; } $this->_parentId = $product->getId(); + if ($this->currentProductIsVisible()) { $this->_parentUrl = $data['url']; } $price = $this->getMailchimpFinalPrice($product, $magentoStoreId); + if ($price) { $this->_parentPrice = $price; } @@ -551,6 +559,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) $helper = $this->getMailChimpHelper(); $dateHelper = $this->getMailChimpDateHelper(); $syncDateFlag = $helper->getEcommMinSyncDateFlag($mailchimpStoreId, $magentoStoreId); + foreach ($items as $item) { $itemProductId = $item->getProductId(); $product = $this->loadProductById($itemProductId); @@ -560,6 +569,7 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) Ebizmarts_MailChimp_Model_Config::IS_PRODUCT, $mailchimpStoreId ); + if ($productId != $itemProductId || $this->isBundleProduct($product) || $this->isGroupedProduct($product) @@ -618,15 +628,15 @@ public function sendModifiedProduct($order, $mailchimpStoreId, $magentoStoreId) /** * update product sync data * - * @param $productId - * @param $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncDeleted - * @param int|null $syncedFlag - * @param bool $saveOnlyIfexists - * @param bool $allowBatchRemoval + * @param $productId + * @param $mailchimpStoreId + * @param int|null $syncDelta + * @param int|null $syncError + * @param int|null $syncModified + * @param int|null $syncDeleted + * @param int|null $syncedFlag + * @param bool $saveOnlyIfexists + * @param bool $allowBatchRemoval */ protected function _updateSyncData( $productId, @@ -677,6 +687,7 @@ public function makeProductsNotSentCollection($magentoStoreId, $isParentProduct * @var Mage_Catalog_Model_Resource_Product_Collection $collection */ $collection = $this->getProductResourceCollection(); + if (!$isParentProduct) { $collection->addFinalPrice(); } @@ -718,13 +729,11 @@ public function getSyncDataTableName() } /** - * @param $mailchimpStoreId - * @param $magentoStoreId * @param $product * @return bool * @throws Mage_Core_Exception */ - protected function shouldSendProductUpdate($mailchimpStoreId, $magentoStoreId, $product) + protected function shouldSendProductUpdate($product) { return $product->getMailchimpSyncModified() && $product->getMailchimpSyncDelta() @@ -859,9 +868,9 @@ protected function getConfigurableChildrenIds($product) } /** - * @param $product - * @param $magentoStoreId - * @param bool $isBuildUpdateProductRequest + * @param $product + * @param $magentoStoreId + * @param bool $isBuildUpdateProductRequest * @return array | return an array with the childs of the product passed by parameter */ public function makeProductChildrenArray($product, $magentoStoreId, $isBuildUpdateProductRequest = false) @@ -1393,6 +1402,7 @@ public function _markSpecialPrices($mailchimpStoreId, $magentoStoreId) ); $collectionNoSpecialPrice->getSelect()->where($whereCondition); + foreach ($collectionNoSpecialPrice as $item) { $this->update($item->getEntityId(), $mailchimpStoreId); } @@ -1406,6 +1416,7 @@ public function isProductEnabled($productId, $magentoStoreId) { $isProductEnabled = false; $status = $this->getCatalogProductStatusModel()->getProductStatus($productId, $magentoStoreId); + if ($status[$productId] == self::PRODUCT_IS_ENABLED) { $isProductEnabled = true; } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index 55f2d74c9..6b2833f3d 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -110,7 +110,7 @@ public function testCreateBatchJson() $productsApiMock ->expects($this->once()) ->method('shouldSendProductUpdate') - ->with($mailchimpStoreId, $magentoStoreId, $productMock) + ->with($productMock) ->willReturn(false); $productsApiMock ->expects($this->once()) From 65ce0bc9dc6b27b0a9756d0939c5b6ed3f482269 Mon Sep 17 00:00:00 2001 From: Javier Giorello Date: Mon, 30 Sep 2019 15:07:51 -0300 Subject: [PATCH 056/160] Solved wrong store Id in carts and Orders when product is modified --- app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php | 4 ++++ app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index 522e1da86..2ae924ec0 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -29,6 +29,9 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) { $helper = $this->getHelper(); $dateHelper = $this->getDateHelper(); + $oldStore = $helper->getCurrentStoreId(); + $helper->setCurrentStore($magentoStoreId); + $allCarts = array(); if (!$helper->isAbandonedCartEnabled($magentoStoreId)) { @@ -56,6 +59,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) // get new carts $allCarts = array_merge($allCarts, $this->_getNewQuotes($mailchimpStoreId, $magentoStoreId)); + $helper->setCurrentStore($oldStore); return $allCarts; } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 6af6e227d..763a2a338 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -41,6 +41,9 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) { $helper = $this->getHelper(); $dateHelper = $this->getDateHelper(); + $oldStore = $helper->getCurrentStoreId(); + $helper->setCurrentStore($magentoStoreId); + $batchArray = array(); $this->_firstDate = $helper->getEcommerceFirstDate($magentoStoreId); $this->_counter = 0; @@ -57,6 +60,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) // get new orders $batchArray = array_merge($batchArray, $this->_getNewOrders($mailchimpStoreId, $magentoStoreId)); + $helper->setCurrentStore($oldStore); return $batchArray; } From 5f1fe906a85d0f1115de20d946ec843bcec736f9 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 30 Sep 2019 15:39:27 -0300 Subject: [PATCH 057/160] Reformatting code and comments. --- .../Ebizmarts/MailChimp/Helper/Data.php | 368 +++++++++--------- .../Ebizmarts/MailChimp/Model/Api/Carts.php | 24 +- .../MailChimp/Model/Api/Customers.php | 35 +- .../Ebizmarts/MailChimp/Model/Api/Orders.php | 9 +- .../MailChimp/Model/Api/Products.php | 9 +- .../MailChimp/Model/Api/PromoCodes.php | 39 +- .../MailChimp/Model/Api/PromoRules.php | 2 +- .../Ebizmarts/MailChimp/Model/Api/Stores.php | 16 +- .../MailChimp/Model/Api/Subscribers.php | 15 +- 9 files changed, 271 insertions(+), 246 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 2fd0c5ebc..18d9ff5d3 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -105,9 +105,9 @@ class Ebizmarts_MailChimp_Helper_Data extends Mage_Core_Helper_Abstract /** * Get Config value for certain scope. * - * @param $path - * @param $scopeId - * @param null $scope + * @param $path + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -125,8 +125,8 @@ public function getConfigValueForScope($path, $scopeId, $scope = null) /** * Get storeId and/or websiteId if scope selected on back end * - * @param null $storeId - * @param null $websiteId + * @param null $storeId + * @param null $websiteId * @return array */ public function getConfigScopeId($storeId = null, $websiteId = null) @@ -299,8 +299,8 @@ public function getMagentoStoresForMCStoreIdByScope($scopeId, $scope) /** * Validate if api key exists, could still be incorrect * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed */ public function validateApiKey($scopeId, $scope = null) @@ -313,8 +313,8 @@ public function validateApiKey($scopeId, $scope = null) /** * Return if module is enabled for given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed */ public function isMailChimpEnabled($scopeId, $scope = null) @@ -328,14 +328,14 @@ public function isMailChimpEnabled($scopeId, $scope = null) */ public function isUseMagentoEmailsEnabled($scopeId) { - return (int) $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $scopeId); + return (int)$this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $scopeId); } /** * Return if module is enabled and list selected for given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed */ public function isSubscriptionEnabled($scopeId, $scope = null) @@ -350,8 +350,8 @@ public function isSubscriptionEnabled($scopeId, $scope = null) /** * Return Api Key if exists for given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -388,8 +388,8 @@ public function encryptData($data) } /** - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -405,8 +405,8 @@ public function getWebhookDeleteAction($scopeId, $scope = null) /** * Get local store_id value of the MC store for given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -422,8 +422,8 @@ public function getMCStoreId($scopeId, $scope = null) /** * Delete all data related to the configured store in a given scope. * - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope */ public function deletePreviousConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope = 'stores') { @@ -464,8 +464,8 @@ public function deletePreviousConfiguredMCStoreLocalData($mailchimpStoreId, $sco /** * Delete all data related to the configured store in a given scope. * - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope */ public function deleteAllConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope = 'stores') { @@ -522,8 +522,8 @@ public function deleteAllMCStoreData($mailchimpStoreId) /** * Return if Ecommerce configuration is enabled for given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -539,8 +539,8 @@ public function isEcommerceEnabled($scopeId, $scope = null) /** * Get general list configured for the given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -556,8 +556,8 @@ public function getGeneralList($scopeId, $scope = null) /** * Get map fields configured for the given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -573,8 +573,8 @@ public function getMapFields($scopeId, $scope = null) /** * Get custom merge fields configured for the given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -588,8 +588,8 @@ public function getCustomMergeFieldsSerialized($scopeId, $scope = null) /** * Get if Abandoned Cart module is enabled. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -605,8 +605,8 @@ public function isAbandonedCartEnabled($scopeId, $scope = null) /** * Get date configured for carts to be sent for the given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -622,8 +622,8 @@ public function getAbandonedCartFirstDate($scopeId, $scope = null) /** * Get date configured for ecommerce data to be sent for the given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -640,9 +640,9 @@ public function getEcommerceFirstDate($scopeId, $scope = null) * Get local is_syncing value of the MC store. * If data was saved in the old way get it from the scope and update it to the new way. * - * @param $mailchimpStoreId - * @param int $scopeId - * @param string $scope + * @param $mailchimpStoreId + * @param int $scopeId + * @param string $scope * @return mixed|null * @throws Mage_Core_Exception */ @@ -668,10 +668,10 @@ public function getMCIsSyncing($mailchimpStoreId, $scopeId = 0, $scope = 'stores //Delete old entry if exists particularly in this scope. if ($oldSyncingFlag !== null && $this->getIfConfigExistsForScope( - Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING, - $scopeId, - $scope - ) + Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING, + $scopeId, + $scope + ) ) { $config = $this->getConfig(); $config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING, $scope, $scopeId); @@ -685,9 +685,9 @@ public function getMCIsSyncing($mailchimpStoreId, $scopeId = 0, $scope = 'stores * Minimum date for which ecommerce data needs to be uploaded. * If data was saved in the old way get it from the scope and update it to the new way. * - * @param $mailchimpStoreId - * @param $scopeId - * @param null $scope + * @param $mailchimpStoreId + * @param $scopeId + * @param null $scope * @return mixed|null * @throws Mage_Core_Exception */ @@ -750,8 +750,8 @@ public function getLogsEnabled() /** * Get if two way sync is enabled for given scope. * - * @param int $scopeId - * @param null $scope + * @param int $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -767,8 +767,8 @@ public function getTwoWaySyncEnabled($scopeId = 0, $scope = null) /** * Get webhook Id. * - * @param int $scopeId - * @param null $scope + * @param int $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -784,8 +784,8 @@ public function getWebhookId($scopeId = 0, $scope = null) /** * Get if monkey should be displayed in order grid. * - * @param int $scopeId - * @param null $scope + * @param int $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -801,8 +801,8 @@ public function getMonkeyInGrid($scopeId = 0, $scope = null) /** * Get if Email Catcher popup is enabled for given scope. * - * @param int $scopeId - * @param null $scope + * @param int $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -812,8 +812,8 @@ public function isEmailCatcherEnabled($scopeId = 0, $scope = null) } /** - * @param int $scopeId - * @param null $scope + * @param int $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -868,9 +868,9 @@ public function resendMCEcommerceData($scopeId, $scope, $filters = null) * Remove items from mailchimp_ecommerce_sync_data table to allow them to be sent. * If scopeId is 0 remova from all scopes. * - * @param $scopeId - * @param $scope - * @param bool $deleteErrorsOnly + * @param $scopeId + * @param $scope + * @param bool $deleteErrorsOnly * @throws Mage_Core_Exception */ public function removeEcommerceSyncData($scopeId, $scope, $deleteErrorsOnly = false, $filters = null) @@ -906,8 +906,8 @@ public function removeAllEcommerceSyncDataErrors($filters = null) } /** - * @param $mailchimpStoreId - * @param bool $deleteErrorsOnly + * @param $mailchimpStoreId + * @param bool $deleteErrorsOnly * @throws Mage_Core_Exception */ public function removeEcommerceSyncDataByMCStore($mailchimpStoreId, $deleteErrorsOnly = false, $filters = null) @@ -940,9 +940,9 @@ public function removeEcommerceSyncDataByMCStore($mailchimpStoreId, $deleteError /** * Check if Ecommerce data is configured to be sent. * - * @param $scopeId - * @param null $scope - * @param bool $isStoreCreation + * @param $scopeId + * @param null $scope + * @param bool $isStoreCreation * @return bool * @throws Mage_Core_Exception */ @@ -1026,8 +1026,8 @@ public function logBatchQuantity($message) /** * Save request made to MailChimp's API in "MailChimp_Requests.log" file. * - * @param $message - * @param null $batchId + * @param $message + * @param null $batchId */ public function logRequest($message, $batchId = null) { @@ -1106,8 +1106,8 @@ public function getWebhooksKey() * Reset error messages from Products, Subscribers, Customers, Orders, Quotes * and set them to be sent again for given scope. * - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @throws Mage_Core_Exception */ public function resetErrors($scopeId, $scope = 'stores') @@ -1123,9 +1123,9 @@ public function resetErrors($scopeId, $scope = 'stores') * Clear mailchimp_errors grid for given scope. * Exclude subscriber if flag set to true. * - * @param $scopeId - * @param $scope - * @param bool $excludeSubscribers + * @param $scopeId + * @param $scope + * @param bool $excludeSubscribers * @throws Mage_Core_Exception */ public function clearErrorGrid($scopeId, $scope, $excludeSubscribers = false, $filters = null) @@ -1384,7 +1384,7 @@ public function createMergeFields($scopeId, $scope) $maps = $this->unserialize($this->getMapFields($scopeId, $scope)); $customFieldTypes = $this->unserialize($this->getCustomMergeFieldsSerialized($scopeId, $scope)); - if (count($maps) > 30 ) { + if (count($maps) > 30) { $success = 2; } else { try { @@ -1506,8 +1506,8 @@ protected function _addMergeFieldByLabel($api, $label, $customAtt, $listId, $chi /** * Get Api object for given scope. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return Ebizmarts_MailChimp|null * @throws Exception */ @@ -1525,7 +1525,7 @@ public function getApi($scopeId, $scope = null) $apiKey, array('timeout' => $timeOut), 'Mailchimp4Magento' - . (string)$this->getConfig()->getNode('modules/Ebizmarts_MailChimp/version') + . (string)$this->getConfig()->getNode('modules/Ebizmarts_MailChimp/version') ); } else { $e = new Ebizmarts_MailChimp_Helper_Data_ApiKeyException('You must provide a MailChimp API key'); @@ -1565,18 +1565,18 @@ public function getApiByKey($apiKey) /** * Save entry for ecommerce_sync_data table overwriting old item if exists or creating a new one if it does not. * - * @param $itemId - * @param $itemType - * @param $mailchimpStoreId - * @param null $syncDelta - * @param null $syncError - * @param int $syncModified - * @param null $syncDeleted - * @param null $token - * @param null $syncedFlag - * @param bool $saveOnlyIfexists - * @param null $deletedRelatedId - * @param bool $allowBatchRemoval + * @param $itemId + * @param $itemType + * @param $mailchimpStoreId + * @param null $syncDelta + * @param null $syncError + * @param int $syncModified + * @param null $syncDeleted + * @param null $token + * @param null $syncedFlag + * @param bool $saveOnlyIfexists + * @param null $deletedRelatedId + * @param bool $allowBatchRemoval */ public function saveEcommerceSyncData( $itemId, @@ -1720,10 +1720,10 @@ public function getDefaultStoreIdForMailChimpScope($magentoStoreId) /** * Save configValues on core_config_data for given scope. * - * @param $configValues - * @param $scopeId - * @param $scope - * @param bool $cleanCache + * @param $configValues + * @param $scopeId + * @param $scope + * @param bool $cleanCache */ public function saveMailchimpConfig($configValues, $scopeId, $scope, $cleanCache = true) { @@ -1892,8 +1892,8 @@ protected function _getImageHelper() } /** - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -1989,8 +1989,8 @@ public function customMergeFieldAlreadyExists($value, $scopeId, $scope) /** * Get custom merge fields for given scope as an array. * - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return array|mixed */ public function getCustomMergeFields($scopeId, $scope = null) @@ -2050,8 +2050,8 @@ public function getMCJs() /** * Retrieve store data and save the MCJs URL for the current store in config table. * - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return bool * @throws Mage_Core_Exception */ @@ -2489,10 +2489,10 @@ protected function delete115MigrationConfigData() /** * Helper function for data migration from version 1.1.5. * - * @param $collection - * @param $mailchimpStoreId - * @param $initialTime - * @param Closure $callback + * @param $collection + * @param $mailchimpStoreId + * @param $initialTime + * @param Closure $callback * @return bool */ protected function _makeForCollectionItem($collection, $mailchimpStoreId, $initialTime, Closure $callback) @@ -2809,8 +2809,8 @@ public function loadListCustomer($listId, $email) } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope */ public function handleWebhookChange($scopeId, $scope = 'stores') { @@ -2983,9 +2983,9 @@ protected function getWebhookUrl() } /** - * @param $path - * @param $scopeId - * @param string $scope + * @param $path + * @param $scopeId + * @param string $scope * @return array|null */ public function getRealScopeForConfig($path, $scopeId, $scope = 'stores') @@ -3032,9 +3032,9 @@ public function getRealScopeForConfig($path, $scopeId, $scope = 'stores') /** * Return true if the configPath has been saved specifically for the given scope. * - * @param $configPath - * @param $scopeId - * @param string $scope + * @param $configPath + * @param $scopeId + * @param string $scope * @return bool|mixed * @throws Mage_Core_Exception */ @@ -3160,8 +3160,8 @@ public function updateSubscriberSyndData( /** * Get date configured for subscriber data to be sent for the given scope. * - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3203,8 +3203,8 @@ public function getApiStores() } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3218,8 +3218,8 @@ public function getCheckoutSubscribeValue($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return bool * @throws Mage_Core_Exception */ @@ -3233,9 +3233,9 @@ public function isCheckoutSubscribeEnabled($scopeId, $scope = 'stores') /** * Modify is_syncing value if initial sync finished in given scope. * - * @param $syncValue - * @param $scopeId - * @param string $scope + * @param $syncValue + * @param $scopeId + * @param string $scope * @throws Mage_Core_Exception */ protected function setIsSyncingIfFinishedPerScope($syncValue, $scopeId, $scope = 'stores') @@ -3253,9 +3253,9 @@ protected function setIsSyncingIfFinishedPerScope($syncValue, $scopeId, $scope = } /** - * @param $value - * @param $scopeId - * @param string $scope + * @param $value + * @param $scopeId + * @param string $scope */ public function setResendTurn($value, $scopeId, $scope = 'stores') { @@ -3264,8 +3264,8 @@ public function setResendTurn($value, $scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3279,8 +3279,8 @@ public function getResendTurn($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3294,8 +3294,8 @@ public function getResendEnabled($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3309,8 +3309,8 @@ public function getCustomerResendLastId($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3324,8 +3324,8 @@ public function getProductResendLastId($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3339,8 +3339,8 @@ public function getOrderResendLastId($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3354,8 +3354,8 @@ public function getCartResendLastId($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3417,8 +3417,8 @@ public function addResendFilter($collection, $magentoStoreId, $itemType) /** * Check if all items have been sent and delete config values used in the resend process * - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope */ public function handleResendFinish($scopeId, $scope = 'stores') { @@ -3429,8 +3429,8 @@ public function handleResendFinish($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope */ protected function deleteResendConfigValues($scopeId, $scope = 'stores') { @@ -3446,8 +3446,8 @@ protected function deleteResendConfigValues($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return bool */ protected function allResendItemsSent($scopeId, $scope = 'stores') @@ -3737,9 +3737,9 @@ protected function isMissingQuoteLowerThanId($itemId, $storeId) } /** - * @param $campaignId - * @param $scopeId - * @param string $scope + * @param $campaignId + * @param $scopeId + * @param string $scope * @return null */ public function getMailChimpCampaignNameById($campaignId, $scopeId, $scope = 'stores') @@ -3846,8 +3846,8 @@ public function getSubscriberAmountLimit() } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return string * @throws Mage_Core_Exception * @throws Mage_Core_Model_Store_Exception @@ -3870,8 +3870,8 @@ public function getStoreLanguageCode($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3881,8 +3881,8 @@ public function getStoreTimeZone($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3908,8 +3908,8 @@ public function getAllMailChimpStoreIds() } /** - * @param $subscriber - * @param bool $forceUpdateStatus + * @param $subscriber + * @param bool $forceUpdateStatus */ public function subscribeMember($subscriber, $forceUpdateStatus = false) { @@ -4088,7 +4088,7 @@ public function isNewApiKeyForSameAccount($oldApiKey, $newApiKey) /** * @param $scopeId - * @param string $scope + * @param string $scope */ public function resendSubscribers($scopeId, $scope = 'stores') { @@ -4166,7 +4166,7 @@ protected function makeWhereString($connection, $scopeId, $scope) /** * Convert language into Mailchimp compatible language code. * - * @param string $languageCode + * @param string $languageCode * @return string Returns empty string if not MC Language match found */ protected function _langToMCLanguage($languageCode = '') @@ -4187,8 +4187,8 @@ protected function _langToMCLanguage($languageCode = '') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return bool * @throws Mage_Core_Exception */ @@ -4202,8 +4202,8 @@ public function isSubscriptionConfirmationEnabled($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param null $scope + * @param $scopeId + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -4341,8 +4341,8 @@ public function getListInterestCategoriesByKeyAndList($apiKey, $listId) } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return array * @throws Exception */ @@ -4378,8 +4378,8 @@ public function getListInterestGroups($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -4393,8 +4393,8 @@ public function getLocalInterestCategories($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -4408,8 +4408,8 @@ public function getCheckoutSuccessHtmlBefore($scopeId, $scope = 'stores') } /** - * @param $scopeId - * @param string $scope + * @param $scopeId + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -4476,10 +4476,10 @@ public function getInterest($storeId) } /** - * @param $customerId - * @param $subscriberId - * @param $storeId - * @param null $interest + * @param $customerId + * @param $subscriberId + * @param $storeId + * @param null $interest * @return array|null * @throws Mage_Core_Exception * @throws MailChimp_Error @@ -4565,10 +4565,10 @@ public function arrayDecode($encodedArray) } /** - * @param $params - * @param $storeId - * @param null $customerId - * @param null $subscriber + * @param $params + * @param $storeId + * @param null $customerId + * @param null $subscriber * @throws Mage_Core_Model_Store_Exception */ public function saveInterestGroupData($params, $storeId, $customerId = null, $subscriber = null) @@ -4696,8 +4696,8 @@ public function getAllApiKeys() } /** - * @param int $scopeId - * @param string $scope + * @param int $scopeId + * @param string $scope * @return bool \ return true if image cache was flushed * @throws Mage_Core_Exception */ @@ -4793,7 +4793,7 @@ protected function getModelMailchimpEcommerceSyncData() } /** - * @param $index + * @param $index * @param int $increment */ public function modifyCounterSentPerBatch($index, $increment = 1) @@ -4819,7 +4819,7 @@ public function getCountersSentPerBatch() } /** - * @param $index + * @param $index * @param int $increment */ public function modifyCounterSubscribers($index, $increment = 1) @@ -4845,7 +4845,7 @@ public function getCountersSubscribers() } /** - * @param $index + * @param $index * @param bool $hasError * @param int $increment */ @@ -5033,8 +5033,8 @@ public function restoreAllCanceledBatches($mailchimpStore) /** * Generates a storable representation of a value using the default adapter. * - * @param mixed $value - * @param array $options + * @param mixed $value + * @param array $options * @return string * @throws Zend_Serializer_Exception */ @@ -5046,8 +5046,8 @@ public function serialize($value, array $options = array()) /** * Creates a PHP value from a stored representation using the default adapter. * - * @param string $serialized - * @param array $options + * @param string $serialized + * @param array $options * @return mixed * @throws Zend_Serializer_Exception */ @@ -5097,7 +5097,7 @@ protected function setEcommerceSyncDataItemValues( $deletedRelatedId, $allowBatchRemoval, Varien_Object $ecommerceSyncDataItem - ){ + ) { if ($syncDelta) { $ecommerceSyncDataItem->setData("mailchimp_sync_delta", $syncDelta); } elseif ($allowBatchRemoval === true) { diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php index 522e1da86..9da62ab6e 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Carts.php @@ -269,7 +269,7 @@ public function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId) ); //json encode failed - $helper->logError("Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")"); + $helper->logError("Carts " . $cart->getId() . " json encode failed (" . $jsonErrorMessage . ")"); } $this->setToken(null); @@ -412,7 +412,7 @@ public function _getNewQuotes($mailchimpStoreId, $magentoStoreId) -1 ); //json encode failed - $helper->logError("Carts " . $cart->getId() . " json encode failed (".$jsonErrorMessage.")"); + $helper->logError("Carts " . $cart->getId() . " json encode failed (" . $jsonErrorMessage . ")"); } $this->setToken(null); @@ -679,16 +679,16 @@ protected function _addBillingAddress($address, $billingAddress) } /** - * @param $cartId - * @param $mailchimpStoreId - * @param null $syncDelta - * @param null $syncError - * @param int $syncModified - * @param null $syncedFlag - * @param null $syncDeleted - * @param null $token - * @param bool $saveOnlyIfExists - * @param bool $allowBatchRemoval + * @param $cartId + * @param $mailchimpStoreId + * @param null $syncDelta + * @param null $syncError + * @param int $syncModified + * @param null $syncedFlag + * @param null $syncDeleted + * @param null $token + * @param bool $saveOnlyIfExists + * @param bool $allowBatchRemoval */ protected function _updateSyncData( $cartId, diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index dc6bb10cf..85091f5a9 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -92,6 +92,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $customersCollection = array(); $customerIds = $this->getCustomersToSync(); + if (!empty($customerIds)) { $customersCollection = $this->makeCustomersNotSentCollection($customerIds); } @@ -101,8 +102,8 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId) $this->setOptInStatusForStore($this->getOptIn($this->getBatchMagentoStoreId())); $subscriber = $this->getSubscriberModel(); $listId = $helper->getGeneralList($magentoStoreId); - $counter = 0; + foreach ($customersCollection as $customer) { $data = $this->_buildCustomerData($customer); $customerJson = json_encode($data); @@ -251,8 +252,8 @@ protected function getCustomerAddressData($customer) { $data = array(); $customerAddress = array(); - $street = explode("\n", $customer->getStreet()); + if (count($street) > 1) { $customerAddress["address1"] = $street[0]; $customerAddress["address2"] = $street[1]; @@ -272,6 +273,7 @@ protected function getCustomerAddressData($customer) if ($customer->getRegionId()) { $customerAddress["province_code"] = $this->_directoryRegionModel->load($customer->getRegionId())->getCode(); + if (!$customerAddress["province_code"]) { unset($customerAddress["province_code"]); } @@ -347,8 +349,8 @@ protected function getOptInConfiguration($magentoStoreId) * @param int|null $syncError * @param int|null $syncModified * @param int|null $syncedFlag - * @param bool $saveOnlyIfexists - * @param bool $allowBatchRemoval + * @param bool $saveOnlyIfexists + * @param bool $allowBatchRemoval */ protected function _updateSyncData( $customerId, @@ -359,7 +361,8 @@ protected function _updateSyncData( $syncedFlag = null, $saveOnlyIfexists = false, $allowBatchRemoval = true - ) { + ) + { $this->_mailchimpHelper->saveEcommerceSyncData( $customerId, Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, @@ -405,7 +408,7 @@ protected function joinDefaultBillingAddress($collection) */ protected function joinMailchimpSyncData($collection) { - $joinCondition = "m4m.related_id = e.entity_id AND m4m.type = '%s' AND m4m.mailchimp_store_id = '%s'"; + $joinCondition = "m4m.related_id = e.entity_id AND m4m.type = '%s' AND m4m.mailchimp_store_id = '%s'"; $mailchimpTableName = $this->getSyncdataTableName(); $collection->getSelect()->joinLeft( @@ -498,7 +501,7 @@ protected function logCouldNotEncodeCustomerError($customer) { $jsonErrorMessage = json_last_error_msg(); $this->_mailchimpHelper->logError( - "Customer " . $customer->getId() . " json encode failed (".$jsonErrorMessage.") on store " + "Customer " . $customer->getId() . " json encode failed (" . $jsonErrorMessage . ") on store " . $this->getBatchMagentoStoreId() ); return $jsonErrorMessage; @@ -512,7 +515,7 @@ protected function logCouldNotEncodeMailchimpTags($customer, $mailchimpTags) { $this->_mailchimpHelper->logError( "MailChimp tags encode failed, Customer " . $customer->getId() . " on store " . - $this->getBatchMagentoStoreId()." mergeFields:" + $this->getBatchMagentoStoreId() . " mergeFields:" ); $this->_mailchimpHelper->logError($mailchimpTags); } @@ -534,8 +537,8 @@ protected function getBatchMagentoStoreId() } /** - * @param $collection - * @param null $mailchimpStoreId + * @param $collection + * @param null $mailchimpStoreId */ public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId = null) { @@ -650,7 +653,7 @@ protected function makePatchBatchStructure($customer, $listId, $mergeFields) protected function isSubscribed($subscriber, $customer) { if ($subscriber->loadByEmail($customer->getEmail())->getSubscriberId() - && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED ) { + && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) { return true; } else { return false; @@ -726,12 +729,12 @@ protected function incrementCounterSentPerBatch( /** * Send merge fields for transactional members * - * @param $magentoStoreId + * @param $magentoStoreId * @param Varien_Object $dataCustomer - * @param $subscriber - * @param $customer - * @param $listId - * @param $counter + * @param $subscriber + * @param $customer + * @param $listId + * @param $counter * @param array $customerArray * @return array */ diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php index 6af6e227d..821d637ff 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php @@ -123,7 +123,7 @@ protected function _getModifiedOrders($mailchimpStoreId, $magentoStoreId) } } else { $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); + $helper->logError("Order " . $order->getEntityId() . " json encode failed (" . $jsonErrorMsg . ")"); $this->_updateSyncData( $orderId, @@ -205,7 +205,7 @@ protected function _getNewOrders($mailchimpStoreId, $magentoStoreId) } } else { $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Order " . $order->getEntityId() . " json encode failed (".$jsonErrorMsg.")"); + $helper->logError("Order " . $order->getEntityId() . " json encode failed (" . $jsonErrorMsg . ")"); $this->_updateSyncData( $orderId, @@ -293,7 +293,7 @@ public function GeneratePOSTPayload($order, $mailchimpStoreId, $magentoStoreId) $this->_getPayloadBilling($data, $billingAddress, $street); } - $shippingAddress = $order->getShippingAddress(); + $shippingAddress = $order->getShippingAddress(); if ($shippingAddress) { $this->_getPayloadShipping($data, $shippingAddress); @@ -748,6 +748,7 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS $orderCollection = $this->getResourceModelOrderCollection(); // select carts for the current Magento store id $orderCollection->addFieldToFilter('store_id', array('eq' => $magentoStoreId)); + if ($lastId) { $orderCollection->addFieldToFilter('entity_id', array('gt' => $lastId)); } @@ -764,10 +765,12 @@ public function replaceAllOrdersBatch($initialTime, $mailchimpStoreId, $magentoS "m4m.mailchimp_sync_delta IS NOT NULL AND m4m.mailchimp_sync_error = ''" ); $orderCollection->getSelect()->limit(self::BATCH_LIMIT_ONLY_ORDERS); + foreach ($orderCollection as $order) { //Delete order $orderId = $order->getEntityId(); $config = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MIGRATE_LAST_ORDER_ID, $orderId)); + if (!$dateHelper->timePassed($initialTime)) { $batchArray[$this->_counter]['method'] = "DELETE"; $batchArray[$this->_counter]['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/orders/' . $orderId; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index 0073b7248..26217d036 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -495,6 +495,7 @@ protected function _processVariants($data, $variants, $product, $magentoStoreId) public function update($productId, $mailchimpStoreId) { $parentIdArray = $this->getAllParentIds($productId); + foreach ($parentIdArray as $parentId) { $this->_updateSyncData( $parentId, @@ -831,6 +832,7 @@ protected function getProductVariantData($product, $magentoStoreId) $data["sku"] = $sku ? $sku : ''; $price = $this->getMailChimpProductPrice($product, $magentoStoreId); + if ($price) { $data["price"] = $price; } @@ -1010,6 +1012,7 @@ public function getNotVisibleProductUrl($childId, $magentoStoreId) { $helper = $this->getMailChimpHelper(); $parentId = null; + if (!$this->_parentId) { $parentId = $this->getParentId($childId); } else { @@ -1018,8 +1021,8 @@ public function getNotVisibleProductUrl($childId, $magentoStoreId) if ($parentId) { $collection = $this->getProductWithAttributesById($magentoStoreId, $parentId); - $rc = $helper->getProductResourceModel(); + if ($this->_parentUrl) { $url = $this->_parentUrl; } else { @@ -1029,6 +1032,7 @@ public function getNotVisibleProductUrl($childId, $magentoStoreId) $tailUrl = '#'; $count = 0; + foreach ($collection as $attribute) { if ($attribute->getAttributeId()) { $attributeId = $attribute->getAttributeId(); @@ -1067,6 +1071,7 @@ public function getParentImageUrl($childId, $magentoStoreId) { $imageUrl = null; $parentId = null; + if (!$this->_parentId) { $parentId = $this->getParentId($childId); } else { @@ -1100,6 +1105,7 @@ public function getProductCategories($product, $magentoStoreId) $categoryIds = $product->getResource()->getCategoryIds($product); $categoryNames = array(); $categoryName = null; + if (is_array($categoryIds) && !empty($categoryIds)) { $collection = $this->makeCatalogCategory()->getCollection(); $collection->addAttributeToSelect(array('name')) @@ -1127,6 +1133,7 @@ protected function getParentId($childId) { $parentId = null; $parentIds = $this->getAllParentIds($childId); + if (!empty($parentIds)) { $parentId = $parentIds[0]; } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php index 9d8aec2a3..2d3e398ae 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php @@ -168,7 +168,7 @@ protected function _getNewPromoCodes($mailchimpStoreId, $magentoStoreId) } } else { $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Promo code" . $codeId . " json encode failed (".$jsonErrorMsg.")"); + $helper->logError("Promo code" . $codeId . " json encode failed (" . $jsonErrorMsg . ")"); $this->_updateSyncData( $codeId, $mailchimpStoreId, @@ -278,16 +278,16 @@ public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId /** * update product sync data * - * @param $codeId - * @param $mailchimpStoreId - * @param int|null $syncDelta - * @param int|null $syncError - * @param int|null $syncModified - * @param int|null $syncDeleted - * @param int|null $token - * @param bool $saveOnlyIfexists - * @param null $deletedRelatedId - * @param bool $allowBatchRemoval + * @param $codeId + * @param $mailchimpStoreId + * @param int|null $syncDelta + * @param int|null $syncError + * @param int|null $syncModified + * @param int|null $syncDeleted + * @param int|null $token + * @param bool $saveOnlyIfexists + * @param null $deletedRelatedId + * @param bool $allowBatchRemoval */ protected function _updateSyncData( $codeId, @@ -375,18 +375,19 @@ protected function getRedemptionUrl($promoCode, $magentoStoreId) $token = $this->getToken(); $promoCode->setToken($token); $url = Mage::getModel('core/url')->setStore($magentoStoreId)->getUrl( - 'mailchimp/cart/loadcoupon', - array( - '_nosid' => true, - '_secure' => true, - 'coupon_id' =>$promoCode->getCouponId(), - 'coupon_token' => $token + 'mailchimp/cart/loadcoupon', + array( + '_nosid' => true, + '_secure' => true, + 'coupon_id' => $promoCode->getCouponId(), + 'coupon_token' => $token + ) ) - ) . 'mailchimp/cart/loadcoupon?coupon_id=' . $promoCode->getCouponId() . '&coupon_token=' . $token; + return $url; } @@ -498,7 +499,7 @@ protected function getPromoCodesForRule($promoRuleId) if ($api !== null) { try { $mailChimpPromoCodes = $api->ecommerce->promoRules->promoCodes - ->getAll($mailchimpStoreId, $promoRuleId); + ->getAll($mailchimpStoreId, $promoRuleId); foreach ($mailChimpPromoCodes['promo_codes'] as $promoCode) { $this->deletePromoCodeSyncData($promoCode['id'], $mailchimpStoreId); diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index 3ff05e956..c76d7bf7a 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -122,7 +122,7 @@ public function getNewPromoRule($ruleId, $mailchimpStoreId, $magentoStoreId) } } else { $jsonErrorMsg = json_last_error_msg(); - $helper->logError("Promo rule " . $ruleId . " json encode failed (".$jsonErrorMsg.")"); + $helper->logError("Promo rule " . $ruleId . " json encode failed (" . $jsonErrorMsg . ")"); $this->_updateSyncData( $ruleId, diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php index 4b7052a6f..0f8f9eeae 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php @@ -177,14 +177,14 @@ private function getUserFriendlyMessage($e) if (strstr($errorMessage, 'A store with the domain')) { $errorMessage = $helper->__( - 'A Mailchimp store with the same domain already exists in this account. ' - . 'You need to have a different URLs for each scope you set up the ecommerce data. ' - . 'Possible solutions ' - ) - . "" - . "HERE and " - . "" - . "HERE"; + 'A Mailchimp store with the same domain already exists in this account. ' + . 'You need to have a different URLs for each scope you set up the ecommerce data. ' + . 'Possible solutions ' + ) + . "" + . "HERE and " + . "" + . "HERE"; } else { if (is_array($e->getMailchimpErrors())) { $errorDetail = ""; diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php index 78bfbbcfc..bc18b0ad4 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php @@ -67,6 +67,7 @@ public function createBatchJson($listId, $storeId, $limit) ); $subscriberArray = array(); + if ($thisScopeHasList && !$thisScopeHasSubMinSyncDateFlag || !$helper->getSubMinSyncDateFlag($this->getStoreId()) ) { @@ -104,7 +105,8 @@ public function createBatchJson($listId, $storeId, $limit) $collection->addFieldToFilter('mailchimp_sync_error', array('eq' => '')); $collection->getSelect()->limit($limit); $date = $dateHelper->getDateMicrotime(); - $batchId = 'storeid-'.$this->getStoreId(). '_' .Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER . '_'.$date; + $batchId = 'storeid-' . $this->getStoreId() . '_' + . Ebizmarts_MailChimp_Model_Config::IS_SUBSCRIBER . '_' . $date; $counter = 0; foreach ($collection as $subscriber) { @@ -139,7 +141,7 @@ public function createBatchJson($listId, $storeId, $limit) //json encode failed $jsonErrorMsg = json_last_error_msg(); $errorMessage = "Subscriber " . $subscriber->getSubscriberId() - . " json encode failed (".$jsonErrorMsg.")"; + . " json encode failed (" . $jsonErrorMsg . ")"; $helper->logError($errorMessage); $subscriber->setData("mailchimp_sync_error", $jsonErrorMsg); @@ -174,12 +176,14 @@ protected function _buildSubscriberData($subscriber) $status = $this->translateMagentoStatusToMailchimpStatus($subscriber->getStatus()); $data["status_if_new"] = $status; + if ($subscriber->getMailchimpSyncModified()) { $data["status"] = $status; } $data["language"] = $helper->getStoreLanguageCode($storeId); $interest = $this->_getInterest($subscriber); + if (!empty($interest)) { $data['interests'] = $interest; } @@ -200,6 +204,7 @@ protected function _getInterest($subscriber) $helper = $this->getMailchimpHelper(); $interestsAvailable = $helper->getInterest($storeId); $interest = $helper->getInterestGroups(null, $subscriber->getSubscriberId(), $storeId, $interestsAvailable); + foreach ($interest as $i) { foreach ($i['category'] as $key => $value) { $rc[$value['id']] = $value['checked']; @@ -220,10 +225,12 @@ public function updateSubscriber($subscriber, $updateStatus = false) $helper = $this->getMailchimpHelper(); $storeId = $subscriber->getStoreId(); $subscriptionEnabled = $helper->isSubscriptionEnabled($storeId); + if ($subscriptionEnabled) { $listId = $helper->getGeneralList($storeId); $newStatus = $this->translateMagentoStatusToMailchimpStatus($subscriber->getStatus()); $forceStatus = ($updateStatus) ? $newStatus : null; + try { $api = $helper->getApi($storeId); } catch (Ebizmarts_MailChimp_Helper_Data_ApiKeyException $e) { @@ -299,6 +306,7 @@ protected function _catchMailchimpSubsNotAppliedIf($e, $isAdmin, $subscriber) $helper = $this->getMailchimpHelper(); $errorMessage = $e->getFriendlyMessage(); $helper->logError($errorMessage); + if ($isAdmin) { $this->addError($errorMessage); } else { @@ -319,6 +327,7 @@ protected function _catchMailchimpSubsNotAppliedElse($e, $isAdmin, $subscriber) $helper = $this->getMailchimpHelper(); $errorMessage = $e->getFriendlyMessage(); $helper->logError($errorMessage); + if ($isAdmin) { $this->addError($errorMessage); } else { @@ -459,6 +468,7 @@ public function deleteSubscriber($subscriber) public function update($emailAddress) { $subscriber = Mage::getSingleton('newsletter/subscriber')->loadByEmail($emailAddress); + if ($subscriber->getId()) { $subscriber->setMailchimpSyncModified(1) ->save(); @@ -529,6 +539,7 @@ protected function getMailchimpDateHelper() protected function getAddressFromLastOrder($lastOrder) { $addressData = array(); + if ($lastOrder && $lastOrder->getShippingAddress()) { $addressData = $lastOrder->getShippingAddress(); } From b54eaf309ae9d0299c272f6e778a0c3f7d8530ef Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 30 Sep 2019 16:42:52 -0300 Subject: [PATCH 058/160] Reformatting code and if() and foreach statements. --- .../Ebizmarts/MailChimp/Helper/Curl.php | 2 +- .../Ebizmarts/MailChimp/Helper/Data.php | 238 ++++++++++++------ .../Ebizmarts/MailChimp/Helper/Date.php | 8 +- .../Ebizmarts/MailChimp/Helper/Mandrill.php | 14 +- .../Ebizmarts/MailChimp/Helper/Oauth2.php | 1 + .../MailChimp/Model/Mailchimperrors.php | 1 + .../Ebizmarts/MailChimp/Model/Observer.php | 28 +-- .../MailChimp/Model/ProcessWebhook.php | 8 +- .../Ebizmarts/MailChimp/Model/Stores.php | 1 + .../Ebizmarts/MailChimp/Model/Subscriber.php | 2 +- .../Model/System/Config/Source/Fieldtype.php | 1 + .../Model/System/Config/Source/ImageSize.php | 1 + .../Model/System/Config/Source/Log.php | 1 + .../Config/Source/MailchimpStoreView.php | 2 +- .../Model/System/Config/Source/OrderGrid.php | 2 +- .../Model/System/Config/Source/Store.php | 5 +- .../Model/System/Config/Source/Userinfo.php | 6 +- .../System/Config/Source/WebhookDelete.php | 1 + .../MailChimp/Model/Webhookrequest.php | 1 + .../Adminhtml/EcommerceController.php | 6 +- .../Adminhtml/MergevarsController.php | 1 + .../MailChimp/controllers/CartController.php | 13 +- .../MailChimp/controllers/GroupController.php | 1 + .../controllers/WebhookController.php | 3 + .../Ebizmarts/MailChimp/etc/adminhtml.xml | 2 +- .../Ebizmarts/MailChimp/etc/config.xml | 12 +- .../Ebizmarts/MailChimp/etc/system.xml | 27 +- .../Block/Adminhtml/NotificationsTest.php | 5 +- .../Ebizmarts/MailChimp/Helper/DataTest.php | 122 +++++---- .../MailChimp/Model/Api/CustomersTest.php | 18 +- .../MailChimp/Model/Api/OrdersTest.php | 18 +- .../MailChimp/Model/Api/ProductsTest.php | 20 +- .../MailChimp/Model/Api/PromoRulesTest.php | 6 +- .../MailChimp/Model/Api/StoresTest.php | 2 +- .../MailChimp/Model/Email/TemplateTest.php | 4 +- .../Model/System/Config/Source/StoreTest.php | 2 +- .../Adminhtml/MailchimpControllerTest.php | 40 +-- .../MailchimperrorsControllerTest.php | 2 +- .../MailchimpstoresControllerTest.php | 2 +- .../controllers/GroupControllerTest.php | 8 +- .../MailChimp/ReportsEmailActivity.php | 1 + lib/Ebizmarts/MailChimp/ReportsLocation.php | 1 + lib/Ebizmarts/MailChimp/ReportsSentTo.php | 1 + lib/Ebizmarts/MailChimp/ReportsSubReports.php | 1 + .../MailChimp/ReportsUnsubscribes.php | 1 + lib/Ebizmarts/MailChimp/Root.php | 2 + lib/Ebizmarts/MailChimp/TemplateFolders.php | 1 + lib/Ebizmarts/MailChimp/Templates.php | 1 + .../MailChimp/TemplatesDefaultContent.php | 1 + shell/getMailchimpResponse.php | 35 +-- 50 files changed, 413 insertions(+), 269 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Curl.php b/app/code/community/Ebizmarts/MailChimp/Helper/Curl.php index 0052b43cf..82e68af54 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Curl.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Curl.php @@ -27,7 +27,7 @@ public function curlExec($options = array()) $headers = isset($options[CURLOPT_HTTPHEADER]) ? $options[CURLOPT_HTTPHEADER] : array(); $body = isset($options[CURLOPT_POSTFIELDS]) ? $options[CURLOPT_POSTFIELDS] : ''; - if($url === false) + if ($url === false) return array(); $curl = new Varien_Http_Adapter_Curl(); diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 18d9ff5d3..d0886a75a 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -143,6 +143,7 @@ public function getConfigScopeId($storeId = null, $websiteId = null) $scopeArray['websiteId'] = $websiteId; $scopeArray['storeId'] = $storeId; + return $scopeArray; } @@ -256,6 +257,7 @@ public function getStoreRelation() { $stores = $this->getMageApp()->getStores(); $storeRelation = array(); + foreach ($stores as $storeId => $store) { if ($this->isEcomSyncDataEnabled($storeId)) { $mcStoreId = $this->getMCStoreId($storeId); @@ -307,6 +309,7 @@ public function validateApiKey($scopeId, $scope = null) { $apiKey = $this->getApiKey($scopeId, $scope); $isApiKeyValid = $apiKey !== null && $apiKey != ""; + return $isApiKeyValid; } @@ -362,6 +365,7 @@ public function getApiKey($scopeId, $scope = null) $scopeId, $scope ); + return $this->decryptData($apiKey); } @@ -971,8 +975,10 @@ public function isEcomSyncDataEnabled($scopeId, $scope = null, $isStoreCreation public function isEcomSyncDataEnabledInAnyScope() { $stores = $this->getMageApp()->getStores(); + foreach ($stores as $storeId => $store) { $ecomEnabled = $this->isEcomSyncDataEnabled($storeId); + if ($ecomEnabled) { return true; } @@ -1065,6 +1071,7 @@ protected function isRequestLogEnabled() { $logEnabled = false; $logConfig = $this->getLogsEnabled(); + if ($logConfig == Ebizmarts_MailChimp_Model_System_Config_Source_Log::REQUEST_LOG || $logConfig == Ebizmarts_MailChimp_Model_System_Config_Source_Log::BOTH ) { @@ -1082,6 +1089,7 @@ public function isErrorLogEnabled() { $logEnabled = false; $logConfig = $this->getLogsEnabled(); + if ($logConfig == Ebizmarts_MailChimp_Model_System_Config_Source_Log::ERROR_LOG || $logConfig == Ebizmarts_MailChimp_Model_System_Config_Source_Log::BOTH ) { @@ -1134,6 +1142,7 @@ public function clearErrorGrid($scopeId, $scope, $excludeSubscribers = false, $f $this->handleOldErrors(); $mailchimpStoreId = $this->getMCStoreId($scopeId, $scope); + if ($excludeSubscribers) { $this->clearErrorGridByMCStore($mailchimpStoreId, $filters); } else { @@ -1188,9 +1197,11 @@ public function handleOldErrors() $errorCollection = Mage::getModel('mailchimp/mailchimperrors')->getCollection() ->addFieldToFilter('type', array('neq' => 'SUB')) ->addFieldToFilter('mailchimp_store_id', array('eq' => '')); + foreach ($errorCollection as $error) { $storeId = $error->getStoreId(); $mailchimpStoreId = $this->getMCStoreId($storeId); + if ($mailchimpStoreId) { $error->setMailchimpStoreId($mailchimpStoreId) ->save(); @@ -1432,6 +1443,7 @@ public function createMergeFields($scopeId, $scope) protected function _createCustomFieldTypes($customFieldTypes, $api, $customAtt, $listId, $chimpTag) { $created = false; + foreach ($customFieldTypes as $customFieldType) { if ($customFieldType['value'] == $customAtt) { try { @@ -1456,6 +1468,7 @@ protected function _createCustomFieldTypes($customFieldTypes, $api, $customAtt, ->addSetInfo() ->getData(); $label = null; + foreach ($attrSetId as $option) { if ($option['attribute_id'] == $customAtt && $option['frontend_label']) { $label = $option['frontend_label']; @@ -1515,6 +1528,7 @@ public function getApi($scopeId, $scope = null) { $apiKey = $this->getApiKey($scopeId, $scope); $api = null; + if ($apiKey != null && $apiKey != "") { $timeOut = $this->getConfigValueForScope( Ebizmarts_MailChimp_Model_Config::GENERAL_TIME_OUT, @@ -1547,6 +1561,7 @@ public function getApi($scopeId, $scope = null) public function getApiByKey($apiKey) { $api = null; + if ($apiKey != null && $apiKey != "") { $api = new Ebizmarts_MailChimp( $apiKey, @@ -1654,6 +1669,7 @@ public function addStoresToFilter($collection, $scopeId, $scope) { $filterArray = array(); $storesForScope = $this->getMagentoStoresForMCStoreIdByScope($scopeId, $scope); + if ($storesForScope) { if ($scopeId === 0) { $filterArray[] = array('eq' => 0); @@ -1685,6 +1701,7 @@ public function getMailChimpScopeByStoreId($storeId) Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $mailChimpStoreId ); + return $mailchimpScope; } @@ -1698,6 +1715,7 @@ public function getMailChimpScopeByStoreId($storeId) public function getDefaultStoreIdForMailChimpScope($magentoStoreId) { $scopeArray = $this->getMailChimpScopeByStoreId($magentoStoreId); + if ($scopeArray) { if ($scopeArray['scope'] == 'websites') { $magentoStoreId = $this->getMageApp() @@ -1762,6 +1780,7 @@ public function getImageUrlById($productId, $magentoStoreId) $productResourceModel = $this->getProductResourceModel(); $productModel = $this->getProductModel(); $configImageSize = $this->getImageSize($magentoStoreId); + switch ($configImageSize) { case self::DEFAULT_SIZE: $imageSize = Ebizmarts_MailChimp_Model_Config::IMAGE_SIZE_DEFAULT; @@ -1788,6 +1807,7 @@ public function getImageUrlById($productId, $magentoStoreId) } else { $curStore = $this->getCurrentStoreId(); $this->setCurrentStore($magentoStoreId); + if ($configImageSize == self::ORIGINAL_SIZE) { $imageUrl = $this->getOriginalPath($productImage); } else { @@ -1835,6 +1855,7 @@ protected function getImageUrlForSize($imageSize, $productModel) { $upperCaseImage = (string)$this->getImageFunctionName($imageSize); $imageUrl = $productModel->$upperCaseImage(); + return $imageUrl; } @@ -1860,6 +1881,7 @@ public function setImageSizeVarToArray($imageSize) public function setWordToCamelCase($imageArray) { $upperCaseImage = ''; + foreach ($imageArray as $word) { $word = ucwords($word); $upperCaseImage .= $word; @@ -1877,6 +1899,7 @@ public function setWordToCamelCase($imageArray) public function setFunctionName($functionName) { $functionName = "get" . $functionName . "Url"; + return $functionName; } @@ -1912,6 +1935,7 @@ public function getImageSize($scopeId, $scope = null) public function getProductResourceModel() { $productResourceModel = Mage::getResourceModel('catalog/product'); + return $productResourceModel; } @@ -1921,6 +1945,7 @@ public function getProductResourceModel() protected function getProductModel() { $productModel = Mage::getModel('catalog/product'); + return $productModel; } @@ -1939,6 +1964,7 @@ public function getMageApp() public function getCurrentStoreId() { $curStore = $this->getMageApp()->getStore()->getId(); + return $curStore; } @@ -1977,6 +2003,7 @@ protected function getCoreWebsite() public function customMergeFieldAlreadyExists($value, $scopeId, $scope) { $customMergeFields = $this->getCustomMergeFields($scopeId, $scope); + foreach ($customMergeFields as $customMergeField) { if ($customMergeField['value'] == $value) { return true; @@ -2406,6 +2433,7 @@ protected function _migrateCartsFrom115($mailchimpStoreId, $initialTime) $readConnection = $resource->getConnection('core_read'); $tableName = $resource->getTableName('sales/quote'); $quoteFields = $readConnection->describeTable($tableName); + if (isset($quoteFields['mailchimp_sync_delta'])) { $mailchimpTableName = $resource->getTableName('mailchimp/ecommercesyncdata'); $quoteCollection = Mage::getResourceModel('sales/quote_collection'); @@ -2432,6 +2460,7 @@ function ($quote, $mailchimpStoreId) { $token = null; $quoteObject = $this->getSalesOrderModel()->load($quoteId); $syncDelta = $quoteObject->getMailchimpSyncDelta(); + if ($quote->getMailchimpSyncError()) { $syncError = $quote->getMailchimpSyncError(); } @@ -2470,6 +2499,7 @@ function ($quote, $mailchimpStoreId) { . $this->__(' See error details below.') ); $this->logError($e->getMessage()); + return false; } } @@ -2498,8 +2528,8 @@ protected function delete115MigrationConfigData() protected function _makeForCollectionItem($collection, $mailchimpStoreId, $initialTime, Closure $callback) { $dateHelper = $this->getDateHelper(); - $finished = false; + if (!$collection->getSize()) { $finished = true; } @@ -2522,6 +2552,7 @@ protected function _makeForCollectionItem($collection, $mailchimpStoreId, $initi // if not done, the same page will be loaded each loop // - will also free memory $collection->clear(); + if ($dateHelper->timePassed($initialTime)) { break; } @@ -2530,6 +2561,7 @@ protected function _makeForCollectionItem($collection, $mailchimpStoreId, $initi $finished = true; } } while ($currentPage <= $pages); + return $finished; } @@ -2542,6 +2574,7 @@ protected function _migrateFrom116($initialTime) { $this->_setIsSyncingIfFinishedInAllStores(true); $finished = $this->_migrateOrdersFrom116($initialTime); + if ($finished) { $this->_setIsSyncingIfFinishedInAllStores(false); $arrayMigrationConfigData = array('115' => false, '116' => true, '1164' => false); @@ -2557,8 +2590,10 @@ protected function _migrateFrom116($initialTime) protected function _setIsSyncingIfFinishedInAllStores($syncValue) { $stores = $this->getMageApp()->getStores(); + foreach ($stores as $storeId => $store) { $ecommEnabled = $this->isEcomSyncDataEnabled($storeId); + if ($ecommEnabled) { $this->setIsSyncingIfFinishedPerScope($syncValue, $storeId); } @@ -2575,9 +2610,11 @@ protected function _migrateOrdersFrom116($initialTime) { $dateHelper = $this->getDateHelper(); $finished = false; + if (!$dateHelper->timePassed($initialTime)) { $finished = true; $stores = $this->getMageApp()->getStores(); + foreach ($stores as $storeId => $store) { if ($this->isEcomSyncDataEnabled($storeId)) { Mage::getModel('mailchimp/api_batches')->replaceAllOrders($initialTime, $storeId); @@ -2608,11 +2645,13 @@ public function migrationFinished() 0, 'default' ); + $migrateFrom116 = $this->getConfigValueForScope( Ebizmarts_MailChimp_Model_Config::GENERAL_MIGRATE_FROM_116, 0, 'default' ); + $migrateFrom1164 = $this->getConfigValueForScope( Ebizmarts_MailChimp_Model_Config::GENERAL_MIGRATE_FROM_1164, 0, @@ -2637,6 +2676,7 @@ public function delete116MigrationConfigData() 'default', 0 ); + foreach ($stores as $storeId => $store) { $this->getConfig()->deleteConfig( Ebizmarts_MailChimp_Model_Config::GENERAL_MIGRATE_LAST_ORDER_ID, @@ -2709,9 +2749,11 @@ public function handleDeleteMigrationConfigData($arrayMigrationConfigData) public function getMagentoStoreIdsByListId($listId) { $storeIds = Mage::registry('mailchimp_store_ids_for_list_' . $listId); + if ($storeIds === null) { $stores = $this->getMageApp()->getStores(); $storeIds = array(); + foreach ($stores as $storeId => $store) { if ($this->isSubscriptionEnabled($storeId)) { $storeListId = $this->getConfigValueForScope( @@ -2742,10 +2784,10 @@ public function getMagentoStoreIdsByListId($listId) public function loadListSubscriber($listId, $email) { $subscriber = null; - $storeIds = $this->getMagentoStoreIdsByListId($listId); //add store id 0 for those created from the back end. $storeIds[] = 0; + if (!empty($storeIds)) { $subscriber = Mage::getModel('newsletter/subscriber')->getCollection() ->addFieldToFilter('store_id', array('in' => $storeIds)) @@ -2760,6 +2802,7 @@ public function loadListSubscriber($listId, $email) $subscriber = Mage::getModel('newsletter/subscriber'); $subscriber->setEmail($email); $customer = $this->loadListCustomer($listId, $email); + if ($customer) { $subscriber->setStoreId($customer->getStoreId()); $subscriber->setCustomerId($customer->getId()); @@ -2790,8 +2833,8 @@ public function loadListSubscriber($listId, $email) public function loadListCustomer($listId, $email) { $customer = null; - $storeIds = $this->getMagentoStoreIdsByListId($listId); + if (!empty($storeIds)) { $customer = Mage::getResourceModel('customer/customer_collection') ->addFieldToFilter('store_id', array('in' => $storeIds)) @@ -2821,6 +2864,7 @@ public function handleWebhookChange($scopeId, $scope = 'stores') ); $listId = $this->getGeneralList($scopeId, $scope); $this->deleteCurrentWebhook($webhookScope['scope_id'], $webhookScope['scope'], $listId); + if ($this->isSubscriptionEnabled($scopeId, $scope)) { $this->createNewWebhook($webhookScope['scope_id'], $webhookScope['scope'], $listId); } @@ -2838,6 +2882,7 @@ protected function deleteCurrentWebhook($scopeId, $scope, $listId) $api = $this->getApi($scopeId, $scope); $webhookId = $this->getWebhookId($scopeId, $scope); $apiKey = $this->getApiKey($scopeId, $scope); + if ($webhookId && $apiKey && $listId) { try { $api->lists->webhooks->delete($listId, $webhookId); @@ -2869,6 +2914,7 @@ protected function deleteCurrentWebhook($scopeId, $scope, $listId) protected function _deletedWebhooksByListId($api, $listId, $webhookUrl) { $webhooks = $api->lists->webhooks->getAll($listId); + foreach ($webhooks['webhooks'] as $webhook) { if (strpos($webhook['url'], $webhookUrl) !== false) { $api->lists->webhooks->delete($listId, $webhook['id']); @@ -2882,8 +2928,10 @@ protected function _deletedWebhooksByListId($api, $listId, $webhookUrl) public function createNewWebhook($scopeId, $scope, $listId) { $hookUrl = $this->getWebhookUrl(); + try { $api = $this->getApi($scopeId, $scope); + if ($this->getTwoWaySyncEnabled($scopeId, $scope)) { $events = array( 'subscribe' => true, @@ -2917,6 +2965,7 @@ public function createNewWebhook($scopeId, $scope, $listId) try { $response = $api->lists->webhooks->getAll($listId); $createWebhook = true; + if (isset($response['total_items']) && $response['total_items'] > 0) { foreach ($response['webhooks'] as $webhook) { if ($webhook['url'] == $hookUrl) { @@ -2931,6 +2980,7 @@ public function createNewWebhook($scopeId, $scope, $listId) $newWebhookId = $newWebhook['id']; $configValues = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_WEBHOOK_ID, $newWebhookId)); $this->saveMailchimpConfig($configValues, $scopeId, $scope); + return true; } else { return $this->__('The webhook already exists.'); @@ -2991,6 +3041,7 @@ protected function getWebhookUrl() public function getRealScopeForConfig($path, $scopeId, $scope = 'stores') { $websiteId = null; + if ($scope == 'stores') { $websiteId = Mage::getModel('core/store')->load($scopeId)->getWebsiteId(); $scopeIdsArray = array($scopeId, $websiteId, 0); @@ -3001,8 +3052,8 @@ public function getRealScopeForConfig($path, $scopeId, $scope = 'stores') $configCollection = Mage::getResourceModel('core/config_data_collection') ->addFieldToFilter('path', array('eq' => $path)) ->addFieldToFilter('scope_id', array('in' => $scopeIdsArray)); - $scopeSoFar = null; + foreach ($configCollection as $config) { //Discard possible extra website or store if ($this->isExtraEntry($config, $scope, $scopeId, $websiteId)) { @@ -3045,12 +3096,14 @@ public function getIfConfigExistsForScope($configPath, $scopeId, $scope = 'store $configAssociatedToScope = Mage::registry( 'mailchimp_' . $configName . '_exists_for_scope_' . $scope . '_' . $scopeId ); + if ($configAssociatedToScope === null) { $configAssociatedToScope = false; $collection = Mage::getResourceModel('core/config_data_collection') ->addFieldToFilter('path', array('eq' => $configPath)) ->addFieldToFilter('scope', array('eq' => $scope)) ->addFieldToFilter('scope_id', array('eq' => $scopeId)); + if ($collection->getSize()) { foreach ($collection as $config) { if ($config->getValue() !== null) { @@ -3138,6 +3191,7 @@ public function updateSubscriberSyndData( $syncDeleted = null ) { $subscriber = Mage::getModel('newsletter/subscriber')->load($itemId); + if ($subscriber->getId()) { if ($syncDelta) { $subscriber->setData("mailchimp_sync_delta", $syncDelta); @@ -3148,6 +3202,7 @@ public function updateSubscriberSyndData( } $subscriber->setData("mailchimp_sync_modified", $syncModified); + if ($syncDeleted) { $subscriber->setData("mailchimp_sync_deleted", $syncDeleted); } @@ -3204,7 +3259,7 @@ public function getApiStores() /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3219,7 +3274,7 @@ public function getCheckoutSubscribeValue($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return bool * @throws Mage_Core_Exception */ @@ -3235,7 +3290,7 @@ public function isCheckoutSubscribeEnabled($scopeId, $scope = 'stores') * * @param $syncValue * @param $scopeId - * @param string $scope + * @param string $scope * @throws Mage_Core_Exception */ protected function setIsSyncingIfFinishedPerScope($syncValue, $scopeId, $scope = 'stores') @@ -3244,6 +3299,7 @@ protected function setIsSyncingIfFinishedPerScope($syncValue, $scopeId, $scope = $mailchimpApi = $this->getApi($scopeId, $scope); $mailchimpStoreId = $this->getMCStoreId($scopeId, $scope); $isSyncing = $this->getMCIsSyncing($mailchimpStoreId, $scopeId, $scope); + if ($mailchimpStoreId && $isSyncing != 1) { $this->getApiStores()->editIsSyncing($mailchimpApi, $syncValue, $mailchimpStoreId); } @@ -3255,7 +3311,7 @@ protected function setIsSyncingIfFinishedPerScope($syncValue, $scopeId, $scope = /** * @param $value * @param $scopeId - * @param string $scope + * @param string $scope */ public function setResendTurn($value, $scopeId, $scope = 'stores') { @@ -3265,7 +3321,7 @@ public function setResendTurn($value, $scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3280,7 +3336,7 @@ public function getResendTurn($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3295,7 +3351,7 @@ public function getResendEnabled($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3310,7 +3366,7 @@ public function getCustomerResendLastId($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3325,7 +3381,7 @@ public function getProductResendLastId($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3340,7 +3396,7 @@ public function getOrderResendLastId($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3355,7 +3411,7 @@ public function getCartResendLastId($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3377,33 +3433,34 @@ public function getPromoCodeResendLastId($scopeId, $scope = 'stores') public function addResendFilter($collection, $magentoStoreId, $itemType) { $resendEnabled = $this->getResendEnabled($magentoStoreId); + if ($resendEnabled) { $resendTurn = $this->getResendTurn($magentoStoreId); $keyCol = 'entity_id'; switch ($itemType) { - case Ebizmarts_MailChimp_Model_Config::IS_ORDER: - $lastItemSent = $this->getOrderResendLastId($magentoStoreId); - break; - case Ebizmarts_MailChimp_Model_Config::IS_PRODUCT: - $lastItemSent = $this->getProductResendLastId($magentoStoreId); - break; - case Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER: - $lastItemSent = $this->getCustomerResendLastId($magentoStoreId); - break; - case Ebizmarts_MailChimp_Model_Config::IS_QUOTE: - $lastItemSent = $this->getCartResendLastId($magentoStoreId); - break; - case Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE: - $keyCol = "coupon_id"; - $lastItemSent = $this->getPromoCodeResendLastId($magentoStoreId); - break; - default: - $lastItemSent = 0; - $this->logError( - $this->__( - 'The item type sent in the filter does not match any of the available options.' - ) - ); + case Ebizmarts_MailChimp_Model_Config::IS_ORDER: + $lastItemSent = $this->getOrderResendLastId($magentoStoreId); + break; + case Ebizmarts_MailChimp_Model_Config::IS_PRODUCT: + $lastItemSent = $this->getProductResendLastId($magentoStoreId); + break; + case Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER: + $lastItemSent = $this->getCustomerResendLastId($magentoStoreId); + break; + case Ebizmarts_MailChimp_Model_Config::IS_QUOTE: + $lastItemSent = $this->getCartResendLastId($magentoStoreId); + break; + case Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE: + $keyCol = "coupon_id"; + $lastItemSent = $this->getPromoCodeResendLastId($magentoStoreId); + break; + default: + $lastItemSent = 0; + $this->logError( + $this->__( + 'The item type sent in the filter does not match any of the available options.' + ) + ); } if ($resendTurn) { @@ -3418,11 +3475,12 @@ public function addResendFilter($collection, $magentoStoreId, $itemType) * Check if all items have been sent and delete config values used in the resend process * * @param $scopeId - * @param string $scope + * @param string $scope */ public function handleResendFinish($scopeId, $scope = 'stores') { $allItemsSent = $this->allResendItemsSent($scopeId, $scope); + if ($allItemsSent) { $this->deleteResendConfigValues($scopeId, $scope); } @@ -3430,7 +3488,7 @@ public function handleResendFinish($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope */ protected function deleteResendConfigValues($scopeId, $scope = 'stores') { @@ -3447,7 +3505,7 @@ protected function deleteResendConfigValues($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return bool */ protected function allResendItemsSent($scopeId, $scope = 'stores') @@ -3481,6 +3539,7 @@ public function handleResendDataBefore() $resendTurn = $this->getResendTurn($scopeId, $scope); $resendEnabled = $this->getResendEnabled($scopeId, $scope); $ecommEnabled = $this->isEcomSyncDataEnabled($scopeId, $scope); + if ($ecommEnabled && $resendEnabled && $resendTurn) { $this->setIsSyncingIfFinishedPerScope(true, $scopeId, $scope); } @@ -3493,11 +3552,13 @@ public function handleResendDataBefore() public function handleResendDataAfter() { $configCollection = $this->getResendTurnConfigCollection(); + foreach ($configCollection as $config) { $scope = $config->getScope(); $scopeId = $config->getScopeId(); $resendTurn = $this->getResendTurn($scopeId, $scope); $ecommEnabled = $this->isEcomSyncDataEnabled($scopeId, $scope); + if ($ecommEnabled) { if ($resendTurn) { $this->setIsSyncingIfFinishedPerScope(false, $scopeId, $scope); @@ -3522,6 +3583,7 @@ public function handleResendDataAfter() protected function allResendItemsSentPerStoreView($storeId) { $customerId = $this->getCustomerResendLastId($storeId); + if ($customerId) { $isMissingCustomer = $this->isMissingItemLowerThanId( $customerId, @@ -3533,6 +3595,7 @@ protected function allResendItemsSentPerStoreView($storeId) } $productId = $this->getProductResendLastId($storeId); + if ($productId) { $isMissingProduct = $this->isMissingItemLowerThanId( $productId, @@ -3544,6 +3607,7 @@ protected function allResendItemsSentPerStoreView($storeId) } $orderId = $this->getOrderResendLastId($storeId); + if ($orderId) { $isMissingOrder = $this->isMissingItemLowerThanId( $orderId, @@ -3555,6 +3619,7 @@ protected function allResendItemsSentPerStoreView($storeId) } $cartId = $this->getCartResendLastId($storeId); + if ($cartId) { $isMissingCart = $this->isMissingItemLowerThanId( $cartId, @@ -3582,6 +3647,7 @@ protected function allResendItemsSentPerStoreView($storeId) protected function allResendItemsSentPerScope($stores) { $allItemsSent = true; + foreach ($stores as $store) { if ($store instanceof Mage_Core_Model_Store) { $storeId = $store->getId(); @@ -3590,6 +3656,7 @@ protected function allResendItemsSentPerScope($stores) } $allItemsSentInCurrentStore = $this->allResendItemsSentPerStoreView($storeId); + if (!$allItemsSentInCurrentStore) { $allItemsSent = false; } @@ -3607,21 +3674,21 @@ protected function allResendItemsSentPerScope($stores) protected function isMissingItemLowerThanId($itemId, $itemType, $mailchimpStoreId) { switch ($itemType) { - case Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER: - $isMissing = $this->isMissingCustomerLowerThanId($itemId, $mailchimpStoreId); - break; - case Ebizmarts_MailChimp_Model_Config::IS_PRODUCT: - $isMissing = $this->isMissingProductLowerThanId($itemId, $mailchimpStoreId); - break; - case Ebizmarts_MailChimp_Model_Config::IS_ORDER: - $isMissing = $this->isMissingOrderLowerThanId($itemId, $mailchimpStoreId); - break; - case Ebizmarts_MailChimp_Model_Config::IS_QUOTE: - $isMissing = $this->isMissingQuoteLowerThanId($itemId, $mailchimpStoreId); - break; - default: - $isMissing = false; - break; + case Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER: + $isMissing = $this->isMissingCustomerLowerThanId($itemId, $mailchimpStoreId); + break; + case Ebizmarts_MailChimp_Model_Config::IS_PRODUCT: + $isMissing = $this->isMissingProductLowerThanId($itemId, $mailchimpStoreId); + break; + case Ebizmarts_MailChimp_Model_Config::IS_ORDER: + $isMissing = $this->isMissingOrderLowerThanId($itemId, $mailchimpStoreId); + break; + case Ebizmarts_MailChimp_Model_Config::IS_QUOTE: + $isMissing = $this->isMissingQuoteLowerThanId($itemId, $mailchimpStoreId); + break; + default: + $isMissing = false; + break; } return $isMissing; @@ -3689,6 +3756,7 @@ protected function isMissingOrderLowerThanId($itemId, $storeId) ->addFieldToFilter('store_id', array('eq' => $storeId)) ->addFieldToFilter('entity_id', array('lteq' => $itemId)); $firstDate = $this->getEcommerceFirstDate($storeId); + if ($firstDate) { $orderCollection->addFieldToFilter('created_at', array('gt' => $firstDate)); } @@ -3696,6 +3764,7 @@ protected function isMissingOrderLowerThanId($itemId, $storeId) Mage::getModel('mailchimp/api_orders') ->joinMailchimpSyncDataWithoutWhere($orderCollection, $mailchimpStoreId); $orderCollection->getSelect()->where("m4m.mailchimp_sync_delta IS null"); + if ($orderCollection->getSize()) { $isMissing = true; } else { @@ -3720,6 +3789,7 @@ protected function isMissingQuoteLowerThanId($itemId, $storeId) ->addFieldToFilter('customer_email', array('notnull' => true)) ->addFieldToFilter('items_count', array('gt' => 0)); $firstDate = $this->getAbandonedCartFirstDate($storeId); + if ($firstDate) { $quoteCollection->addFieldToFilter('updated_at', array('gt' => $firstDate)); } @@ -3727,6 +3797,7 @@ protected function isMissingQuoteLowerThanId($itemId, $storeId) Mage::getModel('mailchimp/api_carts') ->joinMailchimpSyncDataWithoutWhere($quoteCollection, $mailchimpStoreId); $quoteCollection->getSelect()->where("m4m.mailchimp_sync_delta IS null"); + if ($quoteCollection->getSize()) { $isMissing = true; } else { @@ -3739,15 +3810,17 @@ protected function isMissingQuoteLowerThanId($itemId, $storeId) /** * @param $campaignId * @param $scopeId - * @param string $scope + * @param string $scope * @return null */ public function getMailChimpCampaignNameById($campaignId, $scopeId, $scope = 'stores') { $campaignName = null; + try { $api = $this->getApi($scopeId, $scope); $campaignData = $api->campaigns->get($campaignId); + if (isset($campaignData['settings'])) { if (isset($campaignData['settings']['title'])) { $campaignName = $campaignData['settings']['title']; @@ -3847,7 +3920,7 @@ public function getSubscriberAmountLimit() /** * @param $scopeId - * @param string $scope + * @param string $scope * @return string * @throws Mage_Core_Exception * @throws Mage_Core_Model_Store_Exception @@ -3856,6 +3929,7 @@ public function getStoreLanguageCode($scopeId, $scope = 'stores') { $isAdmin = $this->isAdmin(); $userLangCode = Mage::app()->getLocale()->getLocaleCode(); + if ($isAdmin || '' == $lang = $this->_langToMCLanguage($userLangCode)) { // IS Admin OR if users lang is not supported, try store views default locale $userLangCode = $this->getConfigValueForScope( @@ -3871,7 +3945,7 @@ public function getStoreLanguageCode($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3882,7 +3956,7 @@ public function getStoreTimeZone($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -3899,6 +3973,7 @@ public function getAllMailChimpStoreIds() $collection = Mage::getResourceModel('core/config_data_collection') ->addFieldToFilter('path', array('eq' => Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID)); $mailchimpStoreIdsArray = array(); + foreach ($collection as $row) { $scopeData = $row->getScope() . '_' . $row->getScopeId(); $mailchimpStoreIdsArray[$scopeData] = $row->getValue(); @@ -3909,12 +3984,13 @@ public function getAllMailChimpStoreIds() /** * @param $subscriber - * @param bool $forceUpdateStatus + * @param bool $forceUpdateStatus */ public function subscribeMember($subscriber, $forceUpdateStatus = false) { $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED); $subscriber->setSubscriberConfirmCode($subscriber->randomSequence()); + if ($forceUpdateStatus) { $subscriber->setMailchimpSyncModified(1); } @@ -4006,6 +4082,7 @@ protected function getResendTurnConfigCollection() { $configCollection = Mage::getResourceModel('core/config_data_collection') ->addFieldToFilter('path', array('eq' => Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_TURN)); + return $configCollection; } @@ -4072,6 +4149,7 @@ public function isNewApiKeyForSameAccount($oldApiKey, $newApiKey) $api = $this->getApiByKey($newApiKey); $newInfo = $api->getRoot()->info('account_id'); $newAccountId = $newInfo['account_id']; + if ($oldAccountId == $newAccountId) { $isNewApiKeyForSameAccount = true; } @@ -4116,6 +4194,7 @@ protected function getAllStoresForScope($scopeId, $scope) switch ($scope) { case 'default': $stores = $this->getMageApp()->getStores(); + foreach ($stores as $storeId => $store) { $storesResult[] = $storeId; } @@ -4142,11 +4221,13 @@ protected function makeWhereString($connection, $scopeId, $scope) { $storesForScope = $this->getMagentoStoresForMCStoreIdByScope($scopeId, $scope); $whereString = "mailchimp_campaign_id IS NOT NULL"; + if (!empty($storesForScope)) { $whereString .= " AND ("; } $counter = 0; + foreach ($storesForScope as $storeId) { if ($counter) { $whereString .= " OR "; @@ -4188,7 +4269,7 @@ protected function _langToMCLanguage($languageCode = '') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return bool * @throws Mage_Core_Exception */ @@ -4203,7 +4284,7 @@ public function isSubscriptionConfirmationEnabled($scopeId, $scope = 'stores') /** * @param $scopeId - * @param null $scope + * @param null $scope * @return mixed * @throws Mage_Core_Exception */ @@ -4261,6 +4342,7 @@ protected function getSyncFlagDataArray($dat) $textArray = explode(': ', $dat['label']); //textArray indexes = 0 -> label / 1 -> status $textArray = $this->fixTimeTextIfNecessary($textArray); + return $textArray; } @@ -4294,9 +4376,11 @@ protected function isDate($textArray) public function getListIdByApiKeyAndMCStoreId($apiKey, $mailchimpStoreId) { $listId = false; + try { $api = $this->getApiByKey($apiKey); $mcStore = $api->getEcommerce()->getStores()->get($mailchimpStoreId, 'list_id'); + if (isset($mcStore['list_id'])) { $listId = $mcStore['list_id']; } @@ -4319,9 +4403,11 @@ public function getListIdByApiKeyAndMCStoreId($apiKey, $mailchimpStoreId) public function getListInterestCategoriesByKeyAndList($apiKey, $listId) { $interestGroupsArray = array(); + try { $api = $this->getApiByKey($apiKey); $interestCategories = $api->getLists()->getInterestCategory()->getAll($listId, 'categories'); + foreach ($interestCategories['categories'] as $interestCategory) { $interestGroupsArray[] = array( 'id' => $interestCategory['id'], @@ -4351,6 +4437,7 @@ public function getListInterestGroups($scopeId, $scope = 'stores') $interestGroupsArray = array(); $api = $this->getApi($scopeId, $scope); $listId = $this->getGeneralList($scopeId, $scope); + try { $apiInterestCategory = $api->getLists()->getInterestCategory(); $interestCategories = $apiInterestCategory->getAll($listId, 'categories'); @@ -4394,7 +4481,7 @@ public function getLocalInterestCategories($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -4409,7 +4496,7 @@ public function getCheckoutSuccessHtmlBefore($scopeId, $scope = 'stores') /** * @param $scopeId - * @param string $scope + * @param string $scope * @return mixed * @throws Mage_Core_Exception */ @@ -4440,6 +4527,7 @@ public function getInterest($storeId) $api = $this->getApi($storeId); $listId = $this->getGeneralList($storeId); + try { $apiInterestCategory = $api->getLists()->getInterestCategory(); $allInterest = $apiInterestCategory->getAll($listId); @@ -4459,6 +4547,7 @@ public function getInterest($storeId) foreach ($interest as $interestId) { $mailchimpInterest = $apiInterestCategoryInterest->getAll($listId, $interestId); + foreach ($mailchimpInterest['interests'] as $mi) { $rc[$mi['category_id']]['category'][$mi['display_order']] = array( @@ -4479,7 +4568,7 @@ public function getInterest($storeId) * @param $customerId * @param $subscriberId * @param $storeId - * @param null $interest + * @param null $interest * @return array|null * @throws Mage_Core_Exception * @throws MailChimp_Error @@ -4684,6 +4773,7 @@ public function getAllApiKeys() foreach ($stores as $storeId => $store) { try { $apiKey = $this->getApiKey($storeId); + if (!isset($ret[$apiKey])) { $ret[$apiKey] = $apiKey; } @@ -4794,7 +4884,7 @@ protected function getModelMailchimpEcommerceSyncData() /** * @param $index - * @param int $increment + * @param int $increment */ public function modifyCounterSentPerBatch($index, $increment = 1) { @@ -4820,7 +4910,7 @@ public function getCountersSentPerBatch() /** * @param $index - * @param int $increment + * @param int $increment */ public function modifyCounterSubscribers($index, $increment = 1) { @@ -4846,8 +4936,8 @@ public function getCountersSubscribers() /** * @param $index - * @param bool $hasError - * @param int $increment + * @param bool $hasError + * @param int $increment */ public function modifyCounterDataSentToMailchimp($index, $hasError = false, $increment = 1) { @@ -4921,6 +5011,7 @@ public function isApiKeyObscure($apiKey) public function getApiKeyValue() { $scopeArray = $this->getCurrentScope(); + return $this->getApiKey($scopeArray['scope_id'], $scopeArray['scope']); } @@ -5046,8 +5137,8 @@ public function serialize($value, array $options = array()) /** * Creates a PHP value from a stored representation using the default adapter. * - * @param string $serialized - * @param array $options + * @param string $serialized + * @param array $options * @return mixed * @throws Zend_Serializer_Exception */ @@ -5097,7 +5188,8 @@ protected function setEcommerceSyncDataItemValues( $deletedRelatedId, $allowBatchRemoval, Varien_Object $ecommerceSyncDataItem - ) { + ) + { if ($syncDelta) { $ecommerceSyncDataItem->setData("mailchimp_sync_delta", $syncDelta); } elseif ($allowBatchRemoval === true) { diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Date.php b/app/code/community/Ebizmarts/MailChimp/Helper/Date.php index b1bfdedb2..ddd7950d5 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Date.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Date.php @@ -63,9 +63,9 @@ public function getCurrentDateTime() * Return date in given format in UTC * or the timezone of the current store ($useStoreTime = true). * - * @param string $format - * @param $date - * @param bool $avoidOffset + * @param string $format + * @param $date + * @param bool $avoidOffset * @return mixed * @throws Mage_Core_Model_Store_Exception */ @@ -89,7 +89,7 @@ public function formatDate($date = null, $format = 'Y-m-d', $useStoreTime = fals protected function _convertUTCToStoreTimestamp($timestamp) { $timeZone = Mage::app()->getStore()->getConfig('general/locale/timezone'); - $offSet = Mage::getModel('core/date')->calculateOffset($timeZone); + $offSet = Mage::getModel('core/date')->calculateOffset($timeZone); return ($timestamp + $offSet); } diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Mandrill.php b/app/code/community/Ebizmarts/MailChimp/Helper/Mandrill.php index 42717d178..e18314f74 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Mandrill.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Mandrill.php @@ -1,4 +1,5 @@ Configuration, section * - * @param Varien_Event_Observer $observer - * @return Varien_Event_Observer - * @throws Mage_Core_Exception + * @param Varien_Event_Observer $observer + * @return Varien_Event_Observer + * @throws Mage_Core_Exception */ public function saveConfigBefore(Varien_Event_Observer $observer) { @@ -189,9 +189,9 @@ protected function isListXorStoreInherited($configData) /** * Handle confirmation emails and subscription to Mailchimp * - * @param Varien_Event_Observer $observer - * @return Varien_Event_Observer - * @throws Mage_Core_Exception + * @param Varien_Event_Observer $observer + * @return Varien_Event_Observer + * @throws Mage_Core_Exception */ public function subscriberSaveBefore(Varien_Event_Observer $observer) { @@ -219,10 +219,10 @@ public function subscriberSaveBefore(Varien_Event_Observer $observer) /** * Handle interest groups for subscriber and allow Magento email to be sent if configured that way. * - * @param Varien_Event_Observer $observer - * @return Varien_Event_Observer - * @throws Mage_Core_Exception - * @throws Mage_Core_Model_Store_Exception + * @param Varien_Event_Observer $observer + * @return Varien_Event_Observer + * @throws Mage_Core_Exception + * @throws Mage_Core_Model_Store_Exception */ public function subscriberSaveAfter(Varien_Event_Observer $observer) { @@ -1123,10 +1123,10 @@ protected function getRequest() /** * Handle frontend customer interest groups only if is not subscribed and all admin customer groups. * - * @param $subscriberEmail - * @param $params - * @param $storeId - * @param null $customerId + * @param $subscriberEmail + * @param $params + * @param $storeId + * @param null $customerId * @return Mage_Newsletter_Model_Subscriber * @throws Mage_Core_Model_Store_Exception */ diff --git a/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php b/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php index f4f95f02a..2e77c4389 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php @@ -87,7 +87,7 @@ public function processWebhookData() /** * Update customer email * - * @param array $data + * @param array $data * @return void */ protected function _updateEmail(array $data) @@ -116,7 +116,7 @@ protected function _updateEmail(array $data) /** * Add "Cleaned Emails" notification to Adminnotification Inbox * - * @param array $data + * @param array $data * @return void */ protected function _clean(array $data) @@ -137,7 +137,7 @@ protected function _clean(array $data) /** * Subscribe email to Magento list, store aware * - * @param array $data + * @param array $data * @return void */ protected function _subscribe(array $data) @@ -174,7 +174,7 @@ protected function _subscribe(array $data) /** * Unsubscribe or delete email from Magento list, store aware * - * @param array $data + * @param array $data * @return void */ protected function _unsubscribe(array $data) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Stores.php b/app/code/community/Ebizmarts/MailChimp/Model/Stores.php index b3cf97407..7312b8914 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Stores.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Stores.php @@ -1,4 +1,5 @@ getCode()==$code) { + if ($this->getCode() == $code) { $this->setStatus(self::STATUS_SUBSCRIBED) ->setIsStatusChanged(true) ->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_CONFIRMATION) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Fieldtype.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Fieldtype.php index 00a4318e5..63842bea6 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Fieldtype.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Fieldtype.php @@ -1,4 +1,5 @@ * File : Fieldtype.php diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/ImageSize.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/ImageSize.php index fb924a52d..a2a88086a 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/ImageSize.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/ImageSize.php @@ -1,4 +1,5 @@ getStoreValuesForForm(false, true); } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/OrderGrid.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/OrderGrid.php index 96a7699b3..24d5a357c 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/OrderGrid.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/OrderGrid.php @@ -1,4 +1,5 @@ self::ICON, 'label' => $helper->__('Icon for Mailchimp orders')), array('value' => self::SYNCED, 'label' => $helper->__('If orders are synced to Mailchimp')), array('value' => self::BOTH, 'label' => $helper->__('Both')) - ); } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Store.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Store.php index 5f1cca3e3..6aa9e4adf 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Store.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Store.php @@ -56,9 +56,10 @@ public function toOptionArray() if (isset($mcStores['stores'])) { $stores[] = array('value' => '', 'label' => $helper->__('--- Select a Mailchimp Store ---')); + foreach ($mcStores['stores'] as $store) { if ($store['platform'] == 'Magento') { - if ($store['list_id']=='') { + if ($store['list_id'] == '') { continue; } @@ -68,7 +69,7 @@ public function toOptionArray() $label = $store['name'] . ' (' . $helper->__("Warning: not connected") . ')'; } - $stores[] = array('value'=> $store['id'], 'label' => $label); + $stores[] = array('value' => $store['id'], 'label' => $label); } } } else { diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Userinfo.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Userinfo.php index 9151d5994..970b06c7a 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Userinfo.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Userinfo.php @@ -38,7 +38,7 @@ public function __construct() } if ((!is_array($this->_accountDetails) - || isset($this->_accountDetails['status'])) + || isset($this->_accountDetails['status'])) && $mandillHelper->getMandrillApiKey($storeId) ) { $api = new Mandrill_Message($mandillHelper->getMandrillApiKey($storeId)); @@ -83,8 +83,8 @@ public function toOptionArray() 'Hourly Quota: %s %s', $this->_accountDetails['hourly_quota'], "the maximum number of emails Mandrill will deliver for this user each hour. " - . "Any emails beyond that will be accepted and queued for later delivery. " - . "Users with higher reputations will have higher hourly quotas" + . "Any emails beyond that will be accepted and queued for later delivery. " + . "Users with higher reputations will have higher hourly quotas" ) ), array( diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/WebhookDelete.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/WebhookDelete.php index ac9c20e4c..f6e5d538c 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/WebhookDelete.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/WebhookDelete.php @@ -1,4 +1,5 @@ getParam('scope'); $scopeId = $request->getParam('scope_id'); $success = 1; + try { $stores = $mageApp->getStores(); + if ($scopeId == 0) { foreach ($stores as $store) { $helper->resetErrors($store->getId()); @@ -51,8 +54,8 @@ public function resendEcommerceDataAction() $filters = $request->getParam('filter'); $scope = $request->getParam('scope'); $scopeId = $request->getParam('scope_id'); - $success = 0; + if (is_array($filters) && empty($filters)) { $this->addWarning($helper->__('At least one type of eCommerce data should be selected to Resend.')); $success = $helper->__('Redirecting... ') @@ -85,6 +88,7 @@ public function createMergeFieldsAction() $scopeId = $request->getParam('scope_id'); $success = 0; $subEnabled = $helper->isSubscriptionEnabled($scopeId, $scope); + if ($subEnabled) { $success = $helper->createMergeFields($scopeId, $scope); } diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php index 078c9366e..77562e056 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php @@ -1,4 +1,5 @@ getRequest()->getParams(); + if (isset($params['id'])) { //restore the quote $quote = Mage::getModel('sales/quote')->load($params['id']); @@ -30,8 +31,9 @@ public function loadquoteAction() $mailchimpStoreId ); $url = Mage::getUrl(Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::ABANDONEDCART_PAGE, $storeId)); + if (isset($params['mc_cid'])) { - $url .= '?mc_cid='.$params['mc_cid']; + $url .= '?mc_cid=' . $params['mc_cid']; } if (!isset($params['token']) || $params['token'] != $quoteSyncData->getMailchimpToken()) { @@ -41,9 +43,11 @@ public function loadquoteAction() } else { $quote->setMailchimpAbandonedcartFlag(1); $quote->save(); + if (!$quote->getCustomerId()) { $this->_getSession()->setQuoteId($quote->getId()); $newQuote = $this->_getSession()->getQuote(); + if ($newQuote->getId() != $quote->getId()) { $newQuote = $this->_getSession()->getQuote(); $newQuote->delete(); @@ -61,8 +65,9 @@ public function loadquoteAction() Mage::getSingleton('customer/session')->addNotice("Login to complete your order"); Mage::getSingleton('customer/session')->setAfterAuthUrl($url, $storeId); $url = Mage::getUrl('customer/account/login'); + if (isset($params['mc_cid'])) { - $url .= '?mc_cid='.$params['mc_cid']; + $url .= '?mc_cid=' . $params['mc_cid']; } $this->getResponse()->setRedirect($url, 301); @@ -75,6 +80,7 @@ public function loadquoteAction() public function loadcouponAction() { $params = $this->getRequest()->getParams(); + if (isset($params['coupon_id']) && isset($params['coupon_token'])) { $helper = Mage::helper('mailchimp'); $id = $params['coupon_id']; @@ -89,14 +95,17 @@ public function loadcouponAction() $mailchimpStoreId ); $couponId = $promoCodeSyncData->getRelatedId(); + if ($couponId && $promoCodeSyncData->getMailchimpToken() == $token) { $coupon = Mage::getModel('salesrule/coupon')->load($couponId); + if ($coupon->getId()) { $code = $coupon->getCode(); Mage::getSingleton("checkout/session")->setData("coupon_code", $code); $quote = Mage::getSingleton('checkout/cart')->getQuote(); $quote->setCouponCode($code)->save(); Mage::getSingleton('core/session')->addSuccess($this->__('Coupon was automatically applied.')); + if (!$quote->getItemsCount()) { Mage::getSingleton('core/session') ->addWarning( diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php b/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php index 5f093c6a4..c1a15d317 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php @@ -26,6 +26,7 @@ public function indexAction() $customerId = $order->getCustomerId(); $subscriber = $this->getSubscriberModel() ->loadByEmail($customerEmail); + try { if (!$subscriber->getSubscriberId()) { $subscriber->setSubscriberEmail($customerEmail); diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php b/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php index 91e9381e3..e1a7fa8e7 100755 --- a/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/WebhookController.php @@ -36,12 +36,15 @@ public function indexAction() $moduleName = $request->getModuleName(); $data = $request->getPost(); $helper = $this->getHelper(); + if ($moduleName == 'monkey') { if (isset($data['data']['list_id'])) { $listId = $data['data']['list_id']; $storeIds = $helper->getMagentoStoreIdsByListId($listId); + if (!empty($storeIds)) { $storeId = $storeIds[0]; + if ($helper->isSubscriptionEnabled($storeId)) { $this->_deleteWebhook($storeId, $listId); } diff --git a/app/code/community/Ebizmarts/MailChimp/etc/adminhtml.xml b/app/code/community/Ebizmarts/MailChimp/etc/adminhtml.xml index cb8cc5672..b8bd67c2c 100644 --- a/app/code/community/Ebizmarts/MailChimp/etc/adminhtml.xml +++ b/app/code/community/Ebizmarts/MailChimp/etc/adminhtml.xml @@ -10,7 +10,7 @@ Mailchimp Errors 810 adminhtml/mailchimperrors/index - + Mailchimp Stores 820 diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml index 374283082..379ed18ad 100644 --- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml +++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml @@ -369,8 +369,10 @@ 1 - - + + + + 3 200 20 @@ -392,8 +394,10 @@ 1 1 - - + + + + 100 diff --git a/app/code/community/Ebizmarts/MailChimp/etc/system.xml b/app/code/community/Ebizmarts/MailChimp/etc/system.xml index 493df1e91..496e279e0 100644 --- a/app/code/community/Ebizmarts/MailChimp/etc/system.xml +++ b/app/code/community/Ebizmarts/MailChimp/etc/system.xml @@ -37,7 +37,8 @@ select adminhtml/system_config_source_yesno - Mailchimp's additional terms.]]> + + Mailchimp's additional terms.]]> mailchimp/system_config_backend_active 10 1 @@ -112,7 +113,8 @@ 1 1 1 - + + @@ -133,7 +135,8 @@ 1 1 1 - + + @@ -187,7 +190,8 @@ 1 1 1 - + + @@ -197,7 +201,8 @@ 1 1 1 - See recommended configuration here.]]> + + See recommended configuration here.]]> @@ -207,7 +212,8 @@ 1 1 1 - + + @@ -217,7 +223,8 @@ 1 1 1 - + + @@ -238,7 +245,8 @@ 1 1 1 - + + @@ -249,7 +257,8 @@ 1 1 1 - + + diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Adminhtml/NotificationsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Adminhtml/NotificationsTest.php index d0eef9e28..9accb212b 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Adminhtml/NotificationsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Adminhtml/NotificationsTest.php @@ -1,4 +1,5 @@ disableOriginalConstructor() ->setMethods( array('getResendTurnConfigCollection', 'getResendTurn', 'getResendEnabled', - 'setIsSyncingIfFinishedPerScope', 'isEcomSyncDataEnabled') + 'setIsSyncingIfFinishedPerScope', 'isEcomSyncDataEnabled') ) ->getMock(); @@ -271,7 +271,7 @@ public function testHandleResendDataAfter() ->disableOriginalConstructor() ->setMethods( array('getResendTurnConfigCollection', 'getResendTurn', 'setIsSyncingIfFinishedPerScope', - 'setResendTurn', 'handleResendFinish', 'isEcomSyncDataEnabled') + 'setResendTurn', 'handleResendFinish', 'isEcomSyncDataEnabled') ) ->getMock(); @@ -338,7 +338,7 @@ public function testHandleWebhookChange() ->disableOriginalConstructor() ->setMethods( array('getRealScopeForConfig', 'getGeneralList', 'deleteCurrentWebhook', - 'isSubscriptionEnabled', 'createNewWebhook') + 'isSubscriptionEnabled', 'createNewWebhook') ) ->getMock(); @@ -376,7 +376,7 @@ public function testGetReSizedImageUrlById($data) ->disableOriginalConstructor() ->setMethods( array('getProductResourceModel', 'getProductModel', 'getImageSize', 'getCurrentStoreId', - 'setCurrentStore', 'getImageUrl', 'getImageUrlForSize') + 'setCurrentStore', 'getImageUrl', 'getImageUrlForSize') ) ->getMock(); @@ -464,7 +464,7 @@ public function testGetOriginalImageUrlById() ->disableOriginalConstructor() ->setMethods( array('getProductResourceModel', 'getProductModel', 'getImageSize', 'getCurrentStoreId', - 'setCurrentStore', 'getImageUrl', 'getOriginalPath') + 'setCurrentStore', 'getImageUrl', 'getOriginalPath') ) ->getMock(); @@ -597,11 +597,11 @@ public function testRemoveEcommerceSyncDataDeleteAll() $mailchimpEcommTableName = 'mailchimp_ecommerce_sync_data'; $mailchimpStoreId = 'a1s2d3f4g5h6j7k8l9n0'; - $storeReturnWhere = "mailchimp_store_id = ".$mailchimpStoreId; + $storeReturnWhere = "mailchimp_store_id = " . $mailchimpStoreId; $storeWhere = "mailchimp_store_id = ?"; $mailchimpFilters = Ebizmarts_MailChimp_Model_Config::IS_ORDER; - $filterReturnWhere = "type IN (".$mailchimpFilters.')'; + $filterReturnWhere = "type IN (" . $mailchimpFilters . ')'; $filterWhere = "type IN (?)"; $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -689,7 +689,7 @@ public function testRemoveEcommerceSyncDataErrorsOnlyForStoreView() public function testRemoveAllEcommerceSynddataErrors() { $mailchimpFilters = Ebizmarts_MailChimp_Model_Config::IS_ORDER; - $filterReturnWhere = "type IN (".$mailchimpFilters.')'; + $filterReturnWhere = "type IN (" . $mailchimpFilters . ')'; $filterWhere = "type IN (?)"; $tableName = 'mailchimp_ecommerce_sync_data'; @@ -743,7 +743,7 @@ public function testRemoveEcommerceSyncDataByMCStore() $storeReturnWhere = "mailchimp_store_id = $mailchimpStoreId AND mailchimp_sync_error != ''"; $mailchimpFilters = Ebizmarts_MailChimp_Model_Config::IS_ORDER; - $filterReturnWhere = "type IN (".$mailchimpFilters.')'; + $filterReturnWhere = "type IN (" . $mailchimpFilters . ')'; $filterWhere = "type IN (?)"; $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -795,11 +795,11 @@ public function testClearErrorGridExcludeSubscribers() $mailchimpEcommTableName = 'mailchimp_errors'; $mailchimpStoreId = 'a1s2d3f4g5h6j7k8l9n0'; - $storeReturnWhere = "mailchimp_store_id = ".$mailchimpStoreId; + $storeReturnWhere = "mailchimp_store_id = " . $mailchimpStoreId; $storeWhere = "mailchimp_store_id = ?"; $mailchimpFilters = Ebizmarts_MailChimp_Model_Config::IS_ORDER; - $filterReturnWhere = "type IN (".$mailchimpFilters.')'; + $filterReturnWhere = "type IN (" . $mailchimpFilters . ')'; $filterWhere = "type IN (?)"; $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -851,13 +851,9 @@ public function testClearErrorGridIncludeSubscribersForDefaultScope() $connectionType = 'core_write'; $mailchimpEcommTableAlias = 'mailchimp/mailchimperrors'; $mailchimpEcommTableName = 'mailchimp_errors'; - $mailchimpStoreId = 'a1s2d3f4g5h6j7k8l9n0'; - $storeReturnWhere = "store_id = ".$mailchimpStoreId; - $storeWhere = "store_id = ?"; - $mailchimpFilters = Ebizmarts_MailChimp_Model_Config::IS_ORDER; - $filterReturnWhere = "type IN (".$mailchimpFilters.')'; + $filterReturnWhere = "type IN (" . $mailchimpFilters . ')'; $filterWhere = "type IN (?)"; $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -911,7 +907,7 @@ public function testClearErrorGridIncludeSubscribersForStoreView() $mailchimpEcommTableName = 'mailchimp_errors'; $mailchimpStoreId = 'a1s2d3f4g5h6j7k8l9n0'; - $storeReturnWhere = "store_id = ". $scopeId; + $storeReturnWhere = "store_id = " . $scopeId; $storeWhere = "store_id = ?"; $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) @@ -1053,7 +1049,7 @@ public function testSaveLastItemsSent() Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER, Ebizmarts_MailChimp_Model_Config::IS_ORDER, Ebizmarts_MailChimp_Model_Config::IS_QUOTE, - Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE. ', ' . Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE); + Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE . ', ' . Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE); $resendEnabled = 1; $resendTurn = 1; @@ -1543,7 +1539,7 @@ public function testSaveInterestGroupData() ->disableOriginalConstructor() ->setMethods( array('getByRelatedIdStoreId', 'getSubscriberId', 'getCustomerId', 'setSubscriberId', - 'setCustomerId', 'setGroupdata', 'getGroupdata', 'setStoreId', 'setUpdatedAt', 'save') + 'setCustomerId', 'setGroupdata', 'getGroupdata', 'setStoreId', 'setUpdatedAt', 'save') ) ->getMock(); @@ -1621,7 +1617,7 @@ public function testGetMCJs() ->disableOriginalConstructor() ->setMethods( array('getMageApp', 'isEcomSyncDataEnabled', 'getConfigValueForScope', - 'retrieveAndSaveMCJsUrlInConfig', 'getMCStoreId') + 'retrieveAndSaveMCJsUrlInConfig', 'getMCStoreId') ) ->getMock(); @@ -1816,39 +1812,39 @@ public function testSetCurrentStore() public function testGetCurrentStoreId() { - $storeId = 1; - $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) - ->disableOriginalConstructor() - ->setMethods(array('getMageApp')) - ->getMock(); - - $mageAppMock = $this->getMockBuilder(Mage_Core_Model_App::class) - ->disableOriginalConstructor() - ->setMethods(array('getStore')) - ->getMock(); - - $mageAppMockStore = $this->getMockBuilder(Mage_Core_Model_Store::class) - ->disableOriginalConstructor() - ->setMethods(array('getId')) - ->getMock(); - - $helperMock - ->expects($this->once()) - ->method('getMageApp') - ->willReturn($mageAppMock); - - $mageAppMock - ->expects($this->once()) - ->method('getStore') - ->willReturn($mageAppMockStore); - - $mageAppMockStore - ->expects($this->once()) - ->method('getId')->willReturn($storeId); - - $return = $helperMock->getCurrentStoreId(); - - $this->assertInternalType('int', $return); + $storeId = 1; + $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) + ->disableOriginalConstructor() + ->setMethods(array('getMageApp')) + ->getMock(); + + $mageAppMock = $this->getMockBuilder(Mage_Core_Model_App::class) + ->disableOriginalConstructor() + ->setMethods(array('getStore')) + ->getMock(); + + $mageAppMockStore = $this->getMockBuilder(Mage_Core_Model_Store::class) + ->disableOriginalConstructor() + ->setMethods(array('getId')) + ->getMock(); + + $helperMock + ->expects($this->once()) + ->method('getMageApp') + ->willReturn($mageAppMock); + + $mageAppMock + ->expects($this->once()) + ->method('getStore') + ->willReturn($mageAppMockStore); + + $mageAppMockStore + ->expects($this->once()) + ->method('getId')->willReturn($storeId); + + $return = $helperMock->getCurrentStoreId(); + + $this->assertInternalType('int', $return); } public function testResetErrors() @@ -1886,7 +1882,7 @@ public function testGetMagentoStoresForMCStoreIdByScope() $storeRelation = array( 'a1s2d3f4g5h6j7k8l9p0' => 1, 'a1s2d3f5h6h6j7k8l9p0' => 2 - ); + ); $helperDataMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() @@ -1920,11 +1916,11 @@ public function testCreateMergeFields() 's:7:"magento";s:1:"5";}}'; $mapFieldsUnserialized = array( - "_1468601283719_719", array("mailchimp", "WEBSITE", "magento", "1"), "_1468609069544_544", - array("mailchimp", "STOREID", "magento", "2"), "_1469026825907_907", - array("mailchimp", "STORENAME", "magento", "3"), - "_1469027411717_717", array("mailchimp","PREFIX","magento", "4"), "_1469027418285_285", - array("mailchimp", "FNAME", "magento", "5") + "_1468601283719_719", array("mailchimp", "WEBSITE", "magento", "1"), "_1468609069544_544", + array("mailchimp", "STOREID", "magento", "2"), "_1469026825907_907", + array("mailchimp", "STORENAME", "magento", "3"), + "_1469027411717_717", array("mailchimp", "PREFIX", "magento", "4"), "_1469027418285_285", + array("mailchimp", "FNAME", "magento", "5") ); $arrayMergeFieldsGetAll = array @@ -1961,9 +1957,9 @@ public function testCreateMergeFields() "href" => "https://us20.api.mailchimp.com/3.0/lists/b514eebd1a/merge-fields", "method" => "GET", "targetSchema" => "https://us20.api.mailchimp.com" - . "/schema/3.0/Definitions/Lists/MergeFields/CollectionResponse.json", + . "/schema/3.0/Definitions/Lists/MergeFields/CollectionResponse.json", "schema" => "https://us20.api.mailchimp.com" - . "/schema/3.0/CollectionLinks/Lists/MergeFields.json", + . "/schema/3.0/CollectionLinks/Lists/MergeFields.json", ), 2 => array @@ -1972,7 +1968,7 @@ public function testCreateMergeFields() "href" => "https://us20.api.mailchimp.com/3.0/lists/b514eebd1a/merge-fields/3", "method" => "PATCH", "targetSchema" => "https://us20.api.mailchimp.com" - . "/schema/3.0/Definitions/Lists/MergeFields/Response.json", + . "/schema/3.0/Definitions/Lists/MergeFields/Response.json", "schema" => "https://us20.api.mailchimp.com" . "/schema/3.0/Definitions/Lists/MergeFields/PATCH.json", ), @@ -2066,7 +2062,7 @@ public function testGetCustomMergeFields() "_1468601283719_719", array("mailchimp", "WEBSITE", "magento", "1"), "_1468609069544_544", array("mailchimp", "STOREID", "magento", "2"), "_1469026825907_907", array("mailchimp", "STORENAME", "magento", "3"), - "_1469027411717_717", array("mailchimp","PREFIX","magento", "4"), "_1469027418285_285", + "_1469027411717_717", array("mailchimp", "PREFIX", "magento", "4"), "_1469027418285_285", array("mailchimp", "FNAME", "magento", "5") ); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php index 6ea852727..ea6050fbf 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php @@ -77,7 +77,7 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() $listId = "e4ef38998b"; $isSubscribed = false; - $patchBatchData = array ( + $patchBatchData = array( 'method' => 'PATCH', 'path' => '/lists/e4ef38998b/members/45c3ddfc868517aefd34ba8f122ad600', 'operation_id' => '_SUB_45c3ddfc868517aefd34ba8f122ad600', @@ -86,7 +86,7 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() "CUSBRAND":"brand pref."}}' ); - $mergeFields = array ( + $mergeFields = array( 'WEBSITE' => '1', 'STOREID' => '1', 'STORENAME' => 'Default Store View', @@ -121,7 +121,7 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() 'getOptInStatusForStore', 'getBatchMagentoStoreId', '_buildCustomerData', 'makePutBatchStructure', '_updateSyncData', 'setMailchimpStoreId', 'setMagentoStoreId', 'getCustomerResourceCollection', 'getSubscriberModel', 'getMailChimpHelper', - 'isSubscribed', 'makePatchBatchStructure', 'incrementCounterSentPerBatch','sendMailchimpTags' + 'isSubscribed', 'makePatchBatchStructure', 'incrementCounterSentPerBatch', 'sendMailchimpTags' ) ) ->getMock(); @@ -147,7 +147,7 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() $syncDataItemMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Ecommercesyncdata::class) ->disableOriginalConstructor() - ->setMethods(array('getId','getMailchimpSyncedFlag')) + ->setMethods(array('getId', 'getMailchimpSyncedFlag')) ->getMock(); $customerArray = array($customerMock); @@ -238,9 +238,9 @@ public function testCreateBatchJsonOptInFalseCustomerNotSubscribed() $customerMock, $listId, 1, - array( 0 => $operationData) + array(0 => $operationData) ) - ->willReturn(array( 0 => $rtnArray, 1 => 2 )); + ->willReturn(array(0 => $rtnArray, 1 => 2)); $return = $this->_customersApiMock->createBatchJson($mailchimpStoreId, $storeId); @@ -262,7 +262,7 @@ public function testCreateBatchJsonOptInTrueCustomerNotSubscribed() $listId = "e4ef38998b"; $isSubscribed = false; - $patchBatchData = array ( + $patchBatchData = array( 'method' => 'PATCH', 'path' => '/lists/e4ef38998b/members/45c3ddfc868517aefd34ba8f122ad600', 'operation_id' => '_SUB_45c3ddfc868517aefd34ba8f122ad600', @@ -271,7 +271,7 @@ public function testCreateBatchJsonOptInTrueCustomerNotSubscribed() "CUSBRAND":"brand pref."}}' ); - $mergeFields = array ( + $mergeFields = array( 'WEBSITE' => '1', 'STOREID' => '1', 'STORENAME' => 'Default Store View', @@ -334,7 +334,7 @@ public function testCreateBatchJsonOptInTrueCustomerNotSubscribed() $syncDataItemMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Ecommercesyncdata::class) ->disableOriginalConstructor() - ->setMethods(array('getId','getMailchimpSyncedFlag')) + ->setMethods(array('getId', 'getMailchimpSyncedFlag')) ->getMock(); $customerArray = array($customerMock); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php index c48e2280a..19bb41018 100755 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/OrdersTest.php @@ -74,7 +74,7 @@ public function testGetPromoData($type) $modelMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Orders::class) ->disableOriginalConstructor() - ->setMethods(array('makeSalesRuleCoupon','makeSalesRule','getSimpleAction')) + ->setMethods(array('makeSalesRuleCoupon', 'makeSalesRule', 'getSimpleAction')) ->getMock(); $orderMock = $this->getMockBuilder(Mage_Sales_Model_Order::class) @@ -167,7 +167,7 @@ public function testGeneratePOSTPayload() $customerEmail = 'test@ebizmarts.com'; $customerFirstName = 'testFirstName'; $billingAddressStreet = array('billingAddress1', 'billingAddress2'); - $currentDate = Mage::getSingleton('core/date'); + $currentDate = Mage::getSingleton('core/date'); $lines['itemsCount'] = 9; $lines[0] = array( @@ -213,7 +213,7 @@ public function testGeneratePOSTPayload() $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() - ->setMethods(array('getCurrentStoreId','setCurrentStore')) + ->setMethods(array('getCurrentStoreId', 'setCurrentStore')) ->getMock(); $subscriberMock = $this->getMockBuilder(Mage_Newsletter_Model_Subscriber::class) @@ -307,9 +307,9 @@ public function testGeneratePOSTPayload() ->method('getUrl') ->with( 'sales/order/view/', array( - 'order_id' => null, - '_nosid' => true, - '_secure' => true + 'order_id' => null, + '_nosid' => true, + '_secure' => true ) ) ->willReturn('http://somedomain.com'); @@ -367,9 +367,9 @@ public function testShouldSendCampaignId() ->disableOriginalConstructor() ->setMethods( array( - 'getGeneralList', - 'getApiKey', - 'getApi') + 'getGeneralList', + 'getApiKey', + 'getApi') ) ->getMock(); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php index 6b2833f3d..3e45d9284 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php @@ -60,9 +60,9 @@ public function testCreateBatchJson() $productsApiMock = $this->_productsApiMock ->setMethods( array('makeBatchId', 'makeProductsNotSentCollection', 'joinMailchimpSyncData', - 'shouldSendProductUpdate', 'getChildrenIdsForConfigurable', - 'getMailChimpHelper', 'isProductFlatTableEnabled', '_buildNewProductRequest', - '_updateSyncData', '_markSpecialPrices') + 'shouldSendProductUpdate', 'getChildrenIdsForConfigurable', + 'getMailChimpHelper', 'isProductFlatTableEnabled', '_buildNewProductRequest', + '_updateSyncData', '_markSpecialPrices') ) ->getMock(); @@ -635,7 +635,7 @@ public function testCreateDeletedProductsBatchJson() $productsApiMock = $this->_productsApiMock ->setMethods( array('getProductResourceCollection', 'joinMailchimpSyncDataDeleted', - 'makeBatchId', '_updateSyncData', '_buildDeleteProductRequest') + 'makeBatchId', '_updateSyncData', '_buildDeleteProductRequest') ) ->getMock(); @@ -692,9 +692,9 @@ public function testCreateDeletedProductsBatchJson() /** * Call protected/private method of a class. * - * @param object &$object Instantiated object that we will run method on. - * @param string $methodName Method name to call - * @param array $parameters Array of parameters to pass into method. + * @param object &$object Instantiated object that we will run method on. + * @param string $methodName Method name to call + * @param array $parameters Array of parameters to pass into method. * * @return mixed Method return. */ @@ -833,7 +833,7 @@ public function testMarkSpecialPrices() ->method("quoteInto") ->with( 'm4m.mailchimp_sync_delta IS NOT NULL AND m4m.mailchimp_sync_delta < ?', - $dateToday ." 00:00:00" + $dateToday . " 00:00:00" ); @@ -867,12 +867,12 @@ public function testMarkSpecialPrices() ->withConsecutive( array('special_price', array('gt' => 0), 'left'), array('special_from_date', - array('lteq' => $dateToday." 23:59:59"), + array('lteq' => $dateToday . " 23:59:59"), 'left'), array('special_from_date', array('gt' => new Zend_Db_Expr('m4m.mailchimp_sync_delta')), 'left'), array('special_price', array('gt' => 0), 'left'), array('special_to_date', - array('lt' => $dateToday." 00:00:00"), + array('lt' => $dateToday . " 00:00:00"), 'left'), array('special_to_date', array('gt' => new Zend_Db_Expr('m4m.mailchimp_sync_delta')), 'left') )->willReturnOnConsecutiveCalls( diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php index 114220fb4..544ca4fcb 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php @@ -585,9 +585,9 @@ public function ruleIsNotCompatibleProvider() /** * Call protected/private method of a class. * - * @param object &$object Instantiated object that we will run method on. - * @param string $methodName Method name to call - * @param array $parameters Array of parameters to pass into method. + * @param object &$object Instantiated object that we will run method on. + * @param string $methodName Method name to call + * @param array $parameters Array of parameters to pass into method. * * @return mixed Method return. */ diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/StoresTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/StoresTest.php index f2e03341d..1268cca6f 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/StoresTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/StoresTest.php @@ -35,7 +35,7 @@ public function testCreateMailChimpStore() 'email_address' => $storeEmail, 'currency_code' => $currencyCode, 'connected_site' => array( - 'site_foreign_id' => 'a1s2d3f4g5h6j7k8l9p0', + 'site_foreign_id' => 'a1s2d3f4g5h6j7k8l9p0', 'site_script' => array( 'url' => 'https://chimpstatic.com/mcjs-connected/js/users/1647ea7abc3f2f3259e2613f9' . '/a946187aed2d57d15cdac9987.js', diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Email/TemplateTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Email/TemplateTest.php index 72382ca96..f2b256379 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Email/TemplateTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Email/TemplateTest.php @@ -21,7 +21,7 @@ public function testSend() $senderEmail = 'sender@email.com'; $bcc = array('bcc@email.com'); $userAgent = 'Ebizmarts_Mandrill1.1.12/MageCE1.9.3.7'; - $emailArray = array ( + $emailArray = array( 'subject' => 'subject', 'to' => array( array('email' => $email, 'name' => $name), @@ -35,7 +35,7 @@ public function testSend() $mandrillSenders = array(array('domain' => 'email.com')); /** - * @var \Ebizmarts_MailChimp_Model_Email_Template $templateMock + * @var Ebizmarts_MailChimp_Model_Email_Template $templateMock */ $templateMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Email_Template::class) ->disableOriginalConstructor() diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/System/Config/Source/StoreTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/System/Config/Source/StoreTest.php index f0ed54d87..40a5ccbe0 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/System/Config/Source/StoreTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/System/Config/Source/StoreTest.php @@ -24,7 +24,7 @@ public function testToOptionArray() 'email_address' => 'email@example.com', 'currency_code' => 'USD', 'connected_site' => array( - 'site_foreign_id' => 'a1s2d3f4g5h6j7k8l9p0', + 'site_foreign_id' => 'a1s2d3f4g5h6j7k8l9p0', 'site_script' => array( 'url' => 'https://chimpstatic.com/mcjs-connected/js/users/1647ea7abc3f2f3259e2613f9' . '/a946187aed2d57d15cdac9987.js', diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpControllerTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpControllerTest.php index b3f8df060..80f9d53da 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpControllerTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpControllerTest.php @@ -249,7 +249,7 @@ public function testGetInfoAction() $syncDate = "2019-02-01 20:00:05"; $optionSyncFlag = array( 'value' => Ebizmarts_MailChimp_Model_System_Config_Source_Account::SYNC_LABEL_KEY, - 'label' => 'Initial sync: '.$syncDate + 'label' => 'Initial sync: ' . $syncDate ); $liElement = "
  • Initial sync: $syncDate
  • "; $liElementEscaped = "
  • Initial sync: " @@ -283,24 +283,24 @@ public function testGetInfoAction() 'label' => ' Total Carts: 10' ) ); - $jsonData = '[{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::USERNAME_KEY - .',"label":"Username: Ebizmarts Corp."},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_ACCOUNT_SUB_KEY - .',"label":"Total Account Subscribers: 104"},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_LIST_SUB_KEY - .',"label":"Total List Subscribers: 18"},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::STORENAME_KEY - .',"label":"Ecommerce Data uploaded to MailChimp store Madison Island - English:"},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::SYNC_LABEL_KEY - .',"label":"'.$liElementEscaped.'"},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_CUS_KEY - .',"label":" Total Customers: 10"},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_PRO_KEY - .',"label":" Total Products: 10"},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_ORD_KEY - .',"label":" Total Orders: 10"},'. - '{"value":'.Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_QUO_KEY - .',"label":" Total Carts: 10"}]'; + $jsonData = '[{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::USERNAME_KEY + . ',"label":"Username: Ebizmarts Corp."},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_ACCOUNT_SUB_KEY + . ',"label":"Total Account Subscribers: 104"},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_LIST_SUB_KEY + . ',"label":"Total List Subscribers: 18"},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::STORENAME_KEY + . ',"label":"Ecommerce Data uploaded to MailChimp store Madison Island - English:"},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::SYNC_LABEL_KEY + . ',"label":"' . $liElementEscaped . '"},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_CUS_KEY + . ',"label":" Total Customers: 10"},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_PRO_KEY + . ',"label":" Total Products: 10"},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_ORD_KEY + . ',"label":" Total Orders: 10"},' + . '{"value":' . Ebizmarts_MailChimp_Model_System_Config_Source_Account::TOTAL_QUO_KEY + . ',"label":" Total Carts: 10"}]'; $mailchimpControllerMock = $this->_mailchimpController ->disableOriginalConstructor() @@ -362,7 +362,7 @@ public function testGetListAction() $listId = 'a1s2d3f4g5'; $data = array(array('id' => $listId, 'name' => 'Newsletter')); - $jsonData = '[{"id":"'.$listId.'","name":"Newsletter"}]'; + $jsonData = '[{"id":"' . $listId . '","name":"Newsletter"}]'; $mailchimpControllerMock = $this->_mailchimpController ->disableOriginalConstructor() diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php index 7ad9abb5e..f6ce4d279 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsControllerTest.php @@ -46,7 +46,7 @@ public function testDownloadresponseAction() ->disableOriginalConstructor() ->setMethods( array('makeHelper', 'getRequest', 'getResponse', 'getMailchimperrorsModel', 'getApiBatches', - 'getFileContent', 'unlink') + 'getFileContent', 'unlink') ) ->getMock(); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresControllerTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresControllerTest.php index 9e700acef..2fc5672ba 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresControllerTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresControllerTest.php @@ -61,7 +61,7 @@ public function testEditAction() ->disableOriginalConstructor() ->setMethods( array('_title', 'getRequest', 'loadMailchimpStore', 'sessionregisterStore', '_initAction', - '_addBreadcrumb', 'getLayout', 'getUrl', '_addContent', 'renderLayout') + '_addBreadcrumb', 'getLayout', 'getUrl', '_addContent', 'renderLayout') ) ->getMock(); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php index 29ae79718..a1b23ed0d 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php @@ -40,8 +40,8 @@ public function testIndexAction() ->disableOriginalConstructor() ->setMethods( array('getSessionLastRealOrder', 'getCoreSession', 'getHelper', 'getRequest', - 'getInterestGroupModel', 'getSubscriberModel', 'getApiSubscriber', '_redirect', - 'getCurrentDateTime','__') + 'getInterestGroupModel', 'getSubscriberModel', 'getApiSubscriber', '_redirect', + 'getCurrentDateTime', '__') ) ->getMock(); @@ -64,7 +64,7 @@ public function testIndexAction() ->disableOriginalConstructor() ->setMethods( array('getSubscriberId', 'setSubscriberEmail', 'setSubscriberFirstname', - 'setSubscriberLastname', 'subscribe', 'getSubscriberEmail', 'loadByEmail') + 'setSubscriberLastname', 'subscribe', 'getSubscriberEmail', 'loadByEmail') ) ->getMock(); @@ -77,7 +77,7 @@ public function testIndexAction() ->disableOriginalConstructor() ->setMethods( array('getByRelatedIdStoreId', 'setGroupdata', 'setSubscriberId', 'setCustomerId', - 'setStoreId', 'setUpdatedAt', 'save') + 'setStoreId', 'setUpdatedAt', 'save') ) ->getMock(); diff --git a/lib/Ebizmarts/MailChimp/ReportsEmailActivity.php b/lib/Ebizmarts/MailChimp/ReportsEmailActivity.php index 33864b418..32c790c1c 100644 --- a/lib/Ebizmarts/MailChimp/ReportsEmailActivity.php +++ b/lib/Ebizmarts/MailChimp/ReportsEmailActivity.php @@ -1,4 +1,5 @@ "https://$dc.api.mailchimp.com/3.0/batches/$batchId", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => "", - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 30, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => "GET", - CURLOPT_POSTFIELDS => "", - CURLOPT_USERPWD => "noname:$apiKey", - CURLOPT_HTTPHEADER => array( - "accept: application/json", - "cache-control: no-cache", - "content-type: application/json" - ), + CURLOPT_URL => "https://$dc.api.mailchimp.com/3.0/batches/$batchId", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "GET", + CURLOPT_POSTFIELDS => "", + CURLOPT_USERPWD => "noname:$apiKey", + CURLOPT_HTTPHEADER => array( + "accept: application/json", + "cache-control: no-cache", + "content-type: application/json" + ), ) ); @@ -48,10 +49,12 @@ printf("cURL Error #:" . $err); } else { $jsonResponse = json_decode($response); + if ($jsonResponse->status == 'finished') { $fileUrl = $jsonResponse->response_body_url; // check if the file is not expired parse_str($fileUrl, $fileParams); + try { $fd = fopen("$batchId.response.tar.gz", 'w'); $ch = curl_init(); From 6bb8a9405d62129a4cec8c47fc2fae52dd8ef372 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 30 Sep 2019 16:47:31 -0300 Subject: [PATCH 059/160] Adding blank line before return statements. --- .../Block/Adminhtml/Mailchimperrors.php | 1 + .../Block/Adminhtml/Mailchimpstores.php | 1 + .../MailChimp/Block/Adminhtml/Notifications.php | 10 +++++----- .../Adminhtml/System/Config/ResetErrors.php | 2 ++ .../MailChimp/Block/Popup/Emailcatcher.php | 16 ++++++++++++---- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimperrors.php b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimperrors.php index 4b07d6a58..2ed1394a9 100644 --- a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimperrors.php +++ b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Mailchimperrors.php @@ -1,4 +1,5 @@ makeHelper(); if ($helper->isImageCacheFlushed() && $helper->isEcomSyncDataEnabledInAnyScope()) { - $message = 'Important: '. + $message = 'Important: ' . 'Image cache has been flushed please ' . '' - . 'resend the products in order to update image URL'; + . 'resend the products in order to update image URL'; return $message; } } @@ -32,8 +33,8 @@ public function getMessage() { $helper = $this->makeHelper(); $message = 'Are you sure you want to delete the local data in order to send all items again?\n' - .'Automations will work normally but the synchronization process for the old data will take ' - . 'longer than resetting the MailChimp store.'; + . 'Automations will work normally but the synchronization process for the old data will take ' + . 'longer than resetting the MailChimp store.'; return $helper->__($message); } @@ -59,7 +60,6 @@ public function getUrlForResendEcommerce() } - /** * @return Ebizmarts_MailChimp_Helper_Data */ diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/ResetErrors.php b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/ResetErrors.php index 67a74ed07..2eb30e6ca 100644 --- a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/ResetErrors.php +++ b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/ResetErrors.php @@ -1,4 +1,5 @@ makeHelper(); $scopeArray = $helper->getCurrentScope(); + if ($helper->isSubscriptionEnabled($scopeArray['scope_id'], $scopeArray['scope']) || $scopeArray['scope_id'] == 0 ) { diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Popup/Emailcatcher.php b/app/code/community/Ebizmarts/MailChimp/Block/Popup/Emailcatcher.php index 4b3fcf842..93deaf83b 100755 --- a/app/code/community/Ebizmarts/MailChimp/Block/Popup/Emailcatcher.php +++ b/app/code/community/Ebizmarts/MailChimp/Block/Popup/Emailcatcher.php @@ -1,4 +1,5 @@ getStore()->getId(); + return Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::ENABLE_POPUP, $storeId) - && Mage::getStoreConfig( - Ebizmarts_MailChimp_Model_Config::POPUP_CAN_CANCEL, - $storeId - ); + && Mage::getStoreConfig( + Ebizmarts_MailChimp_Model_Config::POPUP_CAN_CANCEL, + $storeId + ); } protected function _popupHeading() { $storeId = Mage::app()->getStore()->getId(); + return Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::POPUP_HEADING, $storeId); } protected function _popupMessage() { $storeId = Mage::app()->getStore()->getId(); + return Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::POPUP_TEXT, $storeId); } protected function _modalSubscribe() { $storeId = Mage::app()->getStore()->getId(); + return Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::POPUP_SUBSCRIPTION, $storeId); } @@ -53,6 +58,7 @@ protected function _handleCookie() $cookieValues = explode('/', $emailCookie); $email = $cookieValues[0]; $email = str_replace(' ', '+', $email); + if (isset($cookieValues[1])) { $fName = $cookieValues[1]; } @@ -63,6 +69,7 @@ protected function _handleCookie() if ($subscribeCookie == 'true') { $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email); + if (!$subscriber->getId()) { $subscriber = Mage::getModel('newsletter/subscriber') ->setStoreId($storeId); @@ -78,6 +85,7 @@ protected function _handleCookie() } $subscriber->subscribe($email); + return 'location.reload'; } } From cefc6ce7080703e3e0cf51c2d7ac85c0b3d03f8b Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Mon, 30 Sep 2019 16:53:34 -0300 Subject: [PATCH 060/160] Reformatting code. --- .../MailChimp/controllers/Adminhtml/MailchimpController.php | 4 ++++ .../controllers/Adminhtml/MailchimperrorsController.php | 5 +++++ .../controllers/Adminhtml/MailchimpstoresController.php | 4 ++-- .../MailChimp/controllers/Adminhtml/MergevarsController.php | 1 - 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php index 4426ab087..6b27da40b 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php @@ -25,6 +25,7 @@ public function preDispatch() public function indexAction() { $customerId = (int)$this->getRequest()->getParam('id'); + if ($customerId) { $block = $this->getLayout() ->createBlock( @@ -99,8 +100,10 @@ public function getInfoAction() } $data = $this->getSourceAccountInfoOptions($apiKey, $mcStoreId); + foreach ($data as $key => $element) { $liElement = ''; + if ($element['value'] == Ebizmarts_MailChimp_Model_System_Config_Source_Account::SYNC_LABEL_KEY) { $liElement = $helper->getSyncFlagDataHtml($element, $liElement); $data[$key]['label'] = $liElement; @@ -268,6 +271,7 @@ protected function getApiKeyValue() { $helper = $this->getHelper(); $scopeArray = $helper->getCurrentScope(); + return $helper->getApiKey($scopeArray['scope_id'], $scopeArray['scope']); } } diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php index 45a9eec8f..f3ad2b060 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimperrorsController.php @@ -40,6 +40,7 @@ public function downloadresponseAction() $batchId = $error->getBatchId(); $storeId = $error->getStoreId(); $mailchimpStoreId = $error->getMailchimpStoreId(); + if ($mailchimpStoreId) { $enabled = $helper->isEcomSyncDataEnabled($storeId); } else { @@ -51,6 +52,7 @@ public function downloadresponseAction() $response->setHeader('Content-disposition', 'attachment; filename=' . $batchId . '.json'); $response->setHeader('Content-type', 'application/json'); $counter = 0; + do { $counter++; $files = $apiBatches->getBatchResponse($batchId, $storeId); @@ -62,6 +64,7 @@ public function downloadresponseAction() foreach ($files as $file) { $items = $this->getFileContent($file); + foreach ($items as $item) { $fileContent[] = array( 'status_code' => $item->status_code, @@ -74,6 +77,7 @@ public function downloadresponseAction() } $baseDir = $apiBatches->getMagentoBaseDir(); + if ($apiBatches->batchDirExists($baseDir, $batchId)) { $apiBatches->removeBatchDir($baseDir, $batchId); } @@ -129,6 +133,7 @@ protected function getApiBatches() protected function getFileContent($file) { $fileContent = $this->getFileHelper()->read($file); + return json_decode($fileContent); } diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php index 7a99fbdad..8d6bfd625 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpstoresController.php @@ -47,7 +47,6 @@ public function gridAction() protected function _initStore($idFieldName = 'id') { $this->_title($this->__('Mailchimp Stores'))->_title($this->__('Manage Mailchimp Stores')); - $storeId = (int)$this->getRequest()->getParam($idFieldName); if ($storeId) { @@ -65,8 +64,8 @@ public function editAction() $mailchimpStore = $this->loadMailchimpStore($id); $this->sessionregisterStore($mailchimpStore); $title = $id ? $this->__('Edit Store') : $this->__('New Store'); - $this->_initAction(); + $block = $this->getLayout() ->createBlock('mailchimp/adminhtml_mailchimpstores_edit') ->setData('action', $this->getUrl('*/*/save')); @@ -332,6 +331,7 @@ protected function createAddressArray($formData) $address['postal_code'] = $formData['address_postal_code']; $address['country'] = ''; $address['country_code'] = $formData['address_country_code']; + return $address; } } diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php index 77562e056..6c9ddec83 100644 --- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php +++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MergevarsController.php @@ -15,7 +15,6 @@ class Ebizmarts_MailChimp_Adminhtml_MergevarsController extends Mage_Adminhtml_C public function addmergevarAction() { - $this->loadLayout(); $this->renderLayout(); } From a37f2a8b4ed93961a00c8d8e2462c2462b0cb3d2 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 1 Oct 2019 15:17:11 -0300 Subject: [PATCH 061/160] Separating some lines. --- app/code/community/Ebizmarts/MailChimp/Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index d0886a75a..64330ce11 100644 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -32,13 +32,11 @@ class Ebizmarts_MailChimp_Helper_Data extends Mage_Core_Helper_Abstract const DATA_SENT_TO_MAILCHIMP = 'SENT'; const BATCH_STATUS_LOG = 'Mailchimp_Batch_Status.log'; - const BATCH_CANCELED = 'canceled'; const BATCH_COMPLETED = 'completed'; const BATCH_PENDING = 'pending'; const BATCH_ERROR = 'error'; - protected $_countersSendBatch = array(); protected $_countersSubscribers = array(); protected $_countersGetResponseBatch = array(); @@ -156,6 +154,7 @@ public function getCurrentScope() { $scopeIdArray = $this->getConfigScopeId(); $scopeArray = array(); + if (isset($scopeIdArray['websiteId'])) { $scopeArray['scope'] = 'websites'; $scopeArray['scope_id'] = $scopeIdArray['websiteId']; @@ -212,6 +211,7 @@ public function isUsingConfigStoreName($scopeId, $scope) $scopeId, $scope ); + if ($storeName == '') { $usingConfigName = false; } else { From 522bf30bb05d61c7525aa37ae8ac8a03fdd11704 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Tue, 1 Oct 2019 17:13:10 -0300 Subject: [PATCH 062/160] Fixing problem about map_fields and customer_map_fields format. These nodes shouldn't have "\n" in their values. --- .../community/Ebizmarts/MailChimp/etc/config.xml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml index 379ed18ad..374283082 100644 --- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml +++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml @@ -369,10 +369,8 @@ 1 - - - - + + 3 200 20 @@ -394,10 +392,8 @@ 1 1 - - - - + + 100 From 662149dfbf1da1b517e08de0c7e2b8b72ac6c49c Mon Sep 17 00:00:00 2001 From: Dwi Nurhadi Afriyanto Date: Wed, 2 Oct 2019 12:51:45 +0700 Subject: [PATCH 063/160] Fix typo readme on mailchimp magento --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c683341a7..ee6764a4a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Integration to sync all the Magento data (Newsletter subscriber, Customers, Orde The integration includes a Mandrill SMTP module that overrides the one integrated from Magento, you will need to enable Mandrill with its API key from your Mandrill account (mandrillapp.com) for the transactional emails to work. If you want to use the Mailchimp integration without Mandrill for SMTP, contact our support so we can tell you how to set that up. -## Features +## Main Features * Two way sync between a MailChimp list and Magento’s newsletter * Responsive Email Catcher Popup when accessing the site @@ -22,7 +22,7 @@ Magento Community Edition (1.7 or above) or Magento Enterprise (1.11 or above) MailChimp Account -## Installation +## Step Installation To get a copy of the project up and running on your local machine for development and testing purposes, just clone this repository on your Magento’s root directory and flush the Magento’s cache. @@ -30,7 +30,7 @@ Alternatively, use modman to install this module. ``modman clone https://github.com/mailchimp/mc-magento.git -b 'master'`` -## Module Configuriation +## Module Configuration To enable MailChimp For Magento: @@ -42,7 +42,7 @@ To enable MailChimp For Magento: More guides and tutorials about the Mailchimp integration with Magento can be found on the [tutorial page of Mailchimp](https://mailchimp.com/help/connect-or-disconnect-mailchimp-for-magento/). -## Report issues +## Report Issues For reporting issues, follow this [guidelines](https://github.com/mailchimp/mc-magento/wiki/Issue-reporting-guidelines) or your issue will be rejected. From 19450322bd15fb14635ffb2fc43a362c01e621d4 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Wed, 2 Oct 2019 10:34:59 -0300 Subject: [PATCH 064/160] Line was exceeding 120 characters limit. Solved. --- lib/Ebizmarts/MailChimp/ListsWebhooks.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Ebizmarts/MailChimp/ListsWebhooks.php b/lib/Ebizmarts/MailChimp/ListsWebhooks.php index ea0340f19..15dc6ca17 100644 --- a/lib/Ebizmarts/MailChimp/ListsWebhooks.php +++ b/lib/Ebizmarts/MailChimp/ListsWebhooks.php @@ -16,7 +16,8 @@ class MailChimp_ListsWebhooks extends MailChimp_Abstract * @param $listId The unique id for the list. * @param null $url Email address for a subscriber. * @param null $events The events that can trigger the webhook and whether they are enabled. - * @param null $sources The possible sources of any events that can trigger a webhook and whether they are enabled. + * @param null $sources The possible sources of any events that can trigger a webhook and + * whether they are enabled. * @return mixed */ public function add($listId, $url = null, $events = null, $sources = null) From b2181ccd693f98176275ec681ca88f1574fdae10 Mon Sep 17 00:00:00 2001 From: Roberto Sarmiento Date: Wed, 2 Oct 2019 17:05:39 -0300 Subject: [PATCH 065/160] MYSQL4 classes deleted. Fixing unnecessary semicolon: "templateData = {;" in array_dropdown.phtml --- .../Model/Resource/Ecommercesyncdata.php | 26 ++++++ .../Resource/Ecommercesyncdata/Collection.php | 26 ++++++ .../Model/Resource/Interestgroup.php | 54 +++++++++++++ .../Resource/Interestgroup/Collection.php | 26 ++++++ .../Model/Resource/Mailchimperrors.php | 26 ++++++ .../Resource/Mailchimperrors/Collection.php | 26 ++++++ .../MailChimp/Model/Resource/Stores.php | 26 ++++++ .../Model/Resource/Stores/Collection.php | 27 +++++++ .../MailChimp/Model/Resource/Synchbatches.php | 26 ++++++ .../Resource/Synchbatches/Collection.php | 26 ++++++ .../Model/Resource/Webhookrequest.php | 26 ++++++ .../Resource/Webhookrequest/Collection.php | 26 ++++++ .../Ebizmarts/MailChimp/etc/config.xml | 8 +- .../config/form/field/array_dropdown.phtml | 80 +++++++++---------- 14 files changed, 381 insertions(+), 48 deletions(-) create mode 100755 app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata.php create mode 100755 app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata/Collection.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup.php create mode 100755 app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup/Collection.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors/Collection.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores/Collection.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches/Collection.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest.php create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest/Collection.php diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata.php new file mode 100755 index 000000000..952d987fd --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:53 + * @file: Ecommercesyncdata.php + */ +class Ebizmarts_MailChimp_Model_Resource_Ecommercesyncdata extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Initialize + * + * @return void + */ + public function _construct() + { + $this->_init('mailchimp/ecommercesyncdata', 'id'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata/Collection.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata/Collection.php new file mode 100755 index 000000000..6f7bef6d2 --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Ecommercesyncdata/Collection.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:57 + */ +class Ebizmarts_MailChimp_Model_Resource_Ecommercesyncdata_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + + /** + * Set resource type + * + * @return void + */ + public function _construct() + { + parent::_construct(); + $this->_init('mailchimp/ecommercesyncdata'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup.php new file mode 100644 index 000000000..e0d8cc50d --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup.php @@ -0,0 +1,54 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:54 + * @file: Interestgroup.php + */ +class Ebizmarts_MailChimp_Model_Resource_Interestgroup extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Initialize + * + * @return void + */ + public function _construct() + { + $this->_init('mailchimp/interestgroup', 'id'); + } + + /** + * @param int $customerId + * @param int $subscriberId + * @param int $storeId + * @return array + */ + public function getByRelatedIdStoreId($customerId = 0, $subscriberId = 0, $storeId = 0) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from($this->getMainTable()) + ->where('store_id = ?', $storeId) + ->where( + '(' + . $read->quoteInto('customer_id = ?', $customerId) + . ' OR ' . $read->quoteInto('subscriber_id = ?', $subscriberId) + . ')' + ); + + $result = $read->fetchRow($select); + + if (!$result) { + return array(); + } + + return $result; + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup/Collection.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup/Collection.php new file mode 100755 index 000000000..936577e1f --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Interestgroup/Collection.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:57 + */ +class Ebizmarts_MailChimp_Model_Resource_Interestgroup_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + + /** + * Set resource type + * + * @return void + */ + public function _construct() + { + parent::_construct(); + $this->_init('mailchimp/interestgroup'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors.php new file mode 100644 index 000000000..1a254150d --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:54 + * @file: Mailchimperrors.php + */ +class Ebizmarts_MailChimp_Model_Resource_Mailchimperrors extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Initialize + * + * @return void + */ + public function _construct() + { + $this->_init('mailchimp/mailchimperrors', 'id'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors/Collection.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors/Collection.php new file mode 100644 index 000000000..e168c6b7a --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Mailchimperrors/Collection.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:57 + */ +class Ebizmarts_MailChimp_Model_Resource_Mailchimperrors_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + + /** + * Set resource type + * + * @return void + */ + public function _construct() + { + parent::_construct(); + $this->_init('mailchimp/mailchimperrors'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores.php new file mode 100644 index 000000000..db01763e9 --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:54 + * @file: Stores.php + */ +class Ebizmarts_MailChimp_Model_Resource_Stores extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Initialize + * + * @return void + */ + public function _construct() + { + $this->_init('mailchimp/stores', 'id'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores/Collection.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores/Collection.php new file mode 100644 index 000000000..64360d8b0 --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Stores/Collection.php @@ -0,0 +1,27 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:57 + */ + +class Ebizmarts_MailChimp_Model_Resource_Stores_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + + /** + * Set resource type + * + * @return void + */ + public function _construct() + { + parent::_construct(); + $this->_init('mailchimp/stores'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches.php new file mode 100644 index 000000000..e22123394 --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:54 + * @file: SychBatches.php + */ +class Ebizmarts_MailChimp_Model_Resource_SynchBatches extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Initialize + * + * @return void + */ + public function _construct() + { + $this->_init('mailchimp/synchbatches', 'id'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches/Collection.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches/Collection.php new file mode 100644 index 000000000..05fcb5866 --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Synchbatches/Collection.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:58 + */ +class Ebizmarts_MailChimp_Model_Resource_Synchbatches_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + + /** + * Set resource type + * + * @return void + */ + public function _construct() + { + parent::_construct(); + $this->_init('mailchimp/synchbatches'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest.php new file mode 100644 index 000000000..4a6549751 --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:56 + * @file: Mailchimperrors.php + */ +class Ebizmarts_MailChimp_Model_Resource_Webhookrequest extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Initialize + * + * @return void + */ + public function _construct() + { + $this->_init('mailchimp/webhookrequest', 'id'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest/Collection.php b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest/Collection.php new file mode 100644 index 000000000..537e34d95 --- /dev/null +++ b/app/code/community/Ebizmarts/MailChimp/Model/Resource/Webhookrequest/Collection.php @@ -0,0 +1,26 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 2019-10-02 15:58 + */ +class Ebizmarts_MailChimp_Model_Resource_Webhookrequest_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + + /** + * Set resource type + * + * @return void + */ + public function _construct() + { + parent::_construct(); + $this->_init('mailchimp/webhookrequest'); + } +} diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml index 374283082..cceabb378 100644 --- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml +++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml @@ -129,10 +129,10 @@ Ebizmarts_MailChimp_Model - mailchimp_mysql4 + mailchimp_resource - - Ebizmarts_MailChimp_Model_Mysql4 + + Ebizmarts_MailChimp_Model_Resource mailchimp_sync_batches
    @@ -153,7 +153,7 @@ mailchimp_stores
    -
    + Ebizmarts_MailChimp_Model_Subscriber diff --git a/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/system/config/form/field/array_dropdown.phtml b/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/system/config/form/field/array_dropdown.phtml index daa344efb..5a976b00b 100644 --- a/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/system/config/form/field/array_dropdown.phtml +++ b/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/system/config/form/field/array_dropdown.phtml @@ -19,7 +19,7 @@ $colspan = $colspan > 1 ? 'colspan="' . $colspan . '"' : ''; - _columns as $columnName => $column):?> + _columns as $columnName => $column): ?> quoteEscape($column['label']) ?> quoteEscape($colspan) ?>> @@ -64,7 +64,7 @@ $colspan = $colspan > 1 ? 'colspan="' . $colspan . '"' : ''; - +