Skip to content

Commit

Permalink
fix datafetchers
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboss86 committed Jul 6, 2019
1 parent 9a9dbd5 commit ba28503
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
22 changes: 20 additions & 2 deletions src/DataFetcher/NumberOfOrdersDataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@
namespace Odiseo\SyliusReportPlugin\DataFetcher;

use Exception;
use Odiseo\SyliusReportPlugin\Filter\QueryFilter;
use Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\NumberOfOrdersType;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\Component\Order\Model\OrderInterface;

/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
* @author Diego D'amico <diego@odiseo.com.ar>
*/
class NumberOfOrdersDataFetcher extends TimePeriodDataFetcher
{
/**
* @var string
*/
private $orderClass;

/**
* @param QueryFilter $queryFilter
* @param string $orderClass
*/
public function __construct(
QueryFilter $queryFilter,
string $orderClass
) {
parent::__construct($queryFilter);

$this->orderClass = $orderClass;
}

/**
* {@inheritdoc}
* @throws Exception
Expand All @@ -22,7 +40,7 @@ protected function setupQueryFilter(array $configuration = []): void
{
$qb = $this->queryFilter->getQueryBuilder();

$from = $qb->getEntityManager()->getClassMetadata(OrderInterface::class)->getName();
$from = $this->orderClass;
$qb
->select('DATE(payment.updatedAt) as date', 'COUNT(o.id) as NumberOfOrders')
->from($from, 'o')
Expand Down
22 changes: 20 additions & 2 deletions src/DataFetcher/SalesTotalDataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@
namespace Odiseo\SyliusReportPlugin\DataFetcher;

use Exception;
use Odiseo\SyliusReportPlugin\Filter\QueryFilter;
use Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\SalesTotalType;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\Component\Order\Model\OrderInterface;

/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
* @author Diego D'amico <diego@odiseo.com.ar>
*/
class SalesTotalDataFetcher extends TimePeriodDataFetcher
{
/**
* @var string
*/
private $orderClass;

/**
* @param QueryFilter $queryFilter
* @param string $orderClass
*/
public function __construct(
QueryFilter $queryFilter,
string $orderClass
) {
parent::__construct($queryFilter);

$this->orderClass = $orderClass;
}

/**
* {@inheritdoc}
* @throws Exception
Expand All @@ -22,7 +40,7 @@ protected function setupQueryFilter(array $configuration = []): void
{
$qb = $this->queryFilter->getQueryBuilder();

$from = $qb->getEntityManager()->getClassMetadata(OrderInterface::class)->getName();
$from = $this->orderClass;
$qb
->select('DATE(payment.updatedAt) as date', 'COUNT(DATE(payment.updatedAt)) as orders', 'ROUND(SUM(o.total/100), 2) as total_'.$configuration['baseCurrency'])
->from($from, 'o')
Expand Down
22 changes: 20 additions & 2 deletions src/DataFetcher/UserRegistrationDataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
namespace Odiseo\SyliusReportPlugin\DataFetcher;

use Exception;
use Odiseo\SyliusReportPlugin\Filter\QueryFilter;
use Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\UserRegistrationType;
use Sylius\Component\Order\Model\OrderInterface;

/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
* @author Diego D'amico <diego@odiseo.com.ar>
*/
class UserRegistrationDataFetcher extends TimePeriodDataFetcher
{
/**
* @var string
*/
private $orderClass;

/**
* @param QueryFilter $queryFilter
* @param string $orderClass
*/
public function __construct(
QueryFilter $queryFilter,
string $orderClass
) {
parent::__construct($queryFilter);

$this->orderClass = $orderClass;
}

/**
* @inheritdoc
* @throws Exception
Expand All @@ -20,7 +38,7 @@ protected function setupQueryFilter(array $configuration = []): void
{
$qb = $this->queryFilter->getQueryBuilder();

$from = $qb->getEntityManager()->getClassMetadata(OrderInterface::class)->getName();
$from = $this->orderClass;
$qb
->select('DATE(u.createdAt) as date', 'count(u.id) as user_total')
->from($from, 'u')
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/services/data_fetcher.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
services:
odiseo_sylius_report.data_fetcher.user_registration:
class: Odiseo\SyliusReportPlugin\DataFetcher\UserRegistrationDataFetcher
arguments: ['@odiseo_sylius_report.filter.query_filter']
arguments: ['@odiseo_sylius_report.filter.query_filter', '%sylius.model.order.class%']
tags:
- { name: odiseo_sylius_report.data_fetcher, fetcher: odiseo_sylius_report_data_fetcher_user_registration, label: "odiseo_sylius_report.data_fetcher.user_registration" }

odiseo_sylius_report.data_fetcher.sales_total:
class: Odiseo\SyliusReportPlugin\DataFetcher\SalesTotalDataFetcher
arguments: ["@odiseo_sylius_report.filter.query_filter"]
arguments: ['@odiseo_sylius_report.filter.query_filter', '%sylius.model.order.class%']
tags:
- { name: odiseo_sylius_report.data_fetcher, fetcher: odiseo_sylius_report_data_fetcher_sales_total, label: "odiseo_sylius_report.data_fetcher.sales_total" }

odiseo_sylius_report.data_fetcher.number_of_orders:
class: Odiseo\SyliusReportPlugin\DataFetcher\NumberOfOrdersDataFetcher
arguments: ['@odiseo_sylius_report.filter.query_filter']
arguments: ['@odiseo_sylius_report.filter.query_filter', '%sylius.model.order.class%']
tags:
- { name: odiseo_sylius_report.data_fetcher, fetcher: odiseo_sylius_report_data_fetcher_number_of_orders, label: "odiseo_sylius_report.data_fetcher.number_of_orders" }

0 comments on commit ba28503

Please sign in to comment.