News:

Support the VirtueMart project and become a member

Main Menu

Display Parent product name, of a child

Started by serazoo, October 03, 2019, 00:35:57 AM

Previous topic - Next topic

serazoo

Hello all

I'm using VirtueMart 3.6.2 10159 with Joomla 3.9

This topic has been discussed several years ago, but no working solution here or elsewhere, forum suggested to start a new topic :)

I display children products in the file mail_html_pricelist.php
I would like to display the parent's name beside each child

User digger149 suggested a code, but I guess with all VM updates over the years, it is sadly not working... As I've searched... I see many users will find a working solution very helpful & so will I :)
Can someone shed a light please?
Much appreciated!

Suggested code:

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('product_name'));
$query->from('#__virtuemart_products_en_us');
$query->where('virtuemart_product_id="'.$prow->product_parent_id.'"');
$db->setQuery($query);
$parent_name = $db->loadResult();
echo $parent_name;
?>












GJC Web Design

in

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('product_name'));
$query->from('#__virtuemart_products_en_us');
$query->where('virtuemart_product_id="'.$prow->product_parent_id.'"');
$db->setQuery($query);
$parent_name = $db->loadResult();
echo $parent_name;
?>

what  is missing?    $prow->product_parent_id  ?  echo out $query
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

serazoo

Thanks GJC.... I've tried several options but I'm really not an expert  :'(

How exactly do I "echo out $query"  with the suggested code from digger149 ?
much appreciated!

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('product_name'));
$query->from('#__virtuemart_products_en_us');
$query->where('virtuemart_product_id="'.$prow->product_parent_id.'"');
$db->setQuery($query);
$parent_name = $db->loadResult();
echo $parent_name;
?>

GJC Web Design

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('product_name'));
$query->from('#__virtuemart_products_en_us');
$query->where('virtuemart_product_id="'.$prow->product_parent_id.'"');
print 'Debug Line '.__LINE__.' $query <pre>'; print_r ($query); print "</pre><br />\n";
$db->setQuery($query);
$parent_name = $db->loadResult();
echo $parent_name;
?>
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

serazoo

#4
This is what I get in the email, instead of the parent's name
Very long debug script
any thoughts? Thanks GJC for taking the time :)

Debug Line 84 $query
JDatabaseQueryMysqli Object
(
    [offset:protected] =>
    [limit:protected] =>
    [db:protected] => JDatabaseDriverMysqli Object
        (
            [name] => mysqli
            [serverType] => mysql
            [connection:protected] => mysqli Object
                (
                    [affected_rows] => 1
                    [client_info] => 10.1.41-MariaDB
                    [client_version] => 100141
                    [connect_errno] => 0
                    [connect_error] =>
                    [errno] => 0
                    [error] =>
                    [error_list] => Array
                        (
                        )

                    [field_count] => 24
                    [host_info] => Localhost via UNIX socket
                    [info] =>
                    [insert_id] => 167
                    [server_info] => 10.1.41-MariaDB-cll-lve
                    [server_version] => 100141
                    [stat] => Uptime: 1926139  Threads: 2  Questions: 49369838  Slow queries: 22222  Opens: 1679434  Flush tables: 81  Open tables: 1500  Queries per second avg: 25.631
                    [sqlstate] => 00000
                    [protocol_version] => 10
                    [thread_id] => 1298575
                    [warning_count] => 0
                )

            [nameQuote:protected] => `
            [nullDate:protected] => 0000-00-00 00:00:00
            [_database:JDatabaseDriver:private] => conc_mor
            [count:protected] => 144
            [cursor:protected] =>
            [debug:protected] =>
            [limit:protected] => 0
            [log:protected] => Array
                (
                )

            [timings:protected] => Array
                (
                )

            [callStacks:protected] => Array
                (
                )

            [offset:protected] => 0
            [options:protected] => Array
                (
                    [driver] => mysqli
                    [host] => localhost
                    [user] => xxxxxx
                    [password] => xxxxxxx
                    [database] => xxxxx
                    [prefix] => apitw_
                    [select] => 1
                    [port] => 3306
                    [socket] =>
                )

            [sql:protected] => SELECT * FROM `#__menu` WHERE `component_id` = "10036" and `language` = "*"
            [tablePrefix:protected] => apitw_
            [utf:protected] => 1
            [utf8mb4:protected] => 1
            [errorNum:protected] => 0
            [errorMsg:protected] =>
            [transactionDepth:protected] => 0
            [disconnectHandlers:protected] => Array
                (
                )

        )

    [sql:protected] =>
    [type:protected] => select
    [element:protected] =>
    [select:protected] => JDatabaseQueryElement Object
        (
            [name:protected] => SELECT
            [elements:protected] => Array
                (
                   
  • => product_name
                    )

                [glue:protected] => ,
            )

        [delete:protected] =>
        [update:protected] =>
        [insert:protected] =>
        [from:protected] => JDatabaseQueryElement Object
            (
                [name:protected] => FROM
                [elements:protected] => Array
                    (
                       
  • => #__virtuemart_products_en_us
                    )

                [glue:protected] => ,
            )

        [join:protected] =>
        [set:protected] =>
        [where:protected] => JDatabaseQueryElement Object
            (
                [name:protected] => WHERE
                [elements:protected] => Array
                    (
                       
  • => virtuemart_product_id=""
                    )

                [glue:protected] =>  AND
            )

        [group:protected] =>
        [having:protected] =>
        [columns:protected] =>
        [values:protected] =>
        [order:protected] =>
        [autoIncrementField:protected] =>
        [call:protected] =>
        [exec:protected] =>
        [union:protected] =>
        [unionAll:protected] =>
        [selectRowNumber:protected] =>
    )

    ?>

GJC Web Design

removed all your user and password info!!!

the problem is here:

[name:protected] => WHERE
            [elements:protected] => Array
                (
                   
=> virtuemart_product_id=""

no product id - so $prow->product_parent_id isn't correct

echo out $prow and see whats there -- if parent isn't incl. then u need more code to get the parent id first
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

serazoo

I simply inserted your final suggested code in mail_html_pricelist.php
and I got the dubug code in the email when testing...
I did not debug it myself, so I guess we're stuck
Christmas will not be coming this year  :'(


<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('product_name'));
$query->from('#__virtuemart_products_en_us');
$query->where('virtuemart_product_id="'.$prow->product_parent_id.'"');
print 'Debug Line '.__LINE__.' $query <pre>'; print_r ($query); print "</pre><br />\n";
$db->setQuery($query);
$parent_name = $db->loadResult();
echo $parent_name;
?>



Studio 42

First, you should verify that you have a product_parent_id.
If your table is en_gb and not en_us, you get no parent name at all.
The simple way is to not use $query->from('#__virtuemart_products_en_us');
but $query->from('#__virtuemart_products_'.VMLANG);

But Virtuemart alays cache parent so you can get the full object with

$productModel = VmModel::getModel('Product');
$parent= $productModel->getProduct ($prow->product_parent_id);

Of course the parent have to be published
and
echo $parent->product_name;

serazoo

Thanks Studio 42... almost there :)

The first email I get, which is the vendor, it is perfect :
Parent               Child
Cowboy hat         blue


The second email I get, which is the buyer :
Parent         Child
blue               blue

The parent takes child's name, since product_name is the same holder name for both
You mentioned cache, is product_name for the parent taking the name of it's child in the buyer's email?

Is there a way to re-script, and target parent and child individually?

Much appreciated taking the time guys, I'm sure this will be usefull for many others
Cheers