Skip to content

Commit f7c6575

Browse files
author
Maxime Leclercq
committed
feat: allow order and payment status to be modified for report
1 parent 28eee63 commit f7c6575

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ monsieurbiz_sales_reports_plugin:
5454
5555
All reports columns are sortable by clicking on it.
5656
57+
If you want to change order or payments states used in the reports, you can configure it in the `config/packages/monsieurbiz_sylius_sales_reports_plugin.yaml` file:
58+
59+
```yaml
60+
parameters:
61+
monsieurbiz.sales_reports.order_states:
62+
- …
63+
monsieurbiz.sales_reports.payment_states:
64+
- …
65+
```
66+
67+
(FYI, is it possible to use `!php/const` to use constants in the config file)
68+
5769
### Global sales report
5870

5971
![Global sales report](screenshots/global.png)

src/Repository/AbstractReportRepository.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ abstract class AbstractReportRepository
7676
*/
7777
public function __construct(
7878
OrderRepositoryInterface $orderRepository,
79-
ProductVariantRepositoryInterface $productVariantRepository
79+
ProductVariantRepositoryInterface $productVariantRepository,
80+
protected ?array $orderStates,
81+
protected ?array $paymentStates,
8082
) {
8183
$this->orderRepository = $orderRepository;
8284
$this->productVariantRepository = $productVariantRepository;
@@ -186,6 +188,8 @@ protected function appendAdjustmentsAndParameters(
186188
bool $isOrder = false
187189
) {
188190
$elementAlias = $isOrder ? 'o' : 'element';
191+
$orderStates = $this->orderStates ?? [OrderInterface::STATE_FULFILLED, OrderInterface::STATE_NEW];
192+
$paymentStates = $this->paymentStates ?? [OrderPaymentStates::STATE_PAID];
189193

190194
return $queryBuilder
191195
// Adjustments joins
@@ -237,8 +241,8 @@ protected function appendAdjustmentsAndParameters(
237241
->andWhere('o.checkoutCompletedAt BETWEEN :from AND :to')
238242
// Filters parameters
239243
->setParameter('channel', $channel)
240-
->setParameter('states', [OrderInterface::STATE_FULFILLED, OrderInterface::STATE_NEW])
241-
->setParameter('payment_states', [OrderPaymentStates::STATE_PAID]) // @TODO Take care of OrderPaymentStates::STATE_PARTIALLY_PAID
244+
->setParameter('states', $orderStates)
245+
->setParameter('payment_states', $paymentStates)
242246
->setParameter('from', $fromDate)
243247
->setParameter('to', $toDate)
244248
;

src/Resources/config/services.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
parameters:
2+
monsieurbiz.sales_reports.order_states:
3+
- !php/const Sylius\Component\Order\Model\OrderInterface::STATE_FULFILLED
4+
- !php/const Sylius\Component\Order\Model\OrderInterface::STATE_NEW
5+
monsieurbiz.sales_reports.payment_states:
6+
- !php/const Sylius\Component\Core\OrderPaymentStates::STATE_PAID
7+
18
services:
29
# Default configuration for services in *this* file
310
_defaults:
@@ -26,3 +33,8 @@ services:
2633
class: MonsieurBiz\SyliusSalesReportsPlugin\Menu\AdminMenuListener
2734
tags:
2835
- { name: kernel.event_listener, event: sylius.menu.admin.main, method: addAdminMenuItem }
36+
37+
MonsieurBiz\SyliusSalesReportsPlugin\Repository\ReportRepository:
38+
arguments:
39+
$orderStates: '%monsieurbiz.sales_reports.order_states%'
40+
$paymentStates: '%monsieurbiz.sales_reports.payment_states%'

0 commit comments

Comments
 (0)