From 963e2bc82a54d14e65a3e357a446f9d7ca6cb9ec Mon Sep 17 00:00:00 2001 From: Santiago Date: Tue, 31 Oct 2017 15:10:24 -0300 Subject: [PATCH 1/2] Send parent image when child has no image and belongs to a configurable. resolves #513 --- .../Ebizmarts/MailChimp/Helper/Data.php | 106 ++++++++++++---- .../Ebizmarts/MailChimp/Model/Api/Batches.php | 8 +- .../MailChimp/Model/Api/Products.php | 119 ++++++++++++------ .../Ebizmarts/MailChimp/Model/Observer.php | 34 ++++- .../Ebizmarts/MailChimp/etc/config.xml | 24 ++-- .../Ebizmarts/MailChimp/Helper/DataTest.php | 44 +++++++ .../MailChimp/Model/Api/BatchesTest.php | 3 +- .../MailChimp/Model/Api/ProductsTest.php | 5 + .../MailChimp/Model/ObserverTest.php | 33 +++++ 9 files changed, 297 insertions(+), 79 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 2a1ae2946..19e9ac95f 100755 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -25,7 +25,7 @@ class Ebizmarts_MailChimp_Helper_Data extends Mage_Core_Helper_Abstract public function getConfigValueForScope($path, $scopeId, $scope = null) { if ($scope == 'websites') { - $configValue = Mage::app()->getWebsite($scopeId)->getConfig($path); + $configValue = $this->getMageApp()->getWebsite($scopeId)->getConfig($path); } else { $configValue = Mage::getStoreConfig($path, $scopeId); } @@ -48,7 +48,7 @@ public function getConfigScopeId($storeId = null, $websiteId = null) } elseif ($code = Mage::getSingleton('adminhtml/config_data')->getWebsite()) { // website level $websiteId = Mage::getModel('core/website')->load($code)->getId(); - $storeId = Mage::app()->getWebsite($websiteId)->getDefaultStore()->getId(); + $storeId = $this->getMageApp()->getWebsite($websiteId)->getDefaultStore()->getId(); } $scopeArray['websiteId'] = $websiteId; $scopeArray['storeId'] = $storeId; @@ -86,15 +86,15 @@ public function getMCStoreName($scopeId, $scope) $storeName = null; switch ($scope) { case 'stores': - $store = Mage::app()->getStore($scopeId); + $store = $this->getMageApp()->getStore($scopeId); $storeName = $store->getFrontendName(); break; case 'websites': - $website = Mage::app()->getWebsite($scopeId); + $website = $this->getMageApp()->getWebsite($scopeId); $storeName = $website->getDefaultStore()->getFrontendName(); break; case 'default': - $storeView = Mage::app()->getDefaultStoreView(); + $storeView = $this->getMageApp()->getDefaultStoreView(); $storeName = $storeView->getWebsite()->getDefaultStore()->getFrontendName(); break; } @@ -120,7 +120,7 @@ public function getStoreDomain($scopeId, $scope) */ public function getStoreRelation() { - $stores = Mage::app()->getStores(); + $stores = $this->getMageApp()->getStores(); $storeRelation = array(); foreach ($stores as $storeId => $store) { $mcStoreId = $this->getMCStoreId($storeId); @@ -1003,12 +1003,12 @@ public function getDefaultStoreIdForMailChimpScope($magentoStoreId) $scopeArray = $this->getMailChimpScopeByStoreId($magentoStoreId); if ($scopeArray) { if ($scopeArray['scope'] == 'websites') { - $magentoStoreId = Mage::app() + $magentoStoreId = $this->getMageApp() ->getWebsite($scopeArray['scope_id']) ->getDefaultGroup() ->getDefaultStoreId(); } elseif ($scopeArray['scope'] == 'default') { - $magentoStoreId = Mage::app() + $magentoStoreId = $this->getMageApp() ->getWebsite(true) ->getDefaultGroup() ->getDefaultStoreId(); @@ -1056,7 +1056,8 @@ public function getMailChimpProductImageUrl($parentImageUrl, $productImageUrl) */ public function getImageUrlById($productId, $magentoStoreId) { - $model = Mage::getResourceModel('catalog/product'); + $productResourceModel = $this->getProductResourceModel(); + $productModel = $this->getProductModel(); $configImageSize = $this->getImageSize($magentoStoreId); switch ($configImageSize) { case 0: @@ -1073,27 +1074,80 @@ public function getImageUrlById($productId, $magentoStoreId) break; } - $productImage = $model->getAttributeRawValue($productId, $imageSize, $magentoStoreId); + $productImage = $productResourceModel->getAttributeRawValue($productId, $imageSize, $magentoStoreId); + $productModel->setData('image', $productImage); if ($productImage == 'no_selection' || $productImage == null) { $imageUrl = null; } else { - $curStore = Mage::app()->getStore()->getId(); - Mage::app()->setCurrentStore($magentoStoreId); - $productImageModel = $this->getProductImageModel(); - $productImageModel->setDestinationSubdir($imageSize); - $productImageModel->setBaseFile($productImage); - $imageUrl = $productImageModel->getUrl(); - Mage::app()->setCurrentStore($curStore); + $curStore = $this->getCurrentStoreId(); + $this->setCurrentStore($magentoStoreId); + $upperCaseImage = str_replace('_', '', ucwords($imageSize, "_")); + $functionName = "get{$upperCaseImage}Url"; + $imageUrl = $productModel->$functionName(); + $this->setCurrentStore($curStore); } return $imageUrl; } + /** + * Return Catalog Product Image helper instance + * + * @return Mage_Catalog_Helper_Image + */ + protected function _getImageHelper() + { + return Mage::helper('catalog/image'); + } + public function getImageSize($scopeId, $scope = null) { return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_IMAGE_SIZE, $scopeId, $scope); } + /** + * @return Object + */ + protected function getProductResourceModel() + { + $productResourceModel = Mage::getResourceModel('catalog/product'); + return $productResourceModel; + } + + /** + * @return false|Mage_Core_Model_Abstract + */ + protected function getProductModel() + { + $productModel = Mage::getModel('catalog/product'); + return $productModel; + } + + /** + * @return Mage_Core_Model_App + */ + protected function getMageApp() + { + return Mage::app(); + } + + /** + * @return int + */ + protected function getCurrentStoreId() + { + $curStore = $this->getMageApp()->getStore()->getId(); + return $curStore; + } + + /** + * @param $magentoStoreId + */ + protected function setCurrentStore($magentoStoreId) + { + $this->getMageApp()->setCurrentStore($magentoStoreId); + } + private function getProductImageModel() { return Mage::getModel('catalog/product_image'); @@ -1172,7 +1226,7 @@ public function getMCJs() { $script = ''; $url = null; - $storeId = Mage::app()->getStore()->getId(); + $storeId = $this->getMageApp()->getStore()->getId(); if ($this->isEcomSyncDataEnabled($storeId)) { $currentUrl = $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $storeId); if ($this->areJsUrlAndListScopesEqual($storeId)) { @@ -1350,7 +1404,7 @@ protected function _migrateProductsFrom115($mailchimpStoreId, $initialTime) $productCollection, $mailchimpStoreId, $initialTime, function ($product, $mailchimpStoreId) { $productId = $product->getEntityId(); $_resource = Mage::getResourceSingleton('catalog/product'); - $syncDelta = $_resource->getAttributeRawValue($productId, 'mailchimp_sync_delta', Mage::app()->getStore()); + $syncDelta = $_resource->getAttributeRawValue($productId, 'mailchimp_sync_delta', $this->getMageApp()->getStore()); $syncError = null; $syncModified = null; if ($product->getMailchimpSyncError()) { @@ -1529,7 +1583,7 @@ protected function _makeForCollectionItem($collection, $mailchimpStoreId, $initi */ public function timePassed($initialTime) { - $storeCount = count(Mage::app()->getStores()); + $storeCount = count($this->getMageApp()->getStores()); $timePassed = false; $finalTime = time(); $difference = $finalTime - $initialTime; @@ -1565,7 +1619,7 @@ protected function _migrateFrom116($initialTime) */ protected function _setIsSyncingIfFinishedInAllStores($syncValue) { - $stores = Mage::app()->getStores(); + $stores = $this->getMageApp()->getStores(); foreach ($stores as $storeId => $store) { $this->setIsSyncingIfFinishedPerScope($syncValue, $storeId); } @@ -1583,7 +1637,7 @@ protected function _migrateOrdersFrom116($initialTime) $finished = false; if (!$this->timePassed($initialTime)) { $finished = true; - $stores = Mage::app()->getStores(); + $stores = $this->getMageApp()->getStores(); foreach ($stores as $storeId => $store) { Mage::getModel('mailchimp/api_batches')->replaceAllOrders($initialTime, $storeId); if ($this->timePassed($initialTime)) { @@ -1619,7 +1673,7 @@ public function migrationFinished() */ public function delete116MigrationConfigData() { - $stores = Mage::app()->getStores(); + $stores = $this->getMageApp()->getStores(); $this->getConfig()->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MIGRATE_FROM_116, 'default', 0); foreach ($stores as $storeId => $store) { $this->getConfig()->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MIGRATE_LAST_ORDER_ID, 'stores', $storeId); @@ -1654,7 +1708,7 @@ public function getMagentoStoreIdsByListId($listId) { $storeIds = Mage::registry('mailchimp_store_ids_for_list_' . $listId); if ($storeIds === null) { - $stores = Mage::app()->getStores(); + $stores = $this->getMageApp()->getStores(); $storeIds = array(); foreach ($stores as $storeId => $store) { if ($this->isMailChimpEnabled($storeId)) { @@ -1839,7 +1893,7 @@ protected function createNewWebhook($scopeId, $scope, $listId) protected function getWebhookUrl() { - $store = Mage::app()->getDefaultStoreView(); + $store = $this->getMageApp()->getDefaultStoreView(); $webhooksKey = $this->getWebhooksKey(); //Generating Webhooks URL $url = Ebizmarts_MailChimp_Model_ProcessWebhook::WEBHOOKS_PATH; @@ -2100,7 +2154,7 @@ protected function allResendItemsSent($scopeId, $scope = 'stores') $storeIds = $website->getStoreIds(); $allItemsSent = $this->allResendItemsSentPerScope($storeIds); } else { - $stores = Mage::app()->getStores(); + $stores = $this->getMageApp()->getStores(); $allItemsSent = $this->allResendItemsSentPerScope($stores); } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index ab8139a2a..7e948a7b2 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -123,8 +123,10 @@ public function handleEcommerceBatches() $helper->handleResendDataBefore(); foreach ($stores as $store) { $storeId = $store->getId(); - $this->_getResults($storeId); - $this->_sendEcommerceBatch($storeId); + if ($helper->isEcomSyncDataEnabled($storeId)) { + $this->_getResults($storeId); + $this->_sendEcommerceBatch($storeId); + } } $helper->handleResendDataAfter(); @@ -646,7 +648,7 @@ protected function handleSyncingValue($syncedDateArray) if ($date) { $api = $helper->getApi($magentoStoreId); $isSyncingDate = $helper->getDateSyncFinishByMailChimpStoreId($mailchimpStoreId); - if (!$isSyncingDate) { + if (!$isSyncingDate && $mailchimpStoreId) { Mage::getModel('mailchimp/api_stores')->editIsSyncing($api, false, $mailchimpStoreId); $scopeToEdit = Mage::helper('mailchimp')->getMailChimpScopeByStoreId($magentoStoreId); if ($scopeToEdit['scope'] != 'stores') { diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php index dd5a623ed..986c0cc11 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php @@ -220,7 +220,7 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru $data["url"] = $url; //image - $imageUrl = $this->getMailChimpHelper()->getMailChimpProductImageUrl($this->_parentImageUrl, $this->getMailChimpHelper()->getImageUrlById($product->getId(), $magentoStoreId)); + $imageUrl = $this->getMailChimpImageUrl($product, $magentoStoreId); if ($imageUrl) { $data["image_url"] = $imageUrl; } @@ -283,13 +283,12 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru public function update($productId, $storeId) { if ($storeId == 0) { - $stores = Mage::app()->getStores(); - foreach ($stores as $curStoreId => $curStore) { - $this->_updateIfEnabled($productId, $curStoreId); - } - } else { $this->_updateIfEnabled($productId, $storeId); } + $stores = Mage::app()->getStores(); + foreach ($stores as $curStoreId => $curStore) { + $this->_updateIfEnabled($productId, $curStoreId); + } } /** @@ -300,10 +299,8 @@ public function update($productId, $storeId) */ protected function _updateIfEnabled($productId, $storeId) { - if ($this->getMailChimpHelper()->isEcomSyncDataEnabled($storeId)) { - $mailchimpStoreId = $this->getMailChimpHelper()->getMCStoreId($storeId); - $this->_updateSyncData($productId, $mailchimpStoreId, null, null, 1, null, true); - } + $mailchimpStoreId = $this->getMailChimpHelper()->getMCStoreId($storeId); + $this->_updateSyncData($productId, $mailchimpStoreId, null, null, 1, null, true); } /** @@ -522,10 +519,10 @@ public function joinProductAttributes($collection, $magentoStoreId) $attributeName = $config->getAttribute("catalog_product", $_code); $collection->joinField( - $_code, $attributeName->getBackendTable(), 'value', 'entity_id = entity_id', - '{{table}}.store_id = ' . $magentoStoreId . ' AND {{table}}.attribute_id = ' . $attributeName->getId(), 'left' + $_code, $attributeName->getBackendTable(), 'value', 'entity_id = entity_id', + '{{table}}.store_id = ' . $magentoStoreId . ' AND {{table}}.attribute_id = ' . $attributeName->getId(), 'left' ); - + $collection->joinField( 'default_' . $_code, $attributeName->getBackendTable(), 'value', 'entity_id = entity_id', '{{table}}.store_id = 0 AND {{table}}.attribute_id = ' . $attributeName->getId(), 'left' @@ -665,31 +662,12 @@ public function getNotVisibleProductUrl($childId, $magentoStoreId) { $parentId = null; if (!$this->_parentId) { - $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($childId); - if (count($parentIds)) { - $parentId = $parentIds[0]; - } + $parentId = $this->getParentIds($childId); } else { $parentId = $this->_parentId; } if ($parentId) { - $tableName = Mage::getSingleton('core/resource')->getTableName('catalog/product_super_attribute'); - $eavTableName = Mage::getSingleton('core/resource')->getTableName('eav/attribute'); - - $collection = $this->getProductResourceCollection(); - $collection->addStoreFilter($magentoStoreId); - $collection->addFieldToFilter('entity_id', array('eq' => $parentId)); - - $collection->getSelect()->joinLeft( - array("super_attribute" => $tableName), - 'entity_id=super_attribute.product_id' - ); - - $collection->getSelect()->joinLeft( - array("eav_attribute" => $eavTableName), - 'super_attribute.attribute_id=eav_attribute.attribute_id' - ); - $collection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns('eav_attribute.attribute_id'); + $collection = $this->getProductWithAttributesById($magentoStoreId, $parentId); $rc = Mage::getResourceModel('catalog/product'); if ($this->_parentUrl) { @@ -720,6 +698,22 @@ public function getNotVisibleProductUrl($childId, $magentoStoreId) return $url; } + public function getParentImageUrl($childId, $magentoStoreId) + { + $imageUrl = null; + $parentId = null; + if (!$this->_parentId) { + $parentId = $this->getParentIds($childId); + } else { + $parentId = $this->_parentId; + } + if ($parentId) { + $helper = $this->getMailChimpHelper(); + $imageUrl = $helper->getImageUrlById($parentId, $magentoStoreId); + } + return $imageUrl; + } + /** * @param $product * @param $magentoStoreId @@ -744,7 +738,7 @@ protected function getProductCategories($product, $magentoStoreId) $collection = Mage::getModel('catalog/category')->getCollection(); $collection->addAttributeToSelect(array('name')) ->setStoreId($magentoStoreId) - ->addAttributeToFilter('is_active', array('eq'=>'1')) + ->addAttributeToFilter('is_active', array('eq' => '1')) ->addAttributeToFilter('entity_id', array('in' => $categoryIds)) ->addAttributeToSort('level', 'asc'); @@ -756,4 +750,59 @@ protected function getProductCategories($product, $magentoStoreId) } return $categoryName; } + + /** + * @param $childId + * @return mixed + */ + protected function getParentIds($childId) + { + $parentId = null; + $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($childId); + if (count($parentIds)) { + $parentId = $parentIds[0]; + } + return $parentId; + } + + /** + * @param $magentoStoreId + * @param $parentId + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function getProductWithAttributesById($magentoStoreId, $parentId) + { + $tableName = Mage::getSingleton('core/resource')->getTableName('catalog/product_super_attribute'); + $eavTableName = Mage::getSingleton('core/resource')->getTableName('eav/attribute'); + + $collection = $this->getProductResourceCollection(); + $collection->addStoreFilter($magentoStoreId); + $collection->addFieldToFilter('entity_id', array('eq' => $parentId)); + + $collection->getSelect()->joinLeft( + array("super_attribute" => $tableName), + 'entity_id=super_attribute.product_id' + ); + + $collection->getSelect()->joinLeft( + array("eav_attribute" => $eavTableName), + 'super_attribute.attribute_id=eav_attribute.attribute_id' + ); + $collection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns('eav_attribute.attribute_id'); + return $collection; + } + + /** + * @param $product + * @param $magentoStoreId + * @return mixed|null + */ + protected function getMailChimpImageUrl($product, $magentoStoreId) + { + $imageUrl = $this->getMailChimpHelper()->getMailChimpProductImageUrl($this->_parentImageUrl, $this->getMailChimpHelper()->getImageUrlById($product->getId(), $magentoStoreId)); + if (!$imageUrl) { + $imageUrl = $this->getParentImageUrl($product->getId(), $magentoStoreId); + } + return $imageUrl; + } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php index 99db0f8f4..15959d465 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php @@ -605,17 +605,39 @@ public function frontInitBefore(Varien_Event_Observer $observer) $helper = $this->makeHelper(); if ($helper->wasProductImageCacheFlushed()) { try { - $tableName = $mailchimpTableName = Mage::getSingleton('core/resource')->getTableName('mailchimp/ecommercesyncdata'); - $sqlQuery = "UPDATE " . $tableName . " SET mailchimp_sync_modified = 1 WHERE type = '" . Ebizmarts_MailChimp_Model_Config::IS_PRODUCT . "';"; - $connection = Mage::getSingleton('core/resource')->getConnection('core_write'); - $connection->query($sqlQuery); + $this->markProductsAsModified(); } catch (Exception $e) { $helper->logError($e->getMessage()); } - $config = Mage::getConfig(); - $config->deleteConfig(Ebizmarts_MailChimp_Model_Config::PRODUCT_IMAGE_CACHE_FLUSH, 0, 'default'); + $config = $this->getConfig(); + $config->deleteConfig(Ebizmarts_MailChimp_Model_Config::PRODUCT_IMAGE_CACHE_FLUSH, 'default', 0); $config->cleanCache(); } } + + /** + * @return Mage_Core_Model_Abstract + */ + protected function getCoreResource() + { + return Mage::getSingleton('core/resource'); + } + + protected function markProductsAsModified() + { + $tableName = $mailchimpTableName = $this->getCoreResource()->getTableName('mailchimp/ecommercesyncdata'); + $sqlQuery = "UPDATE " . $tableName . " SET mailchimp_sync_modified = 1 WHERE type = '" . Ebizmarts_MailChimp_Model_Config::IS_PRODUCT . "';"; + $connection = $this->getCoreResource()->getConnection('core_write'); + $connection->query($sqlQuery); + } + + /** + * @return Mage_Core_Model_Config + */ + protected function getConfig() + { + $config = Mage::getConfig(); + return $config; + } } diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml index ba914aaf8..54e21fcbe 100755 --- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml +++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml @@ -133,6 +133,22 @@ + + + + mailchimp/observer + cleanProductImagesCacheAfter + + + + + + + mailchimp/observer + frontInitBefore + + + @@ -231,14 +247,6 @@ - - - - mailchimp/observer - frontInitBefore - - - 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 12979f9fc..816779fd1 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php @@ -290,4 +290,48 @@ public function testSaveMailChimpConfig() $helperMock->saveMailChimpConfig(array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MIGRATE_FROM_116, 1)), 0, 'default'); } + + public function testGetImageUrlById() + { + $productId = 1; + $magentoStoreId = 1; + $defaultStoreId = 0; + $imageSize = 'image'; + + $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) + ->disableOriginalConstructor() + ->setMethods(array('getProductResourceModel', 'getProductModel', 'getImageSize', 'getCurrentStoreId', 'setCurrentStore')) + ->getMock(); + + $productModelMock = $this->getMockBuilder(Mage_Catalog_Model_Product::class) + ->disableOriginalConstructor() + ->setMethods(array('setData', 'getImageUrl')) + ->getMock(); + + $productResourceModelMock = $this->getMockBuilder(Mage_Catalog_Model_Resource_Product::class) + ->disableOriginalConstructor() + ->setMethods(array('getAttributeRawValue')) + ->getMock(); + + $imageModelMock = $this->getMockBuilder(Mage_Media_Model_Image::class) + ->disableOriginalConstructor() + ->getMock(); + + $helperMock->expects($this->once())->method('getProductResourceModel')->willReturn($productResourceModelMock); + $helperMock->expects($this->once())->method('getProductModel')->willReturn($productModelMock); + $helperMock->expects($this->once())->method('getImageSize')->with($magentoStoreId)->willReturn($imageSize); + + $productResourceModelMock->expects($this->once())->method('getAttributeRawValue')->with($productId, $imageSize, $magentoStoreId)->willReturn($imageModelMock); + + $productModelMock->expects($this->once())->method('setData')->with($imageSize, $imageModelMock); + $productModelMock->expects($this->once())->method('getImageUrl')->willReturn('ImageUrl'); + + $helperMock->expects($this->once())->method('getCurrentStoreId')->willReturn($defaultStoreId); + + $helperMock->expects($this->exactly(2))->method('setCurrentStore')->withConsecutive(array($magentoStoreId), array($defaultStoreId)); + + $return = $helperMock->getImageUrlById($productId, $magentoStoreId); + + $this->assertEquals($return, 'ImageUrl'); + } } \ No newline at end of file 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 0d629027a..35dd40bfa 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 @@ -28,7 +28,7 @@ public function testHandleEcommerceBatches() $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() - ->setMethods(array('handleResendDataBefore', 'handleResendDataAfter')) + ->setMethods(array('handleResendDataBefore', 'handleResendDataAfter', 'isEcomSyncDataEnabled')) ->getMock(); $storeArrayMock = $this->getMockBuilder(Mage_Core_Model_Resource_Store_Collection::class) @@ -48,6 +48,7 @@ public function testHandleEcommerceBatches() $helperMock->expects($this->once())->method('handleResendDataBefore'); $helperMock->expects($this->once())->method('handleResendDataAfter'); + $helperMock->expects($this->once())->method('isEcomSyncDataEnabled')->with($storeId)->willReturn(true); $apiBatchesMock->expects($this->once())->method('getHelper')->willReturn($helperMock); $apiBatchesMock->expects($this->once())->method('getStores')->willReturn($storeArrayMock); 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 72db51486..bad07512e 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 @@ -168,4 +168,9 @@ private function configurableNoChildren() { return \Ebizmarts_MailChimp_Model_Api_Products::$noChildrenIds; } + + public function testUpdate() + { + + } } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php index be3c809cb..68a7f8f11 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php @@ -90,4 +90,37 @@ private function makeEventObserverMock($eventMock, $callCount) return $eventObserverMock; } + + public function testFrontInitBefore() + { + $modelMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Observer::class) + ->disableOriginalConstructor() + ->setMethods(array('makeHelper', 'markProductsAsModified', 'getConfig')) + ->getMock(); + + $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) + ->disableOriginalConstructor() + ->setMethods(array('wasProductImageCacheFlushed')) + ->getMock(); + + $configMock = $this->getMockBuilder(Mage_Core_Model_Config::class) + ->disableOriginalConstructor() + ->setMethods(array('deleteConfig', 'cleanCache')) + ->getMock(); + + $eventObserverMock = $this->getMockBuilder(Varien_Event_Observer::class) + ->disableOriginalConstructor() + ->getMock(); + + $modelMock->expects($this->once())->method('makeHelper')->willReturn($helperMock); + $modelMock->expects($this->once())->method('markProductsAsModified'); + $modelMock->expects($this->once())->method('getConfig')->willReturn($configMock); + + $helperMock->expects($this->once())->method('wasProductImageCacheFlushed')->willReturn(1); + + $configMock->expects($this->once())->method('deleteConfig')->with(Ebizmarts_MailChimp_Model_Config::PRODUCT_IMAGE_CACHE_FLUSH, 'default', 0); + $configMock->expects($this->once())->method('cleanCache'); + + $modelMock->frontInitBefore($eventObserverMock); + } } \ No newline at end of file From 99745dd83c4e86a761c18052bc331fa7c0628efd Mon Sep 17 00:00:00 2001 From: Santiago Date: Tue, 31 Oct 2017 15:30:46 -0300 Subject: [PATCH 2/2] Removed empty method. --- .../tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php | 5 ----- 1 file changed, 5 deletions(-) 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 bad07512e..72db51486 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 @@ -168,9 +168,4 @@ private function configurableNoChildren() { return \Ebizmarts_MailChimp_Model_Api_Products::$noChildrenIds; } - - public function testUpdate() - { - - } }