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.

203 linhas
6.2KB

  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. use StatusTrait;
  21. /**
  22. * @Gedmo\Blameable(on="create")
  23. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  24. * @ORM\JoinColumn(nullable=true)
  25. */
  26. protected $createdBy;
  27. /**
  28. * @Gedmo\Blameable(on="update")
  29. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  30. * @ORM\JoinColumn(nullable=true)
  31. */
  32. protected $updatedBy;
  33. /**
  34. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", inversedBy="products", cascade={"persist"})
  35. * @ORM\JoinColumn(nullable=false)
  36. */
  37. protected $productFamily;
  38. /**
  39. * @ORM\Column(type="string", length=255, nullable=true)
  40. */
  41. protected $title;
  42. public function __construct()
  43. {
  44. $this->orderProducts = new ArrayCollection();
  45. $this->status = 1;
  46. }
  47. public function __toString()
  48. {
  49. $title = $this->getProductFamily()->getTitle() ;
  50. if($this->getTitle() && strlen($this->getTitle())) {
  51. $title .= ' - '. $this->getTitle() ;
  52. }
  53. return $title ;
  54. }
  55. public function getBuyingPriceInherited()
  56. {
  57. if ($this->getBuyingPrice()) {
  58. return $this->getBuyingPrice();
  59. } else {
  60. return $this->getProductFamily()->getBuyingPrice();
  61. }
  62. }
  63. public function getBuyingPriceByRefUnitInherited()
  64. {
  65. if ($this->getBuyingPriceByRefUnit()) {
  66. return $this->getBuyingPriceByRefUnit();
  67. } else {
  68. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  69. }
  70. }
  71. public function getPriceInherited()
  72. {
  73. if ($this->getPrice()) {
  74. return $this->getPrice();
  75. } else {
  76. return $this->getProductFamily()->getPrice();
  77. }
  78. }
  79. public function getPriceByRefUnitInherited()
  80. {
  81. if ($this->getPriceByRefUnit()) {
  82. return $this->getPriceByRefUnit();
  83. } else {
  84. return $this->getProductFamily()->getPriceByRefUnit();
  85. }
  86. }
  87. public function getBehaviorPriceInherited()
  88. {
  89. return $this->getProductFamily()->getBehaviorPrice();
  90. }
  91. public function getReductionCatalogInherited()
  92. {
  93. return $this->getProductFamily()->getReductionCatalog();
  94. }
  95. public function getUnitInherited()
  96. {
  97. if ($this->getUnit()) {
  98. return $this->getUnit();
  99. } else {
  100. return $this->getProductFamily()->getUnit();
  101. }
  102. }
  103. public function getTitleInherited()
  104. {
  105. if ($this->getTitle()) {
  106. return $this->getTitle();
  107. } else {
  108. return $this->getProductFamily()->getTitle();
  109. }
  110. }
  111. public function getQuantityInherited()
  112. {
  113. if ($this->getQuantity()) {
  114. return $this->getQuantity();
  115. }
  116. else {
  117. return $this->getProductFamily()->getQuantity();
  118. }
  119. }
  120. public function getQuantityLabelInherited()
  121. {
  122. $quantity = $this->getQuantityInherited();
  123. $unit = $this->getUnitInherited();
  124. return $quantity . $unit->getWordingShort();
  125. }
  126. public function getQuantityTitle($productFamily)
  127. {
  128. $title = $this->getQuantityLabelInherited();
  129. if ($productFamily->hasProductsWithVariousWeight()) {
  130. $title .= ', ' . $this->getTitleInherited();
  131. }
  132. return $title;
  133. }
  134. public function getAvailableQuantityInherited()
  135. {
  136. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  137. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  138. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  139. return $this->getProductFamily()->getAvailableQuantity();
  140. break;
  141. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  142. return $this->getAvailableQuantity();
  143. break;
  144. case ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  145. return false;
  146. break;
  147. }
  148. }
  149. public function getTaxRateInherited()
  150. {
  151. return $this->getProductFamily()->getTaxRateInherited();
  152. }
  153. public function getProductFamily(): ?ProductFamily
  154. {
  155. return $this->productFamily;
  156. }
  157. public function setProductFamily(?ProductFamily $productFamily): self
  158. {
  159. $this->productFamily = $productFamily;
  160. return $this;
  161. }
  162. public function getTitle(): ?string
  163. {
  164. return $this->title;
  165. }
  166. public function setTitle(?string $title): self
  167. {
  168. $this->title = $title;
  169. return $this;
  170. }
  171. }