-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
3,416 additions
and
1,360 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# 1.0.0a | ||
# 1.1.0 | ||
- Handle empty/default Settings values | ||
- Save refunds to db, and reload order tab on changes | ||
|
||
# 1.0.0 | ||
- First version of the Wallee integrations for Shopware 6 |
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
70 changes: 70 additions & 0 deletions
70
src/Core/Api/OrderDeliveryState/Handler/OrderDeliveryStateHandler.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,70 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace WalleePayment\Core\Api\OrderDeliveryState\Handler; | ||
|
||
use Shopware\Core\{ | ||
Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryDefinition, | ||
Framework\Context, | ||
System\StateMachine\StateMachineRegistry, | ||
System\StateMachine\Transition}; | ||
|
||
/** | ||
* Class OrderDeliveryStateHandler | ||
* | ||
* @package WalleePayment\Core\Api\OrderDeliveryState\Handler | ||
*/ | ||
class OrderDeliveryStateHandler { | ||
|
||
public const STATE_HOLD = 'hold'; | ||
public const ACTION_HOLD = 'hold'; | ||
public const ACTION_UNHOLD = 'unhold'; | ||
|
||
/** | ||
* @var \Shopware\Core\System\StateMachine\StateMachineRegistry | ||
*/ | ||
private $stateMachineRegistry; | ||
|
||
/** | ||
* OrderDeliveryStateHandler constructor. | ||
* | ||
* @param \Shopware\Core\System\StateMachine\StateMachineRegistry $stateMachineRegistry | ||
*/ | ||
public function __construct(StateMachineRegistry $stateMachineRegistry) | ||
{ | ||
$this->stateMachineRegistry = $stateMachineRegistry; | ||
} | ||
|
||
/** | ||
* @param string $entityId | ||
* @param \Shopware\Core\Framework\Context $context | ||
*/ | ||
public function hold(string $entityId, Context $context): void | ||
{ | ||
$this->stateMachineRegistry->transition( | ||
new Transition( | ||
OrderDeliveryDefinition::ENTITY_NAME, | ||
$entityId, | ||
self::ACTION_HOLD, | ||
'stateId' | ||
), | ||
$context | ||
); | ||
} | ||
|
||
/** | ||
* @param string $entityId | ||
* @param \Shopware\Core\Framework\Context $context | ||
*/ | ||
public function unhold(string $entityId, Context $context): void | ||
{ | ||
$this->stateMachineRegistry->transition( | ||
new Transition( | ||
OrderDeliveryDefinition::ENTITY_NAME, | ||
$entityId, | ||
self::ACTION_UNHOLD, | ||
'stateId' | ||
), | ||
$context | ||
); | ||
} | ||
} |
187 changes: 187 additions & 0 deletions
187
src/Core/Api/OrderDeliveryState/Service/OrderDeliveryStateService.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,187 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace WalleePayment\Core\Api\OrderDeliveryState\Service; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Shopware\Core\{ | ||
Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryStates, | ||
Framework\Context, | ||
Framework\DataAbstractionLayer\Search\Criteria, | ||
Framework\DataAbstractionLayer\Search\Filter\EqualsFilter, | ||
Framework\Uuid\Uuid}; | ||
use WalleePayment\Core\Api\OrderDeliveryState\Handler\OrderDeliveryStateHandler; | ||
|
||
/** | ||
* Class OrderDeliveryStateService | ||
* | ||
* @package WalleePayment\Core\Api\OrderDeliveryState\Service | ||
*/ | ||
class OrderDeliveryStateService { | ||
|
||
/** | ||
* @var \Psr\Container\ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
/** | ||
* OrderDeliveryStateHandler constructor. | ||
* | ||
* @param \Psr\Container\ContainerInterface $container | ||
*/ | ||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @param \Shopware\Core\Framework\Context $context | ||
*/ | ||
public function install(Context $context): void | ||
{ | ||
$stateMachineId = $this->getStateMachineEntity($context); | ||
$holdStateId = $this->getHoldStateId($stateMachineId, $context); | ||
$openStateId = $this->getOpenStateId($stateMachineId, $context); | ||
|
||
$this->upsertHoldTransition($stateMachineId, $openStateId, $holdStateId, $context); | ||
$this->upsertUnholdTransition($stateMachineId, $holdStateId, $openStateId, $context); | ||
|
||
} | ||
|
||
/** | ||
* @param \Shopware\Core\Framework\Context $context | ||
* @return \Shopware\Core\System\StateMachine\StateMachineEntity | ||
*/ | ||
protected function getStateMachineEntity(Context $context): string | ||
{ | ||
$stateMachineCriteria = (new Criteria()) | ||
->addFilter(new EqualsFilter('technicalName', OrderDeliveryStates::STATE_MACHINE)); | ||
$stateMachineEntity = $this->container->get('state_machine.repository')->search($stateMachineCriteria, $context)->first(); | ||
return $stateMachineEntity->getId(); | ||
} | ||
|
||
/** | ||
* @param string $stateMachineId | ||
* @param \Shopware\Core\Framework\Context $context | ||
* @return string | ||
*/ | ||
protected function getHoldStateId(string $stateMachineId, Context $context): string | ||
{ | ||
$stateMachineStateRepository = $this->container->get('state_machine_state.repository'); | ||
|
||
$holdStateMachineStateCriteria = (new Criteria()) | ||
->addFilter( | ||
new EqualsFilter('technicalName', OrderDeliveryStateHandler::STATE_HOLD), | ||
new EqualsFilter('stateMachineId', $stateMachineId) | ||
); | ||
|
||
$holdStateMachineStateEntity = $stateMachineStateRepository->search($holdStateMachineStateCriteria, $context)->first(); | ||
|
||
$holdStateId = is_null($holdStateMachineStateEntity) ? Uuid::randomHex() : $holdStateMachineStateEntity->getId(); | ||
|
||
if (is_null($holdStateMachineStateEntity)) { | ||
$data = [ | ||
'id' => $holdStateId, | ||
'technicalName' => OrderDeliveryStateHandler::STATE_HOLD, | ||
'stateMachineId' => $stateMachineId, | ||
'translations' => [ | ||
'en-GB' => [ | ||
'name' => 'Hold', | ||
], | ||
'de-DE' => [ | ||
'name' => 'Halten', | ||
], | ||
], | ||
]; | ||
$stateMachineStateRepository->upsert([$data], $context); | ||
} | ||
|
||
return $holdStateId; | ||
} | ||
|
||
/** | ||
* @param string $stateMachineId | ||
* @param \Shopware\Core\Framework\Context $context | ||
* @return string | ||
*/ | ||
protected function getOpenStateId(string $stateMachineId, Context $context): string | ||
{ | ||
$stateMachineStateRepository = $this->container->get('state_machine_state.repository'); | ||
|
||
$stateMachineStateCriteria = (new Criteria()) | ||
->addFilter( | ||
new EqualsFilter('technicalName', OrderDeliveryStates::STATE_OPEN), | ||
new EqualsFilter('stateMachineId', $stateMachineId) | ||
); | ||
|
||
$stateMachineStateEntity = $stateMachineStateRepository->search($stateMachineStateCriteria, $context)->first(); | ||
return $stateMachineStateEntity->getId(); | ||
} | ||
|
||
/** | ||
* @param string $stateMachineId | ||
* @param string $openStateId | ||
* @param string $holdStateId | ||
* @param \Shopware\Core\Framework\Context $context | ||
*/ | ||
protected function upsertHoldTransition(string $stateMachineId, string $openStateId, string $holdStateId, Context $context) | ||
{ | ||
$translations = [ | ||
'en-GB' => [ | ||
'name' => 'Hold', | ||
], | ||
'de-DE' => [ | ||
'name' => 'Halten', | ||
], | ||
]; | ||
|
||
$this->upsertTransition(OrderDeliveryStateHandler::ACTION_HOLD, $stateMachineId, $openStateId, $holdStateId, $translations, $context); | ||
} | ||
|
||
protected function upsertTransition(string $actionName, string $stateMachineId, string $fromStateId, string $toStateId, array $translations, Context $context): void | ||
{ | ||
$stateMachineTransitionRepository = $this->container->get('state_machine_transition.repository'); | ||
$criteria = (new Criteria()) | ||
->addFilter( | ||
new EqualsFilter('actionName', $actionName), | ||
new EqualsFilter('stateMachineId', $stateMachineId), | ||
new EqualsFilter('fromStateId', $fromStateId), | ||
new EqualsFilter('toStateId', $toStateId) | ||
); | ||
|
||
$stateMachineTransitionEntity = $stateMachineTransitionRepository->search($criteria, $context)->first(); | ||
$transitionId = is_null($stateMachineTransitionEntity) ? Uuid::randomHex() : $stateMachineTransitionEntity->getId(); | ||
|
||
if (is_null($stateMachineTransitionEntity)) { | ||
$data = [ | ||
'id' => $transitionId, | ||
'actionName' => $actionName, | ||
'stateMachineId' => $stateMachineId, | ||
'fromStateId' => $fromStateId, | ||
'toStateId' => $toStateId, | ||
'translations' => $translations, | ||
]; | ||
$stateMachineTransitionRepository->upsert([$data], $context); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @param string $stateMachineId | ||
* @param string $openStateId | ||
* @param string $holdStateId | ||
* @param \Shopware\Core\Framework\Context $context | ||
*/ | ||
protected function upsertUnholdTransition(string $stateMachineId, string $holdStateId, string $openStateId, Context $context) | ||
{ | ||
$translations = [ | ||
'en-GB' => [ | ||
'name' => 'Unhold', | ||
], | ||
'de-DE' => [ | ||
'name' => 'Aufheben', | ||
], | ||
]; | ||
|
||
$this->upsertTransition(OrderDeliveryStateHandler::ACTION_UNHOLD, $stateMachineId, $holdStateId, $openStateId, $translations, $context); | ||
} | ||
} |
Oops, something went wrong.