Skip to content

Commit

Permalink
5.6 (#513)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* WIP

* WIP

* WIP

* CI

* travis
  • Loading branch information
Pfabeck authored Sep 4, 2019
1 parent b940d02 commit 9f48b62
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php

php:
- 7.1
- 7.2
- 7.3

sudo: false

Expand All @@ -13,7 +13,7 @@ services:

env:
matrix:
- SHOPWARE_VERSION="5.5"
- SHOPWARE_VERSION="5.6"

global:
- PLUGIN_NAME=PlentyConnector
Expand All @@ -39,4 +39,4 @@ before_script:

script:
- composer cs-travis
- composer test-travis
- composer test-travis
7 changes: 6 additions & 1 deletion Adapter/ShopwareAdapter/DependencyInjection/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- Misc Components -->
<service id="shopware_adapter.shopware_translation_component" class="Shopware_Components_Translation" />
<service id="shopware_adapter.shopware_translation_component" class="Shopware_Components_Translation" >
<argument type="service" id="dbal_connection"/>
<argument type="service" id="service_container"/>
</service>

<service id="shopware.tax_repository" class="Shopware\Models\Tax\Repository">
<factory service="models" method="getRepository" />
Expand Down Expand Up @@ -229,6 +232,8 @@
<argument type="service" id="shopware_adapter.data_provider.media" />
<argument type="service" id="shopware_adapter.attribute_helper" />
<argument type="service" id="shopware_adapter.data_persister.attribute" />
<argument type="service" id="shopware.api.media" />
<argument type="service" id="models" />

<tag name="plenty_connector.command_handler" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@

class HandleCategoryCommandHandler implements CommandHandlerInterface
{
/**
* @var EntityManagerInterface
*/
private $entityManager;

/**
* @var IdentityServiceInterface
*/
Expand Down Expand Up @@ -72,6 +77,7 @@ public function __construct(
AttributeDataPersisterInterface $attributePersister,
TranslationDataPersisterInterface $translationDataPersister
) {
$this->entityManager = $entityManager;
$this->identityService = $identityService;
$this->translationHelper = $translationHelper;
$this->attributePersister = $attributePersister;
Expand Down Expand Up @@ -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(),
Expand All @@ -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());
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
*/
Expand All @@ -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,
Expand All @@ -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(),
Expand All @@ -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');
}
}
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<plugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/5.5/engine/Shopware/Components/Plugin/schema/plugin.xsd">
<label>plentymarkets Shopware Connector</label>
<label lang="de">plentymarkets Shopware Connector</label>
<version>5.2.1</version>
<version>5.3.0</version>
<copyright>(c) plentymarkets GmbH</copyright>
<link>https://www.plentymarkets.eu/</link>
<author>arvatis media GmbH</author>
<compatibility minVersion="5.5.0" />
<compatibility minVersion="5.6.0" />
<license>MIT</license>
</plugin>

0 comments on commit 9f48b62

Please sign in to comment.