Skip to content

Commit

Permalink
Merge branch 'develop' into capital-c-issue718
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiagoebizmarts authored Jun 28, 2018
2 parents 971bacc + d85bd53 commit 87c85d8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 34 deletions.
32 changes: 21 additions & 11 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ public function deleteStore($scopeId, $scope)
}
}

protected function saveLastItemsSent($scopeId, $scope)
public function saveLastItemsSent($scopeId, $scope)
{
$isSyncing = $this->getMCIsSyncing($scopeId, $scope);
if ($isSyncing != 1) {
Expand Down Expand Up @@ -876,10 +876,12 @@ protected function getLastCustomerSent($scopeId, $scope)
$mcStoreId = $this->getMCStoreId($scopeId, $scope);
$syncDataCollection = Mage::getModel('mailchimp/ecommercesyncdata')->getCollection()
->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId))
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER));
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_CUSTOMER))
->setOrder('related_id', 'DESC')
->getSelect()->limit(1);

if ($syncDataCollection->getSize()) {
$customerSyncData = $syncDataCollection->getLastItem();
$customerSyncData = $syncDataCollection->getFirstItem();
$lastCustomerSent = $customerSyncData->getRelatedId();
}

Expand All @@ -892,10 +894,12 @@ protected function getLastProductSent($scopeId, $scope)
$mcStoreId = $this->getMCStoreId($scopeId, $scope);
$syncDataCollection = Mage::getModel('mailchimp/ecommercesyncdata')->getCollection()
->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId))
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_PRODUCT));
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_PRODUCT))
->setOrder('related_id', 'DESC')
->getSelect()->limit(1);

if ($syncDataCollection->getSize()) {
$productSyncData = $syncDataCollection->getLastItem();
$productSyncData = $syncDataCollection->getFirstItem();
$lastProductSent = $productSyncData->getRelatedId();
}

Expand All @@ -908,10 +912,12 @@ protected function getLastOrderSent($scopeId, $scope)
$mcStoreId = $this->getMCStoreId($scopeId, $scope);
$syncDataCollection = Mage::getModel('mailchimp/ecommercesyncdata')->getCollection()
->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId))
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_ORDER));
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_ORDER))
->setOrder('related_id', 'DESC')
->getSelect()->limit(1);

if ($syncDataCollection->getSize()) {
$orderSyncData = $syncDataCollection->getLastItem();
$orderSyncData = $syncDataCollection->getFirstItem();
$lastOrderSent = $orderSyncData->getRelatedId();
}

Expand All @@ -924,10 +930,12 @@ protected function getLastCartSent($scopeId, $scope)
$mcStoreId = $this->getMCStoreId($scopeId, $scope);
$syncDataCollection = Mage::getModel('mailchimp/ecommercesyncdata')->getCollection()
->addFieldToFilter('mailchimp_store_id', array('eq' => $mcStoreId))
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_QUOTE));
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_QUOTE))
->setOrder('related_id', 'DESC')
->getSelect()->limit(1);

if ($syncDataCollection->getSize()) {
$cartSyncData = $syncDataCollection->getLastItem();
$cartSyncData = $syncDataCollection->getFirstItem();
$lastCartSent = $cartSyncData->getRelatedId();
}
return $lastCartSent;
Expand All @@ -939,10 +947,12 @@ protected function getLastPromoCodeSent($scopeId, $scope)
$mcStoreId = $this->getMCStoreId($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));
->addFieldToFilter('type', array('eq' => Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE))
->setOrder('related_id', 'DESC')
->getSelect()->limit(1);

if ($syncDataCollection->getSize()) {
$promoCodeSyncData = $syncDataCollection->getLastItem();
$promoCodeSyncData = $syncDataCollection->getFirstItem();
$lastPromoCodeSent = $promoCodeSyncData->getRelatedId();
}

Expand Down
17 changes: 0 additions & 17 deletions app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ public function handleEcommerceBatches()
$syncedDateArray = array();
foreach ($stores as $store) {
$storeId = $store->getId();
$this->handleResetIfNecessary($storeId);
$syncedDateArray = $this->addSyncValueToArray($storeId, $syncedDateArray);
}
$this->handleSyncingValue($syncedDateArray);
Expand Down Expand Up @@ -778,22 +777,6 @@ public function handleSyncingValue($syncedDateArray)
}
}

/**
* @param $storeId
*/
protected function handleResetIfNecessary($storeId)
{
$helper = $this->getHelper();
if ($helper->getIsReset($storeId)) {
$scopeToReset = $helper->getMailChimpScopeByStoreId($storeId);
if ($scopeToReset) {
$helper->resetMCEcommerceData($scopeToReset['scope_id'], $scopeToReset['scope'], true);
$configValue = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTORE_RESETED, 0));
$helper->saveMailchimpConfig($configValue, $scopeToReset['scope_id'], $scopeToReset['scope']);
}
}
}

/**
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function testGetDateSyncFinishByStoreId()
->getMock();

$helperMock->expects($this->once())->method('getMCStoreId')->with($scopeId, $scope)->willReturn($mailchimpStoreId);
$helperMock->expects($this->once())->method('getConfigValueForScope')->with(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE."_$mailchimpStoreId", $scopeId, $scope);
$helperMock->expects($this->once())->method('getConfigValueForScope')->with(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE . "_$mailchimpStoreId", $scopeId, $scope);

$helperMock->getDateSyncFinishByStoreId($scopeId, $scope);
}
Expand Down Expand Up @@ -441,7 +441,8 @@ public function testGetImageFunctionName()

}

public function testSetImageSizeVarToArray(){
public function testSetImageSizeVarToArray()
{
$imageSize = 'image_size';

$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
Expand Down Expand Up @@ -772,10 +773,10 @@ public function testGetMCStoreNameForDefault()
$helperMock->expects($this->exactly(2))->method('getConfigValueForScope')->withConsecutive(
array(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME, $scopeId, $scope),
array('web/unsecure/base_url', 0)
)->willReturnOnConsecutiveCalls(
)->willReturnOnConsecutiveCalls(
'',
$storeName
);
);

$result = $helperMock->getMCStoreName($scopeId, $scope);

Expand Down Expand Up @@ -931,4 +932,40 @@ public function testResetCampaign()

$helperMock->resetCampaign($scopeId, $scope);
}

public function testSaveLastItemsSent()
{
$scope = 'stores';
$scopeId = 1;
$customerLastId = 10;
$productLastId = 10;
$orderLastId = 10;
$cartLastId = 10;
$promoCodeLastId = 10;
$configValues = array(
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CUSTOMER_LAST_ID, $customerLastId),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PRODUCT_LAST_ID, $productLastId),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_ORDER_LAST_ID, $orderLastId),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CART_LAST_ID, $cartLastId),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PCD_LAST_ID, $promoCodeLastId),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_ENABLED, 1),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_TURN, 1)
);

$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
->disableOriginalConstructor()
->setMethods(array('getMCIsSyncing', 'getLastCustomerSent', 'getLastProductSent', 'getLastOrderSent',
'getLastCartSent', 'getLastPromoCodeSent', 'saveMailchimpConfig'))
->getMock();

$helperMock->expects($this->once())->method('getMCIsSyncing')->with($scopeId, $scope)->willReturn(false);
$helperMock->expects($this->once())->method('getLastCustomerSent')->with($scopeId, $scope)->willReturn($customerLastId);
$helperMock->expects($this->once())->method('getLastProductSent')->with($scopeId, $scope)->willReturn($productLastId);
$helperMock->expects($this->once())->method('getLastOrderSent')->with($scopeId, $scope)->willReturn($orderLastId);
$helperMock->expects($this->once())->method('getLastCartSent')->with($scopeId, $scope)->willReturn($cartLastId);
$helperMock->expects($this->once())->method('getLastPromoCodeSent')->with($scopeId, $scope)->willReturn($promoCodeLastId);
$helperMock->expects($this->once())->method('saveMailchimpConfig')->with($configValues, $scopeId, $scope);

$helperMock->saveLastItemsSent($scopeId, $scope);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function testHandleEcommerceBatches()
$storeId = 1;
$apiBatchesMock = $this->apiBatchesMock
->disableOriginalConstructor()
->setMethods(array('getHelper', '_getResults', '_sendEcommerceBatch', 'handleResetIfNecessary', 'addSyncValueToArray', 'handleSyncingValue', 'getStores'))
->setMethods(array('getHelper', '_getResults', '_sendEcommerceBatch', 'addSyncValueToArray', 'handleSyncingValue', 'getStores'))
->getMock();

$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
Expand Down Expand Up @@ -206,7 +206,6 @@ public function testHandleEcommerceBatches()
$apiBatchesMock->expects($this->once())->method('getStores')->willReturn($storeArrayMock);
$apiBatchesMock->expects($this->once())->method('_getResults')->with($storeId);
$apiBatchesMock->expects($this->once())->method('_sendEcommerceBatch')->with($storeId);
$apiBatchesMock->expects($this->once())->method('handleResetIfNecessary')->with($storeId);
$apiBatchesMock->expects($this->once())->method('addSyncValueToArray')->with($storeId, $syncedArray)->willReturn($syncedArray);

$apiBatchesMock->handleEcommerceBatches();
Expand Down

0 comments on commit 87c85d8

Please sign in to comment.