Update importer to grab downloads id from export file when updating rows

This commit is contained in:
Jonathan Sadowski 2021-05-21 15:39:04 -05:00
parent 84eaa48511
commit c67fda9552
3 changed files with 13 additions and 2 deletions

View File

@ -566,6 +566,8 @@ class WC_Product_CSV_Importer_Controller {
/* translators: %d: Attribute number */ /* translators: %d: Attribute number */
__( 'Attribute %d default', 'woocommerce' ) => 'attributes:default', __( 'Attribute %d default', 'woocommerce' ) => 'attributes:default',
/* translators: %d: Download number */ /* translators: %d: Download number */
__( 'Download %d ID', 'woocommerce' ) => 'downloads:id',
/* translators: %d: Download number */
__( 'Download %d name', 'woocommerce' ) => 'downloads:name', __( 'Download %d name', 'woocommerce' ) => 'downloads:name',
/* translators: %d: Download number */ /* translators: %d: Download number */
__( 'Download %d URL', 'woocommerce' ) => 'downloads:url', __( 'Download %d URL', 'woocommerce' ) => 'downloads:url',
@ -721,6 +723,7 @@ class WC_Product_CSV_Importer_Controller {
'downloads' => array( 'downloads' => array(
'name' => __( 'Downloads', 'woocommerce' ), 'name' => __( 'Downloads', 'woocommerce' ),
'options' => array( 'options' => array(
'downloads:id' . $index => __( 'Download ID', 'woocommerce' ),
'downloads:name' . $index => __( 'Download name', 'woocommerce' ), 'downloads:name' . $index => __( 'Download name', 'woocommerce' ),
'downloads:url' . $index => __( 'Download URL', 'woocommerce' ), 'downloads:url' . $index => __( 'Download URL', 'woocommerce' ),
'download_limit' => __( 'Download limit', 'woocommerce' ), 'download_limit' => __( 'Download limit', 'woocommerce' ),

View File

@ -102,6 +102,7 @@ function wc_importer_default_special_english_mappings( $mappings ) {
'Attribute %d visible' => 'attributes:visible', 'Attribute %d visible' => 'attributes:visible',
'Attribute %d global' => 'attributes:taxonomy', 'Attribute %d global' => 'attributes:taxonomy',
'Attribute %d default' => 'attributes:default', 'Attribute %d default' => 'attributes:default',
'Download %d ID' => 'downloads:id',
'Download %d name' => 'downloads:name', 'Download %d name' => 'downloads:name',
'Download %d URL' => 'downloads:url', 'Download %d URL' => 'downloads:url',
'Meta: %s' => 'meta:', 'Meta: %s' => 'meta:',

View File

@ -894,6 +894,12 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
} }
unset( $data[ $key ] ); unset( $data[ $key ] );
} elseif ( $this->starts_with( $key, 'downloads:id' ) ) {
if ( ! empty( $value ) ) {
$downloads[ str_replace( 'downloads:id', '', $key ) ]['id'] = $value;
}
unset( $data[ $key ] );
} elseif ( $this->starts_with( $key, 'downloads:name' ) ) { } elseif ( $this->starts_with( $key, 'downloads:name' ) ) {
if ( ! empty( $value ) ) { if ( ! empty( $value ) ) {
$downloads[ str_replace( 'downloads:name', '', $key ) ]['name'] = $value; $downloads[ str_replace( 'downloads:name', '', $key ) ]['name'] = $value;
@ -935,6 +941,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
} }
$data['downloads'][] = array( $data['downloads'][] = array(
'download_id' => isset( $file['id'] ) ? $file['id'] : null,
'name' => $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['url'] ), 'name' => $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['url'] ),
'file' => $file['url'], 'file' => $file['url'],
); );