Also support methods in case direct accessing key is deprecated.
For example, in case of refunds, directly accessing parent_id is deprecated, we should use get_parent_id instead.
This commit is contained in:
parent
8ab9fd26ef
commit
975783b2b4
|
@ -914,7 +914,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
'limit' => - 1,
|
||||
)
|
||||
);
|
||||
$cache_hydration->add_to_collection( $refunds, 'refunds', 'parent' );
|
||||
$cache_hydration->add_to_collection( $refunds, 'refunds', 'get_parent_id' );
|
||||
$refunds_by_order_id = $cache_hydration->get_collection( 'refunds' );
|
||||
foreach ( $order_ids as $order_id ) {
|
||||
if ( ! isset( $refunds_by_order_id[ $order_id ] ) ) {
|
||||
|
|
|
@ -93,16 +93,20 @@ class CacheHydration {
|
|||
/**
|
||||
* Adds rows to a collection.
|
||||
*
|
||||
* @param array $data Actual collection data. Should be an array of std objects.
|
||||
* @param string $key Name to identify collection.
|
||||
* @param string $index_key Name of the index key.
|
||||
* @param array $data Actual collection data. Should be an array of std objects.
|
||||
* @param string $key Name to identify collection.
|
||||
* @param string $index_function Name of the index key.
|
||||
* */
|
||||
public function add_to_collection( $data, $key, $index_key ) {
|
||||
public function add_to_collection( $data, $key, $index_function ) {
|
||||
if ( ! isset( $this->collection_hydration[ $key ] ) ) {
|
||||
$this->collection_hydration[ $key ] = array();
|
||||
}
|
||||
foreach ( $data as $row ) {
|
||||
$index = $row->$index_key;
|
||||
if ( method_exists( $row, $index_function ) ) {
|
||||
$index = $row->$index_function();
|
||||
} else {
|
||||
$index = $row->$index_function;
|
||||
}
|
||||
$this->append_collection_for_object( $key, $index, $row );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue