|
- <?php
-
- namespace domain\Product\ProductPrice\Service;
-
- use domain\PointSale\PointSale\PointSale;
- use domain\Product\Product\Product;
- use domain\Product\ProductPrice\Model\ProductPrice;
- use domain\User\User\User;
- use domain\User\UserGroup\UserGroup;
- use domain\_\AbstractBuilder;
-
- class ProductPriceBuilder extends AbstractBuilder
- {
- public function instanciateProductPrice(
- Product $product,
- float $price,
- User $user = null,
- UserGroup $userGroup = null,
- PointSale $pointSale = null,
- float $quantityFrom = null): ProductPrice
- {
- $productPrice = new ProductPrice();
-
- $productPrice->populateProduct($product);
- $productPrice->price = $price;
-
- if($user) {
- $productPrice->populateUser($user);
- }
-
- if($userGroup) {
- $productPrice->populateUserGroup($userGroup);
- }
-
- if($pointSale) {
- $productPrice->populatePointSale($pointSale);
- }
-
- if($quantityFrom) {
- $productPrice->quantity_from = $quantityFrom;
- }
-
- return $productPrice;
- }
-
- public function createProductPrice(): ProductPrice
- {
- $productPrice = $this->instanciateProductPrice();
- $this->saveCreate($productPrice);
-
- return $productPrice;
- }
- }
|