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.

114 lines
3.0KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Lc\ShopBundle\Context\PriceInterface;
  5. use Lc\ShopBundle\Context\ProductPropertyInterface;
  6. use Lc\ShopBundle\Context\SortableInterface;
  7. use Lc\ShopBundle\Services\Price;
  8. /**
  9. * @ORM\MappedSuperclass()
  10. */
  11. abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface, PriceInterface
  12. {
  13. use SortableTrait;
  14. use ProductPropertyTrait;
  15. /**
  16. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", inversedBy="products")
  17. * @ORM\JoinColumn(nullable=false)
  18. */
  19. protected $productFamily;
  20. /**
  21. * @ORM\Column(type="string", length=255, nullable=true)
  22. */
  23. protected $title;
  24. public function getPriceInherited()
  25. {
  26. if($this->price) {
  27. return $this->price;
  28. }
  29. else {
  30. return $this->productFamily->getPrice();
  31. }
  32. }
  33. public function getUnitInherited()
  34. {
  35. if($this->unit) {
  36. return $this->unit;
  37. }
  38. else{
  39. return $this->productFamily->getUnit();
  40. }
  41. }
  42. public function getTitleInherited()
  43. {
  44. if($this->title){
  45. return $this->title;
  46. }
  47. else{
  48. return $this->productFamily->getTitle();
  49. }
  50. }
  51. public function getQuantityInherited()
  52. {
  53. if($this->quantity) {
  54. return $this->quantity;
  55. }
  56. else{
  57. return $this->productFamily->getQuantity();
  58. }
  59. }
  60. public function getAvailableQuantityInherited()
  61. {
  62. if($this->productFamily->getBehaviorCountStock()) {
  63. return $this->availableQuantity;
  64. }
  65. else{
  66. return $this->productFamily->getAvailableQuantity();
  67. }
  68. }
  69. public function getTaxRateInherited()
  70. {
  71. if($this->productFamily->getTaxRate()) {
  72. return $this->productFamily->getTaxRate();
  73. }
  74. else{
  75. return $this->productFamily->getMerchant()->getTaxRate()->getValue();
  76. }
  77. }
  78. public function getProductFamily(): ?ProductFamily
  79. {
  80. return $this->productFamily;
  81. }
  82. public function setProductFamily(?ProductFamily $productFamily): self
  83. {
  84. $this->productFamily = $productFamily;
  85. return $this;
  86. }
  87. public function getTitle(): ?string
  88. {
  89. return $this->title;
  90. }
  91. public function setTitle(?string $title): self
  92. {
  93. $this->title = $title;
  94. return $this;
  95. }
  96. }