No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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