Skip to content

Commit

Permalink
Merge branch 'hotfix/1.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pölönen committed Feb 28, 2018
2 parents 5a1f407 + 2793a11 commit ef77764
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
39 changes: 29 additions & 10 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Shopware_Plugins_Frontend_NostoTagging_Bootstrap extends Shopware_Componen
{

const PLATFORM_NAME = 'shopware';
const PLUGIN_VERSION = '1.2.5';
const PLUGIN_VERSION = '1.2.6';
const MENU_PARENT_ID = 23; // Configuration
const NEW_ENTITY_MANAGER_VERSION = '5.0.0';
const NEW_ATTRIBUTE_MANAGER_VERSION = '5.2.0';
Expand Down Expand Up @@ -103,7 +103,7 @@ class Shopware_Plugins_Frontend_NostoTagging_Bootstrap extends Shopware_Componen
*/
public function afterInit()
{
NostoHttpRequest::buildUserAgent(self::PLATFORM_NAME, \Shopware::VERSION, self::PLUGIN_VERSION);
NostoHttpRequest::buildUserAgent(self::PLATFORM_NAME, $this->getShopwareVersion(), self::PLUGIN_VERSION);
$this->registerCustomModels();
}

Expand Down Expand Up @@ -226,7 +226,7 @@ private function addMyAttribute(array $attribute)
{
self::validateMyAttribute($attribute);
/* Shopware()->Models()->removeAttribute will be removed in Shopware 5.3.0 */
if (version_compare(Shopware::VERSION, self::NEW_ATTRIBUTE_MANAGER_VERSION, '>=')) {
if (version_compare($this->getShopwareVersion(), self::NEW_ATTRIBUTE_MANAGER_VERSION, '>=')) {
$fieldName = sprintf('%s_%s', $attribute['prefix'], $attribute['field']);
/* @var \Shopware\Bundle\AttributeBundle\Service\CrudService $attributeService */
$attributeService = $this->get(self::SERVICE_ATTRIBUTE_CRUD);
Expand Down Expand Up @@ -290,7 +290,7 @@ public static function validateMyAttribute(array $attribute)
*/
protected function createMyMenu()
{
$compareResult = version_compare(Shopware::VERSION, self::NEW_ENTITY_MANAGER_VERSION);
$compareResult = version_compare($this->getShopwareVersion(), self::NEW_ENTITY_MANAGER_VERSION);
if ($compareResult < 0) {
$parentMenu = $this->Menu()->findOneBy('id', self::MENU_PARENT_ID);
} else {
Expand All @@ -308,6 +308,24 @@ protected function createMyMenu()
);
}

/**
* Returns the Shopware platform version
* @return mixed|string
* @throws NostoException in case version cannot be determined
*/
protected function getShopwareVersion()
{
if (Shopware::VERSION !== null && Shopware::VERSION !== '___VERSION___') {
return Shopware::VERSION;
} elseif (Shopware()->Container()->getParameter('shopware.release.version')) {
return Shopware()->Container()->getParameter('shopware.release.version');
} elseif (Nosto::getEnvVariable('SHOPWARE_VERSION')) {
return Nosto::getEnvVariable('SHOPWARE_VERSION');
}

throw new NostoException('Could not determine shopware version');
}

/**
* Creates Nosto emotions for Shopping World templates
*
Expand All @@ -329,11 +347,11 @@ protected function createMyEmotions()
'supportText' => 'E.g. frontpage-nosto-1, nosto-shopware-1',
'helpTitle' => 'Nosto recommendation slot',
'helpText' => '
Nosto slot div ID is the id attribute of the element where
Nosto recommendations are populated. It is recommended that
you create new recommendation slot for Shopping World elements
from Nosto settings. You must have matching slot created in Nosto
settings.',
Nosto slot div ID is the id attribute of the element where
Nosto recommendations are populated. It is recommended that
you create new recommendation slot for Shopping World elements
from Nosto settings. You must have matching slot created in Nosto
settings.',
'defaultValue' => 'frontpage-nosto-1',
'allowBlank' => false
)
Expand Down Expand Up @@ -515,12 +533,13 @@ protected function dropMyAttributes()
* @see self::$_customAttributes
*
* @param array $attribute
* @throws NostoException
*/
private function removeMyAttribute(array $attribute)
{
self::validateMyAttribute($attribute);
/* Shopware()->Models()->removeAttribute will be removed in Shopware 5.3.0 */
if (version_compare(Shopware::VERSION, self::NEW_ATTRIBUTE_MANAGER_VERSION, '>=')) {
if (version_compare($this->getShopwareVersion(), self::NEW_ATTRIBUTE_MANAGER_VERSION, '>=')) {
$fieldName = sprintf('%s_%s', $attribute['prefix'], $attribute['field']);
/* @var \Shopware\Bundle\AttributeBundle\Service\CrudService $attributeService */
$attributeService = $this->get(self::SERVICE_ATTRIBUTE_CRUD);
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]

## [1.2.6]
- Add support for Shopware 5.4

## [1.2.5]
- Add support for Shopware 5.3

Expand Down Expand Up @@ -142,7 +145,8 @@ recommendations
- Initial beta-release


[unreleased]: https://github.com/nosto/nosto-shopware-plugin/compare/1.2.5...develop
[unreleased]: https://github.com/nosto/nosto-shopware-plugin/compare/1.2.6...develop
[1.2.6]: https://github.com/nosto/nosto-shopware-plugin/compare/1.2.5...1.2.6
[1.2.5]: https://github.com/nosto/nosto-shopware-plugin/compare/1.2.4...1.2.5
[1.2.4]: https://github.com/nosto/nosto-shopware-plugin/compare/1.2.3...1.2.4
[1.2.3]: https://github.com/nosto/nosto-shopware-plugin/compare/1.2.2...1.2.3
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": [
"BSD-3-Clause"
],
"version": "1.2.5",
"version": "1.2.6",
"require": {
"php": ">=5.5.0",
"nosto/php-sdk": "1.16.3"
Expand Down

0 comments on commit ef77764

Please sign in to comment.