Skip to content

Commit

Permalink
Merged PR 12472: Release 6.4.12
Browse files Browse the repository at this point in the history
Related work items: #80912, #83641, #84050, #84691
  • Loading branch information
adeelq committed Mar 13, 2019
2 parents 1c5a423 + 4b3d3fc commit f6db1ef
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 24 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ You are welcome to contribute to Engagement Cloud for Magento! You can either:
- Fix a bug: please fork this repo and submit the Pull Request to our [Develop branch](https://github.com/dotmailer/dotmailer-magento-extension/tree/develop)
Request a feature on our [roadmap](https://roadmap.dotdigital.com)

# V6.4.12

##### Improvements

* We've improved the performance of the product sync process by setting a limit when querying products before import
* Resubscribed contacts weren't added back to the "subscriber" address book; they are now
* Configurable, grouped, and bundled products are now correctly synced to Engagement Cloud with the lowest relevant price of their children

##### Bug Fixes
* We've fixed incorrect syntax in the Order model (#309)
* We've fixed an issue that caused errors within the Sweet Tooth (Smile.io) integration

# V6.4.11

##### Improvements
Expand Down
28 changes: 27 additions & 1 deletion code/Dotdigitalgroup/Email/Model/Apiconnector/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1534,5 +1534,31 @@ public function getCampaignByIdWithPreparedContent($campaignId)

return $response;
}


/**
* Resubscribes a previously unsubscribed contact to a given address book
*
* @param int $addressBookId
* @param string $email
*
* @return mixed
*/
public function postAddressBookContactResubscribe($addressBookId, $email)
{
$contact = array('unsubscribedContact' => array('email' => $email));
$url = $this->getApiEndpoint() . self::REST_ADDRESS_BOOKS . $addressBookId
. '/contacts/resubscribe';
$this->setUrl($url)
->setVerb('POST')
->buildPostBody($contact);

$response = $this->execute();

if (isset($response->message)) {
$message = 'POST ADDRESS BOOK CONTACT RESUBSCRIBE' . $response->message;
Mage::helper('ddg')->log($message);
}

return $response;
}
}
29 changes: 20 additions & 9 deletions code/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public function setRewardCustomer(Mage_Customer_Model_Customer $customer)
//get tbt reward customer
$tbtReward = Mage::getModel('rewards/customer')
->getRewardsCustomer($customer);

if (! is_object($tbtReward)) {
return;
}

$this->rewardCustomer = $tbtReward;

//get transfers collection from tbt reward. only active and order by last updated.
Expand Down Expand Up @@ -722,6 +727,9 @@ public function getRewardReferralUrl()
*/
public function getRewardPointBalance()
{
if (! isset($this->rewardCustomer)) {
return 0;
}
return $this->cleanString($this->rewardCustomer->getPointsSummary());
}

Expand All @@ -730,29 +738,32 @@ public function getRewardPointBalance()
*/
public function getRewardPointPending()
{
return $this->cleanString(
$this->rewardCustomer->getPendingPointsSummary()
);
if (! isset($this->rewardCustomer)) {
return 0;
}
return $this->cleanString($this->rewardCustomer->getPendingPointsSummary());
}

/**
* @return int
*/
public function getRewardPointPendingTime()
{
return $this->cleanString(
$this->rewardCustomer->getPendingTimePointsSummary()
);
if (! isset($this->rewardCustomer)) {
return 0;
}
return $this->cleanString($this->rewardCustomer->getPendingTimePointsSummary());
}

/**
* @return int
*/
public function getRewardPointOnHold()
{
return $this->cleanString(
$this->rewardCustomer->getOnHoldPointsSummary()
);
if (! isset($this->rewardCustomer)) {
return 0;
}
return $this->cleanString($this->rewardCustomer->getOnHoldPointsSummary());
}

/**
Expand Down
1 change: 1 addition & 0 deletions code/Dotdigitalgroup/Email/Model/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ protected function _getProductsToExport($store, $modified = false)
'imported', array('null' => 'true')
);
}
$connectorCollection->getSelect()->limit($limit);

if ($connectorCollection->getSize()) {
$productIds = $connectorCollection->getColumnValues('product_id');
Expand Down
2 changes: 1 addition & 1 deletion code/Dotdigitalgroup/Email/Model/Connector/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ protected function _setOrderItems($orderData)
$attributes[][$attributeCode]
= $this->_limitLength($value);
} elseif (is_array($value)) {
$value = implode($value, ', ');
$value = implode(', ', $value);
$attributes[][$attributeCode]
= $this->_limitLength($value);
}
Expand Down
165 changes: 155 additions & 10 deletions code/Dotdigitalgroup/Email/Model/Connector/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ public function __construct(Mage_Catalog_Model_Product $product)
$options = Mage::getModel('catalog/product_visibility')
->getOptionArray();
$this->visibility = $options[$product->getVisibility()];
$this->price = (float)number_format(
$product->getPrice(), 2, '.', ''
);
$this->specialPrice = (float)number_format(
$product->getSpecialPrice(), 2, '.', ''
);

$this->getMinPrices($product);

$this->url = $product->getProductUrl();
$this->imagePath = Mage::getModel('catalog/product_media_config')
->getMediaUrl($product->getSmallImage());
$stock = Mage::getModel('cataloginventory/stock_item')
->loadByProduct($product);
$this->stock = (float)number_format(
$stock->getQty(), 2, '.', ''
$stock->getQty(),
2,
'.',
''
);

$shortDescription = $product->getShortDescription();
Expand Down Expand Up @@ -153,7 +153,10 @@ public function __construct(Mage_Catalog_Model_Product $product)
$sOptions[$count]['sku'] = $selection->getSku();
$sOptions[$count]['id'] = $selection->getProductId();
$sOptions[$count]['price'] = (float)number_format(
$selection->getPrice(), 2, '.', ''
$selection->getPrice(),
2,
'.',
''
);
$count++;
}
Expand All @@ -177,7 +180,10 @@ public function __construct(Mage_Catalog_Model_Product $product)
foreach ($productAttribute['values'] as $attribute) {
$options[$count]['option'] = $attribute['default_label'];
$options[$count]['price'] = (float)number_format(
$attribute['pricing_value'], 2, '.', ''
$attribute['pricing_value'],
2,
'.',
''
);
$count++;
}
Expand All @@ -196,4 +202,143 @@ public function expose()
{
return get_object_vars($this);
}
}

/**
* Set the Minimum Prices for Configurable and Bundle products.
*
* @param Mage_Catalog_Model_Product $product
*
* @return null
*/
private function getMinPrices($product)
{
switch ($product->getTypeId()) {
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE:
$this->getMinConfigurablePrices($product);
break;
case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
$this->getMinBundlePrices($product);
break;
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
$this->getMinGroupedPrices($product);
break;
default:
$this->price = $product->getPrice();
$this->specialPrice = $product->getSpecialPrice();
}

$this->formatPriceValues();
}

/**
* Calculates the Minimum Final Price and Special Price for the Configurable Products.
*
* @param Mage_Catalog_Model_Product $product
*
* @return null
*/
private function getMinConfigurablePrices($product)
{
foreach ($product->getTypeInstance()->getChildrenIds($product->getId()) as $childProductIds) {
foreach ($childProductIds as $id) {
$productById = Mage::getModel('catalog/product')->load($id);
$childPrices[] = $productById->getPrice();
if ($productById->getSpecialPrice() !== null) {
$childSpecialPrices[] = $productById->getSpecialPrice();
}
}
}
$this->price = isset($childPrices) ? min($childPrices) : null;
$this->specialPrice = isset($childSpecialPrices) ? min($childSpecialPrices) : null;
}

/**
* Calculates the Minimum Final Price and Special Price for the Bundle Products.
*
* @param Mage_Catalog_Model_Product $product
*
* @return null
*/
private function getMinBundlePrices($product)
{
$this->price = 0;
$this->specialPrice = 0;
$productTypeInstance = $product->getTypeInstance(true);
$optionCol= $productTypeInstance->getOptionsCollection($product);
$selectionCol= $productTypeInstance->getSelectionsCollection(
$productTypeInstance->getOptionsIds($product),
$product
);
$optionCol->appendSelections($selectionCol);
foreach ($optionCol as $option) {
if ($option->getRequired()) {
$selections = $option->getSelections();
$specialPriceArrayFlag = [];
$minPrice = min(array_map(function ($s) use (&$specialPriceArrayFlag) {
if ($s->getSpecialPrice() > 0) {
$specialPriceArrayFlag[] = $s->getSpecialPrice();
}
return $s->price;
}, $selections));
$specialPriceSimpleProducts = min($specialPriceArrayFlag);

if ($specialPriceSimpleProducts > 0) {
if ($product->getSpecialPrice() > 0) {
$specialPriceSimpleProducts = ($specialPriceSimpleProducts * $product->getSpecialPrice()/100);
$this->specialPrice += $specialPriceSimpleProducts;
} else {
$this->specialPrice += $specialPriceSimpleProducts;
}
} elseif ($product->getSpecialPrice() > 0) {
$minSpecialPrice = ($minPrice * $product->getSpecialPrice()/100);
$this->specialPrice += $minSpecialPrice;
}

$this->price += round($minPrice, 2);
$this->specialPrice = ($this->price === $this->specialPrice) ? null : $this->specialPrice;
}
}
}

/**
* Calculates the Minimum Final Price and Special Price for the Grouped Products.
*
* @param Mage_Catalog_Model_Product $product
*
* @return null
*/
private function getMinGroupedPrices($product)
{
$childProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
foreach ($childProducts as $childProduct) {
$childPrices[] = $childProduct->getPrice();
if ($childProduct->getSpecialPrice() !== null) {
$childSpecialPrices[] = $childProduct->getSpecialPrice();
}
}
$this->price = isset($childPrices) ? min($childPrices) : null;
$this->specialPrice = isset($childSpecialPrices) ? min($childSpecialPrices) : null;
}


/**
* Formats the price values.
*
* @return null
*/
private function formatPriceValues()
{
$this->price = (float)number_format(
$this->price,
2,
'.',
''
);
$this->specialPrice = (float)number_format(
$this->specialPrice,
2,
'.',
''
);
}
}
6 changes: 4 additions & 2 deletions code/Dotdigitalgroup/Email/Model/Sync/Contact/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public function processCollection($collection)
if (isset($apiContact->message) && $apiContact->message ==
Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_CONTACT_SUPPRESSED
) {
$apiContact = $this->client->getContactByEmail($email);
$result = $this->client->postContactsResubscribe($apiContact);
$subscribersAddressBook = Mage::helper('ddg')->getSubscriberAddressBook($websiteId);
$result = ($subscribersAddressBook) ?
$this->client->postAddressBookContactResubscribe($subscribersAddressBook, $email) :
$this->client->postContactsResubscribe($this->client->getContactByEmail($email));
}
} elseif ($item->getImportMode() == Dotdigitalgroup_Email_Model_Importer::MODE_SUBSCRIBER_UPDATE) {
$email = $importData['email'];
Expand Down
2 changes: 1 addition & 1 deletion code/Dotdigitalgroup/Email/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Dotdigitalgroup_Email>
<version>6.4.11</version>
<version>6.4.12</version>
</Dotdigitalgroup_Email>
</modules>
<frontend>
Expand Down

0 comments on commit f6db1ef

Please sign in to comment.