Index: trunk/core/units/general/helpers/image_helper.php =================================================================== diff -u -N -r8686 -r8687 --- trunk/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 8686) +++ trunk/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 8687) @@ -169,9 +169,6 @@ // no images found in POST -> create default image fields $image_names = Array ('PrimaryImage' => ''); $image_count = $this->Application->ConfigValue($prefix.'_MaxImageCount'); - if (!$image_count) { - $image_count = 3; // primary image + 2 additional images - } $created_count = 1; while ($created_count < $image_count) { @@ -187,6 +184,38 @@ $this->Application->setUnitOption($prefix, 'Fields', $fields); $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields); } + + /** + * Puts existing item images (from subitem) to virtual fields (in main item) + * + * @param kCatDBItem $object + */ + function LoadItemImages(&$object) + { + $max_image_count = $this->Application->ConfigValue($object->Prefix.'_MaxImageCount'); + + $sql = 'SELECT * + FROM '.TABLE_PREFIX.'Images + WHERE ResourceId = '.$object->GetDBField('ResourceId').' + ORDER BY ImageId ASC + LIMIT 0, '.(int)$max_image_count; + $item_images = $this->Conn->Query($sql); + + $image_counter = 1; + foreach ($item_images as $item_image) { + $image_path = preg_replace('/^'.preg_quote(IMAGES_PATH, '/').'(.*)/', '\\1', $item_image['ThumbPath']); + if ($item_image['DefaultImg'] == 1 || $item_image['Name'] == 'main') { + // process primary image separately + $object->SetDBField('PrimaryImage', $image_path); + $object->Fields['PrimaryImage']['original_field'] = $item_image['Name']; + continue; + } + + $object->SetDBField('Image'.$image_counter, $image_path); + $object->Fields['Image'.$image_counter]['original_field'] = $item_image['Name']; + $image_counter++; + } + } } ?> \ No newline at end of file