1212namespace BitBag \SyliusProductBundlePlugin \Twig \Extension ;
1313
1414use BitBag \SyliusProductBundlePlugin \Entity \ProductBundleInterface ;
15+ use BitBag \SyliusProductBundlePlugin \Entity \ProductBundleItemInterface ;
1516use BitBag \SyliusProductBundlePlugin \Entity \ProductInterface ;
17+ use BitBag \SyliusProductBundlePlugin \Repository \ProductBundleItemRepositoryInterface ;
1618use BitBag \SyliusProductBundlePlugin \Repository \ProductBundleRepositoryInterface ;
1719use Twig \Extension \AbstractExtension ;
1820use Twig \TwigFunction ;
@@ -21,13 +23,15 @@ final class ProductBundlesExtension extends AbstractExtension
2123{
2224 public function __construct (
2325 private readonly ProductBundleRepositoryInterface $ productBundleRepository ,
26+ private readonly ProductBundleItemRepositoryInterface $ productBundleItemRepository ,
2427 ) {
2528 }
2629
2730 public function getFunctions (): array
2831 {
2932 return [
3033 new TwigFunction ('bitbag_get_bundles_containing_product ' , [$ this , 'getBundlesForProduct ' ], ['is_safe ' => ['html ' ]]),
34+ new TwigFunction ('bitbag_get_products_from_bundle ' , [$ this , 'getProductsFromBundle ' ], ['is_safe ' => ['html ' ]]),
3135 ];
3236 }
3337
@@ -36,4 +40,10 @@ public function getBundlesForProduct(ProductInterface $product): array
3640 {
3741 return $ this ->productBundleRepository ->findBundlesByVariants ($ product ->getVariants ());
3842 }
43+
44+ /** @return ProductBundleItemInterface[] */
45+ public function getProductsFromBundle (ProductInterface $ product ): array
46+ {
47+ return $ this ->productBundleItemRepository ->findByBundleCode ((string ) $ product ->getCode ());
48+ }
3949}
0 commit comments