/**
  * {@inheritdoc}
  */
 public function create()
 {
     $channel = $this->channelFactory->createNamed(self::DEFAULT_CHANNEL_NAME);
     $channel->setCode(self::DEFAULT_CHANNEL_CODE);
     $this->channelRepository->add($channel);
     return ['channel' => $channel];
 }
 function it_creates_a_default_united_states_channel_with_country_zone_and_usd_as_default_currency(RepositoryInterface $channelRepository, RepositoryInterface $countryRepository, RepositoryInterface $currencyRepository, RepositoryInterface $localeRepository, RepositoryInterface $zoneMemberRepository, RepositoryInterface $zoneRepository, ChannelFactoryInterface $channelFactory, FactoryInterface $countryFactory, FactoryInterface $currencyFactory, FactoryInterface $localeFactory, FactoryInterface $zoneFactory, FactoryInterface $zoneMemberFactory, ZoneMemberInterface $zoneMember, ZoneInterface $zone, ChannelInterface $channel, CountryInterface $unitedStates, CurrencyInterface $currency, LocaleInterface $locale)
 {
     $channel->getName()->willReturn('United States');
     $channelFactory->createNamed('United States')->willReturn($channel);
     $localeFactory->createNew()->willReturn($locale);
     $locale->setCode('en_US')->shouldBeCalled();
     $zoneMemberFactory->createNew()->willReturn($zoneMember);
     $zoneFactory->createNew()->willReturn($zone);
     $channel->setCode('WEB-US')->shouldBeCalled();
     $channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled();
     $zoneMember->setCode('US')->shouldBeCalled();
     $zone->setCode('US')->shouldBeCalled();
     $zone->setName('United States')->shouldBeCalled();
     $zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled();
     $zone->addMember($zoneMember)->shouldBeCalled();
     $countryFactory->createNew()->willReturn($unitedStates);
     $unitedStates->setCode('US')->shouldBeCalled();
     $currencyFactory->createNew()->willReturn($currency);
     $currency->setCode('USD')->shouldBeCalled();
     $currency->setExchangeRate(1.0)->shouldBeCalled();
     $channel->setDefaultCurrency($currency)->shouldBeCalled();
     $channel->addCurrency($currency)->shouldBeCalled();
     $channel->setDefaultLocale($locale)->shouldBeCalled();
     $channel->addLocale($locale)->shouldBeCalled();
     $currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null);
     $localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null);
     $currencyRepository->add($currency)->shouldBeCalled();
     $localeRepository->add($locale)->shouldBeCalled();
     $countryRepository->add($unitedStates)->shouldBeCalled();
     $channelRepository->add($channel)->shouldBeCalled();
     $zoneRepository->add($zone)->shouldBeCalled();
     $zoneMemberRepository->add($zoneMember)->shouldBeCalled();
     $this->create();
 }
Example #3
0
 private function getCurrency($code)
 {
     if (isset($this->cache[$code])) {
         return $this->cache[$code];
     }
     return $this->cache[$code] = $this->currencyRepository->findOneBy(array('code' => $code));
 }
 function it_calls_proper_method_with_arguments_based_on_configuration(RepositoryInterface $repository, $configuration)
 {
     $configuration->getRepositoryMethod('findBy')->willReturn('findAll');
     $configuration->getRepositoryArguments(array())->willReturn(array(5));
     $repository->findAll(5)->shouldBeCalled()->willReturn(array('foo', 'bar'));
     $this->getResource($repository, 'findBy')->shouldReturn(array('foo', 'bar'));
 }
 /**
  * @return null|ProviderInterface
  */
 public function getActivedProvider()
 {
     if ($provider = $this->repository->findOneBy(array('actived' => true))) {
         return $provider;
     }
     return $this->findByName($this->defaultProvider);
 }
 function it_uses_a_custom_method_if_configured(RequestConfiguration $requestConfiguration, RepositoryInterface $repository, ResourceInterface $resource)
 {
     $requestConfiguration->getRepositoryMethod()->willReturn('findAll');
     $requestConfiguration->getRepositoryArguments()->willReturn(array('foo'));
     $repository->findAll('foo')->willReturn($resource);
     $this->get($requestConfiguration, $repository)->shouldReturn($resource);
 }
 /**
  * {@inheritdoc}
  */
 public function getAvailableCurrenciesCodes()
 {
     $currencies = $this->currencyRepository->findBy(['enabled' => true]);
     return array_map(function (CurrencyInterface $currency) {
         return $currency->getCode();
     }, $currencies);
 }
 function it_checks_if_the_locale_is_available(RepositoryInterface $repository, LocaleInterface $locale)
 {
     $repository->findBy(Argument::any())->willReturn(array($locale));
     $locale->getCode()->willReturn('en');
     $this->isLocaleAvailable('en')->shouldReturn(true);
     $this->isLocaleAvailable('fr')->shouldReturn(false);
 }
 function it_does_not_add_customer_if_they_not_exist(FormEvent $event, RepositoryInterface $customerRepository, FormInterface $form)
 {
     $event->getData()->willReturn(['email' => '*****@*****.**']);
     $customerRepository->findOneBy(['email' => '*****@*****.**'])->willReturn(null);
     $form->setData(null)->shouldNotBeCalled();
     $this->preSubmit($event);
 }
Example #10
0
 function it_creates_a_taxon_and_assigns_a_taxonomy_to_id(FactoryInterface $factory, RepositoryInterface $taxonomyRepository, TaxonomyInterface $taxonomy, TaxonInterface $taxon)
 {
     $factory->createNew()->willReturn($taxon);
     $taxonomyRepository->find(13)->willReturn($taxonomy);
     $taxon->setTaxonomy($taxonomy)->shouldBeCalled();
     $this->createForTaxonomy(13)->shouldReturn($taxon);
 }
 /**
  * {@inheritdoc}
  */
 public function update(OrderInterface $order)
 {
     /** @var CurrencyInterface $currency */
     $currency = $this->currencyRepository->findOneBy(['code' => $this->currencyContext->getCurrencyCode()]);
     $order->setCurrencyCode($currency->getCode());
     $order->setExchangeRate($currency->getExchangeRate());
 }
Example #12
0
 /**
  * @Given /^the store has disabled country "([^"]*)"$/
  */
 public function theStoreHasDisabledCountry($countryName)
 {
     $country = $this->createCountryNamed(trim($countryName));
     $country->disable();
     $this->sharedStorage->set('country', $country);
     $this->countryRepository->add($country);
 }
Example #13
0
 /**
  * @param string $code
  *
  * @return CurrencyInterface
  */
 protected function getCurrency($code)
 {
     if (isset($this->cache[$code])) {
         return $this->cache[$code];
     }
     return $this->cache[$code] = $this->currencyRepository->findOneBy(['code' => $code]);
 }
 /**
  * @param array $options
  *
  * @return array
  */
 private function getZones(array $options)
 {
     if (isset($options['scope'])) {
         return $this->zoneRepository->findBy(['scope' => $options['scope']]);
     }
     return $this->zoneRepository->findAll();
 }
Example #15
0
 /**
  * {@inheritDoc}
  *
  * @param $request Notify
  */
 public function execute($request)
 {
     if (!$this->supports($request)) {
         throw RequestNotSupportedException::createActionNotSupported($this, $request);
     }
     $this->payment->execute($httpRequest = new GetHttpRequest());
     $details = $httpRequest->query;
     if (!$this->api->verifyHash($details)) {
         throw new BadRequestHttpException('Hash cannot be verified.');
     }
     if (empty($details['ORDERID'])) {
         throw new BadRequestHttpException('Order id cannot be guessed');
     }
     $payment = $this->paymentRepository->findOneBy(array($this->identifier => $details['ORDERID']));
     if (null === $payment) {
         throw new BadRequestHttpException('Payment cannot be retrieved.');
     }
     if ((int) $details['AMOUNT'] !== $payment->getAmount()) {
         throw new BadRequestHttpException('Request amount cannot be verified against payment amount.');
     }
     // Actually update payment details
     $details = array_merge($payment->getDetails(), $details);
     $payment->setDetails($details);
     $status = new GetStatus($payment);
     $this->payment->execute($status);
     $nextState = $status->getValue();
     $this->updatePaymentState($payment, $nextState);
     $this->objectManager->flush();
     throw new HttpResponse(new Response('OK', 200));
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function getPermission($code)
 {
     if (null === ($permission = $this->repository->findOneBy(array('code' => $code)))) {
         throw new PermissionNotFoundException($code);
     }
     return $permission;
 }
Example #17
0
 /**
  * @Transform /^country "([^"]+)"$/
  * @Transform /^"([^"]+)" country$/
  * @Transform /^"([^"]+)" as shipping country$/
  */
 public function getCountryByName($countryName)
 {
     $countryCode = $this->countryNameConverter->convertToCode($countryName);
     $country = $this->countryRepository->findOneBy(['code' => $countryCode]);
     Assert::notNull($country, sprintf('Country with name "%s" does not exist', $countryName));
     return $country;
 }
Example #18
0
 /**
  * @param string $name
  */
 private function createCountryNamed($name)
 {
     /** @var CountryInterface $country */
     $country = $this->countryFactory->createNew();
     $country->setCode($this->countryNameConverter->convertToCode($name));
     $this->countryRepository->add($country);
 }
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($code)
 {
     if (null === $code || '' === $code) {
         return null;
     }
     return $this->promotionCouponRepository->findOneBy(['code' => $code]);
 }
Example #20
0
 /**
  * @Given I added product :name to the cart
  */
 public function iAddedProductToTheCart($name)
 {
     /** @var ProductInterface $product */
     $product = $this->productRepository->findOneBy(array('name' => $name));
     $productShowPage = $this->getPage('Product\\ProductShowPage')->openSpecificProductPage($product);
     $productShowPage->addToCart();
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 public function getAvailableLocalesCodes()
 {
     $locales = $this->localeRepository->findBy(['enabled' => true]);
     return array_map(function (LocaleInterface $locale) {
         return $locale->getCode();
     }, $locales);
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function getDefinedLocalesCodes()
 {
     $locales = $this->localeRepository->findAll();
     return array_map(function (LocaleInterface $locale) {
         return $locale->getCode();
     }, $locales);
 }
 /**
  * {@inheritdoc}
  */
 public function validate($customer, Constraint $constraint)
 {
     $existingCustomer = $this->customerRepository->findOneBy(['email' => $customer->getEmail()]);
     if (null !== $existingCustomer && null !== $existingCustomer->getUser()) {
         $this->context->addViolationAt('email', $constraint->message, [], null);
     }
 }
Example #24
0
 /**
  * @param string $token
  *
  * @return Boolean
  */
 protected function isUsedCode($token)
 {
     $this->manager->getFilters()->disable('softdeleteable');
     $isUsed = null !== $this->repository->findOneBy(array('confirmationToken' => $token));
     $this->manager->getFilters()->enable('softdeleteable');
     return $isUsed;
 }
Example #25
0
 /**
  * Moves resource directly behind the position of existing object with id $target
  *
  * @param RequestConfiguration $requestConfiguration
  * @param MetadataInterface $metadataInterface
  * @param $resource
  * @param RepositoryInterface $repository
  * @param int $target
  */
 public function moveAfter(RequestConfiguration $requestConfiguration, MetadataInterface $metadataInterface, $resource, RepositoryInterface $repository, $target)
 {
     $property = $requestConfiguration->getSortablePosition();
     $targetResource = $repository->find($target);
     $accessor = PropertyAccess::createPropertyAccessor();
     $strategy = $requestConfiguration->getSortingStrategy();
     $resourceValue = $accessor->getValue($resource, $property);
     $targetValue = $accessor->getValue($targetResource, $property);
     if ($resourceValue === null || $targetValue === null || $resourceValue == $targetValue) {
         // Errors in value consistency: recalculate all position values for this entity
         $this->recalculateSortingProperty($property, $repository);
         $resourceValue = $accessor->getValue($resource, $property);
         $targetValue = $accessor->getValue($targetResource, $property);
     }
     // Adjust target position based on the resources position relative to the targets position
     if (($strategy == self::STRATEGY_ASC_LAST || $strategy == self::STRATEGY_ASC_FIRST) && $resourceValue > $targetValue) {
         // Resource is below target
         // To get to position one below target, we don't need to move target, only get to position one below, which means to position + 1 in asc strategies.
         $targetPosition = $targetValue + 1;
     } elseif (($strategy == self::STRATEGY_DESC_LAST || $strategy == self::STRATEGY_DESC_FIRST) && $resourceValue < $targetValue) {
         // Resource is below target
         // To get to position one below target, we don't need to move target, only get to position one below, which means to position - 1 in desc strategies.
         $targetPosition = $targetValue - 1;
     } else {
         // Resource is above target, we need to move target as well to get to the position one below
         $targetPosition = $targetValue;
     }
     // Execute movement
     $this->moveToPosition($resource, $targetPosition, $property, $strategy, $repository);
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function generate(VariableInterface $variable)
 {
     if (!$variable->hasOptions()) {
         throw new \InvalidArgumentException('Cannot generate variants for an object without options.');
     }
     $optionSet = array();
     $optionMap = array();
     foreach ($variable->getOptions() as $k => $option) {
         foreach ($option->getValues() as $value) {
             $optionSet[$k][] = $value->getId();
             $optionMap[$value->getId()] = $value;
         }
     }
     $permutations = $this->getPermutations($optionSet);
     foreach ($permutations as $permutation) {
         $variant = $this->variantRepository->createNew();
         $variant->setObject($variable);
         $variant->setDefaults($variable->getMasterVariant());
         if (is_array($permutation)) {
             foreach ($permutation as $id) {
                 $variant->addOption($optionMap[$id]);
             }
         } else {
             $variant->addOption($optionMap[$permutation]);
         }
         $variable->addVariant($variant);
         $this->process($variable, $variant);
     }
 }
Example #27
0
 /**
  * @param string $name
  */
 private function createCountryNamed($name)
 {
     /** @var CountryInterface $country */
     $country = $this->countryFactory->createNew();
     $country->setCode($this->getCountryCodeByEnglishCountryName($name));
     $this->countryRepository->add($country);
 }
 function it_gets_province_code_if_its_abbreviation_is_not_set(RepositoryInterface $provinceRepository, ProvinceInterface $province)
 {
     $province->getCode()->willReturn('IE-UL');
     $province->getAbbreviation()->willReturn(null);
     $provinceRepository->findOneBy(['code' => 'IE-UL'])->willReturn($province);
     $this->getAbbreviation('IE-UL')->shouldReturn('IE-UL');
 }
Example #29
0
 function it_creates_a_variant_and_assigns_a_product_to_id(FactoryInterface $factory, RepositoryInterface $productRepository, ProductInterface $product, VariantInterface $variant)
 {
     $factory->createNew()->willReturn($variant);
     $productRepository->find(13)->willReturn($product);
     $variant->setProduct($product)->shouldBeCalled();
     $this->createForProduct(13)->shouldReturn($variant);
 }
 /**
  * @return array
  */
 private function getLocales()
 {
     /** @var LocaleInterface[] $locales */
     $locales = $this->localeRepository->findAll();
     foreach ($locales as $locale) {
         (yield $locale->getCode());
     }
 }