Trouble Shooting Wiki

Troubleshooting Joomla! And VirtueMart

From TroubleshootingWiki

Jump to: navigation, search
Troubleshooting Joomla! And VirtueMart
Official Page
Project Documentation
Download
Source Book
200px-1847196748.jpg
ISBN 978-1-847196-74-3
Publisher Packt Publishing
Author(s) Suhreed Sarkar

As with any software, users of Joomla! and VirtueMart will likely encounter problems at some point during development. One of the most active communities for support are the Joomla! and VirtueMart forums. Check the existing posts first, and if you find that solution to your problem is not already provided, ask for help. While posting on the forums, please try to be specific and describe the problem as accurately as possible. Providing the error messages and log files can expedite your solution.

In general, we can divide the common problems into several categories, namely Joomla!-related problems, VirtueMart-related problems, PHP-related problems, and problems related to other third-party extensions.

Contents

[edit] Joomla!-related problems

The best place to search for solutions related to Joomla! problems is the Joomla! forum at http://forum.joomla.org. First, search the forum for the problem and solution. If you cannot find that a similar problem has been reported, register with the forum and post the problem on the forum. As the Joomla! community is very large, you may expect to get the solution quickly. The more descriptive and clearer your report problem, the greater your chances are to get the correct solution quickly.

The Joomla! forum has many sections, and it is convenient to browse the specific sections. For example, if you suspect that the problem on your Joomla! site is caused by a particular component, then visit the Extensions | Components section in the Joomla! forum.

[edit] Problems with installation of extensions

In Joomla! 1.5, you can install all extensions from one place, that is, Extensions | Install/Uninstall. However, in Joomla! 1.0.x, you need to select a different screen based on the type of extension you are going to install. Usually, that used to create a lot of trouble with installation of extensions as some of the administrators use to try installing modules from the component installation screen, and vice versa. Joomla! 1.5.x eliminates that confusion. However, you may still face some problems during the installation of an extension.

The following are some of the common errors that occur during the installation of an extension:

  • You may get an error message saying that direct access to the directory is not possible. This mainly happens due to inappropriate permissions to the directory, or a Joomla! installation with inappropriate access rights. You can solve the problem by setting the appropriate permissions to the directory, especially, write permissions to the group in the component and template installation directories.
  • For some extensions, you may be warned that the extension is written for an earlier version of Joomla! and you need to enable the System – Legacy plugin for working with this extension. This happens when you are trying to install an extension marked as '1.5 legacy mode'. You must enable the System – Legacy plugin from Extensions | Plugin Manager to run this type of extensions.
  • While installing some extensions, you may be notified that another template, component, module, or extension is at that location. This happens if you have already installed that extension, or another extension in the same name exists. For solving the problem, first uninstall any previously installed extension, and then try installing the extension again. If you cannot uninstall that extension from Joomla!'s admin area, then login to cPanel and delete the respective folder (for example, ./administrator/components/com_links) from the web server.
  • For some extensions, you may get an error message saying that the XML setup file could not be found in the package. It may be due to the fact that the XML file is corrupt, missing, or does not exist at all. For verifying the package, open the zipped package file on your local computer and verify that the XML file exists and is in the correct name and format. You may also get this message when trying to install an extension which is solely designed for Joomla! 1.0.x.

As we can see, most of the installation problems are related to either insufficient permissions or inappropriate package files. You can easily avoid these by checking the appropriate version of package and permissions set to the directories.

[edit] SEF problems

Joomla! administrators often face some common errors after enabling search engine friendly URLs. When you enable SEF from the Global Configuration screen,Joomla! generates SEF URLs. However, when you choose to use mod_rewrite, the SEF may not work as you expected. This may happen due to the fact that you have not renamed the htaccess.txt file to .htaccess. When you choose to use mod_rewrite, you also need to use the .htaccess file which comes with the Joomla! installation package. You may also face problems even after renaming the htaccess.txt to .htaccess. In that case, you may need to check the .htaccess file. First, make sure that RewriteEngine On is there. Then, check the RewriteBase line. This line should reflect your Joomla! root directory. For example, if Joomla! is installed in the ./public_html/bdosn/ directory, then the .htaccess file should contain RewriteBase ./public_html/bdosn/.

[edit] VirtueMart-related problems

In addition to problems directly related to Joomla!, you may also find some problems with the VirtueMart component. The problems can be classified into some broader categories. The following sections describe some common problems which you may face with the VirtueMart extension.

[edit] Problem after relocation

After relocating the VirtueMart store from your localhost to remote host, you may find that the VirtueMart product images are not displayed. Even you cannot use the VirtueMart features like adding to cart and checking out. When you tried to click on a VirtueMart product link, it may redirect you to your local site. This happens if you do not change the site URLs in VirtueMart's configuration. To solve this problem, go to VirtueMart's administration panel and click on Configuration. Go to Security tab:

In the Security Settings section, you will find two fields: Site URL, and SECUREURL. Check the settings in these two fields. The values are probably for your localhost. Change these values to your shop's online server address, something like: http://bdosn.suhreedsarkar.com/.

[edit] Issues related to user registration

Sometimes you may find that users can register to your site but they are not available as customers in the VirtueMart store. This may happen mainly due to two settings: user registration settings in VirtueMart's configuration, and use of the VirtueMart User Login module. As we have seen, in the VirtueMart | Configuration | Global | User Registration Settings section, we can choose how users for VirtueMart will be created. If No User Creation is selected in the User Registration Type field, then you may not see the users registered in VirtueMart. On the other hand, if you use Joomla!'s built-in Login Form module, that will create a normal Joomla! account, but not a VirtueMart user account. When you are using VirtueMart, disable Joomla!'s Login Form and enable VirtueMart Login Form.

[edit] Showing latest products

While configuring the theme file for VirtueMart, we can specify it to show the featured products, latest products, and recent products on the shop's home page. However, the latest products are not displayed, even though you select it to display. This happens due to a bug in the ./administrator/components/com_virtuemart/classes/ps_product.php file. In this file, you will find the following code block:

    function latestProducts($random, $products) {
       return "";
    }

As you understand, the code block will not show anything. Let us add some codes inside the block so that it selects the latest products from the catalog and displays the product snapshots for those products. Replace the entire code block with the following:

function latestProducts($random, $category_id) {
global $VM_LANG;
require_once( CLASSPATH . 'ps_product_attribute.php');
$ps_product_attribute = new ps_product_attribute();
$max_items = 4;
$db = new ps_DB;
$tpl = new $GLOBALS['VM_THEMECLASS']();
$category_id = null;
if($categories) {
     $category_id = vmRequest::getInt('category_id');
   }
$q  = "SELECT DISTINCT product_sku,#__{vm}_product.product_id,
product_name, product_s_desc,product_thumb_image, product_full_image, product_in_stock, 
product_url FROM #__{vm}_product, #__{vm}_product_category_xref, #__{vm}_category WHERE \n";
$q .= "(#__{vm}_product.product_parent_id='' OR #__{vm}_product.product_parent_id='0') \n";
$q .= "AND #__{vm}_product.product_id=#__{vm}_product_category_xref.product_i                d \n";
$q .= "AND #__{vm}_category.category_id=#__{vm}_product_category_xref.category_id \n";

if( !empty( $category_id ) ) {
        $q .= "AND #__{vm}_category.category_id='$category_id' ";
}
if( CHECK_STOCK && PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS != "1") {
       $q .= " AND product_in_stock > 0 ";

}

$q .= "AND #__{vm}_product.product_publish='Y' ";
$q .= "ORDER BY #__{vm}_product.product_id DESC ";
$q .= "LIMIT 0, $max_items ";
$db->query($q);

if( $db->num_rows() > 0 ){
$i = 0;
$latest_products = array();
while($db->next_record() ){
        $flypage = $this->get_flypage($db->f("product_id"));
        $latest_products[$i]['product_sku'] = $db->f("product_sku");
        $latest_products[$i]['product_name'] = $db->f("product_name");
        $price = "";
if (_SHOW_PRICES == '1') {
// Show price, but without "including X% tax"
  $price = $this->show_price( $db->f("product_id"), false );
}

$latest_products[$i]['product_price'] = $price;
$latest_products[$i]['product_s_desc'] = $db->f("product_s_desc");
$latest_products[$i]['product_url'] = $db->f("product_url");
$latest_products[$i]['product_thumb'] = $db->f("product_thumb_image");

$latest_products[$i]['product_full_image']= $db->f("product_full_image");
$latest_products[$i]['product_id'] = $db->f("product_id");
$latest_products[$i]['flypage'] = $flypage;
  $latest_products[$i]['form_addtocart'] = "";
  if (USE_AS_CATALOGUE != '1' && $price != ""
    && !stristr( $price, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') )
    && !$this->product_has_attributes( $db->f('product_id'), true )
    && $tpl->get_cfg( 'showAddtocartButtonOnProductList' ) ) {
     $tpl->set( 'i', $i );
     $tpl->set( 'product_id', $db->f('product_id') );
     $tpl->set( 'ps_product_attribute', $ps_product_attribute );
     $tpl->set( 'product_in_stock', $db->f('product_in_stock'));
    $latest_products[$i]['form_addtocart'] = $tpl->fetch( 'browse/includes/addtocart_form.tpl.php' );
    $latest_products[$i]['has_addtocart'] = true;
   }
   $i++;
  }

$tpl->set( 'latest_products', $latest_products );

return $tpl->fetch( 'common/latestProducts.tpl.php');

  }
}

In addition to this block, save the ps_product.php file. Now, the Latest Products will be displayed on the shop's home page.

[edit] Issues related to vendors

While configuring the VirtueMart shop, you have learned that the vendor feature of VirtueMart is still immature and will hopefully be developed soon. The shop owners who try to add other vendors know that it supports only one vendor as they cannot change the vendor. Actually, there is a bug in the SQL query which prevents updating vendor information and associating the vendor to a product. You can easily solve this problem by editing the ./administrator/components/com_virtuemart/classes/ps_product.php file. In this file, at around line # 503, you will get the following line of code:

$db->buildQuery( 'UPDATE', '#__{vm}_product', $fields, 
'WHERE    product_id='. (int)$d["product_id"] . ' AND vendor_id=' .
  (int)$old_vendor_id );

As you can see, while updating the query, it also tries to insert the old vendor id. This prevents changing the vendors for a product. We can correct this by replacing the above line of code with the following:

$db->buildQuery( 'UPDATE', '#__{vm}_product', $fields, 
  'WHERE product_id='. (int)$d["product_id"]);

Once this change is made to the ps_product.php file and saved, you can change the vendor for a product from the product update page in the VirtueMart administration panel.

[edit] Issues related to VirtueMart SEF

As we saw earlier, the default SEF feature of Joomla! does not work with VirtueMart as expected. For a work around with this, we suggested using third-party SEF extension such as sh404SEF. The component works fine with VirtueMart and multilingual contents including the Joom!Fish extension. However, you need to remember that while enabling the sh404SEF component, you must keep the Joomla! core SEF disabled. You can also use sh404SEF with or without mod_rewrite (.htaccess file). Without using mod_rewrite, sh404SEF will generate SEF URLs which contain index.php.

When you use mod_rewrite, the URLs do not contain index.php. However, using mod_rewrite needs some understanding for .htaccess file. For using mod_rewrite with sh404SEF, please consult the documentation available with the component. It describes where you can activate mod_rewrite mode and what changes you need to do in the .htaccess file.

When you publish mod_virtuemart, you can mouse over the link List All Products. Clicking on this link shows a listing of all the products available in the store. When you enable sh404SEF, you may find that the SEF URL for this link became http://yourdomain.com/view-all-products-in-shop.html?category=. As you can see, the URL is not fully SEF, the last portion, ?category=, is unexpected. This happened due to some bug in the mod_virtuemart file. Open ./modules/mod_virtuemart/mod_virtuemart.php file and go to line #102. You will see the following lines:

<a href="<?php $sess->purl($mm_action_url."index.php?
   page=shop.browse&category=") ?>">
   <?php echo $VM_LANG->_('PHPSHOP_LIST_ALL_PRODUCTS') ?>
</a>

Note the word purl in the code above. Don't think that it's a typo. In fact, it is a web service. PURL means Persistent Uniform Resources Locator. You may learn details about PURL at http://www.purl.org.

The error is in the highlighted line above. Let us correct the highlighted line so that it looks like the following:

<a href="<?php $sess->purl($mm_action_url."index.php?page=shop.browse") ?>">

Save the file and refresh the home page of your site. Now, the SEF URL for this link becomes perfect, you see http://yourdomain.com/view-all-products-in-shop.html.

Another problem in VirtueMart and sh404SEF use is that PDF, Print, and Email buttons for the products do not work. This can be solved by editing the ./administrator/ components/com_virtuemart/classes/htmlTools.class.php file. First, find the following at around line #961:

$link .= '&pop=1';
Change it to:

$link .= '&pop=1';
$link = mosConfig_live_site."/".$link; /* sh40sef FIX */

Find the following at around line #981:

$link = $sess->url( 'index2.php?page=shop.recommend&
product_id= '.$product_id.
'&pop=1'.(vmIsJoomla('1.5') ? 
'&tmpl=component' : '') );

Change it to:

$link = $mosConfig_live_site.'/index2.php?option=com_virtuemart&
   page=shop.recommend&product_id='.$product_id.'&pop=1'.
   (vmIsJoomla('1.5') ? '&tmpl=component' : ''); /* sh404sef FIX */

Find the following at around line #997:

$query_string = str_replace( 'only_page=1', 'only_page=0', vmAmpReplace(vmGet($_SERVER,'QUERY_STRING')) );
$link = 'index2.php?'.$query_string.'&pop=1'.(vmIsJoomla('1.5') ? 
'&tmpl=component' : '');

Change it to:

$query_string = ""; /* sh404sef FIX */
foreach($_GET as $opt=>$val) {
      $query_string .= $opt."=".$val."&";
  }
$query_string = str_replace( 'only_page=1', 'only_page=0',
  $query_string);
$link = $mosConfig_live_site.'/index2.php?pop=1&'.$query_string; /*
   sh404sef FIX */

With all of these fixes in the htmlTools.class.php file, the pdf, print, and email buttons on VirtueMart product pages will work fine.

[edit] Issues related to multilingual contents in VirtueMart

As we are using Joomla! and VirtueMart's language files, as well as Joom!Fish for content translation, there may be some problem during translation and showing the translated content. When translating the language files, both for Joomla! and VirtueMart, be careful about missing quotation marks. Whenever you see a T_STRING error for a language file, check for such missing quotation marks or special characters.

For Joom!Fish, the translations should work fine. However, you should know about the basic principles of its working. Virtually all content (whatever stored in the database) can be translated through Joom!Fish. Joom!Fish allows you to translate the content through importing content elements. Content elements for Joom!Fish are defined through XML files. The structure of the content, element XML files are straight forward. First, it starts with an XML tag, then the name, author, version, and description will be there. The main section is the <reference> </reference> section, under which we refer to the table through
tag. Table's name must be the name of the table used in database, except the prefix, jos_.

Then inside table, we must define the fields which should be translated. For example, we want to create the content elements for VirtueMart vendors. The table used to store vendor information is jos_vm_vendor. Therefore, a content-element definition file will be as follows:

<?xml version="1.0" ?>
<joomfish type="contentelement">
 <name>VirtueMart Store Information</name>
 <author>Suhreed Sarkar</author>
 <version>2.0</version>
 <description>Definition for VirtueMart component (Store Information)
   </description>
 <reference>
  <table name="vm_vendor">
     <field type="referenceid" name="vendor_id"
            translate="0">ID</field>
     <field type="titletext" name="vendor_store_name"
            translate="1">Store Name</field>
     <field type="text" name="contact_last_name"
            translate="1">Contact Last Name</field>
     <field type="text" name="contact_first_name"
            translate="1">Contact First Name</field>
     <field type="text" name="contact_title" translate="1">
            Contact Title</field>
     <field type="htmltext" name="vendor_store_desc"
        translate="1">Description</field>
     <field type="text" name="vendor_address_1" translate="1">
            Address Line 1</field>
     <field type="text" name="vendor_address_2" translate="1">
            Address Line 2</field>
     <field type="text" name="vendor_city" translate="1">City</field>
     <field type="text" name="vendor_country"
            translate="1">Country</field>
     <field type="htmltext" name="vendor_terms_of_service"
            translate="1">Terms of service</field>
  </table>
 </reference>
</joomfish>

This file should be saved as vm_vendor.xml. The naming of the filename should be as per the referenced table. As this file refers to the vm_vendor table, therefore, its name should be vm_vendor.xml. In fact, there is a similar file named vm_store_info.xml, but that does not work as the name of the file and the name of the table differs.

For more information on writing content-element definition files, you can consult the Joom!Fish manual available at http://www.joomfish.net/en/ documentation/developer-docs/30-creation-of-content-elements.

You should remember another point about Joom!Fish. Whenever you want to use Joom!Fish for translating the contents of a table, the SQL queries should be formed in a way, that it always select the primary key (vendor_id) and do not use a table alias. As we are dealing with vendors, the queries for vendor functions are in the ./administrator/components/com_virtuemart/classes/ps_vendor.php file. Open the file and find the following query (line #413):

if ($vendor_id) {
 $q = "SELECT vendor_name FROM #__{vm}_vendor WHERE vendor_id
   ='$vendor_id'";
  } elseif ($product_id) {
   $q  = "SELECT vendor_name FROM #__{vm}_product, #__{vm}_vendor ";
   $q .= "WHERE product_id = '$product_id' ";
   $q .= "AND #__{vm}_product.vendor_id = #__{vm}_vendor.vendor_id ";
   } else {
    /* ERROR: No arguments were specified. */
   return 0;
}
Now, change the above block as follows:
if ($vendor_id) {
   $q = "SELECT vendor_id, vendor_name FROM #__{vm}_vendor
     WHERE vendor_id = '$vendor_id'";
   } elseif ($product_id) {
   $q  = "SELECT vendor_id, vendor_name FROM #__{vm}_product,
     #__{vm}_vendor ";
   $q .= "WHERE product_id = '$product_id' ";
   $q .= "AND #__{vm}_product.vendor_id = #__{vm}_vendor.vendor_id ";
} else {
   /* ERROR: No arguments were specified. */
   return 0;
}

We have now added vendor_id in the query. Like this code block, find other queries in the ps_vendor.php file and add the vendor_id field in the SQL queries. When you have changed the queries and saved the file, you can proceed to installing the content elements and translating the vendor information through Joom!Fish's translator interface.

[edit] Additional References

  • For instructions on Installing Joomla! and VirtueMart, click here
  • For instructions on Customizing VirtueMart, click here
  • For instructions on Handling Joomla! Errors, click here
  • For instructions on Creating Joomla v1.0 Templates, click here
  • For instructions on Customizing Joomla v1.0 Templates, click here
  • For instructions on Creating Accessible Joomla Templates, click here
  • For instructions on Debugging Joomla! 1.5x, click here

[edit] Source

The source of this content is Chapter 10: Troubleshooting Joomla! And VirtueMart of Joomla! E-Commerce with VirtueMart by Suhreed Sarkar (Packt Publishing, 2008).

Personal tools