[Admin][Dashboard] Only fulfilled orders included in statistics

This commit is contained in:
Mert Oksuz 2017-07-17 09:29:45 +00:00 committed by Grzegorz Sadowski
parent 94db3b8471
commit 61e5fc5de9
7 changed files with 24 additions and 21 deletions

View file

@ -219,6 +219,9 @@
* `UserInterface::setExpiresAt` * `UserInterface::setExpiresAt`
* `UserInterface::setLastLogin` * `UserInterface::setLastLogin`
* In statistics to be correct data with orders informations
`OrderRepositoryInterface::countByChannel()` signature was changed to `OrderRepositoryInterface::countFulfilledByChannel()`.
# UPGRADE FROM 1.0.0-beta.2 to 1.0.0-beta.3 # UPGRADE FROM 1.0.0-beta.2 to 1.0.0-beta.3
## Packages: ## Packages:

View file

@ -17,22 +17,22 @@ Feature: Statistics dashboard in a single channel
Given 3 customers have placed 4 orders for total of "$8566.00" Given 3 customers have placed 4 orders for total of "$8566.00"
And then 2 more customers have placed 2 orders for total of "$459.00" And then 2 more customers have placed 2 orders for total of "$459.00"
When I open administration dashboard When I open administration dashboard
Then I should see 6 new orders Then I should see 0 new orders
And I should see 5 new customers And I should see 5 new customers
And there should be total sales of "$9,025.00" And there should be total sales of "$0.00"
And the average order value should be "$1,504.17" And the average order value should be "$0.00"
@ui @ui
Scenario: Statistics include only placed orders that were not cancelled Scenario: Statistics include only fulfilled orders that were not cancelled
Given 4 customers have placed 4 orders for total of "$5241.00" Given 4 customers have placed 4 orders for total of "$5241.00"
And 2 customers have added products to the cart for total of "$3450.00" And 2 customers have added products to the cart for total of "$3450.00"
And 1 customers have placed 1 orders for total of "$1000.00" And 1 customers have placed 1 orders for total of "$1000.00"
But the customer cancelled this order But the customer cancelled this order
When I open administration dashboard When I open administration dashboard
Then I should see 4 new orders Then I should see 0 new orders
And I should see 7 new customers And I should see 7 new customers
And there should be total sales of "$5,241.00" And there should be total sales of "$0.00"
And the average order value should be "$1,310.25" And the average order value should be "$0.00"
@ui @ui
Scenario: Seeing recent orders and customers Scenario: Seeing recent orders and customers

View file

@ -18,10 +18,10 @@ Feature: Statistics dashboard per channel
Given 3 customers have placed 4 orders for total of "$8566.00" mostly "Onion" product Given 3 customers have placed 4 orders for total of "$8566.00" mostly "Onion" product
And then 2 more customers have placed 2 orders for total of "$459.00" mostly "Banana" product And then 2 more customers have placed 2 orders for total of "$459.00" mostly "Banana" product
When I open administration dashboard When I open administration dashboard
Then I should see 4 new orders Then I should see 0 new orders
And I should see 5 new customers And I should see 5 new customers
And there should be total sales of "$8,566.00" And there should be total sales of "$0.00"
And the average order value should be "$2,141.50" And the average order value should be "$0.00"
@ui @ui
Scenario: Changing viewing channel in administration dashboard Scenario: Changing viewing channel in administration dashboard
@ -29,10 +29,10 @@ Feature: Statistics dashboard per channel
And then 2 more customers have placed 2 orders for total of "$459.00" mostly "Banana" product And then 2 more customers have placed 2 orders for total of "$459.00" mostly "Banana" product
When I open administration dashboard When I open administration dashboard
And I choose "United States" channel And I choose "United States" channel
Then I should see 2 new orders Then I should see 0 new orders
And I should see 6 new customers And I should see 6 new customers
And there should be total sales of "$459.00" And there should be total sales of "$0.00"
And the average order value should be "$229.50" And the average order value should be "$0.00"
@ui @ui
Scenario: Seeing recent orders in a specific channel Scenario: Seeing recent orders in a specific channel

View file

@ -204,9 +204,9 @@ class OrderRepository extends BaseOrderRepository implements OrderRepositoryInte
return (int) $this->createQueryBuilder('o') return (int) $this->createQueryBuilder('o')
->select('SUM(o.total)') ->select('SUM(o.total)')
->andWhere('o.channel = :channel') ->andWhere('o.channel = :channel')
->andWhere('o.state NOT IN (:states)') ->andWhere('o.state = :state')
->setParameter('channel', $channel) ->setParameter('channel', $channel)
->setParameter('states', [OrderInterface::STATE_CART, OrderInterface::STATE_CANCELLED]) ->setParameter('state', OrderInterface::STATE_FULFILLED)
->getQuery() ->getQuery()
->getSingleScalarResult() ->getSingleScalarResult()
; ;
@ -215,14 +215,14 @@ class OrderRepository extends BaseOrderRepository implements OrderRepositoryInte
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function countByChannel(ChannelInterface $channel): int public function countFulfilledByChannel(ChannelInterface $channel): int
{ {
return (int) $this->createQueryBuilder('o') return (int) $this->createQueryBuilder('o')
->select('COUNT(o.id)') ->select('COUNT(o.id)')
->andWhere('o.channel = :channel') ->andWhere('o.channel = :channel')
->andWhere('o.state NOT IN (:states)') ->andWhere('o.state = :state')
->setParameter('channel', $channel) ->setParameter('channel', $channel)
->setParameter('states', [OrderInterface::STATE_CART, OrderInterface::STATE_CANCELLED]) ->setParameter('state', OrderInterface::STATE_FULFILLED)
->getQuery() ->getQuery()
->getSingleScalarResult() ->getSingleScalarResult()
; ;

View file

@ -51,7 +51,7 @@ class DashboardStatisticsProvider implements DashboardStatisticsProviderInterfac
{ {
return new DashboardStatistics( return new DashboardStatistics(
$this->orderRepository->getTotalSalesForChannel($channel), $this->orderRepository->getTotalSalesForChannel($channel),
$this->orderRepository->countByChannel($channel), $this->orderRepository->countFulfilledByChannel($channel),
$this->customerRepository->count() $this->customerRepository->count()
); );
} }

View file

@ -106,7 +106,7 @@ interface OrderRepositoryInterface extends BaseOrderRepositoryInterface
* *
* @return int * @return int
*/ */
public function countByChannel(ChannelInterface $channel): int; public function countFulfilledByChannel(ChannelInterface $channel): int;
/** /**
* @param int $count * @param int $count

View file

@ -43,7 +43,7 @@ final class DashboardStatisticsProviderSpec extends ObjectBehavior
$expectedStats = new DashboardStatistics(450, 2, 6); $expectedStats = new DashboardStatistics(450, 2, 6);
$orderRepository->getTotalSalesForChannel($channel)->willReturn(450); $orderRepository->getTotalSalesForChannel($channel)->willReturn(450);
$orderRepository->countByChannel($channel)->willReturn(2); $orderRepository->countFulfilledByChannel($channel)->willReturn(2);
$customerRepository->count()->willReturn(6); $customerRepository->count()->willReturn(6);
$this->getStatisticsForChannel($channel)->shouldBeLike($expectedStats); $this->getStatisticsForChannel($channel)->shouldBeLike($expectedStats);