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.

96 lines
2.6KB

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