Skip to content

Commit

Permalink
Run with shop 8.0.x, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter committed Dec 13, 2024
1 parent 5233a6c commit 1032297
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require": {
"php": "^8.2",
"doctrine/dbal": "^v2.7",
"oxid-esales/graphql-base": "dev-b-7.2.x"
"oxid-esales/graphql-base": "dev-b-8.0.x-compatibility-OXDEV-7248"
},
"conflict": {
"oxid-esales/oxideshop-ce": "<7.2",
Expand Down
17 changes: 9 additions & 8 deletions src/Voucher/Infrastructure/Voucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Exception;
use OxidEsales\Eshop\Application\Model\Basket as EshopBasketModel;
use OxidEsales\Eshop\Core\Exception\ObjectException as EshopObjectException;
use OxidEsales\EshopCommunity\Internal\Framework\Database\TransactionServiceInterface as EshopTransactionService;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactoryInterface as EshopConnectionFactory;
use OxidEsales\GraphQL\Storefront\Basket\DataType\Basket as BasketDataType;
use OxidEsales\GraphQL\Storefront\Shared\Infrastructure\Basket as SharedBasketInfrastructure;
use OxidEsales\GraphQL\Storefront\Shared\Shop\Voucher as StorefrontVoucherModel;
Expand All @@ -29,24 +29,25 @@ final class Voucher
/** @var SharedBasketInfrastructure */
private $sharedBasketInfrastructure;

/** @var EshopTransactionService */
private $transactionService;
/** @var EshopConnectionFactory */
private $connectionService;

public function __construct(
Repository $repository,
SharedBasketInfrastructure $sharedBasketInfrastructure,
EshopTransactionService $transactionService
EshopConnectionFactory $connectionService
) {
$this->repository = $repository;
$this->sharedBasketInfrastructure = $sharedBasketInfrastructure;
$this->transactionService = $transactionService;
$this->connectionService = $connectionService;
}

public function addVoucher(
VoucherDataType $voucher,
BasketDataType $basket
): void {
$this->transactionService->begin();
$connection = $this->connectionService->create();
$connection->beginTransaction();

try {
$basketModel = $this->sharedBasketInfrastructure->getCalculatedBasket($basket);
Expand All @@ -68,11 +69,11 @@ public function addVoucher(

$this->repository->addBasketIdToVoucher($basket->id(), $voucherModel->getId());
} catch (Exception $exception) {
$this->transactionService->rollback();
$connection->rollBack();

throw VoucherNotUsable::withMessage($exception->getMessage());
}
$this->transactionService->commit();
$connection->commit();
}

public function removeVoucher(
Expand Down

0 comments on commit 1032297

Please sign in to comment.