src/Framework/ShopBundle/Entity/Product.php line 439

Open in your IDE?
  1. <?php
  2. /*
  3.  *
  4.  * (c) Loïc Haas <loic.haas@outlook.com>
  5.  * http://www.haas-info.com/
  6.  *
  7.  */
  8. namespace App\Framework\ShopBundle\Entity;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass="App\Framework\ShopBundle\Repository\ProductRepository")
  16.  * @ORM\Table(name="framework_shop_product")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  *
  19.  */
  20. class Product
  21. {
  22.     /**
  23.      * @var int
  24.      *
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private $id;
  30.     /**
  31.     * @ORM\ManyToOne(targetEntity="\App\Framework\ShopBundle\Entity\Category", fetch="EAGER")
  32.     * @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
  33.     **/
  34.     private $category;
  35.     /**
  36.      * @ORM\Column(type="integer", length=11, nullable=true)
  37.      */
  38.     protected $position;
  39.     /**
  40.      * @var string
  41.      *
  42.      * @ORM\Column(type="string")
  43.      */
  44.     private $slug;
  45.     /**
  46.      * @var string
  47.      *
  48.      * @ORM\Column(type="string")
  49.      */
  50.     private $type;
  51.     /**
  52.      * @var string
  53.      *
  54.      * @ORM\Column(type="string")
  55.      */
  56.     private $tags;
  57.     /**
  58.      * @var array
  59.      *
  60.      * @ORM\Column(type="json")
  61.      */
  62.     private $name = [];
  63.     /**
  64.      * @var array
  65.      *
  66.      * @ORM\Column(type="json")
  67.      */
  68.     private $usecase = [];
  69.     /**
  70.      * @var array
  71.      *
  72.      * @ORM\Column(type="json")
  73.      */
  74.     private $description = [];
  75.     /**
  76.      * @var array
  77.      *
  78.      * @ORM\Column(type="json")
  79.      */
  80.     private $additional = [];
  81.     /**
  82.      * @var array
  83.      *
  84.      * @ORM\Column(type="json")
  85.      */
  86.     private $attributes = [];
  87.     /**
  88.      * @ORM\Column(type="float", nullable=true)
  89.      */
  90.     protected $price;
  91.     /**
  92.      * @ORM\Column(type="float", nullable=true)
  93.      */
  94.     protected $amountShow;
  95.     /**
  96.      * @ORM\Column(type="boolean",nullable=true)
  97.      */
  98.     protected $published;
  99.     /**
  100.      * @ORM\Column(type="boolean",nullable=true)
  101.      */
  102.     protected $pinned;
  103.     /**
  104.      * @ORM\Column(type="boolean",nullable=true)
  105.      */
  106.     protected $slider;
  107.     
  108.     /**
  109.      * @ORM\Column(type="boolean",nullable=true)
  110.      */
  111.     protected $featured;
  112.     /**
  113.      * @ORM\Column(type="boolean", nullable=true)
  114.      */
  115.     protected $stock;
  116.     /**
  117.      * @ORM\Column(type="integer", length=11, nullable=true)
  118.      */
  119.     protected $stockTotal;
  120.     /**
  121.      * @ORM\Column(type="integer", length=11, nullable=true)
  122.      */
  123.     protected $stockLeft;
  124.     /**
  125.      * @ORM\Column(type="float", nullable=true)
  126.      */
  127.     protected $weight;
  128.     /**
  129.      * @ORM\Column(type="string", length=255, nullable=true)
  130.      */
  131.     protected $packaging;
  132.     /**
  133.      * @var \DateTime $created
  134.      *
  135.      * @ORM\Column(name="created_at", type="datetime", nullable=false)
  136.      */
  137.     protected $createdAt;
  138.     /**
  139.      * @var \DateTime $updated
  140.      *
  141.      * @ORM\Column(name="updated_at", type="datetime", nullable=false)
  142.      */
  143.     protected $updatedAt;
  144.     /**
  145.      * @var string
  146.      *
  147.      * @ORM\Column(name="dataform", type="json", nullable=true)
  148.      */
  149.     private $dataform;
  150.     /**
  151.      * @ORM\PrePersist
  152.      * @ORM\PreUpdate
  153.      */
  154.     public function updatedTimestamps(): void
  155.     {
  156.         $dateTimeNow = new \DateTime('now');
  157.         $this->setUpdatedAt($dateTimeNow);
  158.         if ($this->getCreatedAt() === null) {
  159.             $this->setCreatedAt($dateTimeNow);
  160.         }
  161.     }
  162.     public function getCreatedAt() :?\DateTime
  163.     {
  164.         return $this->createdAt;
  165.     }
  166.     
  167.     public function setCreatedAt(\DateTime $createdAt): self
  168.     {
  169.         $this->createdAt $createdAt;
  170.         return $this;
  171.     }
  172.     public function getUpdatedAt() :?\DateTime
  173.     {
  174.         return $this->updatedAt;
  175.     }
  176.     
  177.     public function setUpdatedAt(\DateTime $updatedAt): self
  178.     {
  179.         $this->updatedAt $updatedAt;
  180.         return $this;
  181.     }
  182.     public function getId(): ?int
  183.     {
  184.         return $this->id;
  185.     }
  186.     public function setId($id)
  187.     {
  188.         $this->id $id;
  189.         return $this;
  190.     }
  191.     public function getPosition(): ?int
  192.     {
  193.         return $this->position;
  194.     }
  195.     public function setPosition($position)
  196.     {
  197.         $this->position $position;
  198.         return $this;
  199.     }
  200.     /**
  201.      * Set category
  202.      *
  203.      * @param \AppBundle\Entity\Category $category
  204.      *
  205.      * @return Category
  206.      */
  207.     public function setCategory(\App\Framework\ShopBundle\Entity\Category $category null)
  208.     {
  209.         $this->category $category;
  210.         return $this;
  211.     }
  212.     /**
  213.      * Get category
  214.      *
  215.      * @return \App\Framework\ShopBundle\Entity\Category
  216.      */
  217.     public function getCategory()
  218.     {
  219.         return $this->category;
  220.     }
  221.     public function getSlug(): ?string
  222.     {
  223.         return $this->slug;
  224.     }
  225.     public function setSlug(string $slug): void
  226.     {
  227.         $this->slug $slug;
  228.     }
  229.     public function getType(): ?string
  230.     {
  231.         return $this->type;
  232.     }
  233.     public function setType(string $type): void
  234.     {
  235.         $this->type $type;
  236.     }
  237.     public function getTags(): ?string
  238.     {
  239.         return $this->tags;
  240.     }
  241.     public function setTags(string $tags): void
  242.     {
  243.         $this->tags $tags;
  244.     }
  245.     public function getName(): array
  246.     {
  247.         return $this->name;
  248.     }
  249.     public function getNameJson()
  250.     {
  251.         return json_encode($this->name);
  252.     }
  253.     public function getNameLocale($locale)
  254.     {
  255.         if( isset($this->name[$locale]) ){
  256.             return $this->name[$locale];
  257.         } else {
  258.             return '';
  259.         }
  260.     }
  261.     public function setName(array $name): void
  262.     {
  263.         $this->name $name;
  264.     }
  265.     public function getDescription(): array
  266.     {
  267.         return $this->description;
  268.     }
  269.     public function getDescriptionLocale($locale)
  270.     {
  271.         if( isset($this->description[$locale]) ){
  272.             return $this->description[$locale];
  273.         } else {
  274.             return '';
  275.         }
  276.     }
  277.     public function setDescription(array $description): void
  278.     {
  279.         $this->description $description;
  280.     }
  281.     public function getUsecase(): array
  282.     {
  283.         return $this->usecase;
  284.     }
  285.     public function getUsecaseLocale($locale)
  286.     {
  287.         if( isset($this->usecase[$locale]) ){
  288.             return $this->usecase[$locale];
  289.         } else {
  290.             return '';
  291.         }
  292.     }
  293.     public function setUsecase(array $usecase): void
  294.     {
  295.         $this->usecase $usecase;
  296.     }
  297.     public function getAdditional(): array
  298.     {
  299.         return $this->additional;
  300.     }
  301.     public function getAdditionalLocale($locale)
  302.     {
  303.         if( isset($this->additional[$locale]) ){
  304.             return $this->additional[$locale];
  305.         } else {
  306.             return '';
  307.         }
  308.     }
  309.     public function setAdditional(array $additional): void
  310.     {
  311.         $this->additional $additional;
  312.     }
  313.     public function getAttributes(): array
  314.     {
  315.         return $this->attributes;
  316.     }
  317.     public function setAttributes(array $attributes): void
  318.     {
  319.         $this->attributes $attributes;
  320.     }
  321.     /**
  322.      * Set price
  323.      *
  324.      * @param float $price
  325.      * @return Reward
  326.      */
  327.     public function setPrice($price)
  328.     {
  329.         $this->price $price;
  330.         return $this;
  331.     }
  332.     /**
  333.      * Get price
  334.      *
  335.      * @return float 
  336.      */
  337.     public function getPrice()
  338.     {
  339.         return $this->price;
  340.     }
  341.     /**
  342.      * Set amountShow
  343.      *
  344.      * @param float $amountShow
  345.      * @return Reward
  346.      */
  347.     public function setAmountShow($amountShow)
  348.     {
  349.         $this->amountShow $amountShow;
  350.         return $this;
  351.     }
  352.     /**
  353.      * Get amountShow
  354.      *
  355.      * @return float 
  356.      */
  357.     public function getAmountShow()
  358.     {
  359.         return $this->amountShow;
  360.     }
  361.     /**
  362.      * Get price
  363.      *
  364.      * @return float 
  365.      */
  366.     public function getPriceFr()
  367.     {   
  368.         setlocale(LC_MONETARY'fr_FR');
  369.         return money_format('%!i'$this->price);
  370.     }
  371.     /**
  372.      * Set published
  373.      *
  374.      * @param boolean $published
  375.      * @return AppPost
  376.      */
  377.     public function setPublished($published)
  378.     {
  379.         $this->published $published;
  380.         return $this;
  381.     }
  382.     /**
  383.      * Get published
  384.      *
  385.      * @return boolean 
  386.      */
  387.     public function getPublished()
  388.     {
  389.         return $this->published;
  390.     }
  391.     /**
  392.      * Set slider
  393.      *
  394.      * @param boolean $slider
  395.      * @return AppPost
  396.      */
  397.     public function setSlider($slider)
  398.     {
  399.         $this->slider $slider;
  400.         return $this;
  401.     }
  402.     /**
  403.      * Get slider
  404.      *
  405.      * @return boolean 
  406.      */
  407.     public function getSlider()
  408.     {
  409.         return $this->slider;
  410.     }
  411.     /**
  412.      * Set pinned
  413.      *
  414.      * @param boolean $pinned
  415.      * @return AppPost
  416.      */
  417.     public function setPinned($pinned)
  418.     {
  419.         $this->pinned $pinned;
  420.         return $this;
  421.     }
  422.     /**
  423.      * Get pinned
  424.      *
  425.      * @return boolean 
  426.      */
  427.     public function getPinned()
  428.     {
  429.         return $this->pinned;
  430.     }
  431.     /**
  432.      * Set featured
  433.      *
  434.      * @param boolean $featured
  435.      * @return AppPost
  436.      */
  437.     public function setFeatured($featured)
  438.     {
  439.         $this->featured $featured;
  440.         return $this;
  441.     }
  442.     /**
  443.      * Get featured
  444.      *
  445.      * @return boolean 
  446.      */
  447.     public function getFeatured()
  448.     {
  449.         return $this->featured;
  450.     }
  451.     /**
  452.      * Set weight
  453.      *
  454.      * @param float $weight
  455.      * @return Reward
  456.      */
  457.     public function setWeight($weight)
  458.     {
  459.         $this->weight $weight;
  460.         return $this;
  461.     }
  462.     /**
  463.      * Get weight
  464.      *
  465.      * @return float 
  466.      */
  467.     public function getWeight()
  468.     {
  469.         return $this->weight;
  470.     }
  471.     /**
  472.      * Set stock
  473.      *
  474.      * @param integer $stock
  475.      *
  476.      * @return Reward
  477.      */
  478.     public function setStock($stock)
  479.     {
  480.         $this->stock $stock;
  481.         return $this;
  482.     }
  483.     /**
  484.      * Get stock
  485.      *
  486.      * @return integer
  487.      */
  488.     public function getStock()
  489.     {
  490.         return $this->stock;
  491.     }
  492.     /**
  493.      * Set stockTotal
  494.      *
  495.      * @param integer $stockTotal
  496.      *
  497.      * @return Reward
  498.      */
  499.     public function setStockTotal($stockTotal)
  500.     {
  501.         $this->stockTotal $stockTotal;
  502.         return $this;
  503.     }
  504.     /**
  505.      * Get stockTotal
  506.      *
  507.      * @return integer
  508.      */
  509.     public function getStockTotal()
  510.     {
  511.         return $this->stockTotal;
  512.     }
  513.     /**
  514.      * Set stockLeft
  515.      *
  516.      * @param integer $stockLeft
  517.      *
  518.      * @return Reward
  519.      */
  520.     public function setStockLeft($stockLeft)
  521.     {
  522.         $this->stockLeft $stockLeft;
  523.         return $this;
  524.     }
  525.     /**
  526.      * Get stockLeft
  527.      *
  528.      * @return integer
  529.      */
  530.     public function getStockLeft()
  531.     {
  532.         return $this->stockLeft;
  533.     }
  534.     public function setPackaging($packaging)
  535.     {
  536.         $this->packaging $packaging;
  537.         return $this;
  538.     }
  539.     public function getPackaging()
  540.     {
  541.         return $this->packaging;
  542.     }
  543.     /**
  544.      * Set dataform
  545.      *
  546.      * @param string $dataform
  547.      *
  548.      * @return Exp
  549.      */
  550.     public function setDataform($dataform)
  551.     {
  552.         $this->dataform json_encode($dataform);
  553.         return $this;
  554.     }
  555.     /**
  556.      * Get dataform
  557.      *
  558.      * @return string
  559.      */
  560.     public function getDataform()
  561.     {
  562.         return json_decode($this->dataformtrue);
  563.     }
  564.     /**
  565.      * Get dataform
  566.      *
  567.      * @return string
  568.      */
  569.     public function getInfo($index)
  570.     {
  571.         $dataform json_decode($this->dataformtrue);
  572.         $str '';
  573.         if(substr($index05) == 'image'){
  574.             if(isset($dataform['images'][$index])){
  575.                 $str $dataform['images'][$index];
  576.             }
  577.         }
  578.         if(isset($dataform[$index])){
  579.             $str $dataform[$index];
  580.         }
  581.         $str str_replace('\n''<br>'$str);
  582.         return $str;
  583.     }
  584.     /**
  585.      * Get dataform
  586.      *
  587.      * @return string
  588.      */
  589.     public function getDataformJson()
  590.     {
  591.         $json $this->dataform;
  592.         // $json = str_replace('\n', '\\\n', $json);
  593.         $json addslashes($json);
  594.         // $json = str_replace('\'', '\\\'', $json);
  595.         // $json = str_replace('\'', '\\\'', $json);
  596.         return $json;
  597.     }
  598.     /**
  599.      * Get dataform
  600.      *
  601.      * @return string
  602.      */
  603.     public function getMainImage()
  604.     {
  605.         $dataform json_decode($this->dataformtrue);
  606.         $images '';
  607.         if(isset($dataform['images'])){
  608.             foreach ($dataform['images'] as $key => $value) {
  609.                 if( substr($value010) == 'image_main' ){
  610.                     $images $value;
  611.                 }
  612.             }
  613.         }
  614.         return $images;
  615.     }
  616.     /**
  617.      * Get dataform
  618.      *
  619.      * @return string
  620.      */
  621.     public function getAllImages()
  622.     {
  623.         $dataform json_decode($this->dataformtrue);
  624.         $images = [];
  625.         if(isset($dataform['images'])){
  626.             foreach ($dataform['images'] as $key => $value) {
  627.                 // if( substr($value, 0, 10) == 'image_add_' ){
  628.                     $images[] = $value;
  629.                 // }
  630.             }
  631.         }
  632.         return $images;
  633.     }
  634.     public function getDateStr($locale)
  635.     {
  636.         $date strtotime($this->getCreatedAt()->format('d-m-Y'));
  637.         switch ($locale) {
  638.             case 'en':
  639.                 setlocale(LC_TIME'en_US');
  640.                 date_default_timezone_set('Europe/Paris');
  641.                 break;
  642.             case 'de':
  643.                 setlocale(LC_TIME'de_DE');
  644.                 date_default_timezone_set('Europe/Paris');
  645.                 break;
  646.             
  647.             default:
  648.                 setlocale(LC_TIME'fr_FR');
  649.                 date_default_timezone_set('Europe/Paris');
  650.                 break;
  651.         }
  652.         $date_str ucwords(utf8_encode(strftime('%d %B %Y'$date)));
  653.         return $date_str.'.';
  654.     }
  655. }