src/Entity/Order/Order.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Order;
  4. use Sylius\Component\Core\Model\Order as BaseOrder;
  5. use Sylius\Component\Promotion\Checker\Eligibility\PromotionRulesEligibilityChecker;
  6. /**
  7.  * Order
  8.  */
  9. class Order extends BaseOrder
  10. {
  11.     protected $dureePanier=30;
  12.     public const DEFAULT_ORIGIN_ORDER 'Internet';
  13.     public const GIFT_WRAP_MODES = [
  14.         'none',
  15.         'gift_wrap_myself'// Le client emballe lui même
  16.         'gift_wrap_ppmc' // PPMC s'occupera de l'emballage
  17.     ];
  18.     /**
  19.      * @var int
  20.      * Numéro de la commande dans "Panda"
  21.      */
  22.     protected $oldSiteIdOrder;
  23.     /**
  24.      * @var string
  25.      * Numéro du ticket dans Generix
  26.      */
  27.     protected $orderGenerixReceiptNumber;
  28.      /**
  29.      * @var string
  30.      * Generix Manage Marketing Context Id
  31.      */
  32.     protected $orderGenerixManageMarketingContextId;
  33.     /**
  34.      * @var int
  35.      * Panda cart id
  36.      */
  37.     protected $orderPandaPanierId;
  38.     /**
  39.      * @var string
  40.      * Numéro de facture dans Divalto
  41.      */
  42.     protected $orderDivaltoInvoiceNumber;
  43.     /**
  44.      * @var string
  45.      * Identifiant du point retrait So Colissimo
  46.      * (ex: "091234")
  47.      */
  48.     protected $orderPickupSoColissimo;
  49.     /**
  50.      * @var string
  51.      * Code de la boutique PPMC
  52.      * (ex: "TAR", "AZE" etc)
  53.      */
  54.     protected $orderPickupShop;
  55.     /**
  56.      * @var string
  57.      * Nom du relais à afficher dans le checkout (colissimo ou shop)
  58.      * (ex: "091234")
  59.      */
  60.     protected $orderPickupName;
  61.     /**
  62.      * @var string
  63.      */
  64.     protected $giftMessage;
  65.     /**
  66.      * @var string
  67.      */
  68.     protected $canLoyalty;
  69.     /**
  70.      * @var string
  71.      */
  72.     protected $hasLoyalty;
  73.     /**
  74.      * @var string
  75.      */
  76.     protected $totalLoyalty;
  77.     /**
  78.      * @var string
  79.      */
  80.     protected $libelleLoyalty;
  81.     /**
  82.      * @var string
  83.      */
  84.     protected $giftWrapMode 'none';
  85.     /**
  86.      * @var string
  87.     */
  88.     protected $codePromo;
  89.     /**
  90.      * @var bool
  91.     */
  92.     protected $codePromoValid;
  93.     /**
  94.      * @var string
  95.     */
  96.     protected $apel;
  97.     /**
  98.      * Origine de la commande (Internet ou Generix-<nom boutique>)
  99.      * @var string
  100.      */
  101.     protected $origin;
  102.     /**
  103.      * @var int
  104.      * Existing Delivery address selected in checkout
  105.      */
  106.     protected $selectedShippingAddressId;
  107.     /**
  108.      * @var int
  109.      * Existing Billing address selected in checkout
  110.      */
  111.     protected $selectedBillingAddressId;
  112.     public function __construct()
  113.     {
  114.         parent::__construct();
  115.         $this->origin self::DEFAULT_ORIGIN_ORDER;
  116.     }
  117.     public function getOldSiteIdOrder(): ?int
  118.     {
  119.         return $this->oldSiteIdOrder;
  120.     }
  121.     public function setOldSiteIdOrder(?int $oldSiteIdOrder): void
  122.     {
  123.         $this->oldSiteIdOrder $oldSiteIdOrder;
  124.     }
  125.     public function getOrderGenerixReceiptNumber(): ?string
  126.     {
  127.         return $this->orderGenerixReceiptNumber;
  128.     }
  129.     public function setOrderGenerixReceiptNumber(?string $orderGenerixReceiptNumber): void
  130.     {
  131.         $this->orderGenerixReceiptNumber $orderGenerixReceiptNumber;
  132.     }
  133.     public function getOrderGenerixManageMarketingContextId(): ?string
  134.     {
  135.         return $this->orderGenerixManageMarketingContextId;
  136.     }
  137.     public function setOrderGenerixManageMarketingContextId(?string $orderGenerixManageMarketingContextId): void
  138.     {
  139.         $this->orderGenerixManageMarketingContextId $orderGenerixManageMarketingContextId;
  140.     }    
  141.     public function getOrderPandaPanierId(): ?int
  142.     {
  143.         return $this->orderPandaPanierId;
  144.     }
  145.     public function setOrderPandaPanierId(?int $orderPandaPanierId): void
  146.     {
  147.         $this->orderPandaPanierId $orderPandaPanierId;
  148.     }    
  149.     public function getOrderDivaltoInvoiceNumber(): ?string
  150.     {
  151.         return $this->orderDivaltoInvoiceNumber;
  152.     }
  153.     public function setOrderDivaltoInvoiceNumber(?string $orderDivaltoInvoiceNumber): void
  154.     {
  155.         $this->orderDivaltoInvoiceNumber $orderDivaltoInvoiceNumber;
  156.     }
  157.     public function getOrderPickupSoColissimo(): ?string
  158.     {
  159.         return $this->orderPickupSoColissimo;
  160.     }
  161.     public function setOrderPickupSoColissimo(?string $orderPickupSoColissimo): void
  162.     {
  163.         $this->orderPickupSoColissimo $orderPickupSoColissimo;
  164.     }
  165.     public function getOrderPickupShop(): ?string
  166.     {
  167.         return $this->orderPickupShop;
  168.     }
  169.     public function setOrderPickupShop(?string $orderPickupShop): void
  170.     {
  171.         $this->orderPickupShop $orderPickupShop;
  172.     }
  173.     public function getOrderPickupName(): ?string
  174.     {
  175.         return $this->orderPickupName;
  176.     }
  177.     public function setOrderPickupName(?string $orderPickupName): void
  178.     {
  179.         $this->orderPickupName $orderPickupName;
  180.     }
  181.     public function getGiftMessage(): ?string
  182.     {
  183.         return $this->giftMessage;
  184.     }
  185.     public function setGiftMessage(?string $giftMessage): void
  186.     {
  187.         $this->giftMessage $giftMessage;
  188.     }
  189.     public function getGiftWrapMode(): ?string
  190.     {
  191.         return $this->giftWrapMode;
  192.     }
  193.     public function setGiftWrapMode(?string $giftWrapMode): void
  194.     {
  195.         $this->giftWrapMode $giftWrapMode;
  196.     }
  197.     public function setOrigin(?string $origin): void
  198.     {
  199.         $this->origin $origin;
  200.     }
  201.     public function getOrigin(): ?string
  202.     {
  203.         return $this->origin;
  204.     }
  205.     public function getCanLoyalty(): ?string
  206.     {
  207.         return $this->canLoyalty;
  208.     }
  209.     public function setCanLoyalty(?string $canLoyalty): void
  210.     {
  211.         $this->canLoyalty $canLoyalty;
  212.     }
  213.     public function getHasLoyalty(): ?string
  214.     {
  215.         return $this->hasLoyalty;
  216.     }
  217.     public function setHasLoyalty(?string $hasLoyalty): void
  218.     {
  219.         $this->hasLoyalty $hasLoyalty;
  220.     }
  221.     public function getTotalLoyalty(): ?string
  222.     {
  223.         return $this->totalLoyalty;
  224.     }
  225.     public function setTotalLoyalty(?string $totalLoyalty): void
  226.     {
  227.         $this->totalLoyalty $totalLoyalty;
  228.     }
  229.     public function getLibelleLoyalty(): ?string
  230.     {
  231.         return $this->libelleLoyalty;
  232.     }
  233.     public function setLibelleLoyalty(?string $libelleLoyalty): void
  234.     {
  235.         $this->libelleLoyalty $libelleLoyalty;
  236.     }
  237.     public function getCodePromo(): ?string
  238.     {
  239.         return $this->codePromo;
  240.     }
  241.     public function setCodePromo(?string $codePromo): void
  242.     {
  243.         $this->codePromo $codePromo;
  244.     }
  245.     public function getCodePromoValid(): ?int
  246.     {
  247.         return $this->codePromoValid;
  248.     }
  249.     public function setCodePromoValid(?int $codePromoValid): void
  250.     {
  251.         $this->codePromoValid $codePromoValid;
  252.     }
  253.     public function getApel(): ?string
  254.     {
  255.         return $this->apel;
  256.     }
  257.     public function setApel(?string $apel): void
  258.     {
  259.         $this->apel $apel;
  260.     }
  261.     public function getSelectedShippingAddressId(): ?int
  262.     {
  263.         return $this->selectedShippingAddressId;
  264.     }
  265.     public function setSelectedShippingAddressId(?string $selectedShippingAddressId): void
  266.     {
  267.         $this->selectedShippingAddressId $selectedShippingAddressId;
  268.     }
  269.     public function getSelectedBillingAddressId(): ?int
  270.     {
  271.         return $this->selectedBillingAddressId;
  272.     }
  273.     public function setSelectedBillingAddressId(?string $selectedBillingAddressId): void
  274.     {
  275.         $this->selectedBillingAddressId $selectedBillingAddressId;
  276.     }
  277.     public function setDureePanier(int $dureePanier) {
  278.         $this->dureePanier $dureePanier;
  279.     }
  280.     public function getCompteur(): float
  281.     {
  282.         
  283.         $from_time time();
  284.         $to_time strtotime((string) $this->getUpdatedAt()->format('Y-m-d H:i:s'));
  285.         $minutes round(abs($to_time $from_time) / 60);
  286.         if($minutes $this->dureePanier){
  287.             return 0;
  288.         }
  289.         return  $this->dureePanier round(abs($to_time $from_time) / 60);
  290.      
  291.     }
  292.     public function getAlreadyPaid()
  293.     {
  294.         $alreadyPaid = [];
  295.         foreach($this->getPayments() as $payment) {
  296.             if($payment->getState() == 'completed') {
  297.                 $alreadyPaid[] = [
  298.                     'method' => $payment->getMethod()->getName(),
  299.                     'amount' => $payment->getAmount()
  300.                 ];
  301.             }
  302.         }
  303.         return $alreadyPaid;        
  304.     }
  305.     public function getAlreadyPaidTotal()
  306.     {
  307.         $alreadyPaidTotal 0;
  308.         foreach($this->getPayments() as $payment) {
  309.             if($payment->getState() == 'completed') {
  310.                 $alreadyPaidTotal+= $payment->getAmount();
  311.             }
  312.         }
  313.         return $alreadyPaidTotal;        
  314.     }
  315.     public function hasCarteKdo() {
  316.         foreach($this->getPayments() as $payment) {
  317.             dump($payment);
  318.             // if($payment->getState() == 'completed') {
  319.             //     $alreadyPaid[] = [
  320.             //         'method' => $payment->getMethod()->getName(),
  321.             //         'amount' => $payment->getAmount()
  322.             //     ];
  323.             // }
  324.         }
  325.     }
  326.     public function getOrderPromotionTotalWithoutGiftCard(): int
  327.     {
  328.         $alreadyPaids $this->getAlreadyPaid();
  329.         $amountAlreadyPaid 0;
  330.         if(!empty($alreadyPaids)) {
  331.             foreach($alreadyPaids as $alreadyPaid) {
  332.                 $amountAlreadyPaid += $alreadyPaid['amount'];
  333.             }
  334.         }
  335.         return $this->getOrderPromotionTotal() + $amountAlreadyPaid;
  336.     }
  337.     public function leftToPay(): float 
  338.     {
  339.         $alreadyPaid $this->getAlreadyPaid();
  340.         $total $this->getTotal();
  341.         // dump($total);
  342.         if(!empty($alreadyPaid)) {
  343.             foreach($alreadyPaid as $payment)  {
  344.                 $total -= $payment['amount'];
  345.             }
  346.         }
  347.         return $total;
  348.     }
  349.     public function getDeliverylabel(): string 
  350.     {
  351.         foreach($this->getAdjustments() as $shipment){
  352.                 
  353.             if($shipment->getType() == 'shipping'){
  354.                 $name $shipment->getDetails();
  355.                 return $name['shippingMethodName'];
  356.             }
  357.         }
  358.         return '';
  359.     }
  360.     public function getDeliveryAmount(): int 
  361.     {
  362.         foreach($this->getAdjustments() as $shipment){
  363.                 
  364.             if($shipment->getType() == 'shipping'){
  365.                 return $shipment->getAmount();
  366.             }
  367.         }
  368.         return 0;
  369.         
  370.     }
  371. }