简体   繁体   中英

Virtuemart 2 - Add the product image to the “add to cart”-popup

I've been looking for this like everywhere now ;)

I want to add the product image to the popup, but I can't figure out how to achieve this! I've been searching for hours and hours now and next to that tried to code this myself but it won't work.

So now I'm asking for help... if anyone has some ideas on this please let me know. Afaik there's more people on the net that would like to see a "add to cart"-popup with some more informations given on it.

Sincerly Thomas

I just recently customised the add to cart popup on a site myself. The file you need to edit is components/com_virtuemart/controllers/cart.php (the function is called addJS if I remember correctly).

You can find the API documentation for VirtueMart here: http://docs.virtuemart.net/api-vm2/ however I wrote my own plugin to fetch the VM data. Then you can just use standard PHP rather than getting your head round the VM API.

If you decide to do it my way you can call custom classes from your plugin and output the image like so:

$cart_image = plgMyCoolPlugin::_getImage($this->product->virtuemart_product_id);
echo '<img src='.$cart_image.'/>';

Remember you need to import your plugin type if you don't make it a system plugin:

JPluginHelper::importPlugin( 'mynewplugintype' );

Here's the function I use in my plugin:

    function _getImage($id)
    {       
        $db   =& JFactory::getDBO();    
        $sql  = "   SELECT
                            b.`file_url`
                    FROM
                            ".$db->nameQuote('#__virtuemart_product_medias')." AS a
                    INNER JOIN 
                            ".$db->nameQuote('#__virtuemart_medias')." AS b ON a.`virtuemart_media_id` = b.`virtuemart_media_id`  
                    WHERE
                            a.".$db->nameQuote('virtuemart_product_id')." = ".$id."
                    AND
                            b.".$db->nameQuote('file_mimetype')." = 'image/jpeg'
                    AND
                            b.".$db->nameQuote('file_type')." = 'product'
                    AND
                            b.".$db->nameQuote('file_is_forSale')." = '0'";

        $query = $db->setQuery($sql);
        $row  = $db->loadResultArray();
        if($db->getErrorNum()) {
            JError::raiseError( 500, $db->stderr());
        }
        if(empty($row)) $row[] = JURI::base().'images/defaultimage.jpg';
        return $row;
    }

Hope this helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM