News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

cloudzoom

Started by FusionNetwork, July 22, 2015, 09:10:32 AM

Previous topic - Next topic

FusionNetwork

Hello,

I am trying to adapt a cloudzoom vm 2 plugin to vm3 but i think i am missing something.
I think the problem is with the functions getMainImage() and getAddImages(). They are not getting the images urls.

Can anyone sugest something?

Here is the code
defined('JPATH_BASE') or die;

jimport('joomla.application.component.helper');
class PlgSystemVmCloudZoom extends JPlugin{

public function onBeforeRender() {
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$view = JRequest::getVar('view');
if ($app->isAdmin()){
return true;
}
if ($view !='productdetails'){
return true;
}
$pluginLivePath = JURI::root(true).'/plugins/system/vmcloudzoom/';
$show_jquery = $this->params->get('show_jquery',1);
if($show_jquery==1){
$doc->addScript($pluginLivePath.'js/jquery-1.6.js');
}
$doc->addScript($pluginLivePath.'js/cloud-zoom.1.0.2.js');
$doc->addStyleSheet($pluginLivePath.'css/cloud-zoom.css');
}
public function onAfterRender() {
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$view = JRequest::getVar('view');
if ($app->isAdmin()){
return true;
}
if ($view !='productdetails'){
return true;
}

$buffer = JResponse::getBody();
$regx = '/<div class="main-image thumbnail">([^`]*?)<\/div>/';
$regx2 = '/<div class="thumbnail col-md-1 col-xs-3">([^`]*?)<\/div>/';
$regx3 = '/<div class="additional-images row">/';
$getMainImage = $this->getMainImage();
$getAddImages = $this->getAddImages();

$buffer = preg_replace($regx2,'',$buffer);
$buffer = preg_replace($regx3,$getAddImages,$buffer);
$buffer = preg_replace($regx,$getMainImage,$buffer);
JResponse::setBody($buffer);

return true;
}

function getCustomJs(){
$zoomWidth = trim($this->params->get('zoomWidth',250));
$zoomHeight = trim($this->params->get('zoomHeight',250));
$xOffset = trim($this->params->get('xOffset',10));
$yOffset = trim($this->params->get('yOffset',0));
$position = $this->params->get('position','right');
$tint = $this->params->get('tint','#aa00aa');
$tintOpacity = $this->params->get('tintOpacity',0.5);
$lensOpacity = $this->params->get('lensOpacity',0.5);
$softFocus = $this->params->get('softFocus',1);
if($softFocus==1){$softFocus ="true";}else{$softFocus ="false";}
$smoothMove = $this->params->get('smoothMove',3);
$showTitle = $this->params->get('showTitle',1);
if($showTitle==1){$showTitle ="true";}else{$showTitle ="false";}
$titleOpacity = trim($this->params->get('titleOpacity',0.5));


$custome_js  = "";
$custome_js  .= "zoomWidth: ".$zoomWidth.",";
        $custome_js  .= "zoomHeight: ".$zoomHeight.",";
        $custome_js  .= "position: '".$position."',";
        $custome_js  .= "tint: '".$tint."',";
        $custome_js  .= "tintOpacity: ".$tintOpacity.",";
        $custome_js  .= "lensOpacity: ".$lensOpacity.",";
        $custome_js  .= "softFocus: ".$softFocus.",";
        $custome_js  .= "smoothMove: ".$smoothMove.",";
        $custome_js  .= "showTitle: ".$showTitle.",";
        $custome_js  .= "titleOpacity: ".$titleOpacity.",";
        $custome_js  .= "adjustX: ".$xOffset.",";
        $custome_js  .= "adjustY: ".$yOffset;

return $custome_js;

}

function getMainImage(){
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
$config = VmConfig::loadConfig();
$pluginLivePath = JURI::root(true).'/plugins/system/vmcloudzoom/';
$product_model = VmModel::getModel('product');
$virtuemart_product_id = JRequest::getInt('virtuemart_product_id', 0);
$product = $product_model->getProduct($virtuemart_product_id);
$images = $product->images;
$main_image_url = $images[0]->file_url;// [file_title][file_description][file_meta]
$main_image_title = $images[0]->file_title;// [file_title][file_description][file_meta]
$main_image_description = $images[0]->file_description;// [file_title][file_description][file_meta]
$main_image_alt = $images[0]->file_meta;// [file_title][file_description][file_meta]
$product_name = $product->product_name;

$j = count($images);
$imageWidth = trim($this->params->get('imageWidth',350));
if($imageWidth==''){$imageWidth = 'auto';}
$imageHeight = trim($this->params->get('imageHeight'));
if($imageHeight==''){$imageHeight = 'auto';}

//add HTML

$html = "";
$html .= "<div class=\"clearfix\">";
$html .= "<div class=\"main-image\">";
$html .= "<a id='zoom1' href=\"$main_image_url\" class=\"cloud-zoom\" data-rokbox=\"\" data-rokbox-caption=\"$product_name\" data-rokbox-album=\"$product_name\" rel=\"".$this->getCustomJs()."\"  title=\"$product_name\" >";
$html .= "<img width=\"".$imageWidth."\" height=\"".$imageHeight."\" src=\"$main_image_url\"  title=\"$product_name \"  style=\"border: 2px solid #666;\" alt=\"$product_name\" />Mareste imaginea";
$html .= "</a>";
$html .= "</div>";
$html .= "<br/>";
$html .= "</div>";
    return $html;
}


function getAddImages(){
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
$config = VmConfig::loadConfig();
$pluginLivePath = JURI::root(true).'/plugins/system/vmcloudzoom/';
$product_model = VmModel::getModel('product');
$virtuemart_product_id = JRequest::getInt('virtuemart_product_id', 0);
$product = $product_model->getProduct($virtuemart_product_id);
$images = $product->images;
$main_image_url = JURI::root(true). $images[0]->file_url;// [file_title][file_description][file_meta]
$main_image_title = $images[0]->file_title;// [file_title][file_description][file_meta]
$main_image_description = $images[0]->file_description;// [file_title][file_description][file_meta]
$main_image_alt = $images[0]->file_meta;// [file_title][file_description][file_meta]
$product_name = $product->product_name;

$j = count($images);
$thumbimageWidth = trim($this->params->get('thumbimageWidth',75));
if($thumbimageWidth==''){$thumbimageWidth = 'auto';}
$thumbimageHeight = trim($this->params->get('thumbimageHeight',75));
if($thumbimageHeight==''){$thumbimageHeight = 'auto';}
//add HTML

$html = "";
$html .= "<div class=\"clearfix\">";
$html .= "<div class=\"additional-images\">";
$html .= "<div class=\"floatleft\"><a href='".JURI::root().'/'.$images[0]->file_url."' class='cloud-zoom-gallery' data-rokbox=\"\" data-rokbox-caption=\"$product_name\" data-rokbox-album=\"$product_name\" title='$product_name\' rel=\"useZoom: 'zoom1', smallImage: '".JURI::root().'/'.$images[0]->file_url."' \"><img style=\"width:".$thumbimageWidth."px !important;height:".$thumbimageHeight."px !important;\" src='".JURI::root().'/'.$images[0]->file_url_thumb."' alt = \"$product_name\"/></a></div>";
if($j >1){
for($i=1; $i<$j; $i++){
$html .= "<div class=\"floatleft\"><a href='".JURI::root().'/'.$images[$i]->file_url."' class='cloud-zoom-gallery' data-rokbox=\"\" data-rokbox-caption=\"$product_name\" data-rokbox-album=\"$product_name\" title='$product_name\' rel=\"useZoom: 'zoom1', smallImage: '".JURI::root().'/'.$images[$i]->file_url."' \"><img style=\"width:".$thumbimageWidth."px !important;height:".$thumbimageHeight."px !important;\" src='".JURI::root().'/'.$images[$i]->file_url_thumb."' alt = \"$product_name\"/></a></div>";
}
}
$html .= "</div>";

    return $html;
}


}