Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

218 lines
6.6KB

  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. /**
  43. * @ORM\Column(type="boolean", nullable=true)
  44. */
  45. protected $originProduct;
  46. public function __construct()
  47. {
  48. $this->orderProducts = new ArrayCollection();
  49. $this->status = 1;
  50. }
  51. public function __toString()
  52. {
  53. $title = $this->getProductFamily()->getTitle();
  54. if ($this->getTitle() && strlen($this->getTitle())) {
  55. $title .= ' - ' . $this->getTitle();
  56. }
  57. return $title;
  58. }
  59. public function getBuyingPriceInherited()
  60. {
  61. if ($this->getBuyingPrice()) {
  62. return $this->getBuyingPrice();
  63. } else {
  64. return $this->getProductFamily()->getBuyingPrice();
  65. }
  66. }
  67. public function getBuyingPriceByRefUnitInherited()
  68. {
  69. if ($this->getBuyingPriceByRefUnit()) {
  70. return $this->getBuyingPriceByRefUnit();
  71. } else {
  72. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  73. }
  74. }
  75. public function getPriceInherited()
  76. {
  77. if ($this->getPrice()) {
  78. return $this->getPrice();
  79. } else {
  80. return $this->getProductFamily()->getPrice();
  81. }
  82. }
  83. public function getPriceByRefUnitInherited()
  84. {
  85. if ($this->getPriceByRefUnit()) {
  86. return $this->getPriceByRefUnit();
  87. } else {
  88. return $this->getProductFamily()->getPriceByRefUnit();
  89. }
  90. }
  91. public function getBehaviorPriceInherited()
  92. {
  93. return $this->getProductFamily()->getBehaviorPrice();
  94. }
  95. public function getReductionCatalogInherited()
  96. {
  97. return $this->getProductFamily()->getReductionCatalog();
  98. }
  99. public function getUnitInherited()
  100. {
  101. if ($this->getUnit()) {
  102. return $this->getUnit();
  103. } else {
  104. return $this->getProductFamily()->getUnit();
  105. }
  106. }
  107. public function getTitleInherited()
  108. {
  109. if ($this->getTitle()) {
  110. return $this->getTitle();
  111. } else {
  112. return $this->getProductFamily()->getTitle();
  113. }
  114. }
  115. public function getQuantityInherited()
  116. {
  117. if ($this->getQuantity()) {
  118. return $this->getQuantity();
  119. } else {
  120. return $this->getProductFamily()->getQuantity();
  121. }
  122. }
  123. public function getQuantityLabelInherited()
  124. {
  125. $quantity = $this->getQuantityInherited();
  126. $unit = $this->getUnitInherited();
  127. return $quantity . $unit->getWordingShort();
  128. }
  129. public function getQuantityTitle($productFamily)
  130. {
  131. $title = $this->getQuantityLabelInherited();
  132. if ($productFamily->hasProductsWithVariousWeight()) {
  133. $title .= ', ' . $this->getTitleInherited();
  134. }
  135. return $title;
  136. }
  137. public function getAvailableQuantityInherited()
  138. {
  139. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  140. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  141. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  142. return $this->getProductFamily()->getAvailableQuantity();
  143. break;
  144. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  145. return $this->getAvailableQuantity();
  146. break;
  147. case ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  148. return false;
  149. break;
  150. }
  151. }
  152. public function getTaxRateInherited()
  153. {
  154. return $this->getProductFamily()->getTaxRateInherited();
  155. }
  156. public function getProductFamily(): ?ProductFamily
  157. {
  158. return $this->productFamily;
  159. }
  160. public function setProductFamily(?ProductFamily $productFamily): self
  161. {
  162. $this->productFamily = $productFamily;
  163. return $this;
  164. }
  165. public function getTitle(): ?string
  166. {
  167. return $this->title;
  168. }
  169. public function setTitle(?string $title): self
  170. {
  171. $this->title = $title;
  172. return $this;
  173. }
  174. public function getOriginProduct(): ?bool
  175. {
  176. return $this->originProduct;
  177. }
  178. public function setOriginProduct(?bool $originProduct): self
  179. {
  180. $this->originProduct = $originProduct;
  181. return $this;
  182. }
  183. }