diff --git a/.travis.yml b/.travis.yml index 7834b1416..437d5933f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 7.1 - 7.2 + - 7.3 sudo: false @@ -13,7 +13,7 @@ services: env: matrix: - - SHOPWARE_VERSION="5.5" + - SHOPWARE_VERSION="5.6" global: - PLUGIN_NAME=PlentyConnector @@ -39,4 +39,4 @@ before_script: script: - composer cs-travis - - composer test-travis \ No newline at end of file + - composer test-travis diff --git a/Adapter/ShopwareAdapter/DependencyInjection/services.xml b/Adapter/ShopwareAdapter/DependencyInjection/services.xml index 31a73c38a..99270f0be 100644 --- a/Adapter/ShopwareAdapter/DependencyInjection/services.xml +++ b/Adapter/ShopwareAdapter/DependencyInjection/services.xml @@ -3,7 +3,10 @@ - + + + + @@ -229,6 +232,8 @@ + + diff --git a/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Category/HandleCategoryCommandHandler.php b/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Category/HandleCategoryCommandHandler.php index 684cc72c3..43ec42e78 100644 --- a/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Category/HandleCategoryCommandHandler.php +++ b/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Category/HandleCategoryCommandHandler.php @@ -35,6 +35,11 @@ class HandleCategoryCommandHandler implements CommandHandlerInterface { + /** + * @var EntityManagerInterface + */ + private $entityManager; + /** * @var IdentityServiceInterface */ @@ -72,6 +77,7 @@ public function __construct( AttributeDataPersisterInterface $attributePersister, TranslationDataPersisterInterface $translationDataPersister ) { + $this->entityManager = $entityManager; $this->identityService = $identityService; $this->translationHelper = $translationHelper; $this->attributePersister = $attributePersister; @@ -326,7 +332,7 @@ private function handleCategory(Category $category, Identity $shopIdentity) } if (null === $categoryIdentity) { - $categoryModel = $resource->create($params); + $categoryModel = $this->createOrUpdateCategory(new CategoryModel(), $params); $categoryIdentity = $this->identityService->insert( $category->getIdentifier(), @@ -335,7 +341,12 @@ private function handleCategory(Category $category, Identity $shopIdentity) ShopwareAdapter::NAME ); } else { - $categoryModel = $resource->update($categoryIdentity->getAdapterIdentifier(), $params); + /** + * @var CategoryModel $categoryModel + */ + $categoryModel = $this->categoryRepository->find($categoryIdentity->getAdapterIdentifier()); + + $this->createOrUpdateCategory($categoryModel, $params); } $this->attributePersister->saveCategoryAttributes($categoryModel, $category->getAttributes()); @@ -433,6 +444,35 @@ private function handleOrphanedCategories(Category $category, array $validIdenti } } + /** + * @param CategoryModel $categoryModel + * @param array $params + * + * @return CategoryModel + */ + private function createOrUpdateCategory(CategoryModel $categoryModel, array $params = []): CategoryModel + { + /** + * @var CategoryModel $parent + */ + $parent = $this->categoryRepository->find($params['parent']); + + $categoryModel->setActive($params['active']); + $categoryModel->setPosition($params['position']); + $categoryModel->setName($params['name']); + $categoryModel->setParent($parent); + $categoryModel->setMetaTitle($params['metaTitle']); + $categoryModel->setMetaKeywords($params['metaKeywords']); + $categoryModel->setMetaDescription($params['metaDescription']); + $categoryModel->setCmsHeadline($params['cmsHeadline']); + $categoryModel->setCmsText($params['cmsText']); + + $this->entityManager->persist($categoryModel); + $this->entityManager->flush(); + + return $categoryModel; + } + /** * @return CategoryResource */ diff --git a/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Media/HandleMediaCommandHandler.php b/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Media/HandleMediaCommandHandler.php index 6af194ed6..6e19636b5 100644 --- a/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Media/HandleMediaCommandHandler.php +++ b/Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Media/HandleMediaCommandHandler.php @@ -2,10 +2,10 @@ namespace ShopwareAdapter\ServiceBus\CommandHandler\Media; +use Doctrine\ORM\EntityManagerInterface; +use Shopware\Components\Api\Exception\CustomValidationException; use Shopware\Components\Api\Exception\NotFoundException as MediaNotFoundException; use Shopware\Components\Api\Exception\ParameterMissingException; -use Shopware\Components\Api\Exception\ValidationException; -use Shopware\Components\Api\Manager; use Shopware\Components\Api\Resource\Media as MediaResource; use ShopwareAdapter\DataPersister\Attribute\AttributeDataPersisterInterface; use ShopwareAdapter\DataProvider\Media\MediaDataProviderInterface; @@ -46,18 +46,32 @@ class HandleMediaCommandHandler implements CommandHandlerInterface */ private $attributePersister; + /** + * @var MediaResource + */ + private $mediaResource; + + /** + * @var EntityManagerInterface + */ + private $entityManager; + public function __construct( IdentityServiceInterface $identityService, MediaRequestGeneratorInterface $mediaRequestGenerator, MediaDataProviderInterface $mediaDataProvider, AttributeHelper $attributeHelper, - AttributeDataPersisterInterface $attributePersister + AttributeDataPersisterInterface $attributePersister, + MediaResource $mediaResource, + EntityManagerInterface $entityManager ) { $this->identityService = $identityService; $this->mediaRequestGenerator = $mediaRequestGenerator; $this->mediaDataProvider = $mediaDataProvider; $this->attributeHelper = $attributeHelper; $this->attributePersister = $attributePersister; + $this->mediaResource = $mediaResource; + $this->entityManager = $entityManager; } /** @@ -75,9 +89,7 @@ public function supports(CommandInterface $command): bool * @param CommandInterface $command * * @throws ParameterMissingException - * @throws ValidationException - * @throws ValidationException - * @throws ParameterMissingException + * @throws CustomValidationException * * @return bool */ @@ -101,14 +113,15 @@ public function handle(CommandInterface $command): bool 'adapterName' => ShopwareAdapter::NAME, ]); - $resource = $this->getMediaResource(); $params = $this->mediaRequestGenerator->generate($media); if (null !== $identity) { try { - $mediaModel = $resource->update($identity->getAdapterIdentifier(), $params); + $mediaModel = $this->mediaResource->update($identity->getAdapterIdentifier(), $params); + $this->entityManager->clear(); } catch (MediaNotFoundException $exception) { - $mediaModel = $resource->create($params); + $mediaModel = $this->mediaResource->internalCreateMediaByFileLink($params['file'], $params['album']); + $this->entityManager->flush(); $this->identityService->update( $identity, @@ -118,7 +131,8 @@ public function handle(CommandInterface $command): bool ); } } else { - $mediaModel = $resource->create($params); + $mediaModel = $this->mediaResource->internalCreateMediaByFileLink($params['file'], $params['album']); + $this->entityManager->flush(); $this->identityService->insert( $media->getIdentifier(), @@ -135,15 +149,4 @@ public function handle(CommandInterface $command): bool return true; } - - /** - * @return MediaResource - */ - private function getMediaResource(): MediaResource - { - // without this reset the entitymanager sometimes the album is not found correctly. - Shopware()->Container()->reset('models'); - - return Manager::getResource('Media'); - } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6def096ef..313e6fe97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [## [unreleased]] +## [## [5.3.0]] ### Fixed - fix handling of important data on item sync (@lacodimizer) - fix tax handling on order export (@lacodimizer) - fixed wrong float cast (@ArvatisJohannes) +- SW 5.6 required +- PHP 7.2 required ## [## [5.2.1]] ### Fixed diff --git a/composer.json b/composer.json index 8cd10d613..1db749bc5 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "homepage": "https://github.com/plentymarkets/plentymarkets-shopware-connector", "require": { - "php": "^7.1", + "php": "^7.2", "viison/address-splitter": "dev-master", "composer/installers": "^1.0", "league/tactician": "^1.0", diff --git a/plugin.xml b/plugin.xml index dc542b35d..e21f28258 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,10 +2,10 @@ - 5.2.1 + 5.3.0 (c) plentymarkets GmbH https://www.plentymarkets.eu/ arvatis media GmbH - + MIT