diff --git a/src/Fixture/Factory/ProductBundleFixtureFactory.php b/src/Fixture/Factory/ProductBundleFixtureFactory.php new file mode 100644 index 00000000..9661bffd --- /dev/null +++ b/src/Fixture/Factory/ProductBundleFixtureFactory.php @@ -0,0 +1,72 @@ +optionsResolver = new OptionsResolver(); + $this->configureOptions($this->optionsResolver); + } + + private function configureOptions(OptionsResolver $resolver): void + { + $resolver + ->setDefault('bundle', '') + ->setAllowedTypes('bundle', 'string') + ->setDefault('items', []) + ->setAllowedTypes('items', 'array') + ->setDefault('is_packed', '') + ->setAllowedTypes('is_packed', 'bool') + ; + } + + public function create(array $options = []): ProductBundleInterface + { + $options = $this->optionsResolver->resolve($options); + + $bundleProduct = $this->productRepository->findOneByCode($options['bundle']); + /** @var ProductBundleInterface $productBundle */ + $productBundle = $this->productBundleFactory->createNew(); + $productBundle->setProduct($bundleProduct); + $productBundle->setIsPackedProduct($options['is_packed']); + + foreach ($options['items'] ?? [] as $item) { + /** @var ProductVariantInterface $productVariant */ + $productVariant = $this->productVariantRepository->findOneBy(['code' => $item]); + /** @var ProductBundleItemInterface $bundleItem */ + $bundleItem = $this->productBundleItemFactory->createNew(); + $bundleItem->setProductVariant($productVariant); + $bundleItem->setQuantity(1); + $bundleItem->setProductBundle($productBundle); + $productBundle->addProductBundleItem($bundleItem); + } + + return $productBundle; + } +} diff --git a/src/Fixture/ProductBundleFixture.php b/src/Fixture/ProductBundleFixture.php new file mode 100644 index 00000000..0e568b45 --- /dev/null +++ b/src/Fixture/ProductBundleFixture.php @@ -0,0 +1,32 @@ +children(); + $resourceNodeChildren->scalarNode('bundle')->end(); + $resourceNodeChildren->arrayNode('items')->scalarPrototype()->end(); + $resourceNodeChildren->booleanNode('is_packed')->end(); + } + + public function getName(): string + { + return 'product_bundle'; + } +} diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index ea17a5b4..145bb073 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -6,6 +6,7 @@ + diff --git a/src/Resources/config/services/fixture.xml b/src/Resources/config/services/fixture.xml new file mode 100644 index 00000000..d86eb6e2 --- /dev/null +++ b/src/Resources/config/services/fixture.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/Application/config/packages/bitbag_sylius_product_bundle_plugin.yml b/tests/Application/config/packages/bitbag_sylius_product_bundle_plugin.yml index bd17eb83..71204aee 100644 --- a/tests/Application/config/packages/bitbag_sylius_product_bundle_plugin.yml +++ b/tests/Application/config/packages/bitbag_sylius_product_bundle_plugin.yml @@ -1,2 +1,46 @@ imports: - - { resource: "@BitBagSyliusProductBundlePlugin/Resources/config/config.yml" } + - { resource: "@BitBagSyliusProductBundlePlugin/Resources/config/config.yml" } + +sylius_fixtures: + suites: + default: + fixtures: + tshirt_bundle_products: + name: product + options: + custom: + - name: 'Packed T-Shirt bundle' + tax_category: 'clothing' + channels: + - 'FASHION_WEB' + main_taxon: 'mens_t_shirts' + taxons: + - 't_shirts' + - 'mens_t_shirts' + + - name: 'Not packed T-Shirt bundle' + tax_category: 'clothing' + channels: + - 'FASHION_WEB' + main_taxon: 'womens_t_shirts' + taxons: + - 't_shirts' + - 'womens_t_shirts' + + tshirt_bundles: + name: product_bundle + options: + custom: + - bundle: 'Packed_T_Shirt_bundle' + items: + - 'Sport_basic_white_T_Shirt-variant-0' + - 'Raglan_grey_&_black_Tee-variant-0' + - 'Oversize_white_cotton_T_Shirt-variant-0' + is_packed: true + + - bundle: 'Not_packed_T_Shirt_bundle' + items: + - 'Everyday_white_basic_T_Shirt-variant-0' + - 'Loose_white_designer_T_Shirt-variant-0' + - 'Ribbed_copper_slim_fit_Tee-variant-0' + is_packed: false