src/Entity/Order/Order.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Order;
  4. use App\Entity\Boutique;
  5. use App\Entity\Giftcard;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Sylius\Component\Core\Model\Order as BaseOrder;
  10. use Sylius\Component\Core\Model\Adjustment as BaseAdjustment;
  11. use Sylius\Component\Core\Model\AdjustmentInterface;
  12. use Sylius\Component\Order\Model\AdjustmentInterface as BaseAdjustmentInterface;
  13. use App\Service\FideliumService;
  14. /**
  15.  * @ORM\Entity
  16.  * @ORM\Table(name="sylius_order")
  17.  */
  18. class Order extends BaseOrder
  19. {
  20.     /** @ORM\Column(type="float", nullable=true) */
  21.     private $fideliumpoints;
  22.     public function getFideliumpoints(): ?float
  23.     {
  24.         return $this->fideliumpoints;
  25.     }
  26.     public function setFideliumpoints(float $fideliumpoints): void
  27.     {
  28.         $this->fideliumpoints $fideliumpoints;
  29.     } 
  30.     
  31.     /**
  32.      * @ORM\ManyToMany(targetEntity=Giftcard::class, inversedBy="orders")
  33.      */
  34.     private $giftCards;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Boutique::class, inversedBy="orders")
  37.      */
  38.     private $boutique;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $invoice_number;
  43.     public function __construct()
  44.     {
  45.         parent::__construct();
  46.         $this->giftCards = new ArrayCollection();
  47.     }
  48.     /*public function hasFidelium ()
  49.     {
  50.         $ajustements = $this->getFideliumAdjustments ();
  51.         if (
  52.             array_key_exists("Fidelium", $ajustements)
  53.             and
  54.             !empty($ajustements["Fidelium"])
  55.         )
  56.             return true;
  57.         else
  58.             return false;
  59.     }*/
  60.     
  61.     public function getTotalWithOutAdjustments()
  62.     {
  63.         $fidelium_Adjustment_amount 0;
  64.         $fidelium_Adjustments $this->getFidelium ();
  65.         if ($fidelium_Adjustments && array_key_exists("amount"$fidelium_Adjustments))
  66.             $fidelium_Adjustment_amount $fidelium_Adjustments["amount"];
  67.         $amount $this->getItemsTotal() - (int)$fidelium_Adjustment_amount;
  68.         
  69.         return $amount;
  70.     }
  71.     public function getFidelium ()
  72.     {
  73.         $ajustements $this->getFideliumAdjustments ();
  74.         if (
  75.             array_key_exists("Fidelium"$ajustements)
  76.             and
  77.             !empty($ajustements["Fidelium"])
  78.             and
  79.             array_key_exists("amount"$ajustements["Fidelium"])
  80.             and
  81.             array_key_exists("points"$ajustements["Fidelium"])
  82.             and            
  83.             (int)$ajustements["Fidelium"]["amount"] != 0
  84.         )
  85.         {            
  86.             $ajustements["points"] = (int)$ajustements["Fidelium"]["points"];
  87.             return $ajustements["Fidelium"];
  88.         }
  89.         else
  90.             return false;
  91.     }    
  92.     public function getFideliumAdjustments ()
  93.     {
  94.         $points 0;
  95.         $total 0;
  96.         $k=0;
  97.         $res = array();
  98.         $res["promo"] = array("amount" => 0);
  99.         $res["Fidelium"] = array("amount" => 0"points" =>0);
  100.         $adjs $this->getAdjustmentsRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT);
  101.         foreach ($adjs as $key => $ad){
  102.             //$details = $ad->getDetails();
  103.             $label $ad->getLabel();
  104.             if ($label=="Fidelium")
  105.             {
  106.                 if ($k=0)                
  107.                 {
  108.                   
  109.                     $res["Fidelium"]["amount"]  = 0;
  110.                 }
  111.             
  112.                 $res["Fidelium"]["amount"]  =  $res["Fidelium"]["amount"] + $ad->getAmount();
  113.                 //$res["Fidelium"]["points"]  =  $points;
  114.                 $total $total $ad->getAmount();
  115.                 $k++;
  116.             }
  117.             else
  118.             {
  119.                 $res["promo"]["amount"]  =  $res["promo"]["amount"]  + $ad->getAmount();
  120.             }
  121.         }     
  122.         if ($res["Fidelium"]["amount"] != 0)
  123.         {
  124.             $customer $this->getCustomer();
  125.             if (isset($customer))
  126.             {
  127.                 $cardnumber $customer->getFideliumcard();
  128.                 if ($cardnumber && $cardnumber!="")
  129.                 {
  130.                     $fs = new FideliumService ($cardnumber);
  131.                     
  132.                     $points $fs->correspondanceMontantsPoints $res["Fidelium"]["amount"]);    
  133.                     $res["Fidelium"]["points"]  =  $points ;                    
  134.                 }
  135.             } 
  136.         }
  137.                     
  138.                     
  139.             
  140.         return $res;
  141.     }
  142.     
  143.     public function getDispoProduct ()
  144.     {
  145.         $DatedispofromMin null;
  146.         $DatedispotoMax null;
  147.         foreach ($this->getItems() as $item){
  148.            $product $item->getProduct();
  149.            $Datedispofrom $product->getDatedispofrom();
  150.            $Datedispoto $product->getDatedispoto();
  151.            if (isset($Datedispofrom))
  152.            {
  153.             if (!isset($DatedispofromMin))
  154.                 $DatedispofromMin $Datedispofrom;
  155.             elseif ($Datedispofrom $DatedispofromMin)
  156.                 $DatedispofromMin $Datedispofrom;
  157.            }
  158.            if (isset($Datedispoto))
  159.            {
  160.             if (!isset($DatedispotoMax))
  161.                 $DatedispotoMax $Datedispoto;
  162.             elseif ($Datedispoto $DatedispotoMax)
  163.                 $DatedispotoMax $Datedispoto;                
  164.            }
  165.         }   
  166.         $DatedispofromMin_str "";
  167.         $DatedispotoMax_str "";
  168.         if (isset($DatedispofromMin))
  169.             $DatedispofromMin_str $DatedispofromMin->format('Y-m-d');
  170.         if (isset($DatedispotoMax))
  171.             $DatedispotoMax_str $DatedispotoMax->format('Y-m-d');
  172.            
  173.        return '{"from": "' $DatedispofromMin_str '","to": "' $DatedispotoMax_str '"}';
  174.     }
  175.     
  176.     public function getTaxes ()
  177.     {
  178.    
  179.         $res = array();
  180.         $taxes $this->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT);
  181.         foreach ($taxes as $key => $taxe){
  182.             $details $taxe->getDetails();
  183.             $taxRateName $details["taxRateName"];
  184.             if (array_key_exists($taxRateName$res ))
  185.                 $res[$taxRateName] =  $res[$taxRateName]  + $taxe->getAmount();
  186.             else
  187.                 $res[$taxRateName] =  $taxe->getAmount();
  188.         }     
  189.  
  190.         return $res;
  191.     }
  192.     public function hasGiftCards(): bool
  193.     {
  194.         return !$this->giftCards->isEmpty();
  195.     }
  196.     /**
  197.      * @return Collection|Giftcard[]
  198.      */
  199.     public function getGiftCards(): Collection
  200.     {
  201.         return $this->giftCards;
  202.     }
  203.     public function addGiftCard(Giftcard $giftCard): self
  204.     {
  205.         if (!$this->giftCards->contains($giftCard)) {
  206.             $this->giftCards[] = $giftCard;
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeGiftCard(Giftcard $giftCard): self
  211.     {
  212.         $this->giftCards->removeElement($giftCard);
  213.         return $this;
  214.     }
  215.     public function getBoutique(): ?Boutique
  216.     {
  217.         return $this->boutique;
  218.     }
  219.     public function setBoutique(?Boutique $boutique): self
  220.     {
  221.         $this->boutique $boutique;
  222.         return $this;
  223.     }
  224.     public function getInvoiceNumber(): ?string
  225.     {
  226.         return $this->invoice_number;
  227.     }
  228.     public function setInvoiceNumber(?string $invoice_number): self
  229.     {
  230.         $this->invoice_number $invoice_number;
  231.         return $this;
  232.     }    
  233. }