/**
  * @param \Magento\Catalog\Model\Product $parentProduct
  * @param array $filterArray
  * @return bool|\Magento\Catalog\Model\Product
  */
 protected function loadSimpleVariation(\Magento\Catalog\Model\Product $parentProduct, array $filterArray)
 {
     $childProduct = $this->swatchHelperData->loadVariationByFallback($parentProduct, $filterArray);
     if ($childProduct && !$childProduct->getImage()) {
         $childProduct = $this->swatchHelperData->loadFirstVariationImage($parentProduct, $filterArray);
     }
     if (!$childProduct) {
         $childProduct = $parentProduct;
     }
     return $childProduct;
 }
Exemple #2
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;
 }
 /**
  * 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;
 }
 public function testLoadVariationByFallbackWithoutProduct()
 {
     $result = $this->swatchHelperObject->loadFirstVariationImage($this->productMock, ['color' => 31]);
     $this->assertFalse($result);
 }