/** * @dataProvider dataForVariationWithSwatchImage */ public function testLoadFirstVariationWithSwatchImage($imageTypes, $expected, $requiredAttributes) { $this->getSwatchAttributes($this->productMock); $this->getUsedProducts($imageTypes + $requiredAttributes); $result = $this->swatchHelperObject->loadFirstVariationWithSwatchImage($this->productMock, $requiredAttributes); if ($expected === false) { $this->assertFalse($result); } else { $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Product', $result); } }
/** * Generate Product Media array * * @param string $attributeCode * @param integer $optionId * @return array */ protected function getVariationMedia($attributeCode, $optionId) { $variationProduct = $this->swatchHelper->loadFirstVariationWithSwatchImage($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; }
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->loadFirstVariationWithSwatchImage($currentConfigurable, $resultAttributes); } if (!$product) { $product = $this->swatchHelper->loadFirstVariationWithImage($currentConfigurable, $resultAttributes); } return $product; }
/** * Generate Product Media array * * @param string $attributeCode * @param integer $optionId * @return array */ protected function getVariationMedia($attributeCode, $optionId) { $variationProduct = $this->swatchHelper->loadFirstVariationWithSwatchImage($this->getProduct(), [$attributeCode => $optionId]); $variationMediaArray = []; if ($variationProduct) { $variationMediaArray = ['value' => $this->getSwatchProductImage($variationProduct, 'swatch_image'), 'thumb' => $this->getSwatchProductImage($variationProduct, 'swatch_thumb')]; } return $variationMediaArray; }
public function testLoadFirstVariationWithSwatchImageWithoutProduct() { $this->swatchHelperObject->loadFirstVariationWithSwatchImage($this->productMock, 'color', 31); }