|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file has been created by developers from BitBag. |
| 5 | + * Feel free to contact us once you face any issues or want to start |
| 6 | + * You can find more information about us on https://bitbag.io and write us |
| 7 | + * an email on hello@bitbag.io. |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace BitBag\SyliusProductBundlePlugin\Provider; |
| 13 | + |
| 14 | +use BitBag\SyliusProductBundlePlugin\Command\AddProductBundleItemToCartCommand; |
| 15 | +use BitBag\SyliusProductBundlePlugin\Factory\AddProductBundleItemToCartCommandFactoryInterface; |
| 16 | +use BitBag\SyliusProductBundlePlugin\Repository\ProductBundleItemRepositoryInterface; |
| 17 | +use Doctrine\Common\Collections\ArrayCollection; |
| 18 | +use Doctrine\Common\Collections\Collection; |
| 19 | + |
| 20 | +final class AddProductBundleItemToCartCommandProvider implements AddProductBundleItemToCartCommandProviderInterface |
| 21 | +{ |
| 22 | + public function __construct( |
| 23 | + private readonly AddProductBundleItemToCartCommandFactoryInterface $addProductBundleItemToCartCommandFactory, |
| 24 | + private readonly ProductBundleItemRepositoryInterface $productBundleItemRepository, |
| 25 | + ) { |
| 26 | + } |
| 27 | + |
| 28 | + /** @return Collection<int, AddProductBundleItemToCartCommand> */ |
| 29 | + public function provide(string $bundleCode, array $variantCodes): Collection |
| 30 | + { |
| 31 | + $bundleItems = $this->productBundleItemRepository->findByBundleCode($bundleCode); |
| 32 | + |
| 33 | + $items = ''; |
| 34 | + foreach ($bundleItems as $bundleItem) { |
| 35 | + $items .= $bundleItem->getProductVariant()->getCode() . ', '; |
| 36 | + } |
| 37 | + |
| 38 | + $commands = []; |
| 39 | + foreach ($bundleItems as $bundleItem) { |
| 40 | + $command = $this->addProductBundleItemToCartCommandFactory->createNew($bundleItem); |
| 41 | + //TODO implement overwritting bundle's variants with variants provided in API call |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments