/**
  * @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);
 }
 /**
  * {@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];
 }
Beispiel #3
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);
 }
 /**
  * @param string $name
  */
 private function createCountryNamed($name)
 {
     /** @var CountryInterface $country */
     $country = $this->countryFactory->createNew();
     $country->setCode($this->getCountryCodeByEnglishCountryName($name));
     $this->countryRepository->add($country);
 }
Beispiel #5
0
 /**
  * @Given the store has disabled locale :localeName
  */
 public function theStoreHasDisabledLocale($localeName)
 {
     $locale = $this->localeFactory->createNew();
     $locale->setCode($this->localeNameConverter->convertToCode($localeName));
     $locale->disable();
     $this->sharedStorage->set('locale', $locale);
     $this->localeRepository->add($locale);
 }
 /**
  * @param string $name
  */
 private function createCustomerGroup($name)
 {
     /** @var CustomerGroupInterface $customerGroup */
     $customerGroup = $this->customerGroupFactory->createNew();
     $customerGroup->setName(ucfirst($name));
     $this->sharedStorage->set('customer_group', $customerGroup);
     $this->customerGroupRepository->add($customerGroup);
 }
Beispiel #7
0
 /**
  * @Given there is user :email identified by :password, with :country as shipping country
  */
 public function thereIsUserWithShippingCountry($email, $password, $country)
 {
     $user = $this->userFactory->create($email, $password);
     $customer = $user->getCustomer();
     $customer->setShippingAddress($this->createAddress($customer->getFirstName(), $customer->getLastName(), $country));
     $this->sharedStorage->set('user', $user);
     $this->userRepository->add($user);
 }
Beispiel #8
0
 /**
  * @Given /^there is "EU" zone containing all members of European Union$/
  */
 public function thereIsEUZoneContainingAllMembersOfEuropeanUnion()
 {
     $zone = $this->zoneFactory->createWithMembers($this->euMembers);
     $zone->setType(ZoneInterface::TYPE_COUNTRY);
     $zone->setCode('EU');
     $zone->setName('European Union');
     $this->zoneRepository->add($zone);
 }
 /**
  * @return OrderSequenceInterface
  */
 private function getSequence()
 {
     $sequence = $this->sequenceRepository->findOneBy([]);
     if (null === $sequence) {
         $sequence = $this->sequenceFactory->createNew();
         $this->sequenceRepository->add($sequence);
     }
     return $sequence;
 }
Beispiel #10
0
 /**
  * @Given default currency is :currencyCode
  */
 public function defaultCurrencyIs($currencyCode)
 {
     $currency = $this->currencyFactory->createNew();
     $currency->setCode($currencyCode);
     $currency->setExchangeRate(1.0);
     $channel = $this->sharedStorage->getCurrentResource('channel');
     $channel->setDefaultCurrency($currency);
     $this->currencyRepository->add($currency);
 }
 /**
  * @Given /^(this product) has one review$/
  */
 public function productHasAReview(ProductInterface $product)
 {
     $review = $this->productReviewFactory->createNew();
     $review->setTitle('title');
     $review->setRating(5);
     $review->setReviewSubject($product);
     $product->addReview($review);
     $this->productReviewRepository->add($review);
 }
Beispiel #12
0
 /**
  * @Given /^there is rest of the world zone containing all other countries$/
  */
 public function thereIsRestOfTheWorldZoneContainingAllOtherCountries()
 {
     $restOfWorldCountries = array_diff(array_keys(Intl::getRegionBundle()->getCountryNames('en')), array_merge($this->euMembers, ['US']));
     $zone = $this->zoneFactory->createWithMembers($restOfWorldCountries);
     $zone->setType(ZoneInterface::TYPE_COUNTRY);
     $zone->setCode('RoW');
     $zone->setName('Rest of the World');
     $this->zoneRepository->add($zone);
 }
Beispiel #13
0
 /**
  * @Given the store classifies its products as :firstTaxonName
  * @Given the store classifies its products as :firstTaxonName and :secondTaxonName
  * @Given the store classifies its products as :firstTaxonName, :secondTaxonName and :thirdTaxonName
  */
 public function storeClassifiesItsProductsAs($firstTaxonName, $secondTaxonName = null, $thirdTaxonName = null)
 {
     foreach ([$firstTaxonName, $secondTaxonName, $thirdTaxonName] as $taxonName) {
         if (null === $taxonName) {
             break;
         }
         $this->taxonRepository->add($this->createTaxon($taxonName));
     }
 }
Beispiel #14
0
 /**
  * @Given catalog has a product :productName priced at $:price
  */
 public function catalogHasAProductPricedAt($productName, $price)
 {
     $product = $this->productFactory->createNew();
     $product->setName($productName);
     $product->setPrice((int) $price);
     $product->setDescription('Awesome star wars mug');
     $channel = $this->sharedStorage->getCurrentResource('channel');
     $product->addChannel($channel);
     $this->productRepository->add($product);
 }
 /**
  * {@inheritdoc}
  */
 public function create()
 {
     $defaultData['channel'] = $this->createChannel();
     $defaultData['zone_member'] = $this->createZoneMember();
     $defaultData['zone'] = $this->createZone($defaultData['zone_member']);
     $this->channelRepository->add($defaultData['channel']);
     $this->zoneRepository->add($defaultData['zone']);
     $this->zoneMemberRepository->add($defaultData['zone_member']);
     return $defaultData;
 }
 /**
  * @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;
 }
Beispiel #17
0
 /**
  * @Given store allows paying offline
  */
 public function storeAllowsPayingOffline()
 {
     $paymentMethod = $this->paymentMethodFactory->createNew();
     $paymentMethod->setCode('PM1');
     $paymentMethod->setGateway('dummy');
     $paymentMethod->setName('Offline');
     $paymentMethod->setDescription('Offline payment method');
     $channel = $this->sharedStorage->getCurrentResource('channel');
     $channel->addPaymentMethod($paymentMethod);
     $this->paymentMethodRepository->add($paymentMethod);
 }
Beispiel #18
0
 /**
  * @Given the store allows paying :paymentMethodName
  */
 public function storeAllowsPaying($paymentMethodName)
 {
     $paymentMethod = $this->paymentMethodFactory->createNew();
     $paymentMethod->setCode('PM_' . $paymentMethodName);
     $paymentMethod->setName(ucfirst($paymentMethodName));
     $paymentMethod->setGateway($this->paymentMethodNameToGatewayConverter->convert($paymentMethodName));
     $paymentMethod->setDescription('Payment method');
     $channel = $this->sharedStorage->get('channel');
     $channel->addPaymentMethod($paymentMethod);
     $this->paymentMethodRepository->add($paymentMethod);
 }
 function it_configures_shipping_destination_countries(FactoryInterface $countryFactory, RepositoryInterface $countryRepository, CountryInterface $australia, CountryInterface $china, CountryInterface $france)
 {
     $countryFactory->createNew()->willReturn($australia, $china, $france);
     $australia->setCode('AU')->shouldBeCalled();
     $china->setCode('CN')->shouldBeCalled();
     $france->setCode('FR')->shouldBeCalled();
     $countryRepository->add($australia)->shouldBeCalled();
     $countryRepository->add($china)->shouldBeCalled();
     $countryRepository->add($france)->shouldBeCalled();
     $this->storeShipsTo('Australia', 'China', 'France');
 }
Beispiel #20
0
 /**
  * @Given the store has :taxRateName tax rate of :taxRateAmount% for :taxCategoryName within :zone zone
  * @Given /^the store has "([^"]+)" tax rate of ([^"]+)% for "([^"]+)" for (the rest of the world)$/
  */
 public function storeHasTaxRateWithinZone($taxRateName, $taxRateAmount, $taxCategoryName, ZoneInterface $zone)
 {
     $taxCategory = $this->getOrCreateTaxCategory($taxCategoryName);
     $taxRate = $this->taxRateFactory->createNew();
     $taxRate->setName($taxRateName);
     $taxRate->setCode($this->getCodeFromNameAndZoneCode($taxRateName, $zone->getCode()));
     $taxRate->setZone($zone);
     $taxRate->setAmount($this->getAmountFromString($taxRateAmount));
     $taxRate->setCategory($taxCategory);
     $taxRate->setCalculator('default');
     $this->taxRateRepository->add($taxRate);
 }
 /**
  * @param string $shippingCategoryName
  * @param string $shippingCategoryCode
  */
 private function createShippingCategory($shippingCategoryName, $shippingCategoryCode = null)
 {
     /** @var ShippingCategoryInterface $shippingCategory */
     $shippingCategory = $this->shippingCategoryFactory->createNew();
     $shippingCategory->setName($shippingCategoryName);
     $shippingCategory->setCode($shippingCategoryCode);
     if (null === $shippingCategoryCode) {
         $shippingCategory->setCode(StringInflector::nameToCode($shippingCategoryName));
     }
     $this->shippingCategoryRepository->add($shippingCategory);
     $this->sharedStorage->set('shipping_category', $shippingCategory);
 }
Beispiel #22
0
 /**
  * @Given store has free shipping method
  */
 public function storeHasFreeShippingMethod()
 {
     $zone = $this->sharedStorage->getCurrentResource('zone');
     $shippingMethod = $this->shippingMethodFactory->createNew();
     $shippingMethod->setCode('SM1');
     $shippingMethod->setName('Free');
     $shippingMethod->setCurrentLocale('FR');
     $shippingMethod->setConfiguration(array('amount' => 0));
     $shippingMethod->setCalculator(DefaultCalculators::PER_ITEM_RATE);
     $shippingMethod->setZone($zone);
     $this->shippingMethodRepository->add($shippingMethod);
 }
Beispiel #23
0
 /**
  * {@inheritdoc}
  */
 public function setup(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper)
 {
     $code = $this->getCurrencyCodeFromUser($input, $output, $questionHelper);
     $existingCurrency = $this->currencyRepository->findOneBy(['code' => $code]);
     if (null !== $existingCurrency) {
         return $existingCurrency;
     }
     /** @var CurrencyInterface $currency */
     $currency = $this->currencyFactory->createNew();
     $currency->setCode($code);
     $this->currencyRepository->add($currency);
     return $currency;
 }
 function it_creates_three_taxons_with_given_name(FactoryInterface $taxonFactory, RepositoryInterface $taxonRepository, TaxonInterface $firstTaxon, TaxonInterface $secondTaxon, TaxonInterface $thirdTaxon)
 {
     $taxonFactory->createNew()->willReturn($firstTaxon, $secondTaxon, $thirdTaxon);
     $firstTaxon->setName('Swords')->shouldBeCalled();
     $firstTaxon->setCode('swords')->shouldBeCalled();
     $secondTaxon->setName('Composite bows')->shouldBeCalled();
     $secondTaxon->setCode('composite_bows')->shouldBeCalled();
     $thirdTaxon->setName('Axes')->shouldBeCalled();
     $thirdTaxon->setCode('axes')->shouldBeCalled();
     $taxonRepository->add($firstTaxon)->shouldBeCalled();
     $taxonRepository->add($secondTaxon)->shouldBeCalled();
     $taxonRepository->add($thirdTaxon)->shouldBeCalled();
     $this->storeClassifiesItsProductsAs('Swords', 'Composite bows', 'Axes');
 }
Beispiel #25
0
 /**
  * {@inheritdoc}
  */
 public function setup(InputInterface $input, OutputInterface $output)
 {
     $name = $this->getLanguageName($this->locale);
     $output->writeln(sprintf('Adding <info>%s</info> locale.', $name));
     $existingLocale = $this->localeRepository->findOneBy(['code' => $this->locale]);
     if (null !== $existingLocale) {
         return $existingLocale;
     }
     /** @var LocaleInterface $locale */
     $locale = $this->localeFactory->createNew();
     $locale->setCode($this->locale);
     $this->localeRepository->add($locale);
     return $locale;
 }
Beispiel #26
0
 /**
  * @Given there is user :email identified by :password
  */
 public function thereIsUserIdentifiedBy($email, $password)
 {
     /** @var UserInterface $user */
     $user = $this->userFactory->createNew();
     $customer = $this->customerFactory->createNew();
     $customer->setFirstName('John');
     $customer->setLastName('Doe');
     $user->setCustomer($customer);
     $user->setUsername('John Doe');
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->addRole('ROLE_USER');
     $this->sharedStorage->setCurrentResource('user', $user);
     $this->userRepository->add($user);
 }
Beispiel #27
0
 /**
  * @param Request $request
  *
  * @return Response
  */
 public function createAction(Request $request)
 {
     $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
     $this->isGrantedOr403($configuration, ResourceActions::CREATE);
     $newResource = $this->newResourceFactory->create($configuration, $this->factory);
     $form = $this->resourceFormFactory->create($configuration, $newResource);
     if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
         $newResource = $form->getData();
         $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource);
         if ($event->isStopped() && !$configuration->isHtmlRequest()) {
             throw new HttpException($event->getErrorCode(), $event->getMessage());
         }
         if ($event->isStopped()) {
             $this->flashHelper->addFlashFromEvent($configuration, $event);
             return $this->redirectHandler->redirectToIndex($configuration, $newResource);
         }
         if ($configuration->hasStateMachine()) {
             $this->stateMachine->apply($configuration, $newResource);
         }
         $this->repository->add($newResource);
         $this->eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource);
         if (!$configuration->isHtmlRequest()) {
             return $this->viewHandler->handle($configuration, View::create($newResource, Response::HTTP_CREATED));
         }
         $this->flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource);
         return $this->redirectHandler->redirectToResource($configuration, $newResource);
     }
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create($form, Response::HTTP_BAD_REQUEST));
     }
     $view = View::create()->setData(['configuration' => $configuration, 'metadata' => $this->metadata, 'resource' => $newResource, $this->metadata->getName() => $newResource, 'form' => $form->createView()])->setTemplate($configuration->getTemplate(ResourceActions::CREATE . '.html'));
     return $this->viewHandler->handle($configuration, $view);
 }
 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();
 }
Beispiel #29
0
 /**
  * @Given the store has a zone :zoneName with code :code
  * @Given the store also has a zone :zoneName with code :code
  */
 public function theStoreHasAZoneWithCode($zoneName, $code)
 {
     $zone = $this->zoneFactory->createTyped(ZoneInterface::TYPE_ZONE);
     $zone->setCode($code);
     $zone->setName($zoneName);
     $this->sharedStorage->set('zone', $zone);
     $this->zoneRepository->add($zone);
 }
 function it_creates_new_customer_if_it_does_not_exist(CustomerInterface $customer, FactoryInterface $customerFactory, RepositoryInterface $customerRepository)
 {
     $customerRepository->findOneBy(['email' => '*****@*****.**'])->willReturn(null);
     $customerFactory->createNew()->willReturn($customer);
     $customer->setEmail('*****@*****.**')->shouldBeCalled();
     $customerRepository->add($customer)->shouldBeCalled();
     $this->getOrCreateCustomerByEmail('*****@*****.**')->shouldReturn($customer);
 }