Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/3.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pölönen committed Mar 1, 2018
2 parents df15b6e + 8d3dad3 commit 30cd82e
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

### 3.5.4
* Invalidate Nosto index if settings affecting the product data has been changed
* Revise some instructional texts

### 3.5.3
* Fix the issue that add to cart popup shows child product added to cart when adding a bundle product to cart

Expand Down
17 changes: 16 additions & 1 deletion app/code/community/Nosto/Tagging/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public function getUseSkus($store = null)
return (bool)Mage::getStoreConfig(self::XML_PATH_USE_SKUS, $store);
}

/**
/**
* Returns on/off setting for custom fields
*
* @param Mage_Core_Model_Store|null $store the store model or null.
Expand Down Expand Up @@ -718,5 +718,20 @@ public function getAllStoresUseProductIndexer()

return true;
}

/**
* Returns an array with Nosto settings
*
* @param null $store
* @return Mage_Core_Model_Store[]
*/
public function getNostoStoreConfig($store = null)
{
if ($store === null) {
$store = Mage::app()->getStore();
}
return Mage::getStoreConfig('nosto_tagging', $store);
}

}

173 changes: 164 additions & 9 deletions app/code/community/Nosto/Tagging/Model/Observer/Setting.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php
/**
* Magento
*
*
* NOTICE OF LICENSE
*
*
* This source file is subject to the Open Software License (OSL 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/osl-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 license@magentocommerce.com so we can send you a copy immediately.
*
*
* DISCLAIMER
*
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
*
* @category Nosto
* @package Nosto_Tagging
* @author Nosto Solutions Ltd <magento@nosto.com>
Expand All @@ -42,6 +42,13 @@
*/
class Nosto_Tagging_Model_Observer_Setting
{

/**
* Scheduled currency exchange rate setting key.
*/
const SCHEDULED_CURRENCY_EXCHANGE_RATE_UPDATE
= 'scheduled_currency_exchange_rate_update';

/**
* Updates / synchronizes Nosto account settings via API to Nosto
* for each store that has Nosto account.
Expand All @@ -53,7 +60,8 @@ class Nosto_Tagging_Model_Observer_Setting
* @return Nosto_Tagging_Model_Observer_Setting
*/
public function syncNostoAccount(/** @noinspection PhpUnusedParameterInspection */ // @codingStandardsIgnoreLine
Varien_Event_Observer $observer)
Varien_Event_Observer $observer
)
{
/** @var Nosto_Tagging_Helper_Data $helper */
$helper = Mage::helper('nosto_tagging');
Expand All @@ -80,9 +88,9 @@ public function syncNostoAccount(/** @noinspection PhpUnusedParameterInspection
);
}
if ($helper->isMultiCurrencyMethodExchangeRate($store)) {
if (
!$accountHelper->updateCurrencyExchangeRates(
$account, $store
if (!$accountHelper->updateCurrencyExchangeRates(
$account,
$store
)
) {
NostoLog::error(
Expand All @@ -101,4 +109,151 @@ public function syncNostoAccount(/** @noinspection PhpUnusedParameterInspection

return $this;
}


/**
* Checks if Nosto settings has changed
* under the magento config panel
*
* Event 'model_config_data_save_before'.
*
* @return Nosto_Tagging_Model_Observer_Setting
*/
public function checkNostoSettingsHaveChanged()
{
/** @var Nosto_Tagging_Helper_Data $helper */
$helper = Mage::helper('nosto_tagging');
try {
$request = Mage::app()->getRequest();
$section = isset($request->getParams()['section']) ? $request->getParams()['section'] : null;
if ($section === 'nosto_tagging' && $helper->isModuleEnabled()) {
/** @var Nosto_Tagging_Helper_Account $accountHelper */
$accountHelper = Mage::helper('nosto_tagging/account');
$persistedConfig = $helper->getNostoStoreConfig();
$postGroups = isset($request->getPost()['groups']) ? $request->getPost()['groups'] : null;
if (empty($persistedConfig) || empty($postGroups)) {
return $this;
}
/** @var Mage_Core_Model_Store $store */
foreach (Mage::app()->getStores() as $store) {
$account = $accountHelper->find($store);
if (!$helper->getUseProductIndexer($store) ||
$account instanceof Nosto_Object_Signup_Account === false) {
continue;
}
// Remove fields key and shift elements one level up
$postGroups = self::removeArrayKeyShiftOneLevelUp($postGroups, 'fields');
// Remove unnecessary configuration section from the array
$persistedConfig = self::filterNonIndexTriggering($persistedConfig);
$postGroups = self::filterNonIndexTriggering($postGroups);
// Normalize attribute_to_tag sub array to match post array structure
if (isset($persistedConfig['attribute_to_tag'])) {
$persistedConfig['attribute_to_tag'] =
self::restructureTagsKey($persistedConfig['attribute_to_tag']);
}
if (self::getDiffNostoSettingsInPost($postGroups, $persistedConfig) != array()) {
Mage::getSingleton('index/indexer')
->getProcessByCode('nosto_indexer')
->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
return $this;
}
}
}
} catch (\Exception $e) {
NostoLog::exception($e);
}
return $this;
}

/**
* Checks if Nosto settings POST array
* is different than the persisted configurations
*
* @param $postArray
*
* @param $persistedArray
*
* @return array
*/
protected function getDiffNostoSettingsInPost($postArray, $persistedArray)
{
$difference = array();
foreach ($postArray as $key => $value) {
if (is_array($value) && $key != 'value') {
if (!isset($persistedArray[$key])) {
$difference[$key] = $value;
} elseif (is_array($persistedArray[$key])) {
$newDiff = self::getDiffNostoSettingsInPost($value, $persistedArray[$key]);
if ($newDiff) {
$difference[$key] = $newDiff;
}
} elseif (array_key_exists('value', $value) && ($value['value'] != $persistedArray[$key])) {
$difference[$key] = $value;
}
} elseif (!isset($persistedArray[$key]) || $persistedArray[$key] != $value) {
$difference[$key] = $value;
}
}
$difference = array_filter($difference);
if (empty($difference)) {
return array();
}
return $difference;
}

/**
* Removes from an array Nosto settings
* that should not trigger product reindex
*
* @param array $array
* @return array[]
*/
protected function filterNonIndexTriggering(array $array)
{
$excludedReindexSettings = array(
self::SCHEDULED_CURRENCY_EXCHANGE_RATE_UPDATE
);
foreach ($excludedReindexSettings as $setting) {
if (isset($array[$setting])) {
unset($array[$setting]);
}
}
return $array;
}

/**
* Normalizes the attribute_to_tag key from the
* Nosto persisted configuration array to match the
* structure of the POST array
*
* @param array $tags
* @return array
*/
protected function restructureTagsKey(array $tags)
{
$returnTags = array();
foreach ($tags as $key => $tag) {
$values = explode(',', $tag);
foreach ($values as $value) {
$returnTags[$key]['value'][] = $value;
}
}
return $returnTags;
}

/**
* Removes array key and shift elements one level up
*
* @param array $array
* @param string $arrayKey
* @return array
*/
protected function removeArrayKeyShiftOneLevelUp(array $array, $arrayKey)
{
foreach ($array as $key => $element) {
unset($element[$key]);
$array[$key] = $element[$arrayKey];
}
return $array;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function getProductAttributesCollection(array $filters = array())
'attribute_code',
Varien_Data_Collection::SORT_ORDER_ASC
);

return $attributes;
}

Expand Down
11 changes: 10 additions & 1 deletion app/code/community/Nosto/Tagging/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<config>
<modules>
<Nosto_Tagging>
<version>3.5.3</version>
<version>3.5.4</version>
</Nosto_Tagging>
</modules>
<global>
Expand Down Expand Up @@ -150,6 +150,15 @@
</nosto_tagging_custom>
</observers>
</admin_system_config_changed_section_nosto_tagging>
<model_config_data_save_before>
<observers>
<nosto_tagging_custom>
<type>singleton</type>
<class>Nosto_Tagging_Model_Observer_Setting</class>
<method>checkNostoSettingsHaveChanged</method>
</nosto_tagging_custom>
</observers>
</model_config_data_save_before>
<review_save_after>
<observers>
<nosto_tagging_custom>
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Nosto/Tagging/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<show_in_store>1</show_in_store>
</use_skus>
<use_custom_fields translate="label">
<label>Send attributes from product attribute set to nosto as custom fields</label>
<label>Send product attributes as custom fields to Nosto</label>
<comment>Set this to true if you would like send attributes from product attribute set to nosto as custom fields</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
Expand Down

0 comments on commit 30cd82e

Please sign in to comment.