Skip to content

Commit

Permalink
Merge pull request #167 from plentymarkets/OrderCommentBugfix
Browse files Browse the repository at this point in the history
revert userid for comments
  • Loading branch information
jochenmanz authored Jun 1, 2017
2 parents 2820279 + e118649 commit 5d2b48e
Show file tree
Hide file tree
Showing 27 changed files with 1,087 additions and 711 deletions.
2 changes: 1 addition & 1 deletion Adapter/PlentymarketsAdapter/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private function getRequestOptions($method, $path, array $params, array $options
}

if (!array_key_exists('timeout', $options)) {
$requestOptions['timeout'] = 30;
$requestOptions['timeout'] = 60;
}

if (!array_key_exists('exceptions', $options)) {
Expand Down
23 changes: 22 additions & 1 deletion Adapter/PlentymarketsAdapter/DependencyInjection/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@

<!-- Request Generator -->

<service id="plentmarkets_adapter.request_generator.address" class="PlentymarketsAdapter\RequestGenerator\Order\Address\AddressRequestGenerator">
<argument type="service" id="plenty_connector.identity_service" />
</service>

<service id="plentmarkets_adapter.request_generator.order" class="PlentymarketsAdapter\RequestGenerator\Order\OrderRequestGenerator">
<argument type="service" id="plenty_connector.identity_service" />
<argument type="service" id="plentmarkets_adapter.client" />
<argument type="service" id="plentmarkets_adapter.request_generator.order_item" />
<argument type="service" id="plentmarkets_adapter.request_generator.customer" />
<argument type="service" id="plentmarkets_adapter.request_generator.address" />
</service>

<service id="plentmarkets_adapter.request_generator.order_item" class="PlentymarketsAdapter\RequestGenerator\Order\OrderItem\OrderItemRequestGenerator">
<argument type="service" id="plenty_connector.identity_service" />
<argument type="service" id="plentmarkets_adapter.client" />
</service>

<service id="plentmarkets_adapter.request_generator.customer" class="PlentymarketsAdapter\RequestGenerator\Order\Customer\CustomerRequestGenerator">
<argument type="service" id="plenty_connector.identity_service" />
</service>

<service id="plentmarkets_adapter.request_generator.payment" class="PlentymarketsAdapter\RequestGenerator\Payment\PaymentRequestGenerator">
<argument type="service" id="plenty_connector.identity_service" />
</service>
Expand Down Expand Up @@ -372,7 +393,7 @@
<service id="plentymarkets_adapter.command_handler.handle_order" class="PlentymarketsAdapter\ServiceBus\CommandHandler\Order\HandleOrderCommandHandler">
<argument type="service" id="plentmarkets_adapter.client" />
<argument type="service" id="plenty_connector.identity_service" />
<argument type="service" id="plenty_connector.logger" />
<argument type="service" id="plentmarkets_adapter.request_generator.order" />

<tag name="plenty_connector.command_handler" />
</service>
Expand Down
11 changes: 6 additions & 5 deletions Adapter/PlentymarketsAdapter/ReadApi/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PlentymarketsAdapter\ReadApi\Order;

use PlentymarketsAdapter\Client\Iterator\Iterator;
use PlentymarketsAdapter\ReadApi\ApiAbstract;

/**
Expand Down Expand Up @@ -31,29 +32,29 @@ public function find($id)
/**
* @param array $criteria
*
* @return array
* @return Iterator
*/
public function findAll(array $criteria = [])
{
$criteria = array_merge($criteria, [
'with' => $this->includes,
]);

return iterator_to_array($this->client->getIterator('orders', $criteria));
return $this->client->getIterator('orders', $criteria);
}

/**
* @param array $criteria
*
* @return array
* @return Iterator
*/
public function findBy(array $criteria = [])
{
$criteria = array_merge($criteria, [
'with' => $this->includes,
]);

return iterator_to_array($this->client->getIterator('orders', $criteria));
return $this->client->getIterator('orders', $criteria);
}

/**
Expand All @@ -63,7 +64,7 @@ public function findBy(array $criteria = [])
*/
public function findOneBy(array $criteria = [])
{
$result = $this->findBy($criteria);
$result = iterator_to_array($this->findBy($criteria));

if (!empty($result)) {
$result = array_shift($result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

namespace PlentymarketsAdapter\RequestGenerator\Order\Address;

use PlentyConnector\Connector\IdentityService\IdentityServiceInterface;
use PlentyConnector\Connector\TransferObject\Country\Country;
use PlentyConnector\Connector\TransferObject\Order\Address\Address;
use PlentyConnector\Connector\TransferObject\Order\Order;
use PlentymarketsAdapter\PlentymarketsAdapter;
use RuntimeException;
use VIISON\AddressSplitter\AddressSplitter;

/**
* Class AddressRequestGenerator
*/
class AddressRequestGenerator implements AddressRequestGeneratorInterface
{
/**
* @var IdentityServiceInterface
*/
private $identityService;

/**
* AddressRequestGenerator constructor.
*
* @param IdentityServiceInterface $identityService
*/
public function __construct(IdentityServiceInterface $identityService)
{
$this->identityService = $identityService;
}

/**
* {@inheritdoc}
*/
public function generate(Address $address, Order $order, $addressType = 0)
{
$countryIdentity = $this->identityService->findOneBy([
'objectIdentifier' => $address->getCountryIdentifier(),
'objectType' => Country::TYPE,
'adapterName' => PlentymarketsAdapter::NAME,
]);

if (null === $countryIdentity) {
throw new RuntimeException('country not mapped');
}

try {
$splitResult = AddressSplitter::splitAddress($address->getStreet());

$address1 = $splitResult['streetName'];
$address2 = $splitResult['houseNumber'];
$address3 = trim($splitResult['additionToAddress1'] . ' ' . $splitResult['additionToAddress2']);
} catch (Exception $exception) {
$address1 = $address->getStreet();
$address2 = '';
$address3 = '';
}

$params = [
'name1' => trim($address->getCompany() . ' ' . $address->getDepartment()),
'name2' => $address->getFirstname(),
'name3' => $address->getLastname(),
'postalCode' => $address->getPostalCode(),
'town' => $address->getCity(),
'countryId' => $countryIdentity->getAdapterIdentifier(),
'typeId' => $addressType,
];

if (0 === strcasecmp($address1, 'Packstation')) {
$params = array_merge($params, [
'isPackstation' => true,
'address1' => 'PACKSTATION',
'address2' => $address2,
'options' => [
[
'typeId' => 5,
'value' => $order->getCustomer()->getEmail(),
],
],
]);

if (null !== $address->getAdditional()) {
$params['options'][] = [
'typeId' => 6,
'value' => $address->getAdditional(),
];
}
} elseif (0 === strcasecmp($address1, 'Postfiliale')) {
$params = array_merge($params, [
'isPostfiliale' => true,
'address1' => 'POSTFILIALE',
'address2' => $address2,
'options' => [
[
'typeId' => 5,
'value' => $order->getCustomer()->getEmail(),
],
],
]);

if (null !== $address->getAdditional()) {
$params['options'][] = [
'typeId' => 6,
'value' => $address->getAdditional(),
];
}
} else {
$params = array_merge($params, [
'address1' => $address1,
'address2' => $address2,
'address3' => $address->getAdditional(),
'address4' => $address3,
'options' => [
[
'typeId' => 5,
'value' => $order->getCustomer()->getEmail(),
],
],
]);
}

if (null !== $order->getCustomer()->getPhoneNumber()) {
$params['options'][] = [
'typeId' => 4,
'value' => $order->getCustomer()->getPhoneNumber(),
];
}

return $params;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace PlentymarketsAdapter\RequestGenerator\Order\Address;

use PlentyConnector\Connector\TransferObject\Order\Address\Address;
use PlentyConnector\Connector\TransferObject\Order\Order;

/**
* Interface AddressRequestGeneratorInterface
*/
interface AddressRequestGeneratorInterface
{
/**
* @param Address $address
* @param Order $order
* @param int $addressType
*
* @return array
*/
public function generate(Address $address, Order $order, $addressType = 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace PlentymarketsAdapter\RequestGenerator\Order\Customer;

use PlentyConnector\Connector\IdentityService\IdentityServiceInterface;
use PlentyConnector\Connector\TransferObject\CustomerGroup\CustomerGroup;
use PlentyConnector\Connector\TransferObject\Language\Language;
use PlentyConnector\Connector\TransferObject\Order\Customer\Customer;
use PlentyConnector\Connector\TransferObject\Order\Order;
use PlentyConnector\Connector\TransferObject\Shop\Shop;
use PlentymarketsAdapter\PlentymarketsAdapter;

/**
* Class CustomerRequestGenerator
*/
class CustomerRequestGenerator implements CustomerRequestGeneratorInterface
{
/**
* @var IdentityServiceInterface
*/
private $identityService;

/**
* CustomerRequestGenerator constructor.
*
* @param IdentityServiceInterface $identityService
*/
public function __construct(IdentityServiceInterface $identityService)
{
$this->identityService = $identityService;
}

/**
* {@inheritdoc}
*/
public function generate(Customer $customer, Order $order)
{
$shopIdentity = $this->identityService->findOneBy([
'objectIdentifier' => $order->getShopIdentifier(),
'objectType' => Shop::TYPE,
'adapterName' => PlentymarketsAdapter::NAME,
]);

if (null === $shopIdentity) {
throw new NotFoundException('shop not mapped - ' . $order->getShopIdentifier());
}

$languageIdentity = $this->identityService->findOneBy([
'objectIdentifier' => $customer->getLanguageIdentifier(),
'objectType' => Language::TYPE,
'adapterName' => PlentymarketsAdapter::NAME,
]);

if (null === $languageIdentity) {
throw new NotFoundException('language not found - ' . $customer->getLanguageIdentifier());
}

$customerGroupIdentitiy = $this->identityService->findOneBy([
'objectIdentifier' => $customer->getCustomerGroupIdentifier(),
'objectType' => CustomerGroup::TYPE,
'adapterName' => PlentymarketsAdapter::NAME,
]);

$customerParams = [
'number' => $customer->getNumber(),
'typeId' => 1,
'firstName' => $customer->getFirstname(),
'lastName' => $customer->getLastname(),
'gender' => $customer->getSalutation() === Customer::SALUTATION_MR ? 'male' : 'female',
'lang' => $languageIdentity->getAdapterIdentifier(),
'singleAccess' => $customer->getType() === Customer::TYPE_GUEST,
'plentyId' => $shopIdentity->getAdapterIdentifier(),
'newsletterAllowanceAt' => '',
'lastOrderAt' => $order->getOrderTime()->format(DATE_W3C),
'options' => [],
'referrerId' => 1,
];

if (null !== $customerGroupIdentitiy) {
$customerParams['classId'] = (int) $customerGroupIdentitiy->getAdapterIdentifier();
}

if (null !== $customer->getBirthday()) {
$customerParams['birthdayAt'] = $customer->getBirthday()->format(DATE_W3C);
}

if ($customer->getNewsletter()) {
if (null !== $customer->getNewsletterAgreementDate()) {
$customerParams['newsletterAllowanceAt'] = $customer->getNewsletterAgreementDate()->format(DATE_W3C);
} else {
$customerParams['newsletterAllowanceAt'] = $order->getOrderTime()->format(DATE_W3C);
}
}

if (null !== $customer->getPhoneNumber()) {
$customerParams['options'][] = [
'typeId' => 1,
'subTypeId' => 4,
'value' => $customer->getPhoneNumber(),
'priority' => 0,
];
}

if (null !== $customer->getMobilePhoneNumber()) {
$customerParams['options'][] = [
'typeId' => 1,
'subTypeId' => 2,
'value' => $customer->getMobilePhoneNumber(),
'priority' => 0,
];
}

if (!empty($customer->getEmail())) {
$customerParams['options'][] = [
'typeId' => 2,
'subTypeId' => 4,
'value' => $customer->getEmail(),
'priority' => 0,
];
}

return $customerParams;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PlentymarketsAdapter\RequestGenerator\Order\Customer;

use PlentyConnector\Connector\TransferObject\Order\Customer\Customer;
use PlentyConnector\Connector\TransferObject\Order\Order;

/**
* Interface CustomerRequestGeneratorInterface
*/
interface CustomerRequestGeneratorInterface
{
/**
* @param Customer $customer
* @param Order $order
*
* @return array
*/
public function generate(Customer $customer, Order $order);
}
Loading

0 comments on commit 5d2b48e

Please sign in to comment.