src/Entity/Product.php line 589

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\ProductDescription;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
  6. use App\Helpers\Encoder;
  7. /**
  8. * Products
  9. *
  10. * @ORM\Table(name="products")
  11. * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
  12. * @ORM\HasLifecycleCallbacks()
  13. */
  14. class Product extends TranslatedEntity
  15. {
  16. public const VAT_RATE = 0.2;
  17. public const SEARCH_INDICES = [
  18. 'fr' => 'fr-products',
  19. 'en' => 'en-products',
  20. ];
  21. public const TYPE_PRODUCT = 'product';
  22. public const TYPE_SAV = 'sav';
  23. protected $tranlatedEntity = 'ProductDescription';
  24. /**
  25. * @var int
  26. *
  27. * @ORM\Column(name="products_id", type="integer", nullable=false)
  28. * @ORM\Id
  29. * @ORM\GeneratedValue(strategy="IDENTITY")
  30. */
  31. private $id;
  32. /**
  33. * @ORM\OneToMany(targetEntity="App\Entity\ProductAttribute", mappedBy="product")
  34. */
  35. private $attributes;
  36. /**
  37. * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="parent")
  38. */
  39. private $children = [];
  40. /**
  41. * @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="children")
  42. * @ORM\JoinColumn(name="products_parent_id", referencedColumnName="products_id", nullable=true)
  43. */
  44. private $parent;
  45. /**
  46. * @ORM\OneToMany(targetEntity="App\Entity\ProductDescription", mappedBy="product")
  47. */
  48. private $descriptions = [];
  49. /**
  50. * @ORM\OneToMany(targetEntity="App\Entity\PictureProduct", mappedBy="product")
  51. * @ORM\OrderBy({"rank" = "ASC", "id" = "ASC"})
  52. */
  53. private $pictures = [];
  54. /**
  55. * @var App\Entity\Manufacturer|null
  56. *
  57. * @ORM\ManyToOne(targetEntity="App\Entity\Manufacturer")
  58. * @ORM\JoinColumn(name="manufacturers_id", referencedColumnName="manufacturers_id", nullable=true)
  59. */
  60. private $manufacturer;
  61. /**
  62. * @ORM\OneToMany(targetEntity="App\Entity\ProductCountryRestriction", mappedBy="product")
  63. */
  64. private $countryRestrictions;
  65. /**
  66. * @ORM\OneToMany(targetEntity="App\Entity\ProductToProductExtraField", mappedBy="product")
  67. */
  68. private $extraFields = [];
  69. /**
  70. * @ORM\OneToMany(targetEntity="App\Entity\ProductPrice", mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true)
  71. */
  72. private $prices = [];
  73. /**
  74. * @var int
  75. *
  76. * @ORM\Column(name="products_quantity", type="integer", nullable=false)
  77. */
  78. private $quantity = '0';
  79. /**
  80. * @var string|null
  81. *
  82. * @ORM\Column(name="products_model", type="string", length=256, nullable=true)
  83. */
  84. private $model;
  85. /**
  86. * @var string|null
  87. *
  88. * @ORM\Column(name="products_model_sap", type="string", length=50, nullable=true)
  89. */
  90. private $modelSAP;
  91. /**
  92. * @var string|null
  93. *
  94. * @ORM\Column(name="products_ean", type="string", length=50, nullable=true)
  95. */
  96. private $ean;
  97. /**
  98. * @var string|null
  99. *
  100. * @ORM\Column(name="products_image", type="string", length=140, nullable=true)
  101. */
  102. private $image;
  103. /**
  104. * @var string|null
  105. *
  106. * @ORM\Column(name="products_image_med", type="string", length=140, nullable=true)
  107. */
  108. private $imageMed;
  109. /**
  110. * @var string|null
  111. *
  112. * @ORM\Column(name="products_image_lrg", type="string", length=140, nullable=true)
  113. */
  114. private $imageLrg;
  115. /**
  116. * @var string|null
  117. *
  118. * @ORM\Column(name="products_image_sm_1", type="string", length=140, nullable=true)
  119. */
  120. private $imageSm1;
  121. /**
  122. * @var string|null
  123. *
  124. * @ORM\Column(name="products_image_xl_1", type="string", length=140, nullable=true)
  125. */
  126. private $imageXl1;
  127. /**
  128. * @var string|null
  129. *
  130. * @ORM\Column(name="products_image_sm_2", type="string", length=140, nullable=true)
  131. */
  132. private $imageSm2;
  133. /**
  134. * @var string|null
  135. *
  136. * @ORM\Column(name="products_image_xl_2", type="string", length=140, nullable=true)
  137. */
  138. private $imageXl2;
  139. /**
  140. * @var string|null
  141. *
  142. * @ORM\Column(name="products_image_sm_3", type="string", length=140, nullable=true)
  143. */
  144. private $imageSm3;
  145. /**
  146. * @var string|null
  147. *
  148. * @ORM\Column(name="products_image_xl_3", type="string", length=140, nullable=true)
  149. */
  150. private $imageXl3;
  151. /**
  152. * @var string|null
  153. *
  154. * @ORM\Column(name="products_image_sm_4", type="string", length=140, nullable=true)
  155. */
  156. private $imageSm4;
  157. /**
  158. * @var string|null
  159. *
  160. * @ORM\Column(name="products_image_xl_4", type="string", length=140, nullable=true)
  161. */
  162. private $imageXl4;
  163. /**
  164. * @var string|null
  165. *
  166. * @ORM\Column(name="products_image_sm_5", type="string", length=140, nullable=true)
  167. */
  168. private $imageSm5;
  169. /**
  170. * @var string|null
  171. *
  172. * @ORM\Column(name="products_image_xl_5", type="string", length=140, nullable=true)
  173. */
  174. private $imageXl5;
  175. /**
  176. * @var string|null
  177. *
  178. * @ORM\Column(name="products_image_sm_6", type="string", length=140, nullable=true)
  179. */
  180. private $imageSm6;
  181. /**
  182. * @var string|null
  183. *
  184. * @ORM\Column(name="products_image_xl_6", type="string", length=140, nullable=true)
  185. */
  186. private $imageXl6;
  187. /**
  188. * @var float
  189. *
  190. * @ORM\Column(name="products_price", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  191. */
  192. private $price = '0.0000';
  193. /**
  194. * @var float
  195. * @ORM\Column(name="products_ecotax", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  196. */
  197. private $ecotax = '0.0000';
  198. /**
  199. * @var \DateTime
  200. *
  201. * @ORM\Column(name="products_date_added", type="datetime", nullable=false)
  202. */
  203. private $dateAdded;
  204. /**
  205. * @var \DateTime|null
  206. *
  207. * @ORM\Column(name="products_last_modified", type="datetime", nullable=true)
  208. */
  209. private $lastModified;
  210. /**
  211. * @var \DateTime|null
  212. *
  213. * @ORM\Column(name="products_date_available", type="datetime", nullable=true)
  214. */
  215. private $dateAvailable;
  216. /**
  217. * @var string
  218. *
  219. * @ORM\Column(name="products_weight", type="decimal", precision=5, scale=2, nullable=false, options={"default"="0.00"})
  220. */
  221. private $weight = '0.00';
  222. /**
  223. * @var bool
  224. *
  225. * @ORM\Column(name="products_status", type="boolean", nullable=false)
  226. */
  227. private $status = '0';
  228. /** *
  229. * @ORM\ManyToOne(targetEntity="App\Entity\TaxClass", inversedBy="rates")
  230. * @ORM\JoinColumn(name="products_tax_class_id", referencedColumnName="tax_class_id")
  231. */
  232. private $taxClass;
  233. /**
  234. * @var int
  235. *
  236. * @ORM\Column(name="products_ordered", type="integer", nullable=false)
  237. */
  238. private $ordered = '0';
  239. /**
  240. * @var string
  241. *
  242. * @ORM\Column(name="products_price1", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  243. */
  244. private $price1 = '0.0000';
  245. /**
  246. * @var string
  247. *
  248. * @ORM\Column(name="products_price2", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  249. */
  250. private $price2 = '0.0000';
  251. /**
  252. * @var string
  253. *
  254. * @ORM\Column(name="products_price3", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  255. */
  256. private $price3 = '0.0000';
  257. /**
  258. * @var string
  259. *
  260. * @ORM\Column(name="products_price4", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  261. */
  262. private $price4 = '0.0000';
  263. /**
  264. * @var string
  265. *
  266. * @ORM\Column(name="products_price5", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  267. */
  268. private $price5 = '0.0000';
  269. /**
  270. * @var string
  271. *
  272. * @ORM\Column(name="products_price6", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  273. */
  274. private $price6 = '0.0000';
  275. /**
  276. * @var string
  277. *
  278. * @ORM\Column(name="products_price7", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  279. */
  280. private $price7 = '0.0000';
  281. /**
  282. * @var string
  283. *
  284. * @ORM\Column(name="products_price8", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  285. */
  286. private $price8 = '0.0000';
  287. /**
  288. * @var string
  289. *
  290. * @ORM\Column(name="products_price9", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  291. */
  292. private $price9 = '0.0000';
  293. /**
  294. * @var string
  295. *
  296. * @ORM\Column(name="products_price10", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  297. */
  298. private $price10 = '0.0000';
  299. /**
  300. * @var string
  301. *
  302. * @ORM\Column(name="products_price11", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  303. */
  304. private $price11 = '0.0000';
  305. /**
  306. * @var int
  307. *
  308. * @ORM\Column(name="products_price1_qty", type="integer", nullable=false)
  309. */
  310. private $price1Qty = '0';
  311. /**
  312. * @var int
  313. *
  314. * @ORM\Column(name="products_price2_qty", type="integer", nullable=false)
  315. */
  316. private $price2Qty = '0';
  317. /**
  318. * @var int
  319. *
  320. * @ORM\Column(name="products_price3_qty", type="integer", nullable=false)
  321. */
  322. private $price3Qty = '0';
  323. /**
  324. * @var int
  325. *
  326. * @ORM\Column(name="products_price4_qty", type="integer", nullable=false)
  327. */
  328. private $price4Qty = '0';
  329. /**
  330. * @var int
  331. *
  332. * @ORM\Column(name="products_price5_qty", type="integer", nullable=false)
  333. */
  334. private $price5Qty = '0';
  335. /**
  336. * @var int
  337. *
  338. * @ORM\Column(name="products_price6_qty", type="integer", nullable=false)
  339. */
  340. private $price6Qty = '0';
  341. /**
  342. * @var int
  343. *
  344. * @ORM\Column(name="products_price7_qty", type="integer", nullable=false)
  345. */
  346. private $price7Qty = '0';
  347. /**
  348. * @var int
  349. *
  350. * @ORM\Column(name="products_price8_qty", type="integer", nullable=false)
  351. */
  352. private $price8Qty = '0';
  353. /**
  354. * @var int
  355. *
  356. * @ORM\Column(name="products_price9_qty", type="integer", nullable=false)
  357. */
  358. private $price9Qty = '0';
  359. /**
  360. * @var int
  361. *
  362. * @ORM\Column(name="products_price10_qty", type="integer", nullable=false)
  363. */
  364. private $price10Qty = '0';
  365. /**
  366. * @var int
  367. *
  368. * @ORM\Column(name="products_price11_qty", type="integer", nullable=false)
  369. */
  370. private $price11Qty = '0';
  371. /**
  372. * @var int
  373. *
  374. * @ORM\Column(name="products_qty_blocks", type="integer", nullable=false, options={"default"="1"})
  375. */
  376. private $productsQtyBlocks = '1';
  377. /**
  378. * @var bool
  379. *
  380. * @ORM\Column(name="products_soleil", type="integer", nullable=false)
  381. */
  382. private $soleil = '0';
  383. /**
  384. * @var int
  385. *
  386. * @ORM\Column(name="products_limite_panier", type="integer", nullable=false)
  387. */
  388. private $limitePanier = '0';
  389. /**
  390. * @var int|null
  391. *
  392. * @ORM\Column(name="products_page", type="integer", nullable=true)
  393. */
  394. private $page;
  395. /**
  396. * @var bool
  397. *
  398. * @ORM\Column(name="products_garantie", type="integer", nullable=false)
  399. */
  400. private $guaranty = '0';
  401. /**
  402. * @var int
  403. *
  404. * @ORM\Column(name="products_cat", type="integer", nullable=true)
  405. */
  406. private $defaultCategoryId = 0;
  407. private $defaultCategory;
  408. /**
  409. * @var int
  410. *
  411. * @ORM\Column(name="products_index", type="integer", nullable=false, options={"default"="1"})
  412. */
  413. private $index = '1';
  414. /**
  415. * @var int
  416. *
  417. * @ORM\Column(name="products_mvente", type="integer", nullable=false, options={"default"="1"})
  418. */
  419. private $mvente = '1';
  420. /**
  421. * @var int
  422. *
  423. * @ORM\Column(name="products_strategique", type="integer", nullable=false)
  424. */
  425. private $strategique = '0';
  426. /**
  427. * @var int
  428. *
  429. * @ORM\Column(name="products_reappro_non", type="integer", nullable=false)
  430. */
  431. private $reapproNon = '0';
  432. /**
  433. * @var int|null
  434. *
  435. * @ORM\Column(name="products_multiple", type="integer", nullable=true)
  436. */
  437. private $multiple = 1;
  438. /**
  439. * @var string|null
  440. *
  441. * @ORM\Column(name="products_origin", type="string", length=3, nullable=true)
  442. */
  443. private $origin = 1;
  444. /**
  445. * @var bool
  446. *
  447. * @ORM\Column(name="products_gift", type="boolean", nullable=true)
  448. */
  449. private $gift = '0';
  450. /**
  451. * @var ?string
  452. *
  453. * @ORM\Column(name="products_type", type="string", length=20, nullable=true)
  454. */
  455. private $type;
  456. /**
  457. * @var int
  458. *
  459. * @ORM\Column(name="products_welcome", type="boolean", nullable=false, options={"default"="1"})
  460. */
  461. private $welcome = '1';
  462. public function __construct()
  463. {
  464. $this->children = new \Doctrine\Common\Collections\ArrayCollection();
  465. $this->prices = new \Doctrine\Common\Collections\ArrayCollection();
  466. $this->descriptions = new \Doctrine\Common\Collections\ArrayCollection();
  467. }
  468. public function getId() {
  469. return $this->id;
  470. }
  471. public function getChildren() {
  472. return $this->children;
  473. }
  474. public function getParent() {
  475. if(!empty($this->parent) && !empty($this->languageId)){
  476. $this->parent->setLanguageId($this->languageId);
  477. }
  478. return $this->parent;
  479. }
  480. public function getDescriptions() {
  481. return $this->descriptions;
  482. }
  483. public function getAttributes() {
  484. return $this->attributes;
  485. }
  486. public function getQuantity() {
  487. return $this->quantity;
  488. }
  489. public function getModel() {
  490. return $this->model;
  491. }
  492. public function getModelSAP(): ?string {
  493. return $this->modelSAP;
  494. }
  495. public function getEan(): ?string {
  496. return $this->ean;
  497. }
  498. public function getName() {
  499. if(!empty($this->languageId)){
  500. $description = null;
  501. foreach($this->descriptions as $d){
  502. if($d->getLanguage()->getId()==$this->languageId){
  503. $description = $d;
  504. break;
  505. }
  506. }
  507. }
  508. if(empty($description) && count($this->descriptions)){
  509. $description = $this->descriptions[0];
  510. }
  511. return empty($description)?'':$description->getName();
  512. }
  513. public function getHeadingTitle() {
  514. if(!empty($this->languageId)){
  515. $description = null;
  516. foreach($this->descriptions as $d){
  517. if($d->getLanguage()->getId()==$this->languageId){
  518. $description = $d;
  519. break;
  520. }
  521. }
  522. }
  523. if(empty($description) && count($this->descriptions)){
  524. $description = $this->descriptions[0];
  525. }
  526. return empty($description)?'':$description->getHeadingTitle();
  527. }
  528. public function getDeclinaison() {
  529. $output = '';
  530. if($this->parent){
  531. $name = $this->getName();
  532. $output = substr($name, strlen($this->getParent()->getName())+2, strlen($name));
  533. }
  534. return $output;
  535. }
  536. public function getUrl() {
  537. if(!empty($this->languageId)){
  538. $description = null;
  539. foreach($this->descriptions as $d){
  540. if($d->getLanguage()->getId()==$this->languageId){
  541. $description = $d;
  542. break;
  543. }
  544. }
  545. }
  546. if(empty($description) && count($this->descriptions)){
  547. $description = $this->descriptions[0];
  548. }
  549. return empty($description)?'':$description->getUrl();
  550. }
  551. public function getDescription() {
  552. if(!empty($this->languageId)){
  553. $description = null;
  554. foreach($this->descriptions as $d){
  555. if($d->getLanguage()->getId()==$this->languageId){
  556. $description = $d;
  557. break;
  558. }
  559. }
  560. }
  561. if(empty($description) && count($this->descriptions)){
  562. $description = $this->descriptions[0];
  563. }
  564. return empty($description)?'':$description->getDescription();
  565. }
  566. public function getExtraFields() {
  567. return $this->extraFields;
  568. }
  569. public function getProductDescription($lang='fr') : ?ProductDescription {
  570. foreach($this->getDescriptions() as $desc){
  571. if($desc->getLanguage()->getCode() == $lang)
  572. return $desc;
  573. }
  574. return null;
  575. }
  576. public function getPicture() {
  577. return empty($this->pictures)?null:$this->pictures[0];
  578. }
  579. public function getPictures() {
  580. return $this->pictures;
  581. }
  582. public function getPicturesUrl() {
  583. $output = [];
  584. foreach($this->pictures as $picture){
  585. $output[] = $picture->getUrl();
  586. }
  587. return $output;
  588. }
  589. public function getImage($absolute=false) {
  590. if($absolute)
  591. return 'https://www.dogcat.com/professionnel/images/'.$this->image;
  592. return $this->image;
  593. }
  594. public function getImageMed($absolute=false) {
  595. if($absolute)
  596. return 'https://www.dogcat.com/professionnel/images/'.$this->imageMed;
  597. return $this->imageMed;
  598. }
  599. public function getImageLrg($absolute=false) {
  600. if($absolute)
  601. return 'https://www.dogcat.com/professionnel/images/'.$this->imageLrg;
  602. return $this->imageLrg;
  603. }
  604. public function getImageSm1() {
  605. return $this->imageSm1;
  606. }
  607. public function getImageXl1() {
  608. return $this->imageXl1;
  609. }
  610. public function getImageSm2() {
  611. return $this->imageSm2;
  612. }
  613. public function getImageXl2() {
  614. return $this->imageXl2;
  615. }
  616. public function getImageSm3() {
  617. return $this->imageSm3;
  618. }
  619. public function getImageXl3() {
  620. return $this->imageXl3;
  621. }
  622. public function getImageSm4() {
  623. return $this->imageSm4;
  624. }
  625. public function getImageXl4() {
  626. return $this->imageXl4;
  627. }
  628. public function getImageSm5() {
  629. return $this->imageSm5;
  630. }
  631. public function getImageXl5() {
  632. return $this->imageXl5;
  633. }
  634. public function getImageSm6() {
  635. return $this->imageSm6;
  636. }
  637. public function getImageXl6() {
  638. return $this->imageXl6;
  639. }
  640. public function getPrice($withEcotax = false, ?PriceGroup $priceGroup = null, $withVat = false) {
  641. $price = $this->price;
  642. $tax = 0;
  643. if($this->isGift()) {
  644. return 0;
  645. }
  646. if($priceGroup) {
  647. $price = $this->getPriceByGroup($priceGroup);
  648. }
  649. if($withVat) {
  650. $tax = Encoder::roundPrice($price*self::VAT_RATE);
  651. }
  652. if($withEcotax === true){
  653. return Encoder::roundPrice($price) + Encoder::roundPrice($this->getEcotax()) + $tax;
  654. }
  655. return Encoder::roundPrice($price) + $tax;
  656. }
  657. public function getPrices() {
  658. return $this->prices;
  659. }
  660. public function getPriceByGroup(PriceGroup $priceGroup) {
  661. foreach($this->prices as $price) {
  662. if($price->getGroup() == $priceGroup)
  663. return $price->getPrice();
  664. }
  665. // throw new \App\Exception\PriceGroupException();
  666. }
  667. public function hasPrice(PriceGroup $priceGroup) {
  668. if($this->hasChildren()) {
  669. foreach($this->getChildren() as $child) {
  670. if($child->hasPrice($priceGroup))
  671. return true;
  672. }
  673. }else{
  674. foreach($this->prices as $price) {
  675. if($price->getGroup() == $priceGroup)
  676. return true;
  677. }
  678. }
  679. return false;
  680. }
  681. public function getEcotax() {
  682. return $this->ecotax;
  683. }
  684. public function getFromProduct(?PriceGroup $priceGroup = null) {
  685. $tmp = null;
  686. $from = null;
  687. foreach($this->children as $product){
  688. if(!$product->isStopped() && $product->isActive()){
  689. if(!empty($priceGroup) && !$product->hasPrice($priceGroup)) {
  690. continue;
  691. }
  692. if(is_null($tmp) || ($tmp>$product->getPrice(false, $priceGroup, false))){
  693. $tmp = $product->getPrice(false, $priceGroup, false);
  694. $from = $product;
  695. }
  696. }
  697. }
  698. return $from;
  699. }
  700. public function getFromPrice($withEcotax = true, ?PriceGroup $priceGroup = null, $withVat = false) {
  701. $tmp = null;
  702. foreach($this->children as $product){
  703. if(!$product->isStopped() && $product->isActive()){
  704. if(!empty($priceGroup) && !$product->hasPrice($priceGroup)) {
  705. continue;
  706. }
  707. if(is_null($tmp) || ($tmp>$product->getPrice($withEcotax, $priceGroup, $withVat))){
  708. $tmp = $product->getPrice($withEcotax, $priceGroup, $withVat);
  709. }
  710. }
  711. }
  712. return is_null($tmp)?0:$tmp;
  713. }
  714. public function getSoleilPrice($withEcotax = true) {
  715. if($this->isNonSoleil()){
  716. return Encoder::roundPrice($this->price * 0.9)+($withEcotax?$this->getEcotax():0);
  717. }else if($this->isSoleil()){
  718. return Encoder::roundPrice($this->price * 0.75)+($withEcotax?$this->getEcotax():0);
  719. }
  720. return Encoder::roundPrice($this->price)+($withEcotax?$this->getEcotax():0);
  721. }
  722. public function getDateAdded() {
  723. return $this->dateAdded;
  724. }
  725. public function getLastModified() {
  726. return $this->lastModified;
  727. }
  728. public function getDateAvailable() {
  729. return $this->dateAvailable;
  730. }
  731. public function getWeight() {
  732. return $this->weight;
  733. }
  734. public function getStatus() {
  735. return $this->status;
  736. }
  737. public function getTaxClass() {
  738. return $this->taxClass;
  739. }
  740. public function getManufacturer() {
  741. return $this->manufacturer;
  742. }
  743. public function getOrdered() {
  744. return $this->ordered;
  745. }
  746. public function getPrice1() {
  747. return $this->price1;
  748. }
  749. public function getPrice2() {
  750. return $this->price2;
  751. }
  752. public function getPrice3() {
  753. return $this->price3;
  754. }
  755. public function getPrice4() {
  756. return $this->price4;
  757. }
  758. public function getPrice5() {
  759. return $this->price5;
  760. }
  761. public function getPrice6() {
  762. return $this->price6;
  763. }
  764. public function getPrice7() {
  765. return $this->price7;
  766. }
  767. public function getPrice8() {
  768. return $this->price8;
  769. }
  770. public function getPrice9() {
  771. return $this->price9;
  772. }
  773. public function getPrice10() {
  774. return $this->price10;
  775. }
  776. public function getPrice11() {
  777. return $this->price11;
  778. }
  779. public function getPrice1Qty() {
  780. return $this->price1Qty;
  781. }
  782. public function getPrice2Qty() {
  783. return $this->price2Qty;
  784. }
  785. public function getPrice3Qty() {
  786. return $this->price3Qty;
  787. }
  788. public function getPrice4Qty() {
  789. return $this->price4Qty;
  790. }
  791. public function getPrice5Qty() {
  792. return $this->price5Qty;
  793. }
  794. public function getPrice6Qty() {
  795. return $this->price6Qty;
  796. }
  797. public function getPrice7Qty() {
  798. return $this->price7Qty;
  799. }
  800. public function getPrice8Qty() {
  801. return $this->price8Qty;
  802. }
  803. public function getPrice9Qty() {
  804. return $this->price9Qty;
  805. }
  806. public function getPrice10Qty() {
  807. return $this->price10Qty;
  808. }
  809. public function getPrice11Qty() {
  810. return $this->price11Qty;
  811. }
  812. public function getProductsQtyBlocks() {
  813. return $this->productsQtyBlocks;
  814. }
  815. public function getSoleil() {
  816. return $this->soleil;
  817. }
  818. public function getLimitePanier() {
  819. return $this->limitePanier;
  820. }
  821. public function getPage() {
  822. return $this->page;
  823. }
  824. public function getGuaranty() {
  825. return $this->guaranty;
  826. }
  827. public function getDefaultCategoryId() {
  828. return $this->defaultCategoryId;
  829. }
  830. public function getDefaultCategory() {
  831. return $this->defaultCategory;
  832. }
  833. public function getIndex() {
  834. if(empty($this->index))
  835. return 0;
  836. return $this->index > 0 ? 1 : 0;
  837. }
  838. public function getMvente() {
  839. return $this->mvente;
  840. }
  841. public function getStrategique() {
  842. return $this->strategique;
  843. }
  844. public function getReapproNon() {
  845. return $this->reapproNon;
  846. }
  847. public function getMultiple() {
  848. return empty($this->multiple)?1:$this->multiple;
  849. }
  850. public function getOrigin() {
  851. return $this->origin;
  852. }
  853. public function getReference() {
  854. return $this->getModel();
  855. }
  856. public function getGift() {
  857. return is_null($this->gift) ? 0 : $this->gift;
  858. }
  859. public function getType(): ?string {
  860. return empty($this->type) ? self::TYPE_PRODUCT : $this->type;
  861. }
  862. public function getCountryRestrictions() {
  863. return $this->countryRestrictions;
  864. }
  865. public function getRestrictedCountries() {
  866. $output = [];
  867. foreach($this->getCountryRestrictions() as $rc) {
  868. $output[] = $rc->getCountry();
  869. }
  870. return $output;
  871. }
  872. public function getWelcome(): int {
  873. return $this->welcome;
  874. }
  875. // public function getUrl($absolute=false) {
  876. // if(!empty($this->parent))
  877. // return $this->getParent()->getUrl($absolute);
  878. // if(!empty($this->languageId)){
  879. // $language = $this->languageId==4?'fr':'en';
  880. // }
  881. // if(empty($language)){
  882. // $language = 'fr';
  883. // }
  884. //// $url = '/professionnel/product_info.php?products_id='.$this->getId().'&language='.$language;
  885. //// if($absolute)
  886. //// return 'https://www.dogcat.com'.$url;
  887. // return $this->getUrl();
  888. // }
  889. public function setId($id) {
  890. $this->id = $id;
  891. }
  892. public function setAttributes($attributes) {
  893. $this->attributes = $attributes;
  894. }
  895. public function setChildren($children) {
  896. $this->children = $children;
  897. }
  898. public function setParent($parent) {
  899. $this->parent = $parent;
  900. }
  901. public function setDescriptions($descriptions) {
  902. $this->descriptions = $descriptions;
  903. }
  904. public function setExtraFields($extraFields): void {
  905. $this->extraFields = $extraFields;
  906. }
  907. public function setQuantity($quantity) {
  908. $this->quantity = $quantity;
  909. }
  910. public function setModel($model) {
  911. $this->model = $model;
  912. }
  913. public function setModelSAP(?string $modelSAP): void {
  914. $this->modelSAP = $modelSAP;
  915. }
  916. public function setEan(?string $ean): void {
  917. $this->ean = $ean;
  918. }
  919. public function setImage($image) {
  920. $this->image = $image;
  921. }
  922. public function setImageMed($imageMed) {
  923. $this->imageMed = $imageMed;
  924. }
  925. public function setImageLrg($imageLrg) {
  926. $this->imageLrg = $imageLrg;
  927. }
  928. public function setImageSm1($imageSm1) {
  929. $this->imageSm1 = $imageSm1;
  930. }
  931. public function setImageXl1($imageXl1) {
  932. $this->imageXl1 = $imageXl1;
  933. }
  934. public function setImageSm2($imageSm2) {
  935. $this->imageSm2 = $imageSm2;
  936. }
  937. public function setImageXl2($imageXl2) {
  938. $this->imageXl2 = $imageXl2;
  939. }
  940. public function setImageSm3($imageSm3) {
  941. $this->imageSm3 = $imageSm3;
  942. }
  943. public function setImageXl3($imageXl3) {
  944. $this->imageXl3 = $imageXl3;
  945. }
  946. public function setImageSm4($imageSm4) {
  947. $this->imageSm4 = $imageSm4;
  948. }
  949. public function setImageXl4($imageXl4) {
  950. $this->imageXl4 = $imageXl4;
  951. }
  952. public function setImageSm5($imageSm5) {
  953. $this->imageSm5 = $imageSm5;
  954. }
  955. public function setImageXl5($imageXl5) {
  956. $this->imageXl5 = $imageXl5;
  957. }
  958. public function setImageSm6($imageSm6) {
  959. $this->imageSm6 = $imageSm6;
  960. }
  961. public function setImageXl6($imageXl6) {
  962. $this->imageXl6 = $imageXl6;
  963. }
  964. public function setPrice($price) {
  965. $this->price = $price;
  966. }
  967. public function setEcotax( $ecotax) {
  968. $this->ecotax = $ecotax;
  969. }
  970. public function setDateAdded(\DateTime $dateAdded) {
  971. $this->dateAdded = $dateAdded;
  972. }
  973. public function setLastModified(\DateTime $lastModified) {
  974. $this->lastModified = $lastModified;
  975. }
  976. public function setDateAvailable(\DateTime $dateAvailable) {
  977. $this->dateAvailable = $dateAvailable;
  978. }
  979. public function setWeight($weight) {
  980. $this->weight = $weight;
  981. }
  982. public function setStatus($status) {
  983. $this->status = $status;
  984. }
  985. public function setTaxClass($taxClass) {
  986. $this->taxClass = $taxClass;
  987. }
  988. public function setManufacturer($manufacturer) {
  989. $this->manufacturer = $manufacturer;
  990. }
  991. public function setOrdered($ordered) {
  992. $this->ordered = $ordered;
  993. }
  994. public function setParentId($parentId) {
  995. $this->parentId = $parentId;
  996. }
  997. public function setPrice1($price1) {
  998. $this->price1 = $price1;
  999. }
  1000. public function setPrice2($price2) {
  1001. $this->price2 = $price2;
  1002. }
  1003. public function setPrice3($price3) {
  1004. $this->price3 = $price3;
  1005. }
  1006. public function setPrice4($price4) {
  1007. $this->price4 = $price4;
  1008. }
  1009. public function setPrice5($price5) {
  1010. $this->price5 = $price5;
  1011. }
  1012. public function setPrice6($price6) {
  1013. $this->price6 = $price6;
  1014. }
  1015. public function setPrice7($price7) {
  1016. $this->price7 = $price7;
  1017. }
  1018. public function setPrice8($price8) {
  1019. $this->price8 = $price8;
  1020. }
  1021. public function setPrice9($price9) {
  1022. $this->price9 = $price9;
  1023. }
  1024. public function setPrice10($price10) {
  1025. $this->price10 = $price10;
  1026. }
  1027. public function setPrice11($price11) {
  1028. $this->price11 = $price11;
  1029. }
  1030. public function setPrice1Qty($price1Qty) {
  1031. $this->price1Qty = $price1Qty;
  1032. }
  1033. public function setPrice2Qty($price2Qty) {
  1034. $this->price2Qty = $price2Qty;
  1035. }
  1036. public function setPrice3Qty($price3Qty) {
  1037. $this->price3Qty = $price3Qty;
  1038. }
  1039. public function setPrice4Qty($price4Qty) {
  1040. $this->price4Qty = $price4Qty;
  1041. }
  1042. public function setPrice5Qty($price5Qty) {
  1043. $this->price5Qty = $price5Qty;
  1044. }
  1045. public function setPrice6Qty($price6Qty) {
  1046. $this->price6Qty = $price6Qty;
  1047. }
  1048. public function setPrice7Qty($price7Qty) {
  1049. $this->price7Qty = $price7Qty;
  1050. }
  1051. public function setPrice8Qty($price8Qty) {
  1052. $this->price8Qty = $price8Qty;
  1053. }
  1054. public function setPrice9Qty($price9Qty) {
  1055. $this->price9Qty = $price9Qty;
  1056. }
  1057. public function setPrice10Qty($price10Qty) {
  1058. $this->price10Qty = $price10Qty;
  1059. }
  1060. public function setPrice11Qty($price11Qty) {
  1061. $this->price11Qty = $price11Qty;
  1062. }
  1063. public function setProductsQtyBlocks($productsQtyBlocks) {
  1064. $this->productsQtyBlocks = $productsQtyBlocks;
  1065. }
  1066. public function setSoleil($soleil) {
  1067. $this->soleil = $soleil;
  1068. }
  1069. public function setLimitePanier($limitePanier) {
  1070. $this->limitePanier = $limitePanier;
  1071. }
  1072. public function setPage($page) {
  1073. $this->page = $page;
  1074. }
  1075. public function setGuaranty($guaranty) {
  1076. $this->guaranty = $guaranty;
  1077. }
  1078. public function setDefaultCategoryId($defaultCategoryId) {
  1079. $this->defaultCategoryId = $defaultCategoryId;
  1080. }
  1081. public function setIndex($index) {
  1082. $this->index = $index;
  1083. }
  1084. public function setMvente($mvente) {
  1085. $this->mvente = $mvente;
  1086. }
  1087. public function setStrategique($strategique) {
  1088. $this->strategique = $strategique;
  1089. }
  1090. public function setReapproNon($reapproNon) {
  1091. $this->reapproNon = $reapproNon;
  1092. }
  1093. public function setMultiple($multiple) {
  1094. return $this->multiple = $multiple;
  1095. }
  1096. public function setOrigin($origin) {
  1097. $this->origin = $origin;
  1098. }
  1099. public function setPrices($prices) {
  1100. $this->prices = $prices;
  1101. }
  1102. public function setGift($gift) {
  1103. $this->gift = $gift;
  1104. }
  1105. public function setType(?string $type): void {
  1106. $this->type = $type;
  1107. }
  1108. public function setCountryRestrictions($countryRestrictions): void {
  1109. $this->countryRestrictions = $countryRestrictions;
  1110. }
  1111. public function setWelcome(int $welcome): void {
  1112. $this->welcome = $welcome;
  1113. }
  1114. public function hasWelcomeDiscount() {
  1115. return !empty($this->welcome);
  1116. }
  1117. public function isMadeInFrance() {
  1118. if(!empty($this->origin))
  1119. return strtoupper($this->origin) == 'FR';
  1120. if($this->hasChildren()){
  1121. foreach($this->children as $child){
  1122. if(!$child->isMadeInFrance()){
  1123. return false;
  1124. }
  1125. }
  1126. return true;
  1127. }
  1128. return false;
  1129. }
  1130. public function isAvailable() {
  1131. return $this->quantity > 0;
  1132. }
  1133. public function hasRestrictionForCountry($country) {
  1134. if($country){
  1135. if($this->countryRestrictions){
  1136. foreach($this->getCountryRestrictions() as $restriction){
  1137. if($restriction->getCountry() == $country){
  1138. return true;
  1139. }
  1140. }
  1141. }
  1142. }
  1143. return false;
  1144. }
  1145. public function isAvailableForCountry($country) {
  1146. if($country && $this->countryRestrictions){
  1147. foreach($this->getCountryRestrictions() as $restriction) {
  1148. if($restriction->getCountry() == $country){
  1149. return false;
  1150. }
  1151. }
  1152. }
  1153. if($country && $this->getManufacturer()){
  1154. return $this->getManufacturer()->isAvailableForCountry($country);
  1155. }
  1156. return true;
  1157. }
  1158. public function isStopped() {
  1159. return $this->quantity == -800;
  1160. }
  1161. public function isActive() {
  1162. return $this->getStatus() == 1;
  1163. }
  1164. public function isGift() {
  1165. return $this->getGift() == 1;
  1166. }
  1167. public function isSoleil() {
  1168. return $this->soleil == 1;
  1169. }
  1170. public function isNonSoleil() {
  1171. return $this->soleil == 0;
  1172. }
  1173. public function isVivog() {
  1174. return $this->isSoleil() || $this->isNonSoleil();
  1175. }
  1176. public function isParent() {
  1177. return empty($this->parent);
  1178. }
  1179. public function isProduct() {
  1180. return $this->getType() == self::TYPE_PRODUCT;
  1181. }
  1182. public function hasChildren() {
  1183. return count($this->children)>0;
  1184. }
  1185. public function hasSoleilPrice() {
  1186. return $this->isSoleil() || $this->isNonSoleil();
  1187. }
  1188. public function hasParent() {
  1189. return !empty($this->parent);
  1190. }
  1191. public function hasSoleil() {
  1192. if($this->hasChildren()){
  1193. foreach($this->children as $child){
  1194. if($child->isSoleil()){
  1195. return true;
  1196. }
  1197. }
  1198. return false;
  1199. }
  1200. return $this->isSoleil();
  1201. }
  1202. public function hasNonSoleil() {
  1203. if($this->hasChildren()){
  1204. foreach($this->children as $child){
  1205. if($child->isNonSoleil()){
  1206. return true;
  1207. }
  1208. }
  1209. return false;
  1210. }
  1211. return $this->isNonSoleil();
  1212. }
  1213. public function addPrice(ProductPrice $productPrice): self
  1214. {
  1215. if (!$this->prices->contains($productPrice)) {
  1216. $this->prices->add($productPrice);
  1217. $productPrice->setProduct($this);
  1218. }
  1219. return $this;
  1220. }
  1221. public function removePrice(ProductPrice $productPrice): self
  1222. {
  1223. if ($this->prices->removeElement($productPrice)) {
  1224. if ($productPrice->getProduct() === $this) {
  1225. $productPrice->setProduct(null);
  1226. }
  1227. }
  1228. return $this;
  1229. }
  1230. public function toArray() : array{
  1231. $parent = $this->getParent();
  1232. $manufacturer = $this->getManufacturer();
  1233. $output = [
  1234. 'id' => $this->getId(),
  1235. 'model' => $this->getModel(),
  1236. 'name' => $this->getName(),
  1237. 'description' => $this->getDescription(),
  1238. 'quantity' => $this->getQuantity(),
  1239. 'image' => $this->getImage(),
  1240. 'price' => $this->getPrice(),
  1241. 'dateAdded' => $this->getDateAdded(),
  1242. 'lastModified' => $this->getLastModified(),
  1243. 'dateAvailable' => $this->getDateAvailable(),
  1244. 'weight' => $this->getWeight(),
  1245. 'status' => $this->getStatus()?1:0,
  1246. 'taxClass ' => $this->getTaxClass()?$this->getTaxClass()->toArray():0,
  1247. 'ordered' => $this->getOrdered(),
  1248. 'parent' => empty($parent)?null:$parent->toArray(),
  1249. 'manufacturer' => empty($manufacturer)?null:$manufacturer->toArray(),
  1250. 'productsQtyBlocks' => $this->getProductsQtyBlocks(),
  1251. 'soleil' => $this->getSoleil(),
  1252. 'nbChildren' => count($this->getChildren()),
  1253. 'limitePanier' => $this->getLimitePanier(),
  1254. 'page' => $this->getPage(),
  1255. 'garantie' => $this->getGuaranty(),
  1256. 'defaultCategoryId' => $this->getDefaultCategoryId(),
  1257. 'index' => $this->getIndex(),
  1258. 'mvente' => $this->getMvente(),
  1259. 'strategique' => $this->getStrategique(),
  1260. 'reapproNon' => $this->getReapproNon(),
  1261. 'multiple' => $this->getMultiple()
  1262. ];
  1263. return $output;
  1264. }
  1265. /**
  1266. * @todo Remove once 0 values in the table are converted to NULL.
  1267. */
  1268. public function loadDescriptions(\Doctrine\ORM\EntityManager $em)
  1269. {
  1270. $conn = $em->getConnection();
  1271. $sql = $conn->prepare('select * from products_description where products_id = '.$this->getId());
  1272. $sql->execute();
  1273. $rows = $sql->fetchAll();
  1274. $descriptions = [];
  1275. foreach($rows as $desc){
  1276. $description = new ProductDescription();
  1277. $description->setName($desc['products_name']);
  1278. $description->setDescription($desc['products_description']);
  1279. $description->setLanguage($em->getRepository('App:Language')->find($desc['language_id']==1?1:4));
  1280. $descriptions[] = $description;
  1281. }
  1282. $this->setDescriptions($descriptions);
  1283. }
  1284. /**
  1285. * @ORM\PostLoad
  1286. *
  1287. * @todo Remove once 0 values in the table are converted to NULL.
  1288. */
  1289. public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $args) {
  1290. if ($this->parent && $this->parent->getId() == 0) {
  1291. $this->parent = null;
  1292. }
  1293. if ($this->manufacturer && $this->manufacturer->getId() <= 0) {
  1294. $this->manufacturer = null;
  1295. }
  1296. if ($this->taxClass && $this->taxClass->getId() <= 0) {
  1297. $this->taxClass = null;
  1298. }
  1299. if ($this->defaultCategoryId) {
  1300. $this->defaultCategory = $args->getObjectManager()->getRepository(Category::class)->find($this->defaultCategoryId);
  1301. }
  1302. }
  1303. public static function getSearchIndex($lang = 'fr')
  1304. {
  1305. return self::SEARCH_INDICES[$lang];
  1306. }
  1307. }