csv export using multiple db read not working

mduda 31 Jul, 2016
Hi Bob and Max!

Trying to export data from a db read. Form is setup. When connecting to just the first db read table, export works fine.

model id="p"
conditions
<?php
return array( 'p.order_product_code' => array( 'Student_Membership', 'Adult_Yearly_Membership', 'Adult_Membership_9', 'Staff_Membership_7', 'Staff_Membership_10'));
?>


csv works fine here.

But, when I enable a relation and add the second table to pull data from, csv is empty. On debug - the data is there.

In csv export data path, I have p. Is there something different I need to do to capture every connected table?
GreyHead 31 Jul, 2016
Hi mduda,

What is the query being created? You can see that if you add a Debugger action after the DB Read.

Bob
mduda 31 Jul, 2016
Debug - data array:
Array
(
    [0] => Array
        (
            
 => Array
                (
                    [order_product_id] => 55
                    [order_id] => 32
                    [product_id] => 7
                    [order_product_quantity] => 1
                    [order_product_name] => Adult Membership<span class="hikashop_product_variant_subname">:  Adult Yearly Membership</span>
                    [order_product_code] => Adult_Yearly_Membership
                    [order_product_price] => 12.00
                    [order_product_tax] => 0.00000
                    [order_product_tax_info] => a:0:{}
                    [order_product_options] => a:2:{i:0;O:8:"stdClass":10:{s:25:"variant_characteristic_id";s:1:"6";s:18:"variant_product_id";s:1:"7";s:8:"ordering";s:1:"0";s:17:"characteristic_id";s:1:"6";s:24:"characteristic_parent_id";s:1:"5";s:20:"characteristic_value";s:23:"Adult Yearly Membership";s:20:"characteristic_alias";s:0:"";s:27:"characteristic_display_type";s:0:"";s:21:"characteristic_params";s:0:"";s:23:"characteristic_ordering";s:1:"0";}s:20:"PTSA Membership Type";s:23:"Adult Yearly Membership";}
                    [order_product_option_parent_id] => 0
                    [order_product_wishlist_id] => 0
                    [order_product_shipping_id] => 
                    [order_product_shipping_method] => 
                    [order_product_shipping_price] => 0.00000
                    [order_product_shipping_tax] => 0.00000
                    [order_product_shipping_params] => 
                    [ptsamembername] => test user
                    [ptsamember2name] => 
                    [ptsamember3name] => 
                    [amount] => 
                    [employermatch] => 
                    [studentfullname] => 
                    [ptsastudentmembergrade] => 
                    [memberfirstname] => 
                    [memberlastname] => 
                )

            [o] => Array
                (
                    [order_id] => 32
                    [order_billing_address_id] => 34
                    [order_shipping_address_id] => 34
                    [order_user_id] => 56
                    [order_status] => created
                    [order_type] => sale
                    [order_number] => B3K2
                    [order_created] => 1438567504
                    [order_modified] => 1438567504
                    [order_invoice_id] => 0
                    [order_invoice_number] => 
                    [order_invoice_created] => 0
                    [order_currency_id] => 2
                    [order_full_price] => 12.00000
                    [order_tax_info] => a:0:{}
                    [order_discount_code] => 
                    [order_discount_price] => 0.00000
                    [order_discount_tax] => 0.00000
                    [order_payment_id] => 2
                    [order_payment_method] => paypal
                    [order_payment_price] => 0.00000
                    [order_payment_params] => 
                    [order_shipping_id] => 
                    [order_shipping_method] => 
                    [order_shipping_price] => 0.00000
                    [order_shipping_tax] => 0.00000
                    [order_shipping_params] => 
                    [order_partner_id] => 0
                    [order_partner_price] => 0.00000
                    [order_partner_paid] => 0
                    [order_partner_currency_id] => 0
                    [order_ip] => 
                    [order_site_id] => 
                    [comments] => 
                    [membership_submitted] => 0
                    [date] => 2015-08-02 21:05:04
                    [membership_comments] => 
                    [gift] => 
                    [order_currency_info] => 
                    [order_payment_tax] => 0.00000
                )

        )

    [1] => Array
        (
            
 => Array
                (
                    [order_product_id] => 45
                    [order_id] => 26
                    [product_id] => 7
                    [order_product_quantity] => 2
                    [order_product_name] => Adult Membership<span class="hikashop_product_variant_subname">:  Adult Yearly Membership</span>
                    [order_product_code] => Adult_Yearly_Membership
                    [order_product_price] => 12.00
                    [order_product_tax] => 0.00000
                    [order_product_tax_info] => a:0:{}
                    [order_product_options] => a:2:{i:0;O:8:"stdClass":10:{s:25:"variant_characteristic_id";s:1:"6";s:18:"variant_product_id";s:1:"7";s:8:"ordering";s:1:"0";s:17:"characteristic_id";s:1:"6";s:24:"characteristic_parent_id";s:1:"5";s:20:"characteristic_value";s:23:"Adult Yearly Membership";s:20:"characteristic_alias";s:0:"";s:27:"characteristic_display_type";s:0:"";s:21:"characteristic_params";s:0:"";s:23:"characteristic_ordering";s:1:"0";}s:20:"PTSA Membership Type";s:23:"Adult Yearly Membership";}
                    [order_product_option_parent_id] => 0
                    [order_product_wishlist_id] => 0
                    [order_product_shipping_id] => 
                    [order_product_shipping_method] => 
                    [order_product_shipping_price] => 0.00000
                    [order_product_shipping_tax] => 0.00000
                    [order_product_shipping_params] => 
                    [ptsamembername] => another user
                    [ptsamember2name] => kid number2
                    [ptsamember3name] => 
                    [amount] => 
                    [employermatch] => 
                    [studentfullname] => 
                    [ptsastudentmembergrade] => 
                    [memberfirstname] => 
                    [memberlastname] => 
                )

            [o] => Array
                (
                    [order_id] => 26
                    [order_billing_address_id] => 27
                    [order_shipping_address_id] => 27
                    [order_user_id] => 51
                    [order_status] => confirmed
                    [order_type] => sale
                    [order_number] => B2D6
                    [order_created] => 1437484935
                    [order_modified] => 1437485083
                    [order_invoice_id] => 0
                    [order_invoice_number] => 
                    [order_invoice_created] => 0
                    [order_currency_id] => 2
                    [order_full_price] => 31.00000
                    [order_tax_info] => a:0:{}
                    [order_discount_code] => 
                    [order_discount_price] => 0.00000
                    [order_discount_tax] => 0.00000
                    [order_payment_id] => 2
                    [order_payment_method] => paypal
                    [order_payment_price] => 0.00000
                    [order_payment_params] => 
                    [order_shipping_id] => 
                    [order_shipping_method] => 
                    [order_shipping_price] => 0.00000
                    [order_shipping_tax] => 0.00000
                    [order_shipping_params] => 
                    [order_partner_id] => 0
                    [order_partner_price] => 0.00000
                    [order_partner_paid] => 0
                    [order_partner_currency_id] => 0
                    [order_ip] => 
                    [order_site_id] => 
                    [comments] => 
                    [membership_submitted] => 0
                    [date] => 2015-07-21 08:22:15
                    [membership_comments] => 
                    [gift] => 
                    [order_currency_info] => 
                    [order_payment_tax] => 0.00000
                )

        )

etc.

Debug - info
Array
(
    [2] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `p`.`order_product_id` AS `p.order_product_id`, `p`.`order_id` AS `p.order_id`, `p`.`product_id` AS `p.product_id`, `p`.`order_product_quantity` AS `p.order_product_quantity`, `p`.`order_product_name` AS `p.order_product_name`, `p`.`order_product_code` AS `p.order_product_code`, `p`.`order_product_price` AS `p.order_product_price`, `p`.`order_product_tax` AS `p.order_product_tax`, `p`.`order_product_tax_info` AS `p.order_product_tax_info`, `p`.`order_product_options` AS `p.order_product_options`, `p`.`order_product_option_parent_id` AS `p.order_product_option_parent_id`, `p`.`order_product_wishlist_id` AS `p.order_product_wishlist_id`, `p`.`order_product_shipping_id` AS `p.order_product_shipping_id`, `p`.`order_product_shipping_method` AS `p.order_product_shipping_method`, `p`.`order_product_shipping_price` AS `p.order_product_shipping_price`, `p`.`order_product_shipping_tax` AS `p.order_product_shipping_tax`, `p`.`order_product_shipping_params` AS `p.order_product_shipping_params`, `p`.`ptsamembername` AS `p.ptsamembername`, `p`.`ptsamember2name` AS `p.ptsamember2name`, `p`.`ptsamember3name` AS `p.ptsamember3name`, `p`.`amount` AS `p.amount`, `p`.`employermatch` AS `p.employermatch`, `p`.`studentfullname` AS `p.studentfullname`, `p`.`ptsastudentmembergrade` AS `p.ptsastudentmembergrade`, `p`.`memberfirstname` AS `p.memberfirstname`, `p`.`memberlastname` AS `p.memberlastname`, `o`.`order_id` AS `o.order_id`, `o`.`order_billing_address_id` AS `o.order_billing_address_id`, `o`.`order_shipping_address_id` AS `o.order_shipping_address_id`, `o`.`order_user_id` AS `o.order_user_id`, `o`.`order_status` AS `o.order_status`, `o`.`order_type` AS `o.order_type`, `o`.`order_number` AS `o.order_number`, `o`.`order_created` AS `o.order_created`, `o`.`order_modified` AS `o.order_modified`, `o`.`order_invoice_id` AS `o.order_invoice_id`, `o`.`order_invoice_number` AS `o.order_invoice_number`, `o`.`order_invoice_created` AS `o.order_invoice_created`, `o`.`order_currency_id` AS `o.order_currency_id`, `o`.`order_full_price` AS `o.order_full_price`, `o`.`order_tax_info` AS `o.order_tax_info`, `o`.`order_discount_code` AS `o.order_discount_code`, `o`.`order_discount_price` AS `o.order_discount_price`, `o`.`order_discount_tax` AS `o.order_discount_tax`, `o`.`order_payment_id` AS `o.order_payment_id`, `o`.`order_payment_method` AS `o.order_payment_method`, `o`.`order_payment_price` AS `o.order_payment_price`, `o`.`order_payment_params` AS `o.order_payment_params`, `o`.`order_shipping_id` AS `o.order_shipping_id`, `o`.`order_shipping_method` AS `o.order_shipping_method`, `o`.`order_shipping_price` AS `o.order_shipping_price`, `o`.`order_shipping_tax` AS `o.order_shipping_tax`, `o`.`order_shipping_params` AS `o.order_shipping_params`, `o`.`order_partner_id` AS `o.order_partner_id`, `o`.`order_partner_price` AS `o.order_partner_price`, `o`.`order_partner_paid` AS `o.order_partner_paid`, `o`.`order_partner_currency_id` AS `o.order_partner_currency_id`, `o`.`order_ip` AS `o.order_ip`, `o`.`order_site_id` AS `o.order_site_id`, `o`.`comments` AS `o.comments`, `o`.`membership_submitted` AS `o.membership_submitted`, `o`.`date` AS `o.date`, `o`.`membership_comments` AS `o.membership_comments`, `o`.`gift` AS `o.gift`, `o`.`order_currency_info` AS `o.order_currency_info`, `o`.`order_payment_tax` AS `o.order_payment_tax` FROM `uh46v_hikashop_order_product` AS `p` LEFT JOIN `uh46v_hikashop_order` AS `o` ON `p`.`order_id`= `o`.`order_id` WHERE `p`.`order_product_code` IN ('Student_Membership', 'Adult_Yearly_Membership', 'Adult_Membership_9', 'Staff_Membership_7', 'Staff_Membership_10')
                        )

                )

        )

)
GreyHead 01 Aug, 2016
Hi Mduda,

It looks as though all the information is there but in separate sub-arrays.

Depending on what you want to do you could use a Custom Code action to merge the subarrays; or you could re-structure the DB Read to use a singe action to get the merged table (use the settings on the Relations tab to do this.

Bob
mduda 01 Aug, 2016
Hi Bob - I actually have a cc that is setup, connecting 4 tables - and it works great. Now I'm trying to find a way to download the info. So this is why I'm attempting to setup the csv. I'm using the same approach with the cf as I did the cc. So why is the data showing in subarrays?

Basic tab:
[attachment=0]cf_csvexport_basic.png[/attachment]

Relation:
[attachment=1]cf_csvexport_relation2.png[/attachment]
GreyHead 01 Aug, 2016
Hi mduda,

It looks as though you have two separate DB REad actions here ?

Bob
mduda 01 Aug, 2016
No sorry - I have one on the load - which is disabled - I just put that one in there to read the debugger. I have the other one enabled on submit.
GreyHead 02 Aug, 2016
Hi Mduda,

If you look at the images you posted the two actions have different IDs - the little blue icon after Edit action: DB Read

That tells me that they are from two different actions.

Bob
mduda 02 Aug, 2016
Hi Bob - sorry for the confusion...I may not have explained fully. I have TWO DB Reads. The first is on Load. It is DISABLED (sorry I originally grabbed a pic of this one-which definitely added to the confusion) I added this DB Read on Load so that I could see the debug data.
[attachment=1]csv_download_two_dbreads.png[/attachment]

The second DB Read is ENABLED. This one is on Submit.
BASIC TAB INFO
[attachment=0]csv_download_dbread_basic.png[/attachment]
[attachment=2]csv_download_dbread_basic_conditions.png[/attachment]

Relation Tab
[attachment=3]csv_download_dbread_relations.png[/attachment]
[attachment=4]csv_download_dbread_relations_conditions.png[/attachment]
mduda 04 Aug, 2016
Hey Bob - any guidance on what I need to do to get this to work?
GreyHead 04 Aug, 2016
Hi mduda,

Sorry, it looks as though an earlier reply got lost when the site was misbehaving.

I can't see what the problem is here.

By all means PM me the site URL, the form name, and a SuperAdmin login and I'll take a quick look.

Bob
GreyHead 07 Aug, 2016
Hi mduda,

I couldn't work out why you were getting double arrays - very odd, it may be a bug in the DB Read code.

I have made a copy of your form membershipdownload_bob that is now working. It has a Custom Code action that merges the two arrays from the DB Read into a single $form->data['data'] array that can then be exported.

Bob
This topic is locked and no more replies can be posted.