Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ts-shopware-connector

* 'master' of https://github.com/plentymarkets/plentymarkets-shopware-connector:
  skip not existing articles in order response parser (plentymarkets#530)
  fixed client for put calls (plentymarkets#529)
  set shipping time on multi package order (plentymarkets#527)
  null check on customer gender (plentymarkets#528)
  add manufacturer external name as attribute (plentymarkets#526)
  5.3.3 (plentymarkets#524)
  add system currency to config (plentymarkets#522)
  amazon Pay Fix (plentymarkets#521)
  add manufacturer external name as attribute (plentymarkets#519)
  add manufacturer attributes (plentymarkets#518)
  limit (plentymarkets#517)
  5.3.1 (plentymarkets#516)
  travis (plentymarkets#514)
  5.6 (plentymarkets#513)
  • Loading branch information
resslinger committed Nov 12, 2019
2 parents 0b8ef5d + c189d3c commit 92b97e0
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 74 deletions.
5 changes: 2 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,3 @@ before_script:

script:
- composer cs-travis
- composer test-travis
4 changes: 4 additions & 0 deletions Adapter/PlentymarketsAdapter/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private function curlRequest($requestUrl, $method, $path, $params, $limit, $offs
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

$headers = [];
curl_setopt($curl, CURLOPT_HEADERFUNCTION, static function ($curl, $header) use (&$headers) {
Expand Down Expand Up @@ -188,6 +189,9 @@ private function curlRequest($requestUrl, $method, $path, $params, $limit, $offs
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params, JSON_PRETTY_PRINT));
} elseif ($method === 'GET') {
$requestUrl = $requestUrl . '?' . http_build_query($params);
} elseif ($method === 'PUT') {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params, JSON_PRETTY_PRINT));
}

curl_setopt($curl, CURLOPT_URL, $requestUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<argument type="service" id="plenty_connector.logger" />
<argument type="service" id="plenty_connector.config_service" />
</service>

<service id="plentymarkets_adapter.helper.property" class="PlentymarketsAdapter\Helper\PropertyHelper"></service>

<!-- Request Generator -->
Expand Down Expand Up @@ -119,6 +119,8 @@

<service id="plentymarkets_adapter.request_generator.payment" class="PlentymarketsAdapter\RequestGenerator\Payment\PaymentRequestGenerator" public="false">
<argument type="service" id="plenty_connector.identity_service" />
<argument type="service" id="plenty_connector.config_service" />

</service>

<!-- Response Parser -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PlentymarketsAdapter\RequestGenerator\Payment;

use PlentymarketsAdapter\PlentymarketsAdapter;
use SystemConnector\ConfigService\ConfigServiceInterface;
use SystemConnector\IdentityService\Exception\NotFoundException;
use SystemConnector\IdentityService\IdentityServiceInterface;
use SystemConnector\TransferObject\Currency\Currency;
Expand All @@ -16,9 +17,15 @@ class PaymentRequestGenerator implements PaymentRequestGeneratorInterface
*/
private $identityService;

public function __construct(IdentityServiceInterface $identityService)
/**
* @var ConfigServiceInterface
*/
private $configService;

public function __construct(IdentityServiceInterface $identityService, ConfigServiceInterface $configService)
{
$this->identityService = $identityService;
$this->configService = $configService;
}

/**
Expand Down Expand Up @@ -49,6 +56,12 @@ public function generate(Payment $payment): array
throw new NotFoundException('currency not mapped');
}

$isSystemCurrency = true;

if ($this->configService->get('system_currency') !== $currencyIdentity->getAdapterIdentifier()) {
$isSystemCurrency = false;
}

$paymentParams = [
'amount' => $payment->getAmount(),
'exchangeRatio' => 1,
Expand All @@ -57,6 +70,7 @@ public function generate(Payment $payment): array
'type' => 'credit',
'transactionType' => 2,
'status' => 2,
'isSystemCurrency' => $isSystemCurrency,
];

$paymentParams['properties'] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use PlentymarketsAdapter\ResponseParser\Media\MediaResponseParserInterface;
use Psr\Log\LoggerInterface;
use SystemConnector\IdentityService\IdentityServiceInterface;
use SystemConnector\TransferObject\Country\Country;
use SystemConnector\TransferObject\Manufacturer\Manufacturer;
use SystemConnector\ValueObject\Attribute\Attribute;

class ManufacturerResponseParser implements ManufacturerResponseParserInterface
{
Expand Down Expand Up @@ -52,6 +54,30 @@ public function parse(array $entry): array
$manufacturer->setIdentifier($identity->getObjectIdentifier());
$manufacturer->setName($entry['name']);

$countryIdentity = $this->identityService->findOneBy([
'adapterIdentifier' => (string) $entry['countryId'],
'objectType' => Country::TYPE,
'adapterName' => PlentymarketsAdapter::NAME,
]);

$additionalValues = [
'street' => $entry['street'],
'houseNo' => $entry['houseNo'],
'postcode' => $entry['postcode'],
'town' => $entry['town'],
'phoneNumber' => $entry['phoneNumber'],
'faxNumber' => $entry['faxNumber'],
'email' => $entry['email'],
'comment' => $entry['comment'],
'externalName' => $entry['externalName'],
];

if (null !== $countryIdentity) {
$additionalValues['countryIdentifier'] = $countryIdentity->getObjectIdentifier();
}

$manufacturer->setAttributes($this->setAttributes($additionalValues));

if (!empty($entry['url'])) {
$manufacturer->setLink($entry['url']);
}
Expand Down Expand Up @@ -83,4 +109,24 @@ public function parse(array $entry): array

return $result;
}

/**
* @param array $additionalValues
*
* @return Attribute[]
*/
private function setAttributes(array $additionalValues): array
{
$attributes = [];

foreach ($additionalValues as $key => $value) {
$attribute = new Attribute();
$attribute->setKey($key);
$attribute->setValue((string) $value);

$attributes[] = $attribute;
}

return $attributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ private function getCustomer(array $entry)
return null;
}

if (null === $entry['customerData']['gender']) {
$this->logger->info('customer gender not defined', [
'customerNumber' => $entry['customerData']['number'],
]);

return null;
}

$customer = new Customer();
$customer->setType(Customer::TYPE_NORMAL);
$customer->setNumber($entry['customerData']['number']);
Expand Down Expand Up @@ -674,20 +682,27 @@ private function getPackages(array $entry): array
return $date['typeId'] === 8;
});

if (!empty($shippingDate)) {
$shippingDate = array_shift($shippingDate);

$shippingDate = DateTimeImmutable::createFromFormat(
DATE_ATOM,
$shippingDate['date']
);
} else {
$now = new \DateTime();
$shippingDate = DateTimeImmutable::createFromFormat(
DATE_ATOM,
$now->format(DATE_ATOM)
);
}

$result = [];
foreach ($numbers as $number) {
$package = new Package();
$package->setShippingCode((string) $number);
$package->setShippingProvider();

if (!empty($shippingDate)) {
$shippingDate = array_shift($shippingDate);

$package->setShippingTime(DateTimeImmutable::createFromFormat(
DATE_ATOM,
$shippingDate['date']
));
}
$package->setShippingTime($shippingDate);

$result[] = $package;
}
Expand All @@ -707,6 +722,14 @@ private function getOrderItems(array $entry): array
foreach ($entry['orderItems'] as $item) {
$number = $this->getNumberFromVariation($item['itemVariationId']);

if (empty($number)) {
$this->logger->info('product not found', [
'itemVariationId' => $item['itemVariationId'],
]);

continue;
}

$orderItem = new OrderItem();
$orderItem->setQuantity((float) $item['quantity']);
$orderItem->setName($item['orderItemName']);
Expand Down Expand Up @@ -737,7 +760,7 @@ private function getOrderItemPrice(array $item): float
}

/**
* @param int $variationId
* @param $variationId
*
* @return string
*/
Expand All @@ -749,9 +772,7 @@ private function getNumberFromVariation($variationId): string
$response = $this->client->request('GET', 'items/variations', ['id' => $variationId]);

if (empty($response)) {
$variations[$variationId] = null;

return $variations[$variationId];
return '';
}

$variation = array_shift($response);
Expand Down
9 changes: 8 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 @@ -209,6 +212,7 @@
<argument type="service" id="shopware_adapter.shopware_resource.manufacturer" />
<argument type="service" id="plenty_connector.identity_service" />
<argument type="service" id="shopware_adapter.data_persister.attribute" />
<argument type="service" id="models" />

<tag name="plenty_connector.command_handler" />
</service>
Expand All @@ -229,6 +233,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 Expand Up @@ -260,6 +266,7 @@
<!-- Order command handlers -->

<service id="shopware_adapter.command_handler.handle_order" class="ShopwareAdapter\ServiceBus\CommandHandler\Order\HandleOrderCommandHandler" public="false">
<argument type="service" id="models" />
<argument type="service" id="plenty_connector.identity_service" />
<argument type="service" id="plenty_connector.logger" />
<argument type="service" id="shopware_adapter.data_persister.attribute" />
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
Loading

0 comments on commit 92b97e0

Please sign in to comment.