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

jQuery selector for virtuemart2 product name on category view.

Started by zero1024, April 22, 2013, 22:38:22 PM

Previous topic - Next topic

zero1024

First of all, please forgive me if I post on the wrong place but it is my first post here  ::)

I have altered the code on default.php for category view on virtuemart 2, here is the full code of the file now:

<?php
/**
*
* Show the products in a category
*
* @package  VirtueMart
* @subpackage
* @author RolandD
* @author Max Milbers
* @todo add pagination
* @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 6053 2012-06-05 12:36:21Z Milbo $
*/

//vmdebug('$this->category',$this->category);
vmdebug('$this->category '.$this->category->category_name);
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
JHTML::_'behavior.modal' );
/* javascript for list Slide
  Only here for the order list
  can be changed by the template maker
*/
$js "
jQuery(document).ready(function () {
    jQuery('.orderlistcontainer').hover(
        function() { jQuery(this).find('.orderlist').stop().show()},
        function() { jQuery(this).find('.orderlist').stop().hide()}
    )
});
"
;

$document JFactory::getDocument();
$document->addScriptDeclaration($js);

/*$edit_link = '';
if(!class_exists('Permissions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'permissions.php');
if (Permissions::getInstance()->check("admin,storeadmin")) {
    $edit_link = '<a href="'.JURI::root().'index.php?option=com_virtuemart&tmpl=component&view=category&task=edit&virtuemart_category_id='.$this->category->virtuemart_category_id.'">
        '.JHTML::_('image', 'images/M_images/edit.png', JText::_('COM_VIRTUEMART_PRODUCT_FORM_EDIT_PRODUCT'), array('width' => 16, 'height' => 16, 'border' => 0)).'</a>';
}

echo $edit_link; */
if ( empty($this->keyword) ) {
    
?>

    <div class="category_description">
    <?php echo $this->category->category_description ?>
    </div>
    <?php
}

/* Show child categories */

if ( VmConfig::get('showCategory',1) and empty($this->keyword)) {
    if (
$this->category->haschildren) {

        
// Category and Columns Counter
        
$iCol 1;
        
$iCategory 1;

        
// Calculating Categories Per Row
        
$categories_per_row VmConfig::get 'categories_per_row');
        
$category_cellwidth ' width'.floor 100 $categories_per_row );

        
// Separator
        
$verticalseparator " vertical-separator";
        
?>


        <div class="category-view">

        <?php // Start the Output
        
if(!empty($this->category->children)){
        foreach ( 
$this->category->children as $category ) {

            
// Show the horizontal seperator
            
if ($iCol == && $iCategory $categories_per_row) { ?>

            <div class="horizontal-separator"></div>
            <?php }

            
// this is an indicator wether a row needs to be opened or not
            
if ($iCol == 1) { ?>

            <div class="row">
            <?php }

            
// Show the vertical seperator
            
if ($iCategory == $categories_per_row or $iCategory $categories_per_row == 0) {
                
$show_vertical_separator ' ';
            } else {
                
$show_vertical_separator $verticalseparator;
            }

            
// Category Link
            
$caturl JRoute::'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' $category->virtuemart_category_id );

                
// Show Category ?>

                <div class="category floatleft<?php echo $category_cellwidth $show_vertical_separator ?>">
                    <div class="spacer">
                        <h2>
                            <a href="<?php echo $caturl ?>" title="<?php echo $category->category_name ?>">
                            <?php echo $category->category_name ?>
                            <br />
                            <?php // if ($category->ids) {
                                
echo $category->images[0]->displayMediaThumb("",false);
                            
//} ?>

                            </a>
                        </h2>
                    </div>
                </div>
            <?php
            $iCategory 
++;

        
// Do we need to close the current row now?
        
if ($iCol == $categories_per_row) { ?>

        <div class="clear"></div>
        </div>
            <?php
            $iCol 
1;
        } else {
            
$iCol ++;
        }
    }
    }
    
// Do we need a final closing row tag?
    
if ($iCol != 1) { ?>

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

<?php }
}
?>

<div class="browse-view">
    <?php
if (!empty($this->keyword)) {
    
?>

    <h3><?php echo $this->keyword?></h3>
    <?php
?>

        <?php if ($this->search !==null ) { ?>
            <form action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=category&limitstart=0&virtuemart_category_id='.$this->category->virtuemart_category_id ); ?>" method="get">

            <!--BEGIN Search Box --><div class="virtuemart_search">
            <?php echo $this->searchcustom ?>
            <br />
            <?php echo $this->searchcustomvalues ?>
            <input name="keyword" class="inputbox" type="text" size="20" value="<?php echo $this->keyword ?>" />
            <input type="submit" value="<?php echo JText::_('COM_VIRTUEMART_SEARCH'?>" class="button" onclick="this.form.keyword.focus();"/>
            </div>
                    <input type="hidden" name="search" value="true" />
                    <input type="hidden" name="view" value="category" />

            </form>
        <!-- End Search Box -->
        <?php ?>

<?php // Show child categories
if (!empty($this->products)) {
?>

            <div class="orderby-displaynumber">
                <div class="width70 floatleft">
                    <?php echo $this->orderByList['orderby']; ?>
                </div>
                <div class="width30 floatright display-number"><?php echo $this->vmPagination->getResultsCounter();?><br/><?php echo $this->vmPagination->getLimitBox(); ?></div>
                <div class="vm-pagination">
                    <?php echo $this->vmPagination->getPagesLinks(); ?>
                    <span style="float:right"><?php echo $this->vmPagination->getPagesCounter(); ?></span>
                </div>

            <div class="clear"></div>
            </div> <!-- end of orderby-displaynumber -->

<h1><?php echo $this->category->category_name?></h1>

<?php
// Category and Columns Counter
$iBrowseCol 1;
$iBrowseProduct 1;

// Calculating Products Per Row
$BrowseProducts_per_row $this->perRow;
$Browsecellwidth ' width'.floor 100 $BrowseProducts_per_row );

// Separator
$verticalseparator " vertical-separator";

// Count products
$BrowseTotalProducts 0;
foreach ( 
$this->products as $product ) {
   
$BrowseTotalProducts ++;
}
?>


<table bordercolor="grey" RULES=ROWS FRAME=HSIDES style="border:1px solid #B3BD70;height:100%;width:100%;overflow-x: scroll;height:30px;padding:8px;background-color:rgba(255,255,255,0.2);border-left:1px solid #B3BD70;border-top:1px solid #B3BD70;border-right:1px solid #B3BD70;border-bottom:1px solid #B3BD70;" class="orders">

<?php
// Start the Output
foreach ( $this->products as $product ) {

    
// Show the horizontal seperator
    
if ($iBrowseCol == && $iBrowseProduct $BrowseProducts_per_row) { ?>

    <div class="horizontal-separator"></div>
    <?php }
?>



<tr>
<td style="padding-left:8px;">
<div class="width30 floatleft center">
                    <a title="<?php echo $product->link ?>" rel="vm-additional-images" href="<?php echo $product->link?>">
                        <?php
                            
echo $product->images[0]->displayMediaThumb('class="browseProductImage"'false);
                        
?>

                     </a>
<div class="paddingtop8">
                            <span class="vmicon vm2-<?php echo $product->stock->stock_level ?>" title="<?php echo $product->stock->stock_tip ?>"></span>
                            <span class="stock-level"><?php echo JText::('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP'?></span>
                        </div>
</td>
<td style="padding-top:5px;padding-bottom:5px;padding-right:50px;padding-left:50px;">
<div style="font-size: 1.8em;">
<?php  echo JHTML::link($product->link$product->product_name); ?>
</div>
<?php // Product Short Description
                    
if (!empty($product->product_s_desc)) {
                        
?>

                        <p class="product_s_desc">
                            <?php echo shopFunctionsF::limitStringByWord ($product->product_s_desc400'...'?>
                        </p>
                        <?php ?>

                    </td>
<td style="padding-right:8px;font-weight:bold;">
<div class="product-price marginbottom12" id="productPrice<?php echo $product->virtuemart_product_id ?>">
                        <?php
                        
if ($this->show_prices == '1') {
                            if (
$product->prices['salesPrice']<=and VmConfig::get ('askprice'1) and  !$product->images[0]->file_is_downloadable) {
                                echo 
JText::('COM_VIRTUEMART_PRODUCT_ASKPRICE');
                            }
                            
//todo add config settings
                            
if ($this->showBasePrice) {
                                echo 
$this->currency->createPriceDiv ('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$product->prices);
                                echo 
$this->currency->createPriceDiv ('basePriceVariant''COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT'$product->prices);
                            }
                            echo 
$this->currency->createPriceDiv ('variantModification''COM_VIRTUEMART_PRODUCT_VARIANT_MOD'$product->prices);
                            if (
round($product->prices['basePriceWithTax'],$this->currency->_priceConfig['salesPrice'][1]) != $product->prices['salesPrice']) {
                                echo 
'<span class="price-crossed" >' $this->currency->createPriceDiv ('basePriceWithTax''COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX'$product->prices) . "</span>";
                            }
                            if (
round($product->prices['salesPriceWithDiscount'],$this->currency->_priceConfig['salesPrice'][1]) != $product->prices['salesPrice']) {
                                echo 
$this->currency->createPriceDiv ('salesPriceWithDiscount''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT'$product->prices);
                            }
                            echo 
$this->currency->createPriceDiv ('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$product->prices);
                            echo 
$this->currency->createPriceDiv ('priceWithoutTax''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX'$product->prices);
                            echo 
$this->currency->createPriceDiv ('discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$product->prices);
                            
$unitPriceDescription JText::sprintf ('COM_VIRTUEMART_PRODUCT_UNITPRICE'$product->product_unit);
                            echo 
$this->currency->createPriceDiv ('unitPrice'$unitPriceDescription$product->prices);
                        } 
?>


                    </div>

<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
        <?php // Product custom_fields
        
if (!empty($product->customfieldsCart)) {  ?>

        <div class="product-fields">
            <?php foreach ($product->customfieldsCart as $field)
            { 
?>
<div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field_type ?>">
                <span class="product-fields-title" ><b><?php echo  JText::_($field->custom_title?></b></span>
                <?php echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>
                <span class="product-field-display"><?php echo $field->display ?></span>

                <span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
                </div><br/ >
                <?php
            
}
            
?>

        </div>
        <?php }
         
/* Product custom Childs
          * to display a simple link use $field->virtuemart_product_id as link to child product_id
          * custom_value is relation value to child
          */

        
if (!empty($this->product->customsChilds)) {  ?>

            <div class="product-fields">
                <?php foreach ($this->product->customsChilds as $field) {  ?>
                    <div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field->field_type ?>">
                    <span class="product-fields-title" ><b><?php echo JText::_($field->field->custom_title?></b></span>
                    <span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
                    <span class="product-field-display"><?php echo $field->display ?></span>

                    </div><br/ >
                    <?php
                
?>

            </div>
        <?php ?>

            <div class="addtocart-bar">

                <?php // Display the quantity box ?>
                <!-- <label for="quantity<?php echo $this->product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
                <span class="quantity-box">
                    <input type="hidden" class="quantity-input" name="quantity[]" value="1" />
                </span>
                <span class="quantity-controls">
                    <input type="hidden" class="quantity-controls quantity-plus" />
                    <input type="hidden" class="quantity-controls quantity-minus" />
                </span>
                <?php // Display the quantity box END ?>

                <?php // Add the button
                
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
                
$button_cls ''//$button_cls = 'addtocart_button';
                
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
                    
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
                    
$button_cls 'notify-button';
                } 
?>


                <?php // Display the add to cart button ?>
                <span class="addtocart-button">
                    <input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
                </span>

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

            <?php // Display the add to cart button END ?>
            <input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
            <input type="hidden" name="option" value="com_virtuemart" />
            <input type="hidden" name="view" value="cart" />
            <noscript><input type="hidden" name="task" value="add" /></noscript>
            <input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
            <?php /** @todo Handle the manufacturer view */ ?>
            <input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
            <input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
    </form>
</form>
</td>


</tr>
<?php }
// end of foreach ( $this->products as $product )
?>




</table></div><!-- end browse-view -->


I have just installed a compare products module and on its settings, it asks from me to insert a value for a jQuery selector in order to define the product title. The problem is, that its default value (h2 a) is not working and I can't seem to find another way to define it myself either. I tried several things such as to enter as a value "td::eq(2)" but it simply selects the first product ignoring the others no matter on witch button I press. The address to my website is this:

http://valexop.no-ip.org/index.php/ct-menu-item-20/ct-menu-item-21/ct-menu-item-22

I hope I explained it as clearly as possible but I am here to explain even more ^_^ and forgive my little knowledge, I am trying to learn!! :D

Mod edit:  bump message removed. See  http://forum.virtuemart.net/index.php?board=114.0

balai

Hi

Its not clear which selector you want to include.

If you are referring to the product's wrapper add a class to the td wrapper
<td style="padding-right:8px;font-weight:bold;" class="product_wrapper">

If you want to use only the title add a class to the title
<a class="product_title" title="<?php echo $product->link ?>" rel="vm-additional-images" href="<?php echo $product->link?>">

zero1024

Thank you for your answer! What I want is a selector for the product title only and your suggestion is not working.

I already tried with classes before and for some reason its not working, still I tried it again with your answer but with the same result, no title. I forgot to mention before, that when I refresh the page the product titles appear correctly for the previously selected (before the page refresh) products.

Another solution I am thinking is to force-refresh the page after you press the "add to compare" button but my php knowledge is a bit limited and it is difficult for me to edit the module itself  :-\

P.S: My Joomla version is 2.5.9 and Virtuemart is 2.0.20b

balai

Since you are using a commercial extension why don't you ask help from the developer?

zero1024


zero1024

Well after all, the developer came with an answer!  :P At first he also suggested a class on the title link with the selector ".classname a". But still, it just selects all titles from all products on the category... So the real problem was on category selector, not the name selector. The selector I used was ".browse-view" but I needed specifically the tr with the title, so the answer is ".browse-view .orders tr".

Thank you for your help my friend and I hope in some way that this post will help others in the future.