diff --git a/.gitignore b/.gitignore index c8ae943a..dfd65b35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ libs/ build/package -build/src \ No newline at end of file +build/src +config*.xml \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f44f186c..e304ca46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning(http://semver.org/). +## 2.7.E3 +- Fix the content forging to use cloned context + ## 2.7.E2 - Fix the context in Nosto settings - Remove incompatible column from tax rules query diff --git a/build.xml b/build.xml index 9df1e074..96367daf 100644 --- a/build.xml +++ b/build.xml @@ -64,14 +64,14 @@ - - - - - - - - + + + + + + + + @@ -117,6 +117,7 @@ + diff --git a/classes/helpers/context-factory.php b/classes/helpers/context-factory.php index d200a6fe..4fe8de90 100644 --- a/classes/helpers/context-factory.php +++ b/classes/helpers/context-factory.php @@ -29,14 +29,25 @@ class NostoTaggingHelperContextFactory { /** - * Forges a new context and replaces the current one. + * Holds the original shop id whever context is forged + * @var int + */ + private $original_shop_id; + + /** + * Forges a new context and returns the altered context * * @param int $id_lang the language ID to add to the new context. * @param int $id_shop the shop ID to add to the new context. + * * @return Context the new context. */ public function forgeContext($id_lang, $id_shop) { + /* @var ContextCore $context */ + $context = Context::getContext(); + $this->saveOriginalContext($context); + $forged_context = $context->cloneContext(); if (_PS_VERSION_ >= '1.5') { // Reset the shop context to be the current processed shop. This will fix the "friendly url" format of urls // generated through the Link class. @@ -60,12 +71,33 @@ public function forgeContext($id_lang, $id_shop) } } - $context = Context::getContext(); - $context->language = new Language($id_lang); - $context->shop = new Shop($id_shop); - $context->link = new Link('http://', 'http://'); - $context->currency = isset($currency) ? $currency : Currency::getDefaultCurrency(); + $forged_context->language = new Language($id_lang); + $forged_context->shop = new Shop($id_shop); + $forged_context->link = new Link('http://', 'http://'); + $forged_context->currency = isset($currency) ? $currency : Currency::getDefaultCurrency(); + + return $forged_context; + } - return $context; + /** + * Saves necessary parts of current context so those can be reverted + * + * @param Context $context + */ + private function saveOriginalContext(Context $context) + { + if (isset($context->shop) && !empty($context->shop->id)) { + $this->original_shop_id = $context->shop->id; + } + } + + /** + * Reverst the active context to the original one (before calling forgeContext) + */ + public function revertToOriginalContext() + { + if (_PS_VERSION_ >= '1.5' && !empty($this->original_shop_id)) { + Shop::setContext(Shop::CONTEXT_SHOP, $this->original_shop_id); + } } -} +} \ No newline at end of file diff --git a/classes/helpers/currency.php b/classes/helpers/currency.php index ce8c75a4..2b3dc392 100644 --- a/classes/helpers/currency.php +++ b/classes/helpers/currency.php @@ -362,6 +362,7 @@ public function updateExchangeRatesForAllStores() ) ); } + $context_factory->revertToOriginalContext(); } } } diff --git a/nostotagging.php b/nostotagging.php index 0ea0a0c0..13de6a9a 100644 --- a/nostotagging.php +++ b/nostotagging.php @@ -74,7 +74,7 @@ */ class NostoTagging extends Module { - const PLUGIN_VERSION = '2.7.E2'; + const PLUGIN_VERSION = '2.7.E3'; /** * Custom hooks to add for this module.