Skip to content

Commit

Permalink
Merge branch 'develop' into release/6.4.20
Browse files Browse the repository at this point in the history
  • Loading branch information
sta1r committed Sep 9, 2019
2 parents 4391121 + dd3a2b0 commit 76f9ed9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
41 changes: 34 additions & 7 deletions code/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ public function toOptionArray()
}

$enabled = Mage::helper('ddg')->isEnabled($website);
$client = Mage::helper('ddg')->getWebsiteApiClient($website);


//api enabled get campaigns
if ($enabled && $client instanceof Dotdigitalgroup_Email_Model_Apiconnector_Client) {
$savedCampaigns = Mage::registry('savedcampigns');
if ($enabled) {
$savedCampaigns = Mage::registry('savedcampaigns');

//get campaigns from registry
if ($savedCampaigns) {
$campaigns = $savedCampaigns;
} else {
$campaigns = $client->getCampaigns();
Mage::unregister('savedcampigns');
Mage::register('savedcampigns', $campaigns);
$campaigns = $this->fetchCampaigns($website);
}

//@codingStandardsIgnoreStart
Expand All @@ -61,4 +59,33 @@ public function toOptionArray()
return $fields;
}

}
/**
* @param int $website
* @return array
* @throws \Exception
*/
private function fetchCampaigns($website)
{
$client = Mage::helper('ddg')->getWebsiteApiClient($website);
if (!$client instanceof Dotdigitalgroup_Email_Model_Apiconnector_Client) {
return;
}

$campaigns = [];

do {
// due to the API limitation of 1000 campaign responses, loop while the campaigns returned === 1000,
// skipping by the count of the total received so far
if (!is_array($campaignResponse = $client->getCampaigns(count($campaigns)))) {
return (array) $campaignResponse;
}
$campaigns = array_merge($campaigns, $campaignResponse);
} while (count($campaignResponse) === 1000);

Mage::unregister('savedcampaigns');
Mage::register('savedcampaigns', $campaigns);

return $campaigns;
}

}
12 changes: 10 additions & 2 deletions code/Dotdigitalgroup/Email/Model/Apiconnector/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,19 @@ public function postAddressBooks($name, $visibility = 'Public')
/**
* Get list of all campaigns.
*
* @param int $skip Number of campaigns to skip
* @param int $select Number of campaigns to select
*
* @return mixed
*/
public function getCampaigns()
public function getCampaigns($skip = 0, $select = 1000)
{
$url = $this->getApiEndpoint() . self::REST_DATA_FIELDS_CAMPAIGNS;
$url = sprintf('%s%s?select=%s&skip=%s',
$this->getApiEndpoint(),
self::REST_DATA_FIELDS_CAMPAIGNS,
$select,
$skip
);
$this->setUrl($url)
->setVerb('GET');

Expand Down
2 changes: 1 addition & 1 deletion code/Dotdigitalgroup/Email/Model/Customer/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ public function expose()
{
return get_object_vars($this);
}
}
}
30 changes: 20 additions & 10 deletions code/Dotdigitalgroup/Email/Model/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ class Dotdigitalgroup_Email_Model_Review extends Mage_Core_Model_Abstract
* @var mixed
*/
public $start;

/**
* @var
*/
public $countReviews;

/**
* @var
*/
public $reviews;

/**
* @var array
*/
public $reviewIds;

public $emailReviewData;

/**
* Constructor.
Expand Down Expand Up @@ -91,7 +93,7 @@ public function sync()
);
//if no error then set imported
if ($check) {
$this->getResource()->setImported($this->reviewIds);
$this->getResource()->setImported(array_keys($this->emailReviewData));
}

//@codingStandardsIgnoreStart
Expand Down Expand Up @@ -121,33 +123,41 @@ protected function _exportReviewsForWebsite(Mage_Core_Model_Website $website)
Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT,
$website
);

$emailReviews = $this->_getReviewsToExport($website, $limit);
$this->reviewIds = $emailReviews->getColumnValues('review_id');
foreach ($emailReviews->getItems() as $item) {
$this->emailReviewData[$item['review_id']] = [
'store_id' => $item['store_id']
];
}

if (! empty($this->reviewIds)) {
if (!empty($this->emailReviewData)) {
$reviews = Mage::getModel('review/review')
->getCollection()
->addFieldToFilter(
'main_table.review_id', array('in' => $this->reviewIds)
'main_table.review_id', array('in' => array_keys($this->emailReviewData))
)
->addFieldToFilter('customer_id', array('notnull' => 'true'));

//@codingStandardsIgnoreStart
$reviews->getSelect()
->joinLeft(
->join(
array('c' => Mage::getSingleton('core/resource')
->getTableName('customer/entity')),
'c.entity_id = customer_id',
array('email', 'store_id')
array('email')
);

if ($reviews->getSize()) {
foreach ($reviews as $mageReview) {
try {
$storeId = $this->emailReviewData[$mageReview->getId()]['store_id'];
$mageReview->setStoreId($storeId);

$product = Mage::getModel('catalog/product')
->getCollection()
->addIdFilter($mageReview->getEntityPkValue())
->setStoreId($mageReview->getStoreId())
->setStoreId($storeId)
->addAttributeToSelect(
array('product_url', 'name', 'store_id', 'small_image')
)
Expand Down Expand Up @@ -204,4 +214,4 @@ protected function _getReviewsToExport(Mage_Core_Model_Website $website, $limit
)
->setPageSize($limit);
}
}
}

0 comments on commit 76f9ed9

Please sign in to comment.