選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

121 行
3.3KB

  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 getQuantityLabelInherited()
  61. {
  62. $quantity = $this->getQuantityInherited() ;
  63. $unit = $this->getUnitInherited() ;
  64. return $quantity.$unit->getWordingShort() ;
  65. }
  66. public function getAvailableQuantityInherited()
  67. {
  68. if($this->productFamily->getBehaviorCountStock()) {
  69. return $this->availableQuantity;
  70. }
  71. else{
  72. return $this->productFamily->getAvailableQuantity();
  73. }
  74. }
  75. public function getTaxRateInherited()
  76. {
  77. if($this->productFamily->getTaxRate()) {
  78. return $this->productFamily->getTaxRate();
  79. }
  80. else{
  81. return $this->productFamily->getMerchant()->getTaxRate()->getValue();
  82. }
  83. }
  84. public function getProductFamily(): ?ProductFamily
  85. {
  86. return $this->productFamily;
  87. }
  88. public function setProductFamily(?ProductFamily $productFamily): self
  89. {
  90. $this->productFamily = $productFamily;
  91. return $this;
  92. }
  93. public function getTitle(): ?string
  94. {
  95. return $this->title;
  96. }
  97. public function setTitle(?string $title): self
  98. {
  99. $this->title = $title;
  100. return $this;
  101. }
  102. }