Skip to content

Commit

Permalink
Using existent generateCodeData() function, instead: _generatePromoCo…
Browse files Browse the repository at this point in the history
…deData()

Removing unnecessary _makeModifiedPromoCodesCollection() function
Passing $magentoStoreId instead $mailchimpStoreId to generateCodeData() function
  • Loading branch information
roberto-ebizmarts committed Jul 30, 2021
1 parent 64be9f2 commit 3965388
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions app/code/community/Ebizmarts/MailChimp/Model/Api/PromoCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ protected function _getNewPromoCodes()
protected function _getModifiedPromoCodes()
{
$mailchimpStoreId = $this->getMailchimpStoreId();
$magentoStoreId = $this->getMagentoStoreId();
$batchArray = array();
$counter = 0;

$modifiedPromoCodes = $this->buildEcommerceCollectionToSync(
Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE,
"m4m.mailchimp_sync_modified = 1 and m4m.mailchimp_store_id = '$mailchimpStoreId'",
"m4m.mailchimp_sync_modified = 1",
"modified"
);

Expand All @@ -223,7 +224,7 @@ protected function _getModifiedPromoCodes()

if ($promoCode->getMailchimpSyncModified()) {
$batchArray[$counter]['method'] = "PATCH";
$ruleData = $this->generateCodeData($promoCode, $promoRuleId, $mailchimpStoreId);
$ruleData = $this->generateCodeData($promoCode, $promoRuleId, $magentoStoreId);
$promoRuleJson = json_encode($ruleData);
$batchArray[$counter]['body'] = $promoRuleJson;
$counter++;
Expand All @@ -233,24 +234,6 @@ protected function _getModifiedPromoCodes()
return $batchArray;
}

/**
* @return Ebizmarts_MailChimp_Model_Resource_Ecommercesyncdata_Collection
*/
protected function _makeModifiedPromoCodesCollection()
{
$modifiedPromoCodes = $this->getMailchimpEcommerceSyncDataModel()->getCollection();

$this->_ecommercePromoCodesCollection->addWhere(
$modifiedPromoCodes,
"mailchimp_store_id = '" . $this->getMailchimpStoreId()
. "' AND type = '" . Ebizmarts_MailChimp_Model_Config::IS_PROMO_CODE
. "' AND (mailchimp_sync_modified = 1)",
$this->getBatchLimitFromConfig()
);

return $modifiedPromoCodes;
}

/**
* @return mixed
*/
Expand Down Expand Up @@ -322,13 +305,9 @@ public function joinMailchimpSyncDataWithoutWhere($collection, $mailchimpStoreId
protected function generateCodeData($promoCode, $promoRuleId, $magentoStoreId)
{
$data = array();
$code = $promoCode->getCode();
$data['id'] = $promoCode->getCouponId();
$data['code'] = $code;

//Set title as description if description null
$data['code'] = $promoCode->getCode();;
$data['redemption_url'] = $this->getRedemptionUrl($promoCode, $magentoStoreId);

$data['usage_count'] = (integer) $promoCode->getTimesUsed();
$data['created_at_foreign'] = $promoCode->getCreatedAt();
$data['updated_at_foreign'] = Mage::getSingleton('core/date')->date("Y-m-d H:i:s");
Expand All @@ -343,17 +322,19 @@ protected function getRedemptionUrl($promoCode, $magentoStoreId)
{
$token = $this->getToken();
$promoCode->setToken($token);
$couponId = $promoCode->getCouponId();

$url = Mage::getModel('core/url')->setStore($magentoStoreId)->getUrl(
'mailchimp/cart/loadcoupon',
array(
'_nosid' => true,
'_secure' => true,
'coupon_id' => $promoCode->getCouponId(),
'coupon_id' => $couponId,
'coupon_token' => $token
)
)
. 'mailchimp/cart/loadcoupon?coupon_id='
. $promoCode->getCouponId()
. $couponId
. '&coupon_token='
. $token;

Expand Down

0 comments on commit 3965388

Please sign in to comment.