/** * {@inheritdoc} */ public function calculate(ProductVariantInterface $productVariant, array $context) { Assert::keyExists($context, 'channel'); $channelPricing = $productVariant->getChannelPricingForChannel($context['channel']); Assert::notNull($channelPricing); return $channelPricing->getPrice(); }
/** * @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; }
/** * Create the tag * * @param string $body Tag body * @param DescriptionFactory $descriptionFactory The description factory * @param Context|null $context The Context is used to resolve Types and FQSENs, although optional * it is highly recommended to pass it. If you omit it then it is assumed that * the DocBlock is in the global namespace and has no `use` statements. * * @return SleepTime */ public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null) { Assert::integerish($body, self::MSG); Assert::greaterThanEq($body, 0, self::MSG); Assert::notNull($descriptionFactory); return new static($descriptionFactory->create($body, $context)); }
/** * @Given /^I am logged in as "([^"]+)" administrator$/ */ public function iAmLoggedInAsAdministrator($email) { $user = $this->userRepository->findOneByEmail($email); Assert::notNull($user); $this->securityService->logIn($user); $this->sharedStorage->set('admin', $user); }
/** * {@inheritdoc} */ public function setPositionOfProduct($productName, $position) { /** @var NodeElement $productsRow */ $productsRow = $this->getElement('table')->find('css', sprintf('tbody > tr:contains("%s")', $productName)); Assert::notNull($productsRow, 'There are no row with given product\'s name!'); $productsRow->find('css', '.sylius-product-taxon-position')->setValue($position); }
/** * Creates a new tag that represents any unknown tag type. * * @param string $body * @param string $name * @param DescriptionFactory $descriptionFactory * @param Context $context * * @return static */ public static function create($body, $name = '', DescriptionFactory $descriptionFactory = null, Context $context = null) { Assert::string($body); Assert::stringNotEmpty($name); Assert::notNull($descriptionFactory); $description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null; return new static($name, $description); }
/** * {@inheritdoc} * * @throws \InvalidArgumentException */ public function update(OrderInterface $order) { $currencyCode = $order->getCurrencyCode(); /** @var CurrencyInterface $currency */ $currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]); Assert::notNull($currency); $order->setExchangeRate($currency->getExchangeRate()); }
/** * {@inheritdoc} */ public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) { Assert::string($body); Assert::notNull($descriptionFactory); $parts = preg_split('/\\s+/Su', $body, 2); $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; return new static($parts[0], $description); }
/** * @Transform /^this order made by "([^"]+)"$/ */ 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); }
/** * @param GenericEvent $event */ public function sendVerificationEmail(GenericEvent $event) { $customer = $event->getSubject(); Assert::isInstanceOf($customer, CustomerInterface::class); $user = $customer->getUser(); Assert::notNull($user); $this->handleUserVerificationToken($user); }
/** * {@inheritdoc} */ public function createForPromotion($promotionId) { /** @var PromotionInterface $promotion */ Assert::notNull($promotion = $this->promotionRepository->find($promotionId), sprintf('Promotion with id %s does not exist.', $promotionId)); Assert::true($promotion->isCouponBased(), sprintf('Promotion with name %s is not coupon based.', $promotion->getName())); $coupon = $this->factory->createNew(); $coupon->setPromotion($promotion); return $coupon; }
/** * {@inheritdoc} */ public function pressDelete() { $this->getDocument()->pressButton('Delete'); $modal = $this->getDocument()->find('css', '#confirmation-modal'); Assert::notNull($modal, 'Confirmation modal not found!'); $confirmButton = $modal->find('css', 'a:contains(Delete)'); $this->waitForModalToAppear($modal); $confirmButton->press(); }
/** * @param Request $request * @param $lastNewPaymentId * * @return Response */ public function prepareCaptureAction(Request $request, $lastNewPaymentId) { $configuration = $this->requestConfigurationFactory->create($this->paymentMetadata, $request); $payment = $this->paymentRepository->find($lastNewPaymentId); Assert::notNull($payment); $request->getSession()->set('sylius_order_id', $payment->getOrder()->getId()); $captureToken = $this->getTokenFactory()->createCaptureToken($payment->getMethod()->getGateway(), $payment, $configuration->getParameters()->get('redirect[route]', null, true), $configuration->getParameters()->get('redirect[parameters]', [], true)); $view = View::createRedirect($captureToken->getTargetUrl()); return $this->viewHandler->handle($configuration, $view); }
/** * @Given /^(my) default address is of "([^"]+)"$/ */ public function myDefaultAddressIsOf(ShopUserInterface $user, $fullName) { list($firstName, $lastName) = explode(' ', $fullName); /** @var AddressInterface $address */ $address = $this->addressRepository->findOneBy(['firstName' => $firstName, 'lastName' => $lastName]); Assert::notNull($address, sprintf('The address of "%s" has not been found.', $fullName)); /** @var CustomerInterface $customer */ $customer = $user->getCustomer(); $this->setDefaultAddressOfCustomer($customer, $address); }
/** * {@inheritdoc} */ public function generate($name, $parentId = null) { $taxonSlug = Transliterator::transliterate($name); if (null === $parentId) { return $taxonSlug; } /** @var TaxonInterface $parent */ $parent = $this->taxonRepository->find($parentId); Assert::notNull($parent, sprintf('There is no parent taxon with id %d.', $parentId)); return $parent->getSlug() . self::SLUG_SEPARATOR . $taxonSlug; }
/** * {@inheritdoc} */ public function getAbbreviation(AddressInterface $address) { if (null !== $address->getProvinceName()) { return $address->getProvinceName(); } if (null === $address->getProvinceCode()) { return ''; } $province = $this->provinceRepository->findOneBy(['code' => $address->getProvinceCode()]); Assert::notNull($province, sprintf('Province with code "%s" not found.', $address->getProvinceCode())); return $province->getAbbreviation() ?: $province->getName(); }
/** * Login form action. */ public function loginAction(Request $request) { $authenticationUtils = $this->get('security.authentication_utils'); $error = $authenticationUtils->getLastAuthenticationError(); $lastUsername = $authenticationUtils->getLastUsername(); $options = $request->attributes->get('_sylius'); $template = isset($options['template']) ? $options['template'] : null; Assert::notNull($template, 'Template is not configured.'); $formType = isset($options['form']) ? $options['form'] : UserLoginType::class; $form = $this->get('form.factory')->createNamed('', $formType); return $this->render($template, ['form' => $form->createView(), 'last_username' => $lastUsername, 'error' => $error]); }
/** * @param Request $request * * @return Response */ public function thankYouAction(Request $request) { $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); $orderId = $request->getSession()->get('sylius_order_id', null); if (null === $orderId) { $options = $configuration->getParameters()->get('after_failure'); return $this->redirectHandler->redirectToRoute($configuration, isset($options['route']) ? $options['route'] : 'sylius_shop_homepage', isset($options['parameters']) ? $options['parameters'] : []); } $request->getSession()->remove('sylius_order_id'); $order = $this->repository->find($orderId); Assert::notNull($order); $view = View::create()->setData(['order' => $order])->setTemplate($configuration->getParameters()->get('template')); return $this->viewHandler->handle($configuration, $view); }
/** * {@inheritdoc} * * @throws \LogicException */ public function getCurrentPageWithForm(array $pages, ProductInterface $product = null) { $resolvedPage = $this->currentPageResolver->getCurrentPageWithForm($pages); if (!$resolvedPage instanceof UpdatePageInterface) { return $resolvedPage; } Assert::notNull($product, 'It is not possible to determine a product edit page without product provided.'); if ($product->isSimple()) { $resolvedPage = $this->getSimplePage($pages); } else { $resolvedPage = $this->getConfigurablePage($pages); } Assert::notNull($resolvedPage, 'Route name could not be matched to provided pages.'); return $resolvedPage; }
/** * {@inheritdoc} */ public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) { Assert::stringNotEmpty($body); Assert::notNull($descriptionFactory); $startingLine = 1; $lineCount = null; $description = null; // Starting line / Number of lines / Description if (preg_match('/^([1-9]\\d*)\\s*(?:((?1))\\s+)?(.*)$/sux', $body, $matches)) { $startingLine = (int) $matches[1]; if (isset($matches[2]) && $matches[2] !== '') { $lineCount = (int) $matches[2]; } $description = $matches[3]; } return new static($startingLine, $lineCount, $descriptionFactory->create($description, $context)); }
/** * @param FactoryInterface $productFactory * @param FactoryInterface $productVariantFactory * @param ProductVariantGeneratorInterface $variantGenerator * @param FactoryInterface $productAttributeValueFactory * @param FactoryInterface $productImageFactory * @param ImageUploaderInterface $imageUploader * @param SlugGeneratorInterface $slugGenerator * @param RepositoryInterface $taxonRepository * @param RepositoryInterface $productAttributeRepository * @param RepositoryInterface $productOptionRepository * @param RepositoryInterface $channelRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $productFactory, FactoryInterface $productVariantFactory, ProductVariantGeneratorInterface $variantGenerator, FactoryInterface $productAttributeValueFactory, FactoryInterface $productImageFactory, ImageUploaderInterface $imageUploader, SlugGeneratorInterface $slugGenerator, RepositoryInterface $taxonRepository, RepositoryInterface $productAttributeRepository, RepositoryInterface $productOptionRepository, RepositoryInterface $channelRepository, RepositoryInterface $localeRepository) { $this->productFactory = $productFactory; $this->productVariantFactory = $productVariantFactory; $this->variantGenerator = $variantGenerator; $this->productImageFactory = $productImageFactory; $this->imageUploader = $imageUploader; $this->slugGenerator = $slugGenerator; $this->localeRepository = $localeRepository; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('short_description', function (Options $options) { return $this->faker->paragraph; })->setDefault('description', function (Options $options) { return $this->faker->paragraphs(3, true); })->setDefault('main_taxon', LazyOption::randomOne($taxonRepository))->setAllowedTypes('main_taxon', ['null', 'string', TaxonInterface::class])->setNormalizer('main_taxon', LazyOption::findOneBy($taxonRepository, 'code'))->setDefault('taxons', LazyOption::randomOnes($taxonRepository, 3))->setAllowedTypes('taxons', 'array')->setNormalizer('taxons', LazyOption::findBy($taxonRepository, 'code'))->setDefault('channels', LazyOption::randomOnes($channelRepository, 3))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($channelRepository, 'code'))->setDefault('product_attributes', [])->setAllowedTypes('product_attributes', 'array')->setNormalizer('product_attributes', function (Options $options, array $productAttributes) use($productAttributeRepository, $productAttributeValueFactory) { $productAttributesValues = []; foreach ($productAttributes as $code => $value) { /** @var ProductAttributeInterface $productAttribute */ $productAttribute = $productAttributeRepository->findOneBy(['code' => $code]); Assert::notNull($productAttribute); /** @var ProductAttributeValueInterface $productAttributeValue */ $productAttributeValue = $productAttributeValueFactory->createNew(); $productAttributeValue->setAttribute($productAttribute); $productAttributeValue->setValue($value ?: $this->getRandomValueForProductAttribute($productAttribute)); $productAttributesValues[] = $productAttributeValue; } return $productAttributesValues; })->setDefault('product_options', [])->setAllowedTypes('product_options', 'array')->setNormalizer('product_options', LazyOption::findBy($productOptionRepository, 'code'))->setDefault('images', [])->setAllowedTypes('images', 'array'); }
/** * {@inheritdoc} */ public function selectShippingMethod($shippingMethod) { $radio = $this->getDocument()->findField($shippingMethod); Assert::notNull($radio, sprintf('Could not find "%s" shipping method', $shippingMethod)); $this->getDocument()->fillField($radio->getAttribute('name'), $radio->getAttribute('value')); }
/** * @Transform /^product option "([^"]+)"$/ * @Transform /^"([^"]+)" option$/ * @Transform :productOption */ public function getProductOptionByName($productOptionName) { $productOption = $this->productOptionRepository->findOneByName($productOptionName); Assert::notNull($productOption, sprintf('Product option with name "%s" does not exist in the product option repository.', $productOptionName)); return $productOption; }
/** * {@inheritdoc} */ public function hasProductInAssociation($productName, $productAssociationName) { $associationHeader = $this->getElement('association', ['%association-name%' => $productAssociationName]); $associations = $associationHeader->getParent()->find('css', '.four'); Assert::notNull($associations); return null !== $associations->find('css', sprintf('.sylius-product-name:contains("%s")', $productName)); }
/** * @Transform /^channel "([^"]+)"$/ * @Transform /^"([^"]+)" channel/ * @Transform /^channel to "([^"]+)"$/ * @Transform :channel */ public function getChannelByName($channelName) { $channel = $this->channelRepository->findOneByName($channelName); Assert::notNull($channel, sprintf('Channel with name "%s" does not exist', $channelName)); return $channel; }
/** * @param string $code */ private function assertCountryCodeIsValid($code) { $country = $this->countryRepository->findOneBy(['code' => $code]); Assert::notNull($country); }
/** * @Transform :taxRate * @Transform /^"([^"]+)" tax rate$/ */ public function getTaxRateByName($taxRateName) { $taxRate = $this->taxRateRepository->findOneBy(['name' => $taxRateName]); Assert::notNull($taxRate, sprintf('Tax rate with name "%s" does not exist', $taxRateName)); return $taxRate; }
/** * @Transform :currency * @Transform /^currency "([^"]+)"$/ * @Transform /^"([^"]+)" currency$/ */ public function getCurrencyByName($currencyName) { $currency = $this->currencyRepository->findOneBy(['code' => $this->getCurrencyCodeByName($currencyName)]); Assert::notNull($currency, sprintf('Currency with name %s does not exist.', $currencyName)); return $currency; }
/** * {@inheritdoc} */ public function getLeaves(TaxonInterface $parentTaxon = null) { $tree = $this->getElement('tree'); Assert::notNull($tree); /** @var NodeElement[] $leaves */ $leaves = $tree->findAll('css', '.item > .content > .header > a'); if (null === $parentTaxon) { return $leaves; } foreach ($leaves as $leaf) { if ($leaf->getText() === $parentTaxon->getName()) { return $leaf->findAll('css', '.item > .content > .header'); } } }
/** * @param array $parameters * * @return ZoneInterface */ private function getZoneBy(array $parameters) { $existingZone = $this->zoneRepository->findOneBy($parameters); Assert::notNull($existingZone, 'Zone does not exist.'); return $existingZone; }