Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

318 lines
8.2KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Product;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait;
  6. use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  10. use Lc\SovBundle\Doctrine\Extension\BlameableNullableTrait;
  11. use Lc\SovBundle\Doctrine\Extension\SortableInterface;
  12. use Lc\SovBundle\Doctrine\Extension\SortableTrait;
  13. use Lc\SovBundle\Doctrine\Extension\StatusTrait;
  14. use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
  15. /**
  16. * @ORM\MappedSuperclass()
  17. */
  18. abstract class ProductModel extends AbstractLightEntity implements SortableInterface, ProductPropertyInterface,
  19. PriceInterface, ProductInterface
  20. {
  21. use SortableTrait;
  22. use ProductPropertyTrait;
  23. use StatusTrait;
  24. /**
  25. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface", inversedBy="products", cascade={"persist"})
  26. * @ORM\JoinColumn(nullable=false)
  27. */
  28. protected $productFamily;
  29. /**
  30. * @ORM\Column(type="string", length=255, nullable=true)
  31. */
  32. protected $title;
  33. /**
  34. * @ORM\Column(type="boolean", nullable=true)
  35. */
  36. protected $originProduct;
  37. /**
  38. * @ORM\Column(type="string", length=255, nullable=true)
  39. */
  40. protected $exportTitle;
  41. /**
  42. * @ORM\Column(type="text", nullable=true)
  43. */
  44. protected $exportNote;
  45. public function __construct()
  46. {
  47. $this->orderProducts = new ArrayCollection();
  48. $this->status = 1;
  49. }
  50. public function __toString()
  51. {
  52. $title = $this->getProductFamily()->getTitle();
  53. if ($this->getTitle() && strlen($this->getTitle())) {
  54. $title .= ' - ' . $this->getTitle();
  55. }
  56. if ($this->getProductFamily()->hasProductsWithVariousWeight()) {
  57. $title .= ' - ' . $this->getQuantityLabelInherited();
  58. }
  59. return $title;
  60. }
  61. // @TODO : move
  62. // getProductQuantityMaxAddCart
  63. public function getQuantityMaxAddCart(OrderShopInterface $orderShop)
  64. {
  65. $productFamily = $this->getProductFamily();
  66. $byWeight = false;
  67. if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  68. $byWeight = true;
  69. }
  70. return $this->getAvailableQuantityInherited() - $orderShop->getQuantityOrderByProduct($this, $byWeight);
  71. }
  72. // @TODO : move
  73. // getProductQuantity
  74. public function getProductQuantity()
  75. {
  76. $productFamily = $this->getProductFamily();
  77. if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  78. return $this->getQuantityInherited() / $this->getUnitInherited()->getCoefficient();
  79. } else {
  80. return 1;
  81. }
  82. }
  83. // @TODO : move
  84. public function getBuyingPriceInherited()
  85. {
  86. if ($this->getBuyingPrice()) {
  87. return $this->getBuyingPrice();
  88. } else {
  89. return $this->getProductFamily()->getBuyingPrice();
  90. }
  91. }
  92. // @TODO : move
  93. public function getBuyingPriceByRefUnitInherited()
  94. {
  95. if ($this->getBuyingPriceByRefUnit()) {
  96. return $this->getBuyingPriceByRefUnit();
  97. } else {
  98. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  99. }
  100. }
  101. // @TODO : move
  102. public function getPriceInherited()
  103. {
  104. if ($this->getPrice()) {
  105. return $this->getPrice();
  106. } else {
  107. return $this->getProductFamily()->getPrice();
  108. }
  109. }
  110. // @TODO : move
  111. public function getPriceByRefUnitInherited()
  112. {
  113. if ($this->getPriceByRefUnit()) {
  114. return $this->getPriceByRefUnit();
  115. } else {
  116. return $this->getProductFamily()->getPriceByRefUnit();
  117. }
  118. }
  119. // @TODO : move
  120. public function getBehaviorPriceInherited()
  121. {
  122. return $this->getProductFamily()->getBehaviorPrice();
  123. }
  124. // @TODO : move
  125. public function getReductionCatalogInherited()
  126. {
  127. return $this->getProductFamily()->getReductionCatalog();
  128. }
  129. // @TODO : move
  130. public function getUnitInherited()
  131. {
  132. if ($this->getUnit()) {
  133. return $this->getUnit();
  134. } else {
  135. return $this->getProductFamily()->getUnit();
  136. }
  137. }
  138. // @TODO : move
  139. public function getTitleInherited()
  140. {
  141. if ($this->getTitle()) {
  142. return $this->getTitle();
  143. } else {
  144. return $this->getProductFamily()->getTitle();
  145. }
  146. }
  147. // @TODO : move
  148. public function getQuantityInherited()
  149. {
  150. if ($this->getQuantity()) {
  151. return $this->getQuantity();
  152. } else {
  153. return $this->getProductFamily()->getQuantity();
  154. }
  155. }
  156. // @TODO : move
  157. public function getQuantityLabelInherited()
  158. {
  159. $quantity = $this->getQuantityInherited();
  160. $unit = $this->getUnitInherited();
  161. return $quantity . $unit->getWordingShort();
  162. }
  163. // @TODO : move
  164. public function getQuantityTitle($productFamily)
  165. {
  166. $title = $this->getQuantityLabelInherited();
  167. if ($productFamily->hasProductsWithVariousWeight()) {
  168. $title .= ', ' . $this->getTitleInherited();
  169. }
  170. return $title;
  171. }
  172. // @TODO : move
  173. public function getAvailableQuantityInherited()
  174. {
  175. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  176. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  177. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  178. return $this->getProductFamily()->getAvailableQuantity();
  179. break;
  180. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  181. return $this->getAvailableQuantity();
  182. break;
  183. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  184. return false;
  185. break;
  186. }
  187. }
  188. // @TODO : move
  189. public function getTaxRateInherited()
  190. {
  191. return $this->getProductFamily()->getTaxRateInherited();
  192. }
  193. public function getProductFamily(): ?ProductFamilyInterface
  194. {
  195. return $this->productFamily;
  196. }
  197. public function setProductFamily(?ProductFamilyInterface $productFamily): self
  198. {
  199. $this->productFamily = $productFamily;
  200. return $this;
  201. }
  202. public function getTitle(): ?string
  203. {
  204. return $this->title;
  205. }
  206. public function setTitle(?string $title): self
  207. {
  208. $this->title = $title;
  209. return $this;
  210. }
  211. public function getOriginProduct(): ?bool
  212. {
  213. return $this->originProduct;
  214. }
  215. public function setOriginProduct(?bool $originProduct): self
  216. {
  217. $this->originProduct = $originProduct;
  218. return $this;
  219. }
  220. public function getExportTitle(): ?string
  221. {
  222. return $this->exportTitle;
  223. }
  224. //TODO move
  225. public function getExportTitleInherited(): ?string
  226. {
  227. $exportTitle = $this->getExportTitle();
  228. if ($exportTitle && strlen($exportTitle)) {
  229. return $exportTitle;
  230. } else {
  231. $productFamily = $this->getProductFamily();
  232. if ($productFamily) {
  233. return $productFamily->getExportTitle();
  234. }
  235. }
  236. return null;
  237. }
  238. public function setExportTitle(?string $exportTitle): self
  239. {
  240. $this->exportTitle = $exportTitle;
  241. return $this;
  242. }
  243. public function getExportNote(): ?string
  244. {
  245. return $this->exportNote;
  246. }
  247. //TODO move
  248. public function getExportNoteInherited(): ?string
  249. {
  250. $exportNote = $this->getExportNote();
  251. if ($exportNote && strlen($exportNote)) {
  252. return $exportNote;
  253. } else {
  254. $productFamily = $this->getProductFamily();
  255. if ($productFamily) {
  256. return $productFamily->getExportNote();
  257. }
  258. }
  259. return null;
  260. }
  261. public function setExportNote(?string $exportNote): self
  262. {
  263. $this->exportNote = $exportNote;
  264. return $this;
  265. }
  266. }