<?php
declare(strict_types=1);
namespace App\Entity\Order;
use Sylius\Component\Core\Model\Order as BaseOrder;
use Sylius\Component\Promotion\Checker\Eligibility\PromotionRulesEligibilityChecker;
/**
* Order
*/
class Order extends BaseOrder
{
protected $dureePanier=30;
public const DEFAULT_ORIGIN_ORDER = 'Internet';
public const GIFT_WRAP_MODES = [
'none',
'gift_wrap_myself', // Le client emballe lui même
'gift_wrap_ppmc' // PPMC s'occupera de l'emballage
];
/**
* @var int
* Numéro de la commande dans "Panda"
*/
protected $oldSiteIdOrder;
/**
* @var string
* Numéro du ticket dans Generix
*/
protected $orderGenerixReceiptNumber;
/**
* @var string
* Generix Manage Marketing Context Id
*/
protected $orderGenerixManageMarketingContextId;
/**
* @var int
* Panda cart id
*/
protected $orderPandaPanierId;
/**
* @var string
* Numéro de facture dans Divalto
*/
protected $orderDivaltoInvoiceNumber;
/**
* @var string
* Identifiant du point retrait So Colissimo
* (ex: "091234")
*/
protected $orderPickupSoColissimo;
/**
* @var string
* Code de la boutique PPMC
* (ex: "TAR", "AZE" etc)
*/
protected $orderPickupShop;
/**
* @var string
* Nom du relais à afficher dans le checkout (colissimo ou shop)
* (ex: "091234")
*/
protected $orderPickupName;
/**
* @var string
*/
protected $giftMessage;
/**
* @var string
*/
protected $canLoyalty;
/**
* @var string
*/
protected $hasLoyalty;
/**
* @var string
*/
protected $totalLoyalty;
/**
* @var string
*/
protected $libelleLoyalty;
/**
* @var string
*/
protected $giftWrapMode = 'none';
/**
* @var string
*/
protected $codePromo;
/**
* @var bool
*/
protected $codePromoValid;
/**
* @var string
*/
protected $apel;
/**
* Origine de la commande (Internet ou Generix-<nom boutique>)
* @var string
*/
protected $origin;
/**
* @var int
* Existing Delivery address selected in checkout
*/
protected $selectedShippingAddressId;
/**
* @var int
* Existing Billing address selected in checkout
*/
protected $selectedBillingAddressId;
public function __construct()
{
parent::__construct();
$this->origin = self::DEFAULT_ORIGIN_ORDER;
}
public function getOldSiteIdOrder(): ?int
{
return $this->oldSiteIdOrder;
}
public function setOldSiteIdOrder(?int $oldSiteIdOrder): void
{
$this->oldSiteIdOrder = $oldSiteIdOrder;
}
public function getOrderGenerixReceiptNumber(): ?string
{
return $this->orderGenerixReceiptNumber;
}
public function setOrderGenerixReceiptNumber(?string $orderGenerixReceiptNumber): void
{
$this->orderGenerixReceiptNumber = $orderGenerixReceiptNumber;
}
public function getOrderGenerixManageMarketingContextId(): ?string
{
return $this->orderGenerixManageMarketingContextId;
}
public function setOrderGenerixManageMarketingContextId(?string $orderGenerixManageMarketingContextId): void
{
$this->orderGenerixManageMarketingContextId = $orderGenerixManageMarketingContextId;
}
public function getOrderPandaPanierId(): ?int
{
return $this->orderPandaPanierId;
}
public function setOrderPandaPanierId(?int $orderPandaPanierId): void
{
$this->orderPandaPanierId = $orderPandaPanierId;
}
public function getOrderDivaltoInvoiceNumber(): ?string
{
return $this->orderDivaltoInvoiceNumber;
}
public function setOrderDivaltoInvoiceNumber(?string $orderDivaltoInvoiceNumber): void
{
$this->orderDivaltoInvoiceNumber = $orderDivaltoInvoiceNumber;
}
public function getOrderPickupSoColissimo(): ?string
{
return $this->orderPickupSoColissimo;
}
public function setOrderPickupSoColissimo(?string $orderPickupSoColissimo): void
{
$this->orderPickupSoColissimo = $orderPickupSoColissimo;
}
public function getOrderPickupShop(): ?string
{
return $this->orderPickupShop;
}
public function setOrderPickupShop(?string $orderPickupShop): void
{
$this->orderPickupShop = $orderPickupShop;
}
public function getOrderPickupName(): ?string
{
return $this->orderPickupName;
}
public function setOrderPickupName(?string $orderPickupName): void
{
$this->orderPickupName = $orderPickupName;
}
public function getGiftMessage(): ?string
{
return $this->giftMessage;
}
public function setGiftMessage(?string $giftMessage): void
{
$this->giftMessage = $giftMessage;
}
public function getGiftWrapMode(): ?string
{
return $this->giftWrapMode;
}
public function setGiftWrapMode(?string $giftWrapMode): void
{
$this->giftWrapMode = $giftWrapMode;
}
public function setOrigin(?string $origin): void
{
$this->origin = $origin;
}
public function getOrigin(): ?string
{
return $this->origin;
}
public function getCanLoyalty(): ?string
{
return $this->canLoyalty;
}
public function setCanLoyalty(?string $canLoyalty): void
{
$this->canLoyalty = $canLoyalty;
}
public function getHasLoyalty(): ?string
{
return $this->hasLoyalty;
}
public function setHasLoyalty(?string $hasLoyalty): void
{
$this->hasLoyalty = $hasLoyalty;
}
public function getTotalLoyalty(): ?string
{
return $this->totalLoyalty;
}
public function setTotalLoyalty(?string $totalLoyalty): void
{
$this->totalLoyalty = $totalLoyalty;
}
public function getLibelleLoyalty(): ?string
{
return $this->libelleLoyalty;
}
public function setLibelleLoyalty(?string $libelleLoyalty): void
{
$this->libelleLoyalty = $libelleLoyalty;
}
public function getCodePromo(): ?string
{
return $this->codePromo;
}
public function setCodePromo(?string $codePromo): void
{
$this->codePromo = $codePromo;
}
public function getCodePromoValid(): ?int
{
return $this->codePromoValid;
}
public function setCodePromoValid(?int $codePromoValid): void
{
$this->codePromoValid = $codePromoValid;
}
public function getApel(): ?string
{
return $this->apel;
}
public function setApel(?string $apel): void
{
$this->apel = $apel;
}
public function getSelectedShippingAddressId(): ?int
{
return $this->selectedShippingAddressId;
}
public function setSelectedShippingAddressId(?string $selectedShippingAddressId): void
{
$this->selectedShippingAddressId = $selectedShippingAddressId;
}
public function getSelectedBillingAddressId(): ?int
{
return $this->selectedBillingAddressId;
}
public function setSelectedBillingAddressId(?string $selectedBillingAddressId): void
{
$this->selectedBillingAddressId = $selectedBillingAddressId;
}
public function setDureePanier(int $dureePanier) {
$this->dureePanier = $dureePanier;
}
public function getCompteur(): float
{
$from_time = time();
$to_time = strtotime((string) $this->getUpdatedAt()->format('Y-m-d H:i:s'));
$minutes = round(abs($to_time - $from_time) / 60);
if($minutes > $this->dureePanier){
return 0;
}
return $this->dureePanier - round(abs($to_time - $from_time) / 60);
}
public function getAlreadyPaid()
{
$alreadyPaid = [];
foreach($this->getPayments() as $payment) {
if($payment->getState() == 'completed') {
$alreadyPaid[] = [
'method' => $payment->getMethod()->getName(),
'amount' => $payment->getAmount()
];
}
}
return $alreadyPaid;
}
public function getAlreadyPaidTotal()
{
$alreadyPaidTotal = 0;
foreach($this->getPayments() as $payment) {
if($payment->getState() == 'completed') {
$alreadyPaidTotal+= $payment->getAmount();
}
}
return $alreadyPaidTotal;
}
public function hasCarteKdo() {
foreach($this->getPayments() as $payment) {
dump($payment);
// if($payment->getState() == 'completed') {
// $alreadyPaid[] = [
// 'method' => $payment->getMethod()->getName(),
// 'amount' => $payment->getAmount()
// ];
// }
}
}
public function getOrderPromotionTotalWithoutGiftCard(): int
{
$alreadyPaids = $this->getAlreadyPaid();
$amountAlreadyPaid = 0;
if(!empty($alreadyPaids)) {
foreach($alreadyPaids as $alreadyPaid) {
$amountAlreadyPaid += $alreadyPaid['amount'];
}
}
return $this->getOrderPromotionTotal() + $amountAlreadyPaid;
}
public function leftToPay(): float
{
$alreadyPaid = $this->getAlreadyPaid();
$total = $this->getTotal();
// dump($total);
if(!empty($alreadyPaid)) {
foreach($alreadyPaid as $payment) {
$total -= $payment['amount'];
}
}
return $total;
}
public function getDeliverylabel(): string
{
foreach($this->getAdjustments() as $shipment){
if($shipment->getType() == 'shipping'){
$name = $shipment->getDetails();
return $name['shippingMethodName'];
}
}
return '';
}
public function getDeliveryAmount(): int
{
foreach($this->getAdjustments() as $shipment){
if($shipment->getType() == 'shipping'){
return $shipment->getAmount();
}
}
return 0;
}
}