From 01b088370cfa163135a5481c49fe8663d6042354 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Thu, 4 Apr 2013 12:20:14 +0200 Subject: [PATCH] [-] FO : Fix bug #PSCFV-7743 and #PSCFV-8286, bigpic source change --- controllers/front/ProductController.php | 59 ++++++++++++++++++++----- themes/default/js/product.js | 50 ++++++++++++--------- themes/default/product.tpl | 17 +++---- 3 files changed, 86 insertions(+), 40 deletions(-) diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 202801041..989c59ee3 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -340,26 +340,39 @@ class ProductControllerCore extends FrontController { $images = $this->product->getImages((int)$this->context->cookie->id_lang); $product_images = array(); + + if(isset($images[0])) + $this->context->smarty->assign('mainImage', $images[0]); foreach ($images as $k => $image) { if ($image['cover']) { - $this->context->smarty->assign('mainImage', $images[0]); + $this->context->smarty->assign('mainImage', $image); $cover = $image; $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$image['id_image']) : $image['id_image']); $cover['id_image_only'] = (int)$image['id_image']; } $product_images[(int)$image['id_image']] = $image; } + if (!isset($cover)) - $cover = array( - 'id_image' => $this->context->language->iso_code.'-default', - 'legend' => 'No picture', - 'title' => 'No picture' + { + if(isset($images[0])) + { + $cover = $images[0]; + $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$images[0]['id_image']) : $images[0]['id_image']); + $cover['id_image_only'] = (int)$images[0]['id_image']; + } + else + $cover = array( + 'id_image' => $this->context->language->iso_code.'-default', + 'legend' => 'No picture', + 'title' => 'No picture' ); + } $size = Image::getSize(ImageType::getFormatedName('large')); $this->context->smarty->assign(array( - 'have_image' => Product::getCover((int)Tools::getValue('id_product')), + 'have_image' => isset($cover['id_image'])? array((int)$cover['id_image']) : Product::getCover((int)Tools::getValue('id_product')), 'cover' => $cover, 'imgWidth' => (int)$size['width'], 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), @@ -432,11 +445,37 @@ class ProductControllerCore extends FrontController else $combinations[$row['id_product_attribute']]['available_date'] = ''; - if (isset($combination_images[$row['id_product_attribute']][0]['id_image'])) - $combinations[$row['id_product_attribute']]['id_image'] = $combination_images[$row['id_product_attribute']][0]['id_image']; - else + if (!isset($combination_images[$row['id_product_attribute']][0]['id_image'])) $combinations[$row['id_product_attribute']]['id_image'] = -1; + else + { + $combinations[$row['id_product_attribute']]['id_image'] = $id_image = (int)$combination_images[$row['id_product_attribute']][0]['id_image']; + if ($row['default_on'] && $id_image > 0) + { + if (isset($this->context->smarty->tpl_vars['images']->value)) + $product_images = $this->context->smarty->tpl_vars['images']->value; + if (is_array($product_images) && isset($product_images[$id_image])) + { + $product_images[$id_image]['cover'] = 1; + $this->context->smarty->assign('mainImage', $product_images[$id_image]); + if (count($product_images)) + $this->context->smarty->assign('images', $product_images); + } + if (isset($this->context->smarty->tpl_vars['cover']->value)) + $cover = $this->context->smarty->tpl_vars['cover']->value; + if (is_array($cover) && is_array($product_images)) + { + $product_images[$cover['id_image']]['cover'] = 0; + if (isset($product_images[$id_image])) + $cover = $product_images[$id_image]; + $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$id_image) : (int)$id_image); + $cover['id_image_only'] = (int)$id_image; + $this->context->smarty->assign('cover', $cover); + } + } + } } + // wash attributes list (if some attributes are unavailables and if allowed to wash it) if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) { @@ -616,4 +655,4 @@ class ProductControllerCore extends FrontController } return $specific_prices; } -} +} \ No newline at end of file diff --git a/themes/default/js/product.js b/themes/default/js/product.js index 7e2ae97a3..755ba2024 100644 --- a/themes/default/js/product.js +++ b/themes/default/js/product.js @@ -118,7 +118,7 @@ function findCombination(firstTime) //show the large image in relation to the selected combination if (combinations[combination]['image'] && combinations[combination]['image'] != -1) - displayImage($('.thumb_' + combinations[combination]['image']).parent()); + displayImage($('#thumb_' + combinations[combination]['image']).parent()); //show discounts values according to the selected combination if (combinations[combination]['idCombination'] && combinations[combination]['idCombination'] > 0) @@ -418,8 +418,12 @@ function displayImage(domAAroundImgThumb, no_animation) if (domAAroundImgThumb.attr('href')) { var newSrc = domAAroundImgThumb.attr('href').replace('thickbox','large'); - if ($('#bigpic').attr('src') != newSrc) + if(typeof(bigpicSrc) == 'undefined' || bigpicSrc == '') + bigpicSrc = $('#bigpic').attr('src'); + if (bigpicSrc != newSrc) { + //fadeOut is too slow, displayImage can be called again before bigpic source has really changed so we use a global bigpicSrc + bigpicSrc = newSrc; $('#bigpic').fadeOut((no_animation ? 0 : 'fast'), function(){ $(this).attr('src', newSrc).show(); if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled) @@ -468,24 +472,29 @@ function serialScrollFixLock(event, targeted, scrolled, items, position) function refreshProductImages(id_product_attribute) { $('#thumbs_list_frame').scrollTo('li:eq(0)', 700, {axis:'x'}); - $('#thumbs_list li').hide(); + id_product_attribute = parseInt(id_product_attribute); - if (typeof(combinationImages) != 'undefined' && typeof(combinationImages[id_product_attribute]) != 'undefined') + if (id_product_attribute > 0 && typeof(combinationImages) != 'undefined' && typeof(combinationImages[id_product_attribute]) != 'undefined') { + $('#thumbs_list li').hide(); + $('#thumbs_list').trigger('goto', 0); for (var i = 0; i < combinationImages[id_product_attribute].length; i++) $('#thumbnail_' + parseInt(combinationImages[id_product_attribute][i])).show(); - } - if (i > 0) - { - var thumb_width = $('#thumbs_list_frame >li').width() + parseInt($('#thumbs_list_frame >li').css('marginRight')); - $('#thumbs_list_frame').width((parseInt((thumb_width)* i) + 3) + 'px'); // Bug IE6, needs 3 pixels more ? + if (parseInt($('#thumbs_list_frame >li').length) != parseInt($('#thumbs_list_frame >li:visible').length)) + $('#wrapResetImages').show('slow'); + else + $('#wrapResetImages').hide('slow'); } else { - $('#thumbnail_' + idDefaultImage).show(); - displayImage($('#thumbnail_' + idDefaultImage + ' a')); + $('#thumbs_list li').show(); + if (parseInt($('#thumbs_list_frame >li').length) == parseInt($('#thumbs_list_frame >li:visible').length)) + $('#wrapResetImages').hide('slow'); } + + var thumb_width = $('#thumbs_list_frame >li').width() + parseInt($('#thumbs_list_frame >li').css('marginRight')); + $('#thumbs_list_frame').width((parseInt((thumb_width) * $('#thumbs_list_frame >li').length)) + 'px'); $('#thumbs_list').trigger('goto', 0); serialScrollFixLock('', '', '', '', 0);// SerialScroll Bug on goto 0 ? } @@ -548,6 +557,12 @@ $(document).ready(function() $('#customizedDatas').append(uploading_in_progress); }); + original_url = window.location + ''; + first_url_check = true; + bigpicSrc = $('#bigpic').attr('src'); + checkUrl(); + initLocationChange(); + //init the price in relation of the selected attributes if (typeof productHasAttributes != 'undefined' && productHasAttributes) findCombination(true); @@ -563,11 +578,6 @@ $(document).ready(function() 'transitionIn' : 'elastic', 'transitionOut' : 'elastic' }); - original_url = window.location + ''; - first_url_check = true; - checkUrl(); - initLocationChange(); - }); function saveCustomization() @@ -668,12 +678,12 @@ function getProductAttribute() function initLocationChange(time) { if(!time) time = 500; - setInterval(checkUrl, time); + setInterval(checkUrl, time); } function checkUrl() { - if (original_url != window.url || first_url_check) + if (original_url != window.location || first_url_check) { first_url_check = false; url = window.location + ''; @@ -710,11 +720,11 @@ function checkUrl() if (count >= 0) { findCombination(false); - original_url = window.location + ''; + original_url = url; } // no combination found = removing attributes from url else window.location = url.substring(0, url.indexOf('#')); } } -} +} \ No newline at end of file diff --git a/themes/default/product.tpl b/themes/default/product.tpl index b90d51a88..decb643cc 100644 --- a/themes/default/product.tpl +++ b/themes/default/product.tpl @@ -201,7 +201,7 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving {assign var=imageIds value="`$product->id`-`$image.id_image`"}
  • - {$image.legend|htmlspecialchars} + {$image.legend|htmlspecialchars}
  • {/foreach} @@ -285,7 +285,7 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving {assign var="groupName" value="group_$id_attribute_group"}
    {if ($group.group_type == 'select')} - {foreach from=$group.attributes key=id_attribute item=group_attribute} {/foreach} @@ -295,9 +295,9 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving {assign var="default_colorpicker" value=""} {foreach from=$group.attributes key=id_attribute item=group_attribute} - + {if file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')} - {$colors.$id_attribute.name}
    + {$colors.$id_attribute.name}
    {/if}
    @@ -311,7 +311,7 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving
      {foreach from=$group.attributes key=id_attribute item=group_attribute}
    • - + {$group_attribute|escape:'htmlall':'UTF-8'}
    • {/foreach} @@ -613,7 +613,7 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving {if $field.type == 1}
    • - +
    • {counter} {/if} @@ -636,13 +636,10 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving
    {/if} - {if isset($packItems) && $packItems|@count > 0}

    {l s='Pack content'}

    {include file="$tpl_dir./product-list.tpl" products=$packItems}
    {/if} - -{/if} - +{/if} \ No newline at end of file