-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from plentymarkets/OrderCommentBugfix
revert userid for comments
- Loading branch information
Showing
27 changed files
with
1,087 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
Adapter/PlentymarketsAdapter/RequestGenerator/Order/Address/AddressRequestGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../PlentymarketsAdapter/RequestGenerator/Order/Address/AddressRequestGeneratorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
124 changes: 124 additions & 0 deletions
124
Adapter/PlentymarketsAdapter/RequestGenerator/Order/Customer/CustomerRequestGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...lentymarketsAdapter/RequestGenerator/Order/Customer/CustomerRequestGeneratorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.