client/state/data-layer/wpcom/sites/simple-payments/index.js
function customPostMetadataToProductAttributes( metadata ) {
	const productAttributes = {};

	metadata.forEach( ( { key, value } ) => {
		const schemaKey = metaKeyToSchemaKeyMap[ key ];
		if ( ! schemaKey ) {
			return;
		}

		// If the property's type is marked as boolean in the schema,
		// convert the value from PHP-ish truthy/falsy numbers to a plain boolean.
		// Strings "0" and "" are converted to false, "1" is converted to true.
		if ( metadataSchema[ schemaKey ].type === 'boolean' ) {
			value = !! Number( value );
		}

		productAttributes[ schemaKey ] = value;
	} );

	return productAttributes;
}
function customPostMetadataToProductAttributes( metadata ) {
	const productAttributes = {};

	metadata.forEach( ( { key, value } ) => {
		const schemaKey = metaKeyToSchemaKeyMap[ key ];
		if ( ! schemaKey ) {
			return;
		}

		// If the property's type is marked as boolean in the schema,
		// convert the value from PHP-ish truthy/falsy numbers to a plain boolean.
		// Strings "0" and "" are converted to false, "1" is converted to true.
		if ( metadataSchema[ schemaKey ].type === 'boolean' ) {
			value = !! Number( value );
		}

		productAttributes[ schemaKey ] = value;
	} );

	return productAttributes;
}
function customPostMetadataToProductAttributes ( metadata ) { const productAttributes = { } ; metadata . forEach ( ( { key , value } ) => { const schemaKey = metaKeyToSchemaKeyMap [ key ] ; if ( ! schemaKey ) { return ; } // If the property's type is marked as boolean in the schema, // convert the value from PHP-ish truthy/falsy numbers to a plain boolean. // Strings "0" and "" are converted to false, "1" is converted to true. if ( metadataSchema [ schemaKey ] . type === 'boolean' ) { value = ! ! Number ( value ) ; } productAttributes [ schemaKey ] = value ; } ) ; return productAttributes ; }
Convert custom post metadata array to product attributes
@param { Array } metadata Array of post metadata
@returns { Object } properties extracted from the metadata, to be merged into the product object
Convert custom post metadata array to product attributes