Skip to content

Commit

Permalink
Merge pull request #253 from Nosto/release/3.5.0
Browse files Browse the repository at this point in the history
Release 3.5.0
  • Loading branch information
liangde-chen committed Aug 2, 2018
2 parents 542521d + f7065a0 commit 0d283e1
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 56 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning(http://semver.org/).

## 3.5.0
- Update customer's marketing permission to Nosto via api
- Fixed a bug that page type div was rendered inside html head
- Fixed a bug that same Nosto account could be connected to different stores or languages.

## 3.4.3
- Fixed a bug that was preventing the tagging to show due to a missing cache clear after the update

Expand Down
1 change: 1 addition & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static function init($moduleDir)
require_once($moduleDir . '/classes/services/NostoSettingsService.php');
require_once($moduleDir . '/classes/services/NostoSignupService.php');
require_once($moduleDir . '/classes/services/NostoCartService.php');
require_once($moduleDir . '/classes/services/NostoCustomerService.php');
require_once($moduleDir . '/classes/helpers/NostoHelperUrl.php');
require_once($moduleDir . '/classes/helpers/NostoHelperCurrency.php');
require_once($moduleDir . '/classes/helpers/NostoHelperPrice.php');
Expand Down
1 change: 1 addition & 0 deletions classes/blocks/NostoDefaultTagging.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function get(NostoTagging $module)
}

$html = '';
$html .= NostoPageTypeTagging::get();
$html .= NostoCustomerTagging::get();
$html .= NostoCartTagging::get();
$html .= NostoVariationTagging::get();
Expand Down
1 change: 0 additions & 1 deletion classes/blocks/NostoHeaderContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static function get(NostoTagging $module)
$html .= $module->render('views/templates/hook/header_embed-script.tpl');
$html .= $module->render('views/templates/hook/header_add-to-cart.tpl');
$html .= $module->render('views/templates/hook/header_prestashop-add-to-cart-event-handler.tpl');
$html .= NostoPageTypeTagging::get();

return $html;
}
Expand Down
7 changes: 3 additions & 4 deletions classes/helpers/NostoHelperAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public static function save(NostoSDKSignupAccountInterface $account)
*/
public static function delete()
{
$success = NostoHelperConfig::deleteAllFromContext();
return $success;
return NostoHelperConfig::deleteAllFromContext();
}

/**
Expand All @@ -81,6 +80,7 @@ public static function deleteAll()
* Finds and returns an account for given criteria.
*
* @return NostoSDKAccount|null the account with loaded API tokens, or null if not found.
* @throws \Nosto\NostoException
*/
public static function getAccount()
{
Expand All @@ -94,13 +94,11 @@ public static function getAccount()
$tokens[$tokenName] = $tokenValue;
}
}

if (!empty($tokens)) {
foreach ($tokens as $name => $value) {
$account->addApiToken(new NostoSDKAPIToken($name, $value));
}
}

return $account;
}
return null;
Expand All @@ -110,6 +108,7 @@ public static function getAccount()
* Checks if an account exists and is "connected to Nosto" for given criteria.
*
* @return bool true if it does, false otherwise.
* @throws \Nosto\NostoException
*/
public static function existsAndIsConnected()
{
Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/NostoHelperContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function runInContext(
self::emulateContext($languageId, $shopId, $currencyId, $employeeId, $countryId);
try {
$retVal = $callable();
} catch (Exception $e) {
} catch (\Exception $e) {
NostoHelperLogger::log($e->getMessage());
}
self::revertToOriginalContext();
Expand Down
132 changes: 132 additions & 0 deletions classes/services/NostoCustomerService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
/**
* 2013-2017 Nosto Solutions Ltd
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@nosto.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author Nosto Solutions Ltd <contact@nosto.com>
* @copyright 2013-2017 Nosto Solutions Ltd
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

use Nosto\Object\Signup\Account as NostoSDKAccount;
use Nosto\Operation\MarketingPermission as NostoSDKMarketingPermission;
use Nosto\Request\Api\Token as NostoSDKToken;

/**
* Helper class for sending Customer data to Nosto.
*/
class NostoCustomerService extends AbstractNostoService
{
/**
* Customer updated event handler. It is called after Customer updated or created.
*
* @param Customer $customer event parameters
* @return bool
*/
public function customerUpdated(Customer $customer)
{
if (!$customer->email
|| !NostoTagging::isEnabled(NostoTagging::MODULE_NAME)
) {
return false;
}
// Try to update marketing permission to all store views that has share_customer flag on
$updatedAccounts = array();
NostoHelperContext::runInContextForEachLanguageEachShop(function () use ($customer, &$updatedAccounts) {
$shopGroup = Shop::getContextShopGroup();
if ($shopGroup !== null
&& (bool)$shopGroup->active
&& (bool)$shopGroup->share_customer
) {
try {
$account = NostoHelperAccount::getAccount();
if ($account instanceof NostoSDKAccount && $account->isConnectedToNosto()) {
$updatedAccounts[$account->getName()] =
self::updateMarketingPermissionInCurrentContext($customer, $account);
}
} catch (\Exception $e) {
NostoHelperLogger::error($e);
}
}
});
// Update marketing permission for the current context, in case it's a single store
try {
$account = NostoHelperAccount::getAccount();
if ($account instanceof NostoSDKAccount
&& $account->isConnectedToNosto()
&& !array_key_exists($account->getName(), $updatedAccounts)
) {
$updatedAccounts[$account->getName()] =
self::updateMarketingPermissionInCurrentContext($customer, $account);
}
} catch (\Exception $e) {
NostoHelperLogger::error($e);
}
return $this->isAllUpdated($updatedAccounts);
}

/**
* Fires the update for the given customer and account
* returns true if the update was successful
*
* @param Customer $customer
* @param NostoSDKAccount $account
* @return bool
*/
private static function updateMarketingPermissionInCurrentContext(Customer $customer, NostoSDKAccount $account)
{
if (!$account->getApiToken(NostoSDKToken::API_EMAIL)) {
NostoHelperLogger::info(
sprintf(
'API_EMAIL api token is missing (%s). Please reconnect Nosto account to create API_EMAIL token',
$account->getName()
)
);
return false;
}
$newsletter = $customer->newsletter;
$email = $customer->email;
$service = new NostoSDKMarketingPermission($account);
return $service->update($email, $newsletter);
}

/**
* Check if all store views that the customer belongs to
* were updated. Logs stores that failed to update.
*
* @param $updatedAccounts
* @return bool
*/
private function isAllUpdated(array $updatedAccounts)
{
$success = true;
foreach ($updatedAccounts as $accountName => $isUpdated) {
if ($isUpdated === false) {
NostoHelperLogger::info(
sprintf(
'Failed to update marketing permission for the account (%s) ',
$accountName
)
);
$success = false;
break;
}
}
return $success;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nosto/nostotagging",
"description": "Nosto Module for Prestashop",
"require": {
"nosto/php-sdk": "3.4.2"
"nosto/php-sdk": "3.5.0"
},
"require-dev": {
"phing/phing": "2.*",
Expand Down

0 comments on commit 0d283e1

Please sign in to comment.