Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

190 linhas
5.8KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\ShopBundle\Context\OrderProductInterface;
  7. use Lc\ShopBundle\Context\PriceInterface;
  8. use Lc\ShopBundle\Context\ProductInterface;
  9. use Lc\ShopBundle\Context\ProductPropertyInterface;
  10. use Lc\ShopBundle\Context\SortableInterface;
  11. use Lc\ShopBundle\Services\Price;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. */
  16. abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface, PriceInterface
  17. {
  18. use SortableTrait;
  19. use ProductPropertyTrait;
  20. /**
  21. * @Gedmo\Blameable(on="create")
  22. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  23. * @ORM\JoinColumn(nullable=true)
  24. */
  25. protected $createdBy;
  26. /**
  27. * @Gedmo\Blameable(on="update")
  28. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  29. * @ORM\JoinColumn(nullable=true)
  30. */
  31. protected $updatedBy;
  32. /**
  33. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", inversedBy="products")
  34. * @ORM\JoinColumn(nullable=false)
  35. */
  36. protected $productFamily;
  37. /**
  38. * @ORM\Column(type="string", length=255, nullable=true)
  39. */
  40. protected $title;
  41. public function __construct()
  42. {
  43. $this->orderProducts = new ArrayCollection();
  44. }
  45. public function getBuyingPriceInherited()
  46. {
  47. if ($this->getBuyingPrice()) {
  48. return $this->getBuyingPrice();
  49. } else {
  50. return $this->getProductFamily()->getBuyingPrice();
  51. }
  52. }
  53. public function getBuyingPriceByRefUnitInherited()
  54. {
  55. if ($this->getBuyingPriceByRefUnit()) {
  56. return $this->getBuyingPriceByRefUnit();
  57. } else {
  58. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  59. }
  60. }
  61. public function getPriceInherited()
  62. {
  63. if ($this->getPrice()) {
  64. return $this->getPrice();
  65. } else {
  66. return $this->getProductFamily()->getPrice();
  67. }
  68. }
  69. public function getPriceByRefUnitInherited()
  70. {
  71. if ($this->getPriceByRefUnit()) {
  72. return $this->getPriceByRefUnit();
  73. } else {
  74. return $this->getProductFamily()->getPriceByRefUnit();
  75. }
  76. }
  77. public function getBehaviorPriceInherited()
  78. {
  79. return $this->getProductFamily()->getBehaviorPrice();
  80. }
  81. public function getReductionCatalogInherited()
  82. {
  83. return $this->getProductFamily()->getReductionCatalog();
  84. }
  85. public function getUnitInherited()
  86. {
  87. if ($this->getUnit()) {
  88. return $this->getUnit();
  89. } else {
  90. return $this->getProductFamily()->getUnit();
  91. }
  92. }
  93. public function getTitleInherited()
  94. {
  95. if ($this->getTitle()) {
  96. return $this->getTitle();
  97. } else {
  98. return $this->getProductFamily()->getTitle();
  99. }
  100. }
  101. public function getQuantityInherited()
  102. {
  103. if ($this->getQuantity()) {
  104. return $this->getQuantity();
  105. }
  106. else {
  107. return $this->getProductFamily()->getQuantity();
  108. }
  109. }
  110. public function getQuantityLabelInherited()
  111. {
  112. $quantity = $this->getQuantityInherited();
  113. $unit = $this->getUnitInherited();
  114. return $quantity . $unit->getWordingShort();
  115. }
  116. public function getQuantityTitle($productFamily)
  117. {
  118. $title = $this->getQuantityLabelInherited();
  119. if ($productFamily->hasProductsWithVariousWeight()) {
  120. $title .= ', ' . $this->getTitleInherited();
  121. }
  122. return $title;
  123. }
  124. public function getAvailableQuantityInherited()
  125. {
  126. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  127. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  128. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  129. return $this->getProductFamily()->getAvailableQuantity();
  130. break;
  131. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  132. return $this->getAvailableQuantity();
  133. break;
  134. case ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  135. return false;
  136. break;
  137. }
  138. }
  139. public function getTaxRateInherited()
  140. {
  141. return $this->getProductFamily()->getTaxRateInherited();
  142. }
  143. public function getProductFamily(): ?ProductFamily
  144. {
  145. return $this->productFamily;
  146. }
  147. public function setProductFamily(?ProductFamily $productFamily): self
  148. {
  149. $this->productFamily = $productFamily;
  150. return $this;
  151. }
  152. public function getTitle(): ?string
  153. {
  154. return $this->title;
  155. }
  156. public function setTitle(?string $title): self
  157. {
  158. $this->title = $title;
  159. return $this;
  160. }
  161. }