diff --git a/modules/product/src/ProductVariationStorage.php b/modules/product/src/ProductVariationStorage.php index db5b989..7332b0e 100644 --- a/modules/product/src/ProductVariationStorage.php +++ b/modules/product/src/ProductVariationStorage.php @@ -7,6 +7,14 @@ use Drupal\commerce_product\Entity\ProductInterface; use Drupal\commerce_product\Event\FilterVariationsEvent; use Drupal\commerce_product\Event\ProductEvents; use Drupal\commerce_product\Entity\ProductVariation; +use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\Request; /** * Defines the product variation storage. @@ -14,6 +22,52 @@ use Drupal\commerce_product\Entity\ProductVariation; class ProductVariationStorage extends CommerceContentEntityStorage implements ProductVariationStorageInterface { /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $currentRequest; + + /** + * Constructs a new object. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param \Drupal\Core\Database\Connection $database + * The database connection to be used. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. + * @param \Drupal\Core\Cache\CacheBackendInterface $cache + * The cache backend to be used. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * The event dispatcher. + * @param \Symfony\Component\HttpFoundation\Request $current_request + * The current Request + */ + public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, EventDispatcherInterface $event_dispatcher, Request $current_request) { + parent::__construct($entity_type, $database, $entity_manager, $cache, $language_manager, $event_dispatcher); + + $this->currentRequest = $current_request; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('database'), + $container->get('entity.manager'), + $container->get('cache.entity'), + $container->get('language_manager'), + $container->get('event_dispatcher'), + $container->get('request_stack')->getCurrentRequest() + ); + } + + /** * {@inheritdoc} */ public function loadEnabled(ProductInterface $product) { @@ -51,7 +105,7 @@ class ProductVariationStorage extends CommerceContentEntityStorage implements Pr * The product variation if found. */ public function getVariationFromContext(ProductInterface $entity) { - if ($variation_id = \Drupal::requestStack()->getCurrentRequest()->query->get('v')) { + if ($variation_id = $this->currentRequest->query->get('v')) { $available_variations = $entity->getVariations(); if (array_key_exists($variation_id, $available_variations)) { return ProductVariation::load($variation_id);