wc-plugin-framework
wc-plugin-framework copied to clipboard
Investigate additional is_array checks in SV_WC_Helper::array_to_xml()
trafficstars
With the latest XML Export version, when iterating over order xml, I'm getting warnings for an invalid foreach argument:
Stack trace
PHP Warning: Invalid argument supplied for foreach() in /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/class-sv-wc-helper.php on line 340
PHP Stack trace:
PHP 1. {main}() /wp-admin/admin-ajax.php:0
PHP 2. do_action() /wp-admin/admin-ajax.php:101
PHP 3. WP_Hook->do_action() /wp-includes/plugin.php:453
PHP 4. WP_Hook->apply_filters() /wp-includes/class-wp-hook.php:323
PHP 5. SV_WP_Background_Job_Handler->maybe_handle() /wp-includes/class-wp-hook.php:298
PHP 6. SV_WP_Background_Job_Handler->handle() /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/utilities/class-sv-wp-background-job-handler.php:131
PHP 7. SV_WP_Background_Job_Handler->process_job() /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/utilities/class-sv-wp-background-job-handler.php:542
PHP 8. WC_Customer_Order_XML_Export_Suite_Background_Export->process_item() /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/utilities/class-sv-wp-background-job-handler.php:607
PHP 9. WC_Customer_Order_XML_Export_Suite_Handler->export_item() /woocommerce-customer-order-xml-export-suite/includes/class-wc-customer-order-xml-export-suite-background-export.php:77
PHP 10. WC_Customer_Order_XML_Export_Suite_Generator->get_output() /woocommerce-customer-order-xml-export-suite/includes/class-wc-customer-order-xml-export-suite-handler.php:721
PHP 11. WC_Customer_Order_XML_Export_Suite_Generator->get_orders_xml() /woocommerce-customer-order-xml-export-suite/includes/class-wc-customer-order-xml-export-suite-generator.php:1304
PHP 12. WC_Customer_Order_XML_Export_Suite_Generator->get_xml() /woocommerce-customer-order-xml-export-suite/includes/class-wc-customer-order-xml-export-suite-generator.php:191
PHP 13. SV_WC_Helper::array_to_xml() /woocommerce-customer-order-xml-export-suite/includes/class-wc-customer-order-xml-export-suite-generator.php:1221
PHP 14. SV_WC_Helper::array_to_xml() /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/class-sv-wc-helper.php:354
PHP 15. SV_WC_Helper::array_to_xml() /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/class-sv-wc-helper.php:341
PHP 16. SV_WC_Helper::array_to_xml() /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/class-sv-wc-helper.php:354
PHP 17. SV_WC_Helper::array_to_xml() /woocommerce-customer-order-xml-export-suite/lib/skyverge/woocommerce/class-sv-wc-helper.php:341
It looks like we're walking to the end of the array and trying to then walk a string instead potentially, as the array before conversion looks fine:
Logged order export
Array
(
[Order] => Array
(
[0] => Array
(
[OrderId] => 1159
[OrderNumber] => 1159
[OrderDate] => 2017-07-25 14:57:23
[OrderStatus] => processing
[BillingFirstName] => Walter
[BillingLastName] => White
[BillingFullName] => Walter White
[BillingCompany] =>
[BillingAddress1] => 308 Negra Arroyo Lane
[BillingAddress2] =>
[BillingCity] => Albuquerque
[BillingState] => NM
[BillingPostCode] => 87104
[BillingCountry] => US
[BillingEmail] => [email protected]
[BillingPhone] => 5558675309
[ShippingFirstName] => Walter
[ShippingLastName] => White
[ShippingFullName] => Walter White
[ShippingCompany] =>
[ShippingAddress1] => 308 Negra Arroyo Lane
[ShippingAddress2] =>
[ShippingCity] => Albuquerque
[ShippingState] => NM
[ShippingPostCode] => 87104
[ShippingCountry] => US
[ShippingMethodId] => local_pickup_plus
[ShippingMethod] => Store Pickup
[PaymentMethodId] => bogus_gateway
[PaymentMethod] => Bogus (Test)
[DiscountTotal] => 0
[ShippingTotal] => 10.8
[ShippingTaxTotal] => 0.00
[OrderTotal] => 226.80
[FeeTotal] => 0
[TaxTotal] => 0.00
[CompletedDate] =>
[CustomerNote] =>
[CustomerId] => 2
[OrderLineItems] => Array
(
[0] => Array
(
[SKU] =>
[Quantity] => 1
[Price] => 216.00
[Meta] => Length (ft): 12, Width (ft): 3, Total Area (sq. ft.): 36
[ItemName] => Tarp
[LineTotal] => 216.00
)
)
[OrderNotes] => Array
(
[OrderNote] => Array
(
[0] => Array
(
[Date] => 2017-07-25 16:17:48
[Author] => WooCommerce
[Content] => Order exported to XML and successfully downloaded.
)
[1] => Array
(
[Date] => 2017-07-25 14:57:25
[Author] => WooCommerce
[Content] => Order status changed from Pending payment to Processing.
)
[2] => Array
(
[Date] => 2017-07-25 14:57:25
[Author] => WooCommerce
[Content] => Tarp (#478) stock reduced from 118.5 to 82.5.
)
[3] => Array
(
[Date] => 2017-07-25 14:57:25
[Author] => WooCommerce
[Content] => Bogus is always approved 😎
)
)
)
)
)
)
Potentially a check in this bit to see if $child_element_value is an array before we loop it / recursively call the function?