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

Using google maps in product

Started by nav007_2000, July 23, 2012, 19:59:38 PM

Previous topic - Next topic

nav007_2000

Hello all,
I need some help. My websites lists companies as products with attributes such as address, zip code, telephone number etc. Each company will sell offers (deals). I have set these up as child products.

What I would like to do is show a map of the company.

I have installed the googlemap plugin which requires me to enter mosmap, zip code to show the map.

Question is, how do i obtain the zip code?
I understand I need to edit the default.php file which is under com_virtuemart/views/productdetails/tmpl.

i was looking for the custom field that is shown in the php code but couldn't find it. can someone help me?

ivus

Hi nav007_2000,

Without knowing how your site is set up, you could probably refer to the following post about how to find values from variables/arrays:

http://forum.virtuemart.net/index.php?topic=105404.msg351417#msg351417

And these two posts specifically address custom fields:


I hope this helps.

nav007_2000

HI Ivus
thanks for your reply.

I have Joomla version 1.5.26 and Virutemart 2.0.8e

My site is www.restaurantscoops.com

If you click on restaurants on the left corner and then click on a restaurant.

what you see is details of a restaurant. i have the address fields in the custom fields. i want to take the post code and place it in the following code to generate a google map:



{mosmap address='POSTCODE'|zoom='15'|zoomType='Large'|zoomNew='1'|mapType='Map'|showMaptype='1'|overview='1'|text='<div style=width:200px;height=50px;>Home</div>'}


copying the code into the product detail pages causes a blank screen when i view in a browser.

ivus

Hi nav007_2000,

This is the part you need.

On the PRODUCTS DETAILS page, place this piece of code where you want to display you image. You can run this right at the beginning of the products loop.



  $postcode = 0;
  foreach ($this->product->customfieldsSorted['normal'] as $customfields) :
  if( $customfields->virtuemart_custom_id == X) :
$postcode = $customfields->display;
endif;
  endforeach;



You will need to substitute the X with the ID of the custom field you're looking for. Then you can use your newly acquired variable in your Map code:



  if ($postcode != 0) :
  {mosmap address=''. $postcode .''|zoom='15'|zoomType='Large'|zoomNew='1'|mapType='Map'|showMaptype='1'|overview='1'|text='<div style=width:200px;height=50px;>Home</div>'}
  endif;



I hope this helps.

nav007_2000

thanks Ivus for the reply.

I still get the blank white screen when i input the code

ivus

Have you checked you error.log file?

nav007_2000

Yes I have, nothing in there relating to the products detail page.
Anywhere else i can look?

nav007_2000

Here is the code from the products detail page. Where can I add the code to?

<?php
/**
 *
 * Show the product details page
 *
 * @package VirtueMart
 * @subpackage
 * @author Max Milbers, Eugen Stranz
 * @author RolandD,
 * @todo handle child products
 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: default.php 6246 2012-07-09 19:00:20Z Milbo $
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

// addon for joomla modal Box
JHTML::_('behavior.modal');
// JHTML::_('behavior.tooltip');
$url JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=askquestion&virtuemart_product_id=' $this->product->virtuemart_product_id '&virtuemart_category_id=' $this->product->virtuemart_category_id '&tmpl=component');
$document JFactory::getDocument();
$document->addScriptDeclaration("
jQuery(document).ready(function($) {
$('a.ask-a-question').click( function(){
$.facebox({
iframe: '" 
$url "',
rev: 'iframe|550|550'
});
return false ;
});
/* $('.additional-images a').mouseover(function() {
var himg = this.href ;
var extension=himg.substring(himg.lastIndexOf('.')+1);
if (extension =='png' || extension =='jpg' || extension =='gif') {
$('.main-image img').attr('src',himg );
}
console.log(extension)
});*/
});
"
);
/* Let's see if we found the product */


  
if (empty($this->product)) {
    echo 
JText::_('COM_VIRTUEMART_PRODUCT_NOT_FOUND');
    echo 
'<br /><br />  ' $this->continue_link_html;
    return;
}
?>




<div class="productdetails-view">

    <?php
    
// Product Navigation
    
if (VmConfig::get('product_navigation'1)) {
?>

        <div class="product-neighbours">
    <?php
    if (!empty(
$this->product->neighbours ['previous'][0])) {
$prev_link JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' $this->product->neighbours ['previous'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' $this->product->virtuemart_category_id);
echo JHTML::_('link'$prev_link$this->product->neighbours ['previous'][0]
['product_name'], array('class' => 'previous-page'));
    }
    if (!empty($this->product->neighbours ['next'][0])) {
$next_link JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' $this->product->neighbours ['next'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' $this->product->virtuemart_category_id);
echo JHTML::_('link'$next_link$this->product->neighbours ['next'][0] ['product_name'], array('class' => 'next-page'));
    }
    ?>

    <div class="clear"></div>
        </div>
    <?php // Product Navigation END
    
?>


<?php // Back To Category Button
if ($this->product->virtuemart_category_id) {
$catURL =  JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$this->product->virtuemart_category_id);
$categoryName $this->product->category_name ;
} else {
$catURL =  JRoute::_('index.php?option=com_virtuemart');
$categoryName jtext::_('COM_VIRTUEMART_SHOP_HOME') ;
}
?>

<div class="back-to-category">
    <a href="<?php echo $catURL ?>" class="product-details" title="<?php echo $categoryName ?>"><?php echo JText::sprintf('COM_VIRTUEMART_CATEGORY_BACK_TO',$categoryName?></a>
</div>

    <?php // Product Title   ?>
    <h1><?php echo $this->product->product_name ?></h1>
    <?php // Product Title END   ?>

    <?php // afterDisplayTitle Event
    
echo $this->product->event->afterDisplayTitle ?>


    <?php
    
// Product Edit Link
    
echo $this->edit_link;
    
// Product Edit Link END
    
?>


    <?php
    
// PDF - Print - Email Icon
    
if (VmConfig::get('show_emailfriend') || VmConfig::get('show_printicon') || VmConfig::get('pdf_button_enable')) {
?>

        <div class="icons">
    <?php
    
//$link = (JVM_VERSION===1) ? 'index2.php' : 'index.php';
    $link 'index.php?tmpl=component&option=com_virtuemart&view=productdetails&virtuemart_product_id=' $this->product->virtuemart_product_id;
    $MailLink 'index.php?option=com_virtuemart&view=productdetails&task=recommend&virtuemart_product_id=' $this->product->virtuemart_product_id '&virtuemart_category_id=' $this->product->virtuemart_category_id '&tmpl=component';

    if (VmConfig::get('pdf_icon'1) == '1') {
echo $this->linkIcon($link '&format=pdf''COM_VIRTUEMART_PDF''pdf_button''pdf_button_enable'false);
    }
    echo $this->linkIcon($link '&print=1''COM_VIRTUEMART_PRINT''printButton''show_printicon');
    echo $this->linkIcon($MailLink'COM_VIRTUEMART_EMAIL''emailButton''show_emailfriend');
    ?>

    <div class="clear"></div>
        </div>
    <?php // PDF - Print - Email Icon END
    
?>


    <?php
   
  
  
    
// Product Short Description
    
if (!empty($this->product->product_s_desc)) {
?>

        <div class="product-short-description">
    <?php
    
/** @todo Test if content plugins modify the product description */
    echo nl2br($this->product->product_s_desc);
    ?>

        </div>
<?php
    
// Product Short Description END


    
if (!empty($this->product->customfieldsSorted['ontop'])) {
$this->position 'ontop';
echo $this->loadTemplate('customfields');
    } 
// Product Custom ontop end
    
?>


    <div>
<div class="width50 floatleft">
<?php
echo $this->loadTemplate('images');
?>

</div>

<div class="width50 floatright">
    <div class="spacer-buy-area">

<?php
// TODO in Multi-Vendor not needed at the moment and just would lead to confusion
/* $link = JRoute::_('index2.php?option=com_virtuemart&view=virtuemart&task=vendorinfo&virtuemart_vendor_id='.$this->product->virtuemart_vendor_id);
  $text = JText::_('COM_VIRTUEMART_VENDOR_FORM_INFO_LBL');
  echo '<span class="bold">'. JText::_('COM_VIRTUEMART_PRODUCT_DETAILS_VENDOR_LBL'). '</span>'; ?>
<a class="modal" href="<?php echo $link ?>"><?php echo $text ?></a><br />
*/
?>

<?php
if ($this->showRating) {
    $maxrating VmConfig::get('vm_maximum_rating_scale'5);

    if (empty($this->rating)) {
?>

<span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' JText::_('COM_VIRTUEMART_UNRATED'?></span>
    <?php
} else {
    $ratingwidth $this->rating->rating 24//I don't use round as percetntage with works perfect, as for me
    ?>

<span class="vote">
<?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' round($this->rating->rating) . '/' $maxrating?><br/>
    <span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . round($this->rating->rating) . '/' $maxrating?>" class="ratingbox" style="display:inline-block;">
<span class="stars-orange" style="width:<?php echo $ratingwidth.'px'?>">
</span>
    </span>
</span>
<?php
    }
}
if (is_array($this->productDisplayShipments)) {
    foreach ($this->productDisplayShipments as $productDisplayShipment) {
echo $productDisplayShipment '<br />';
    }
}
if (is_array($this->productDisplayPayments)) {
    foreach ($this->productDisplayPayments as $productDisplayPayment) {
echo $productDisplayPayment '<br />';
    }
}
// Product Price
if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {
    echo $this->loadTemplate('showprices');
}
?>


<?php
// Add To Cart Button
//  if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {
if (!VmConfig::get('use_as_catalog'0) and !empty($this->product->prices)) {
    echo $this->loadTemplate('addtocart');
}  // Add To Cart Button END
?>


<?php
// Availability Image
$stockhandle VmConfig::get('stockhandle''none');
if (($this->product->product_in_stock $this->product->product_ordered) < 1) {
if ($stockhandle == 'risetime' and VmConfig::get('rised_availability') and empty($this->product->product_availability)) {
?>
<div class="availability">
    <?php echo (file_exists(JPATH_BASE DS VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability'))) ? JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability''7d.gif'), VmConfig::get('rised_availability''7d.gif'), array('class' => 'availability')) : VmConfig::get('rised_availability'); ?>
</div>
    <?php
} else if (!empty($this->product->product_availability)) {
?>

<div class="availability">
<?php echo (file_exists(JPATH_BASE DS VmConfig::get('assets_general_path') . 'images/availability/' $this->product->product_availability)) ? JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' $this->product->product_availability$this->product->product_availability, array('class' => 'availability')) : $this->product->product_availability?>
</div>
<?php
}
}
?>


<?php
// Ask a question about this product
if (VmConfig::get('ask_question'1) == '1') {
    
?>

    <div class="ask-a-question">
        <a class="ask-a-question" href="<?php echo $url ?>" ><?php echo JText::_('COM_VIRTUEMART_PRODUCT_ENQUIRY_LBL'?></a>
        <!--<a class="ask-a-question modal" rel="{handler: 'iframe', size: {x: 700, y: 550}}" href="<?php echo $url ?>"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_ENQUIRY_LBL'?></a>-->
    </div>
<?php }
?>


<?php
// Manufacturer of the Product
if (VmConfig::get('show_manufacturers'1) && !empty($this->product->virtuemart_manufacturer_id)) {
    echo $this->loadTemplate('manufacturer');
}
?>


    </div>
</div>
<div class="clear"></div>
    </div>

<?php // event onContentBeforeDisplay
echo $this->product->event->beforeDisplayContent?>


<?php
// Product Description
if (!empty($this->product->product_desc)) {
    ?>

        <div class="product-description">
<?php /** @todo Test if content plugins modify the product description */ ?>
    <span class="title"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_DESC_TITLE'?></span>
<?php echo $this->product->product_desc?>
        </div>
<?php
    
// Product Description END

    
if (!empty($this->product->customfieldsSorted['normal'])) {
$this->position 'normal';
echo $this->loadTemplate('customfields');
    } 
// Product custom_fields END
    // Product Packaging
    
$product_packaging '';
    if (
$this->product->packaging || $this->product->box) {
?>

        <div class="product-packaging">

    <?php
    if (
$this->product->packaging) {
$product_packaging .= JText::_('COM_VIRTUEMART_PRODUCT_PACKAGING1') . $this->product->packaging;
if ($this->product->box)
    $product_packaging .= '<br />';
    }
    if ($this->product->box)
$product_packaging .= JText::_('COM_VIRTUEMART_PRODUCT_PACKAGING2') . $this->product->box;
    echo str_replace("{unit}"$this->product->product_unit $this->product->product_unit JText::_('COM_VIRTUEMART_PRODUCT_FORM_UNIT_DEFAULT'), $product_packaging);
    ?>

        </div>
    <?php // Product Packaging END
    
?>


    <?php
    
// Product Files
    // foreach ($this->product->images as $fkey => $file) {
    // Todo add downloadable files again
    // if( $file->filesize > 0.5) $filesize_display = ' ('. number_format($file->filesize, 2,',','.')." MB)";
    // else $filesize_display = ' ('. number_format($file->filesize*1024, 2,',','.')." KB)";

    /* Show pdf in a new Window, other file types will be offered as download */
    // $target = stristr($file->file_mimetype, "pdf") ? "_blank" : "_self";
    // $link = JRoute::_('index.php?view=productdetails&task=getfile&virtuemart_media_id='.$file->virtuemart_media_id.'&virtuemart_product_id='.$this->product->virtuemart_product_id);
    // echo JHTMl::_('link', $link, $file->file_title.$filesize_display, array('target' => $target));
    // }
    
if (!empty($this->product->customfieldsRelatedProducts)) {
echo $this->loadTemplate('relatedproducts');
    } 
// Product customfieldsRelatedProducts END

    
if (!empty($this->product->customfieldsRelatedCategories)) {
echo $this->loadTemplate('relatedcategories');
    } 
// Product customfieldsRelatedCategories END
    // Show child categories
    
if (VmConfig::get('showCategory'1)) {
echo $this->loadTemplate('showcategory');
    }
    if (!empty(
$this->product->customfieldsSorted['onbot'])) {
    
$this->position='onbot';
    
echo $this->loadTemplate('customfields');
    } 
// Product Custom ontop end
    
?>


<?php // onContentAfterDisplay event
echo $this->product->event->afterDisplayContent?>


<?php
echo $this->loadTemplate('reviews');
?>

</div>

nav007_2000

looks like the first part of the code is ok.

But when I enter the second part of the code, the browser  goes blank

if ($postcode != 0) :
  {mosmap address=''. $postcode .''|zoom='15'|zoomType='Large'|zoomNew='1'|mapType='Map'|showMaptype='1'|overview='1'|text='<div style=width:200px;height=50px;>Home</div>'}
  endif;

ivus

hi nav007_2000,

is that the code that breaks?

I'm not sure how that plugin/module works so you'll need to figure out how to call it, but at least now you have $postcode. Echo it out just to make sure the value is correct:

if ($postcode != 0) :
     echo  $postcode . "<br/>";
endif;

nav007_2000

Just ran your command and it didn't echo anything

ivus

How about just

echo  $postcode . "<br/>";

or

echo '<pre>'; print_r($this->product->customfieldsSorted['normal']); echo '</pre>';

nav007_2000

here are the instructions for the plugin

How to use the plugin in content

You can put the {mosmap} with parameters anywhere in content in Joomla: intro text or main text of an article, components and modules. You can see examples and documentation on my demo site: tech.reumer.net.

Check the html of the content item so there are no html like <br />, <span> or &nbsp; between { } or in the html a return.
If you work with pure html code, be sure that there isn't any "\r " tags in the mosmap string between { } in your database code.
The plugin works for one line!

It can be once, twice or more to display multiple, inline maps on a single content page for different locations and configurations.

Usage: {mosmap width='500'|height='400'|lat='52.052312'|lon='4.447141'|
zoom='3'|mapType='Satellite'|text='sv DWO'|tooltip='DWO'|
marker='1'|align='center' }
(goto html view of an article and remove the returns between the line or <br /> so its one line. Second remove the slash before the pipe |)

You can change any of the parameters:

width, height   to whatever you want although if its too small, you won't see very much.
lon and lat for the coordinates
zoom can be between 0 (world) and 19 (detailed).
mapType can be Normal (default), Satellite, Hybrid, Terrain or Earth.
text is for the marker, that will show on the map with a balloon. If you don't want to see the text, just set text=" and it will not display, the text is the data displayed above the location pin. Usually it would be used to display an address or hyperlink. A hyperlink is possible use the format: <a href=linkAddress target=linkTarget title=linkTitle>linkName</a>. Don't use (double) quotes!
marker is for opening the infowindow (1 default) or close the infowindow (0) initially.
dir for adding get directions form for a route at maps.google.com to the coordinates.
tooltip is for the marker to have a tooltip when the mouse is on the marker (don't use HTML)
address is for a address to search for the coordinates
kml is for a url to a kmlfile to load as a overlay on the map for multiple markers or a route
Behind the parameter name or values is defined what version of Google Maps supports the parameters (v2) is version 2 and (v3) is version 3. If nothing is stated it works for both versions.

For all parameters see here



You can set the single Google key or Multiple urls and Google keys at the parameters by the plugin in the administrator of Joomla. You can register for a Google API Key Google API Console.

nav007_2000

adding the mosmap syntax back into the product details page gives me the following error message


Parse error: syntax error, unexpected T_STRING in components/com_virtuemart/views/productdetails/tmpl/default.php on line 294

ivus

Hi nav007_2000,

OK now I see. You're using a plugin for content blocks. Which means it gets triggered when you display a content item from the table #__content. VM doesn't use that table so this solution isn't going to work for you.

The solution that would work for you is to draw the GoogleMap directly on your products details page.

https://developers.google.com/maps/documentation/javascript/

There's sample code on that site which will tell you how to implement it on your page.

I don't use that plugin so I can't really offer you any solutions.

What fields have you setup to capture the address of your store location? these are all required by GoogleMap API:

   address?
   suburb?
   state?
   postcode?
   country?

Can you give me the custom field ID's?