Page 1 of 1

VirtueMart Link Update for VM 2.0 RC

Posted: 31 Aug 2011, 17:50
by Cleanshooter
I am working on a new site and I am trying to use the latest version of Joomla (1.7.0) with the release candidate for Virtuemart (1.9.8F). In the new version they have done away with flypages in exchange for layout so... the link will no longer work even if I've enabled it in the parameters (options button in Joomla 1.7) and put in the correct product ID. So I am going to try and find a way to fix the connection on my own but it would be great if the developer of Phoca Gallery could help me out by during my adventure to update his great Component!

First things first I have to find when you do the check to look for the virtue mart product so if you could let me know where to start looking that would be great otherwise I'm just going to start poking around until I come across it.

Thanks for the great component and wish me luck I will post any progress I make on this thread.

-Cleanshooter

Re: VirtueMart Link Update for VM 2.0 RC

Posted: 31 Aug 2011, 18:12
by Cleanshooter
Found it virtuemart.php in the administrator/components/com_phocagallery/libraries/phocagallery/virtuemart but comes the hard part... In order to fix this for the new version I'll need to look into the changes that VirtueMart has made to their end of things... this might take a while...

Re: VirtueMart Link Update for VM 2.0 RC

Posted: 31 Aug 2011, 19:06
by Cleanshooter
First thing I'm doing is outputting all the error messages to the page and the first one that comes up is that the "VirtueMart Parser Not Found" Which is bad.

Turns out they removed the virtuemart_parser.php in VM2 so we are going to have to find another way to link to the product description page and to check if the product exists...

Re: VirtueMart Link Update for VM 2.0 RC

Posted: 31 Aug 2011, 20:44
by Jan
Hi, I didn't test the VM 2 yet, this will be tested until VM 2 will be stable - as it is written in MVC, the url to product page must be changed.

Jan

Re: VirtueMart Link Update for VM 2.0 RC

Posted: 31 Aug 2011, 23:48
by Cleanshooter
Since the parser no longer exists I'm going to try and push forward with out it. The next thing it looks for is the virtuemart_config.php file which has move to this location:

JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php'

After that change.... we still can pull the
if (VM_TABLEPREFIX && FLYPAGE) {
$vmPrefixC = VM_TABLEPREFIX;
$flyPageC = FLYPAGE;
$checkStockC = CHECK_STOCK;
$showOutStockC = PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS;
}

Info because the parser is gone... back to the parser issue.

Re: VirtueMart Link Update for VM 2.0 RC

Posted: 01 Sep 2011, 18:27
by Cleanshooter
Hey all got an update for you. I got Phoca Gallery to connect to VirtueMart2 today the link is up and working again. Just needed to redo some database calls to reflect the changes to VirtueMart.

I'm not sure if the menu item selection part works because I'm not using this yet but... I'll let someone who needs it figure it out :)

Here is what you need to do to update to use Phoca Gallery with VM2.

Open up your ftp and go to: joomla_cms>administrator>components>com_phocagallery>libraries>phocagallery>virtuemart
and open up your virtuemart.php and replace the code with-in with the following

Code: Select all

<?php
/*
 * @package Joomla 1.5
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component Phoca Gallery
 * @copyright Copyright (C) Jan Pavelka www.phoca.cz
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * Revised by Joe "Moto' Motacek for VirtueMart 2 RC
 */
defined( '_JEXEC' ) or die( 'Restricted access' );

class PhocaGalleryVirtueMart
{
	function getVmLink($id, &$errorMsg) {
	
		$dbO =& JFactory::getDBO();

		if (is_file( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php')) {
			//echo is_file( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
			require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php' );
		} else {
			$errorMsg = 'VirtueMart Cfg Not Found';
			echo $errorMsg . "</br>";
			return false;
		}
		
		
		if (VM_TABLEPREFIX && FLYPAGE) {     //IDK what this is looking at to be honest :( - Moto
			$vmPrefixC 		= 'virtuemart';  //why would this not be "virtuemart"  I don't think this is a setting you can change during install 
			//plus thisisn't working as a variable in the queries for some reason, I'm no php and mySQL expert though
			
			//$flyPageC		= FLYPAGE;       //Needs to be redone at some point (Changed to VIEW)
			
			//New Database call to find stock of current item
			$stockQuery = 'SELECT product_in_stock FROM  #__'.$vmPrefixC.'_products WHERE virtuemart_product_id =' . (int) $id;
			$dbO->setQuery($stockQuery);
			$result = $dbO->loadObject();
			if (isset($result->product_in_stock)){
				$checkStockC = (int) $result->product_in_stock;
			}
			else {
				$errorMsg = "Could not find product stock";
				echo $errorMsg . "</br>";
				return false;
			}
			
			//New Database call to find we show out of stock products
			$stockQuery = 'SELECT config FROM  #__'.$vmPrefixC.'_configs WHERE virtuemart_config_id = 1';
			$dbO->setQuery($stockQuery);
			$result = $dbO->loadObject();
			if (isset($result->config)){
				//Crappy thing about the config info in the virtuemart database is it's all stored in base64 encrypted values all in the same string so this is going to look stupid
				$OStemp = (string) $result->config;
				$startPOS = strpos($OStemp, 'show_out_of_stock_products');
				$endPOS = strpos($OStemp, '|', $startPOS);
				$endPOS = $endPOS - $startPOS;
				$OStemp = substr($OStemp, $startPOS, $endPOS);
				$OStemp = parse_str($OStemp);
				if($show_out_of_stock_products == "czoxOiIxIjs="){//Means yes
					$showOutStockC = 1;
				}
				else if ($show_out_of_stock_products == "czoxOiIwIjs="){//Means no
					$showOutStockC = 0;
				}
				else{
					$errorMsg = "Could not find cofiguration variable";
					echo $errorMsg . "</br>";
					return false;	
				}
			}
			else {
				$errorMsg = "Could not find configuration variable";
				echo $errorMsg . "</br>";
				return false;
			}
		} 
		else {
			$errorMsg = 'VirtueMart Constants Not Found';
			echo $errorMsg . "</br>";
			return false;
		}

		if( $checkStockC && $showOutStockC != "1") {
		    $checkStockSql = " AND product_in_stock > 0";
	    } 
		else {
			$checkStockSql = '';
		}
		
		// We check publish and if the product is published
		$query = 'SELECT published FROM  #__'.$vmPrefixC.'_products WHERE virtuemart_product_id =' . (int) $id . $checkStockSql;
		$dbO->setQuery($query);
		$publish = $dbO->loadObject();
		
		if (isset($publish->published) && $publish->published == '1') {
			$query = 'SELECT virtuemart_category_id FROM #__'.$vmPrefixC.'_product_categories WHERE virtuemart_product_id = '.(int) $id;
			$dbO->setQuery($query);
			$categoryId = $dbO->loadObject();
		
			if (isset($categoryId->virtuemart_category_id)) {
				
				$itemId		= PhocaGalleryVirtueMart::_getVmItemid(); //Not sure why this is here or what it's really trying to do yet since i'm not using the virtuemart menu 
				
				//the way that I understand MVC the defualt for the productdetail view is set else where so...
				//aslong as we always want the product details we don't need to figure out which flypage our view to use since...
				//the system will automatically use the one that the user selects in the virtuemart settings.
				//That's why I removed the _getFlyPage function no longer necessary
				$vmLink 	= 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $id . '&virtuemart_category_id/' . (int) $categoryId->virtuemart_category_id . '/' . $itemId;
				return $vmLink;
			} 
			else {
				$errorMsg = 'VirtueMart Category Not Found';
				return false;
			}
		
		} 
		else {
			$errorMsg = 'VirtueMart Product Not Found';
			echo $errorMsg . "</br>";
			return false;
		}
	}
	
	function _getVmItemid() {
		// Set Itemid id, exists this link in Menu?
		// I'm not using the VM Meun so I'm probably not going ot fix this :P - Moto
		$menu 	= &JSite::getMenu();
		$itemVM	= $menu->getItems('link', 'index.php?option=com_virtuemart');
		

		if(isset($itemVM[0])) {
			$itemId = $itemVM[0]->id;
		} else {
			$itemId = 0;
		}
	
		return $itemId;
	}
}
Save and enjoy! 8)

-Love Cleanshooter

Re: VirtueMart Link Update for VM 2.0 RC

Posted: 05 Sep 2011, 20:11
by maddop
Hi,
This is great but i've just tried the solution but i'm getting the following error:

Could not find cofiguration variable

when viewing the images within phoca gallery. Any ideas?

Cheers,
Paul.

Re: VirtueMart Link Update for VM 2.0 RC

Posted: 28 Sep 2011, 21:17
by Jan
Hi, the link to VM2 will be added in 3.1

Jan