Пример #1
0
 public function getConfigurableImagesFallbackArray(Mage_Catalog_Model_Product $product, array $imageTypes, $keepFrame = false)
 {
     if (!$product->hasConfigurableImagesFallbackArray()) {
         $mapping = $product->getChildAttributeLabelMapping();
         $mediaGallery = $product->getMediaGallery();
         if (!isset($mediaGallery['images'])) {
             return array();
             //nothing to do here
         }
         // ensure we only attempt to process valid image types we know about
         $imageTypes = array_intersect(array('image', 'small_image'), $imageTypes);
         $imagesByLabel = array();
         $imageHaystack = array_map(function ($value) {
             return Mage_ConfigurableSwatches_Helper_Data::normalizeKey($value['label']);
         }, $mediaGallery['images']);
         // load images from the configurable product for swapping
         foreach ($mapping as $map) {
             $imagePath = null;
             //search by store-specific label and then default label if nothing is found
             $imageKey = array_search($map['label'], $imageHaystack);
             if ($imageKey === false) {
                 $imageKey = array_search($map['default_label'], $imageHaystack);
             }
             //assign proper image file if found
             if ($imageKey !== false) {
                 $imagePath = $mediaGallery['images'][$imageKey]['file'];
             }
             $imagesByLabel[$map['label']] = array('configurable_product' => array(Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_SMALL => null, Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_BASE => null), 'products' => $map['product_ids']);
             if ($imagePath) {
                 $imagesByLabel[$map['label']]['configurable_product'][Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_SMALL] = $this->_resizeProductImage($product, 'small_image', $keepFrame, $imagePath);
                 $imagesByLabel[$map['label']]['configurable_product'][Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_BASE] = $this->_resizeProductImage($product, 'image', $keepFrame, $imagePath);
             }
         }
         $imagesByType = array('image' => array(), 'small_image' => array());
         // iterate image types to build image array, normally one type is passed in at a time, but could be two
         foreach ($imageTypes as $imageType) {
             $keepFrame = $imageType == 'small_image';
             // load image from the configurable product's children for swapping
             /* @var $childProduct Mage_Catalog_Model_Product */
             if ($product->hasChildrenProducts()) {
                 foreach ($product->getChildrenProducts() as $childProduct) {
                     if ($image = $this->_resizeProductImage($childProduct, $imageType, $keepFrame)) {
                         $imagesByType[$imageType][$childProduct->getId()] = $image;
                     }
                 }
             }
             // load image from configurable product for swapping fallback
             if ($image = $this->_resizeProductImage($product, $imageType, $keepFrame, null, true)) {
                 $imagesByType[$imageType][$product->getId()] = $image;
             }
         }
         $array = array('option_labels' => $imagesByLabel, Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_SMALL => $imagesByType['small_image'], Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_BASE => $imagesByType['image']);
         $product->setConfigurableImagesFallbackArray($array);
     }
     return $product->getConfigurableImagesFallbackArray();
 }
Пример #2
0
 /**
  * Determine whether to show an image in the product media gallery
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Varien_Object $image
  * @return bool
  */
 public function filterImageInGallery($product, $image)
 {
     if (!Mage::helper('configurableswatches')->isEnabled()) {
         return true;
     }
     if (!isset($this->_productImageFilters[$product->getId()])) {
         $mapping = call_user_func_array("array_merge_recursive", $product->getChildAttributeLabelMapping());
         $filters = array_unique($mapping['labels']);
         $filters = array_merge($filters, array_map(function ($label) {
             return $label . Mage_ConfigurableSwatches_Helper_Productimg::SWATCH_LABEL_SUFFIX;
         }, $filters));
         $this->_productImageFilters[$product->getId()] = $filters;
     }
     return !in_array(Mage_ConfigurableSwatches_Helper_Data::normalizeKey($image->getLabel()), $this->_productImageFilters[$product->getId()]);
 }
Пример #3
0
 /**
  * Determine whether to show an image in the product media gallery
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Varien_Object $image
  * @return bool
  */
 public function filterImageInGallery($product, $image)
 {
     if (!Mage::helper('configurableswatches')->isEnabled()) {
         return true;
     }
     if (!isset($this->_productImageFilters[$product->getId()])) {
         $mapping = call_user_func_array("array_merge_recursive", $product->getChildAttributeLabelMapping());
         /* Wigman: this goes out: */
         //$filters = array_unique($mapping['labels']);
         /* Wigman: and this comes in (that's because we changed the labels object to include sort_ids) */
         $filters = array();
         foreach ($mapping['labels'] as $index => $label) {
             $filters[$index] = $label['label'];
         }
         $filters = array_unique($filters);
         $filters = array_merge($filters, array_map(function ($label) {
             return $label . Mage_ConfigurableSwatches_Helper_Productimg::SWATCH_LABEL_SUFFIX;
         }, $filters));
         $this->_productImageFilters[$product->getId()] = $filters;
     }
     return !in_array(Mage_ConfigurableSwatches_Helper_Data::normalizeKey($image->getLabel()), $this->_productImageFilters[$product->getId()]);
 }