File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,10 +12,12 @@ class ProductStockFacade
1212 /**
1313 * @param \Shopsys\FrameworkBundle\Model\Stock\ProductStockRepository $productStockRepository
1414 * @param \Doctrine\ORM\EntityManagerInterface $em
15+ * @param \Shopsys\FrameworkBundle\Model\Stock\ProductStockFactory $productStockFactory
1516 */
1617 public function __construct (
1718 protected readonly ProductStockRepository $ productStockRepository ,
1819 protected readonly EntityManagerInterface $ em ,
20+ protected readonly ProductStockFactory $ productStockFactory ,
1921 ) {
2022 }
2123
@@ -105,7 +107,7 @@ public function editProductStockRelations(
105107 */
106108 protected function createProductStock (Product $ product , Stock $ stock ): ProductStock
107109 {
108- $ productStock = new ProductStock ($ stock , $ product );
110+ $ productStock = $ this -> productStockFactory -> create ($ stock , $ product );
109111 $ this ->em ->persist ($ productStock );
110112
111113 return $ productStock ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Shopsys \FrameworkBundle \Model \Stock ;
6+
7+ use Shopsys \FrameworkBundle \Component \EntityExtension \EntityNameResolver ;
8+ use Shopsys \FrameworkBundle \Model \Product \Product ;
9+
10+ class ProductStockFactory
11+ {
12+ /**
13+ * @param \Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver $entityNameResolver
14+ */
15+ public function __construct (
16+ protected readonly EntityNameResolver $ entityNameResolver ,
17+ ) {
18+ }
19+
20+ /**
21+ * @param \Shopsys\FrameworkBundle\Model\Stock\Stock $stock
22+ * @param \Shopsys\FrameworkBundle\Model\Product\Product $product
23+ * @return \Shopsys\FrameworkBundle\Model\Stock\ProductStock
24+ */
25+ public function create (Stock $ stock , Product $ product ): ProductStock
26+ {
27+ $ classData = $ this ->entityNameResolver ->resolve (ProductStock::class);
28+
29+ return new $ classData ($ stock , $ product );
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments