You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3KB

  1. <?php
  2. namespace common\logic\Product\ProductPrice\Service;
  3. use common\logic\AbstractBuilder;
  4. use common\logic\PointSale\PointSale\Model\PointSale;
  5. use common\logic\Product\Product\Model\Product;
  6. use common\logic\Product\ProductPrice\Model\ProductPrice;
  7. use common\logic\User\User\Model\User;
  8. use common\logic\User\UserGroup\Model\UserGroup;
  9. class ProductPriceBuilder extends AbstractBuilder
  10. {
  11. public function instanciateProductPrice(
  12. Product $product,
  13. float $price,
  14. User $user = null,
  15. UserGroup $userGroup = null,
  16. PointSale $pointSale = null,
  17. float $quantityFrom = null): ProductPrice
  18. {
  19. $productPrice = new ProductPrice();
  20. $productPrice->populateProduct($product);
  21. $productPrice->price = $price;
  22. if($user) {
  23. $productPrice->populateUser($user);
  24. }
  25. if($userGroup) {
  26. $productPrice->populateUserGroup($userGroup);
  27. }
  28. if($pointSale) {
  29. $productPrice->populatePointSale($pointSale);
  30. }
  31. if($quantityFrom) {
  32. $productPrice->quantity_from = $quantityFrom;
  33. }
  34. return $productPrice;
  35. }
  36. public function createProductPrice(): ProductPrice
  37. {
  38. $productPrice = $this->instanciateProductPrice();
  39. $this->saveCreate($productPrice);
  40. return $productPrice;
  41. }
  42. }