-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusProductBundlePlugin\Provider; | ||
|
||
use BitBag\SyliusProductBundlePlugin\Command\AddProductBundleItemToCartCommand; | ||
use BitBag\SyliusProductBundlePlugin\Factory\AddProductBundleItemToCartCommandFactoryInterface; | ||
use BitBag\SyliusProductBundlePlugin\Repository\ProductBundleItemRepositoryInterface; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
|
||
final class AddProductBundleItemToCartCommandProvider implements AddProductBundleItemToCartCommandProviderInterface | ||
{ | ||
public function __construct( | ||
private readonly AddProductBundleItemToCartCommandFactoryInterface $addProductBundleItemToCartCommandFactory, | ||
private readonly ProductBundleItemRepositoryInterface $productBundleItemRepository, | ||
) { | ||
} | ||
|
||
/** @return Collection<int, AddProductBundleItemToCartCommand> */ | ||
public function provide(string $bundleCode, array $variantCodes): Collection | ||
{ | ||
$bundleItems = $this->productBundleItemRepository->findByBundleCode($bundleCode); | ||
|
||
$items = ''; | ||
foreach ($bundleItems as $bundleItem) { | ||
$items .= $bundleItem->getProductVariant()->getCode() . ', '; | ||
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 35 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
|
||
} | ||
|
||
$commands = []; | ||
foreach ($bundleItems as $bundleItem) { | ||
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.12, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.3, Symfony ^5.4
Check failure on line 39 in src/Provider/AddProductBundleItemToCartCommandProvider.php GitHub Actions / Sylius ^1.13, PHP 8.2, Symfony ^6.4
|
||
$command = $this->addProductBundleItemToCartCommandFactory->createNew($bundleItem); | ||
//TODO implement overwritting bundle's variants with variants provided in API call | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusProductBundlePlugin\Provider; | ||
|
||
use BitBag\SyliusProductBundlePlugin\Command\AddProductBundleItemToCartCommand; | ||
use Doctrine\Common\Collections\Collection; | ||
|
||
interface AddProductBundleItemToCartCommandProviderInterface | ||
{ | ||
/** @return Collection<int, AddProductBundleItemToCartCommand> */ | ||
public function provide(string $bundleCode, array $variantCodes): Collection; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusProductBundlePlugin\Repository; | ||
|
||
use BitBag\SyliusProductBundlePlugin\Entity\ProductBundleItemInterface; | ||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; | ||
|
||
class ProductBundleItemRepository extends EntityRepository implements ProductBundleItemRepositoryInterface | ||
{ | ||
/** @return ProductBundleItemInterface[] */ | ||
public function findByBundleCode(string $bundleCode): array | ||
{ | ||
return $this | ||
->createQueryBuilder('pbi') | ||
->leftJoin('pbi.productBundle', 'pb') | ||
->leftJoin('pb.product', 'p') | ||
->where('p.code = :code') | ||
->setParameter('code', $bundleCode) | ||
->getQuery() | ||
->getResult(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusProductBundlePlugin\Repository; | ||
|
||
use BitBag\SyliusProductBundlePlugin\Entity\ProductBundleItemInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
|
||
interface ProductBundleItemRepositoryInterface extends RepositoryInterface | ||
{ | ||
/** @return ProductBundleItemInterface[] */ | ||
public function findByBundleCode(string $bundleCode): array; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service | ||
id="bitbag_sylius_product_bundle.provider.add_product_bundle_item_to_cart_command" | ||
class="BitBag\SyliusProductBundlePlugin\Provider\AddProductBundleItemToCartCommandProvider" | ||
> | ||
<argument type="service" id="bitbag_sylius_product_bundle.factory.add_product_bundle_item_to_cart_command"/> | ||
<argument type="service" id="bitbag_sylius_product_bundle.repository.product_bundle_item"/> | ||
</service> | ||
</services> | ||
</container> |