/**
  * @dataProvider priceDataProvider
  */
 public function testPriceFinder($currency, $country, $customerGroup, $channel, $result)
 {
     $price = PriceFinder::findPriceFor($this->getPrices(), $currency, $country, is_null($customerGroup) ? null : CustomerGroupReference::ofId($customerGroup), is_null($channel) ? null : ChannelReference::ofId($channel));
     $this->assertSame($result, $price->getValue()->getCentAmount());
 }
 protected function getProductData($cachePrefix, ProductProjection $product, ProductVariant $productVariant, $locale, $includeDetails, $selectSku = null)
 {
     $cacheKey = $cachePrefix . '-' . $productVariant->getSku() . $selectSku . '-' . $locale;
     if ($this->config['cache.products'] && $this->cache->has($cacheKey)) {
         return unserialize($this->cache->fetch($cacheKey));
     }
     $country = \Locale::getRegion($locale);
     $currency = $this->config['currencies.' . $country];
     $productModel = new ViewData();
     $productModelProduct = new ViewData();
     $productModelVariant = new ViewData();
     if (!is_null($productVariant->getPrice())) {
         $price = $productVariant->getPrice();
     } else {
         $price = PriceFinder::findPriceFor($productVariant->getPrices(), $currency, $country);
     }
     if (empty($selectSku)) {
         $productUrl = $this->generator->generate('pdp-master', ['slug' => (string) $product->getSlug()]);
     } else {
         $productUrl = $this->generator->generate('pdp', ['slug' => (string) $product->getSlug(), 'sku' => $productVariant->getSku()]);
     }
     $productModelProduct->variantId = $productVariant->getId();
     $productModelVariant->url = $productUrl;
     $productModelProduct->productId = $product->getId();
     $productModelProduct->slug = (string) $product->getSlug();
     $productModelVariant->name = (string) $product->getName();
     if (!is_null($price->getDiscounted())) {
         $productModelVariant->price = (string) $price->getDiscounted()->getValue();
         $productModelVariant->priceOld = (string) $price->getValue();
     } else {
         $productModelVariant->price = (string) $price->getValue();
     }
     $productModel->sale = isset($productModelVariant->priceOld);
     $productModelProduct->gallery = new ViewData();
     $productModelVariant->image = (string) $productVariant->getImages()->current()->getUrl();
     $productModelProduct->gallery->list = new ViewDataCollection();
     foreach ($productVariant->getImages() as $image) {
         $imageData = new ViewData();
         $imageData->thumbImage = $image->getUrl();
         $imageData->bigImage = $image->getUrl();
         $productModelProduct->gallery->list->add($imageData);
     }
     if ($includeDetails) {
         $productModelVariant->description = (string) $product->getDescription();
         $productType = $this->productTypeRepository->getById($product->getProductType()->getId());
         list($attributes, $variantKeys, $variantIdentifiers) = $this->getVariantSelectors($product, $productType, $selectSku);
         $productModelProduct->variants = $variantKeys;
         $productModelProduct->variantIdentifiers = $variantIdentifiers;
         if ($selectSku || count($variantIdentifiers) == 0) {
             $productModelVariant->variantId = $productVariant->getId();
             $productModelVariant->sku = $productVariant->getSku();
         }
         $productModelProduct->attributes = $attributes;
         $productModelProduct->details = new ViewData();
         $productModelProduct->details->list = new ViewDataCollection();
         $productVariant->getAttributes()->setAttributeDefinitions($productType->getAttributes());
         if (isset($this->config['sunrise.products.details.attributes'][$productType->getName()])) {
             $attributeList = $this->config['sunrise.products.details.attributes.' . $productType->getName()];
             foreach ($attributeList as $attributeName) {
                 $attribute = $productVariant->getAttributes()->getByName($attributeName);
                 if ($attribute) {
                     $attributeDefinition = $productType->getAttributes()->getByName($attributeName);
                     $attributeData = new ViewData();
                     $attributeData->text = (string) $attributeDefinition->getLabel() . ': ' . (string) $attribute->getValue();
                     $productModelProduct->details->list->add($attributeData);
                 }
             }
         }
     }
     $productModel->product = $productModelProduct;
     $productModel->product->variant = $productModelVariant;
     $productModel = $productModel->toArray();
     $this->cache->store($cacheKey, serialize($productModel));
     return $productModel;
 }