Skip to content

Commit

Permalink
Merge pull request #1256 from mailchimp/issue_1253
Browse files Browse the repository at this point in the history
Promo Rule and Promo Code related are properly deleted both in Magento and Mailchimp
  • Loading branch information
roberto-ebizmarts authored Aug 9, 2021
2 parents a4cfb1b + e23b346 commit 1e8cdaf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ protected function deleteUnsentItems()
$resource = $helper->getCoreResource();
$connection = $resource->getConnection('core_write');
$tableName = $resource->getTableName('mailchimp/ecommercesyncdata');
$where = array("batch_id IS NULL AND mailchimp_sync_modified != 1");
$where = array("batch_id IS NULL AND mailchimp_sync_modified != 1 AND mailchimp_sync_deleted != 1");
$connection->delete($tableName, $where);
}

Expand Down Expand Up @@ -709,7 +709,7 @@ public function getBatchResponse($batchId, $magentoStoreId)
if ($fileHelper->isDir($baseDir.DS.'var'.DS.'mailchimp') == false)
{
$fileHelper->mkDir($baseDir.DS.'var'.DS.'mailchimp');
}
}
if ($api) {
// check the status of the job
$response = $api->batchOperation->status($batchId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ protected function _setDeleted($codeId, $promoRuleId)

foreach ($promoCodes as $promoCode) {
$mailchimpStoreId = $promoCode->getMailchimpStoreId();
$this->setMailchimpStoreId($mailchimpStoreId);
$this->addDeletedRelatedId($codeId, $promoRuleId);
}
}
Expand Down
7 changes: 6 additions & 1 deletion app/code/community/Ebizmarts/MailChimp/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,11 +1025,16 @@ public function salesruleSaveAfter(Varien_Event_Observer $observer)

public function salesruleDeleteAfter(Varien_Event_Observer $observer)
{
$promoRulesApi = $this->makeApiPromoRule();
$rule = $observer->getEvent()->getRule();
$ruleId = $rule->getRuleId();
$couponId = $rule->getPrimaryCoupon()->getData() ['coupon_id'];

$promoRulesApi = $this->makeApiPromoRule();
$promoRulesApi->markAsDeleted($ruleId);

$promoCodesApi = $this->makeApiPromoCode();
$promoCodesApi->markAsDeleted($couponId, $ruleId);

return $observer;
}

Expand Down

0 comments on commit 1e8cdaf

Please sign in to comment.