/** * @Transform /^this order made by "([^"]+)"$/ * @Transform /^order placed by "([^"]+)"$/ * @Transform /^the order of "([^"]+)"$/ */ public function getOrderByCustomer($email) { $customer = $this->customerRepository->findOneBy(['email' => $email]); Assert::notNull($customer, sprintf('Cannot find customer with email %s.', $email)); $orders = $this->orderRepository->findByCustomer($customer); Assert::notEmpty($orders); return end($orders); }
function it_obtains_order_and_customer_statistics_from_the_repositories(OrderRepositoryInterface $orderRepository, CustomerRepositoryInterface $customerRepository) { $expectedStats = new DashboardStatistics(450, 2, 6); $orderRepository->getTotalSales()->willReturn(450); $orderRepository->count()->willReturn(2); $customerRepository->count()->willReturn(6); $this->getStatistics()->shouldBeLike($expectedStats); }
function it_obtains_order_and_customer_statistics_by_given_channel(OrderRepositoryInterface $orderRepository, CustomerRepositoryInterface $customerRepository, ChannelInterface $channel) { $expectedStats = new DashboardStatistics(450, 2, 6); $orderRepository->getTotalSalesForChannel($channel)->willReturn(450); $orderRepository->countByChannel($channel)->willReturn(2); $customerRepository->count()->willReturn(6); $this->getStatisticsForChannel($channel)->shouldBeLike($expectedStats); }
/** * @Transform :customer * @Transform /^customer "([^"]+)"$/ */ public function getOrCreateCustomerByEmail($email) { /** @var CustomerInterface $customer */ $customer = $this->customerRepository->findOneBy(['email' => $email]); if (null === $customer) { $customer = $this->customerFactory->createNew(); $customer->setEmail($email); $this->customerRepository->add($customer); } return $customer; }
/** * @param string $email * @param string $password * @param bool $enabled * @param string|null $firstName * @param string|null $lastName * @param string|null $role */ private function createCustomerWithUserAccount($email, $password, $enabled = true, $firstName = null, $lastName = null, $role = null) { $user = $this->userFactory->createNew(); /** @var CustomerInterface $customer */ $customer = $this->customerFactory->createNew(); $customer->setFirstName($firstName); $customer->setLastName($lastName); $customer->setEmail($email); $user->setUsername($email); $user->setPlainPassword($password); $user->setEnabled($enabled); $user->addRole($role); $customer->setUser($user); $this->sharedStorage->set('customer', $customer); $this->customerRepository->add($customer); }
/** * {@inheritdoc} */ public function getStatisticsForChannel(ChannelInterface $channel) { return new DashboardStatistics($this->orderRepository->getTotalSalesForChannel($channel), $this->orderRepository->countByChannel($channel), $this->customerRepository->count()); }
/** * {@inheritdoc} */ public function getStatistics() { return new DashboardStatistics($this->orderRepository->getTotalSales(), $this->orderRepository->count(), $this->customerRepository->count()); }