Пример #1
0
 protected function getProductVariationWithMedia(Product $currentConfigurable, array $attributes)
 {
     $product = null;
     $layeredAttributes = [];
     $configurableAttributes = $this->swatchHelper->getAttributesFromConfigurable($currentConfigurable);
     if ($configurableAttributes) {
         $layeredAttributes = $this->getLayeredAttributesIfExists($configurableAttributes);
     }
     $resultAttributes = array_merge($layeredAttributes, $attributes);
     $product = $this->swatchHelper->loadVariationByFallback($currentConfigurable, $resultAttributes);
     if (!$product || (!$product->getImage() || $product->getImage() == 'no_selection')) {
         $product = $this->swatchHelper->loadFirstVariationSwatchImage($currentConfigurable, $resultAttributes);
     }
     if (!$product) {
         $product = $this->swatchHelper->loadFirstVariationImage($currentConfigurable, $resultAttributes);
     }
     return $product;
 }
Пример #2
0
 /**
  * @dataProvider dataForVariationWithSwatchImage
  */
 public function testLoadFirstVariationSwatchImage($imageTypes, $expected, $requiredAttributes)
 {
     $this->getSwatchAttributes($this->productMock);
     $this->getUsedProducts($imageTypes + $requiredAttributes);
     $result = $this->swatchHelperObject->loadFirstVariationSwatchImage($this->productMock, $requiredAttributes);
     if ($expected === false) {
         $this->assertFalse($result);
     } else {
         $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Product', $result);
     }
 }
Пример #3
0
 /**
  * Generate Product Media array
  *
  * @param string $attributeCode
  * @param integer $optionId
  * @return array
  */
 protected function getVariationMedia($attributeCode, $optionId)
 {
     $variationProduct = $this->swatchHelper->loadFirstVariationSwatchImage($this->getProduct(), [$attributeCode => $optionId]);
     if (!$variationProduct) {
         $variationProduct = $this->swatchHelper->loadFirstVariationImage($this->getProduct(), [$attributeCode => $optionId]);
     }
     $variationMediaArray = [];
     if ($variationProduct) {
         $variationMediaArray = ['value' => $this->getSwatchProductImage($variationProduct, Swatch::SWATCH_IMAGE_NAME), 'thumb' => $this->getSwatchProductImage($variationProduct, Swatch::SWATCH_THUMBNAIL_NAME)];
     }
     return $variationMediaArray;
 }