Browse Source

Commandes : système de statut de commande

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
5020af75f7
8 changed files with 121 additions and 30 deletions
  1. +4
    -14
      backend/views/user/orders.php
  2. +0
    -4
      console/migrations/m240528_072445_init_order_status_history.php
  3. +1
    -1
      domain/Order/Order/Order.php
  4. +55
    -0
      domain/Order/Order/OrderSolver.php
  5. +15
    -5
      domain/Order/OrderStatus/OrderStatusModule.php
  6. +1
    -1
      domain/Order/OrderStatusHistory/OrderStatusHistory.php
  7. +21
    -5
      domain/Order/OrderStatusHistory/OrderStatusHistoryModule.php
  8. +24
    -0
      domain/Order/OrderStatusHistory/OrderStatusHistorySolver.php

+ 4
- 14
backend/views/user/orders.php View File

@@ -66,20 +66,10 @@ $this->addBreadcrumb('Commandes') ;
'label' => 'Statut',
'format' => 'raw',
'value' => function ($order) use ($orderModule) {
if($orderModule->getSolver()->isOrderStatusOrdered($order)) {
if($order->date_update) {
return '<span class="label label-warning">Modifiée</span>';
}
else {
return '<span class="label label-success">Validée</span>';
}
}
elseif($orderModule->getSolver()->isOrderStatusCanceled($order)) {
return '<span class="label label-danger">Annulée</span>';
}
elseif($orderModule->getSolver()->isOrderStatusDeleted($order)) {
return '<span class="label label-danger">Supprimée</span>';
}
$orderStatusCssClass = $orderModule->getSolver()->getOrderStatusCssClass($order);
$orderStatusLabel = $orderModule->getSolver()->getOrderStatusLabel($order);
$orderStatusHistorySummaryTitleTag = $orderModule->getSolver()->getOrderStatusHistorySummaryTitleTag($order);
return '<span class="label label-'.$orderStatusCssClass.'" title="'.$orderStatusHistorySummaryTitleTag.'">'.$orderStatusLabel.'</span>';
}
],
[

+ 0
- 4
console/migrations/m240528_072445_init_order_status_history.php View File

@@ -1,9 +1,5 @@
<?php

use domain\Order\Order\OrderModule;
use domain\Order\OrderStatus\OrderStatus;
use domain\Producer\Producer\ProducerModule;
use domain\User\User\UserModule;
use yii\db\Migration;
use yii\db\Schema;


+ 1
- 1
domain/Order/Order/Order.php View File

@@ -265,6 +265,6 @@ class Order extends ActiveRecordCommon
public function getOrderStatusHistoryRelation()
{
return $this->hasMany(OrderStatusHistory::class, ['id_order' => 'id'])
->orderBy(['order_status.id' => SORT_DESC]);
->orderBy(['order_status_history.id' => SORT_ASC]);
}
}

+ 55
- 0
domain/Order/Order/OrderSolver.php View File

@@ -7,6 +7,7 @@ use domain\Document\Document\Document;
use domain\Document\Document\DocumentSolver;
use domain\Order\OrderStatus\OrderStatus;
use domain\Order\OrderStatusHistory\OrderStatusHistory;
use domain\Order\OrderStatusHistory\OrderStatusHistorySolver;
use domain\Order\ProductOrder\ProductOrderSolver;
use domain\Payment\Payment;
use domain\Payment\PaymentSolver;
@@ -26,6 +27,7 @@ class OrderSolver extends AbstractService implements SolverInterface
protected PaymentSolver $paymentSolver;
protected ProducerSolver $producerSolver;
protected ProductOrderSolver $productOrderSolver;
protected OrderStatusHistorySolver $orderStatusHistorySolver;

public function loadDependencies(): void
{
@@ -34,6 +36,7 @@ class OrderSolver extends AbstractService implements SolverInterface
$this->paymentSolver = $this->loadService(PaymentSolver::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class);
$this->orderStatusHistorySolver = $this->loadService(OrderStatusHistorySolver::class);
}

public function getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = ''): string
@@ -598,4 +601,56 @@ class OrderSolver extends AbstractService implements SolverInterface

return 'Supprimer';
}

public function getOrderStatusCssClass(Order $order): string
{
if($this->isOrderStatusOrdered($order)) {
if($order->date_update) {
return 'warning';
}
else {
return 'success';
}
}
elseif($this->isOrderStatusCanceled($order)) {
return 'danger';
}
elseif($this->isOrderStatusDeleted($order)) {
return 'danger';
}

return '';
}

public function getOrderStatusLabel(Order $order): string
{
if($this->isOrderStatusOrdered($order)) {
if($order->date_update) {
return 'Modifiée';
}
else {
return 'Validée';
}
}
elseif($this->isOrderStatusCanceled($order)) {
return 'Annulée';
}
elseif($this->isOrderStatusDeleted($order)) {
return 'Supprimée';
}

return '';
}

public function getOrderStatusHistorySummaryTitleTag(Order $order): string
{
$titleTagString = '';

foreach($order->getOrderStatusHistory() as $orderStatusHistory) {
$titleTagString .= $this->orderStatusHistorySolver->getOrderStatusHistoryLabel($orderStatusHistory).' '
.date('\l\e d/m/Y à H:i:s', $orderStatusHistory->getDate()->getTimestamp()).'&#013;';
}

return $titleTagString;
}
}

+ 15
- 5
domain/Order/OrderStatus/OrderStatusModule.php View File

@@ -6,11 +6,6 @@ use domain\_\AbstractModule;

class OrderStatusModule extends AbstractModule
{
public function getDefinition(): OrderStatusDefinition
{
return OrderStatusDefinition::getInstance();
}

public function getServices(): array
{
return [
@@ -19,4 +14,19 @@ class OrderStatusModule extends AbstractModule
OrderStatusBuilder::class,
];
}

public function getDefinition(): OrderStatusDefinition
{
return OrderStatusDefinition::getInstance();
}

public function getRepository(): OrderStatusRepository
{
return OrderStatusRepository::getInstance();
}

public function getBuilder(): OrderStatusBuilder
{
return OrderStatusBuilder::getInstance();
}
}

+ 1
- 1
domain/Order/OrderStatusHistory/OrderStatusHistory.php View File

@@ -35,7 +35,7 @@ class OrderStatusHistory extends ActiveRecordCommon

public function getDate(): \DateTime
{
return new \DateTime(strtotime($this->date));
return new \DateTime($this->date);
}

public function setDate(\DateTime $date): self

+ 21
- 5
domain/Order/OrderStatusHistory/OrderStatusHistoryModule.php View File

@@ -6,17 +6,33 @@ use domain\_\AbstractModule;

class OrderStatusHistoryModule extends AbstractModule
{
public function getDefinition(): OrderStatusHistoryDefinition
{
return OrderStatusHistoryDefinition::getInstance();
}

public function getServices(): array
{
return [
OrderStatusHistoryDefinition::class,
OrderStatusHistorySolver::class,
OrderStatusHistoryBuilder::class,
OrderStatusHistoryManager::class,
];
}

public function getDefinition(): OrderStatusHistoryDefinition
{
return OrderStatusHistoryDefinition::getInstance();
}

public function getSolver(): OrderStatusHistorySolver
{
return OrderStatusHistorySolver::getInstance();
}

public function getBuilder(): OrderStatusHistoryBuilder
{
return OrderStatusHistoryBuilder::getInstance();
}

public function getManager(): OrderStatusHistoryManager
{
return OrderStatusHistoryManager::getInstance();
}
}

+ 24
- 0
domain/Order/OrderStatusHistory/OrderStatusHistorySolver.php View File

@@ -0,0 +1,24 @@
<?php

namespace domain\Order\OrderStatusHistory;

use domain\_\AbstractSolver;
use domain\Order\OrderStatus\OrderStatus;

class OrderStatusHistorySolver extends AbstractSolver
{
public function getOrderStatusHistoryLabel(OrderStatusHistory $orderStatusHistory): string
{
if($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_ORDERED) {
return 'Validée';
}
elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_CANCELED) {
return 'Annulée';
}
elseif($orderStatusHistory->getOrderStatusAlias() == OrderStatus::ALIAS_DELETED) {
return 'Supprimée';
}

return '';
}
}

Loading…
Cancel
Save