/** * @Transform /^"([^"]+)" variant of product "([^"]+)"$/ */ public function getProductVariantByNameAndProduct($variantName, $productName) { $products = $this->productRepository->findByName($productName, 'en_US'); Assert::eq(1, count($products), sprintf('%d products has been found with name "%s".', count($products), $productName)); $productVariants = $this->productVariantRepository->findByNameAndProduct($variantName, 'en_US', $products[0]); Assert::notEmpty($productVariants, sprintf('Product variant with name "%s" of product "%s" does not exist', $variantName, $productName)); return $productVariants[0]; }
/** * @Transform /^"([^"]+)" variant of product "([^"]+)"$/ */ public function getProductVariantByNameAndProduct($variantName, $productName) { $products = $this->productRepository->findByName($productName, 'en_US'); Assert::eq(1, count($products), sprintf('%d products has been found with name "%s".', count($products), $productName)); $productVariant = $this->productVariantRepository->findOneBy(['name' => $variantName, 'product' => $products[0]]); if (null === $productVariant) { throw new \InvalidArgumentException(sprintf('Product variant with name "%s" of product "%s" does not exist', $variantName, $productName)); } return $productVariant; }
/** * @Transform /^product(?:|s) "([^"]+)"$/ * @Transform /^"([^"]+)" product(?:|s)$/ * @Transform /^(?:a|an) "([^"]+)"$/ * @Transform :product * @Transform /^"[^"]+" product$/ */ public function getProductByName($productName) { $products = $this->productRepository->findByName($productName, 'en_US'); Assert::eq(1, count($products), sprintf('%d products has been found with name "%s".', count($products), $productName)); return $products[0]; }