Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_all_import_parsed_product_attributes #58

Open
Programmer095 opened this issue May 24, 2019 · 3 comments
Open

wp_all_import_parsed_product_attributes #58

Programmer095 opened this issue May 24, 2019 · 3 comments
Assignees

Comments

@Programmer095
Copy link
Contributor

WooCo Add-On 3.0.7+

This allows for the use of delimited Attribute names and values, but you must write the custom code to process those values and return them to WP All Import.

add_filter("wp_all_import_parsed_product_attributes", "wpai_wp_all_import_parsed_product_attributes", 10, 3);
/**
 * Filter product attributes.
 * @param array $attributes - Parsed product attributes
 * [
 *    'name' => string, 'value' => string, 'in_taxonomy' => bool, 'is_create_taxonomy_terms' => bool, 'is_visible' => bool, 'in_variation' => bool
 * ]
 * @param int $pid - Product ID
 * @param int $import_id
 */
function wpai_wp_all_import_parsed_product_attributes($attributes, $pid, $import_id) {  
  return $attributes;
}
@Programmer095
Copy link
Contributor Author

Programmer095 commented May 25, 2019

Here's an example of how to use it:

add_filter("wp_all_import_parsed_product_attributes", "wpai_wp_all_import_parsed_product_attributes", 10, 3);
/**
 * Filter product attributes.
 * @param array $attributes - Parsed product attributes
 * [
 *    'name' => string, 'value' => string, 'in_taxonomy' => bool, 'is_create_taxonomy_terms' => bool, 'is_visible' => bool, 'in_variation' => bool
 * ]
 * @param int $pid - Product ID
 * @param int $import_id
 */
function wpai_wp_all_import_parsed_product_attributes($attributes, $pid, $import_id) {  
	// Here's the example attribute layout https://d.pr/i/bcVI5v
	
	// hold new attributes
	$new_attributes = array();
	
	// process each attribute row one by one
	foreach($attributes as $attribute ){
		// split the individual names and values
		$names = explode('|', $attribute['name']);
		$values = explode('|', $attribute['value']);
	
		foreach( $names as $key => $name ){
			$temp = array();
			$temp['name'] = $name;
			$temp['value'] = isset($values[$key]) ? $values[$key] : '';
			$temp['in_taxonomy'] = $attribute['in_taxonomy'];
			$temp['is_create_taxonomy_terms'] = $attribute['is_create_taxonomy_terms'];
			$temp['in_variation'] = $attribute['in_variation'];
                       $temp['is_visible'] = $attribute['is_visible'];
			
			$new_attributes[] = $temp;
		}
	}
	return $new_attributes;
}

@dimmisel
Copy link

dimmisel commented Jul 4, 2019

Hello guys. Please note that the above code has a bug. The visible field is missing.
Look my code below fixed and tried in action.

add_filter("wp_all_import_parsed_product_attributes", "wpai_wp_all_import_parsed_product_attributes", 10, 3);
/**
 * Filter product attributes.
 * @param array $attributes - Parsed product attributes
 * [
 *    'name' => string, 'value' => string, 'in_taxonomy' => bool, 'is_create_taxonomy_terms' => bool, 'is_visible' => bool, 'in_variation' => bool
 * ]
 * @param int $pid - Product ID
 * @param int $import_id
 */
function wpai_wp_all_import_parsed_product_attributes($attributes, $pid, $import_id) {  
	// Here's the example attribute layout https://d.pr/i/bcVI5v

	// hold new attributes
	$new_attributes = array();
	
	// process each attribute row one by one
	foreach($attributes as $attribute ){
		// splite the individual names and values
		$names = explode('|', $attribute['name']);
		$values = explode('|', $attribute['value']);
	
		foreach( $names as $key => $name ){
			$temp = array();
			$temp['name'] = $name;
			$temp['value'] = isset($values[$key]) ? $values[$key] : '';
			$temp['in_taxonomy'] = $attribute['in_taxonomy'];
			$temp['is_create_taxonomy_terms'] = $attribute['is_create_taxonomy_terms'];
			$temp['in_variation'] = $attribute['in_variation'];
			$temp['is_visible'] = $attribute['is_visible'];
			
			$new_attributes[] = $temp;
		}
	}
	return $new_attributes;
}

@Programmer095
Copy link
Contributor Author

Hi @dimmisel,

Thanks for pointing that out! ( This was generalized from some project code where the visibility was set elsewhere and I missed adding it back in )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants