Skip to content

Commit

Permalink
Fix encoding issue with attribute values and move variation data to t…
Browse files Browse the repository at this point in the history
…ooltip Closes woocommerce#5169
  • Loading branch information
mikejolley committed Mar 24, 2014
1 parent e41f9d3 commit 8815e2f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 2 additions & 0 deletions assets/js/admin/meta-boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jQuery( function($){
});
}

runTipTip();

// Allow tabbing
$('#titlediv #title').keyup(function( event ) {
var code = event.keyCode || event.which;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin/meta-boxes.min.js

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions includes/admin/post-types/meta-boxes/views/html-order-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
if ( $_product && $_product->get_sku() )
echo '<br/><strong>' . __( 'Product SKU:', 'woocommerce' ).'</strong> ' . esc_html( $_product->get_sku() );

if ( $_product && isset( $_product->variation_data ) )
echo '<br/>' . wc_get_formatted_variation( $_product->variation_data, true );

?>"><?php echo $_product->get_image( 'shop_thumbnail', array( 'title' => '' ) ); ?></a>
<?php else : ?>
<?php echo wc_placeholder_img( 'shop_thumbnail' ); ?>
Expand All @@ -34,11 +37,6 @@

<input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" />

<?php
if ( $_product && isset( $_product->variation_data ) )
echo '<br/>' . wc_get_formatted_variation( $_product->variation_data, true );
?>

<div class="view">
<?php
if ( $metadata = $order->has_meta( $item_id ) ) {
Expand All @@ -55,11 +53,14 @@
'_line_subtotal_tax',
'_line_total',
'_line_tax',
) ) ) ) continue;
) ) ) ) {
continue;
}

// Skip serialised meta
if ( is_serialized( $meta['meta_value'] ) )
if ( is_serialized( $meta['meta_value'] ) ) {
continue;
}

echo '<tr><th>' . wp_kses_post( urldecode( $meta['meta_key'] ) ) . ':</th><td>' . wp_kses_post( wpautop( urldecode( $meta['meta_value'] ) ) ) . '</td></tr>';
}
Expand Down Expand Up @@ -89,11 +90,14 @@
'_line_subtotal_tax',
'_line_total',
'_line_tax',
) ) ) ) continue;
) ) ) ) {
continue;
}

// Skip serialised meta
if ( is_serialized( $meta['meta_value'] ) )
if ( is_serialized( $meta['meta_value'] ) ) {
continue;
}

$meta['meta_key'] = urldecode( $meta['meta_key'] );
$meta['meta_value'] = esc_textarea( urldecode( $meta['meta_value'] ) ); // using a <textarea />
Expand Down
3 changes: 2 additions & 1 deletion includes/wc-attribute-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ function wc_attribute_label( $name ) {

$label = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );

if ( ! $label )
if ( ! $label ) {
$label = ucfirst( $name );
}
} else {
$label = $name;
}
Expand Down
33 changes: 17 additions & 16 deletions includes/wc-product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,20 @@ function wc_placeholder_img( $size = 'shop_thumbnail' ) {
* @return string
*/
function wc_get_formatted_variation( $variation = '', $flat = false ) {
$return = '';

if ( is_array( $variation ) ) {

if ( ! $flat )
if ( ! $flat ) {
$return = '<dl class="variation">';
else
$return = '';
}

$variation_list = array();

foreach ( $variation as $name => $value ) {

if ( ! $value )
if ( ! $value ) {
continue;
}

// If this is a term slug, get the term's nice name
if ( taxonomy_exists( esc_attr( str_replace( 'attribute_', '', $name ) ) ) ) {
Expand All @@ -324,24 +325,24 @@ function wc_get_formatted_variation( $variation = '', $flat = false ) {
$value = $term->name;
}

if ( $flat )
$variation_list[] = wc_attribute_label(str_replace('attribute_', '', $name)).': '.$value;
else
$variation_list[] = '<dt>'.wc_attribute_label(str_replace('attribute_', '', $name)).':</dt><dd>'.$value.'</dd>';
if ( $flat ) {
$variation_list[] = wc_attribute_label( str_replace( 'attribute_', '', $name ) ) . ': ' . urldecode( $value );
} else {
$variation_list[] = '<dt>' . wc_attribute_label( str_replace( 'attribute_', '', $name ) ) . ':</dt><dd>' . urldecode( $value ) . '</dd>';
}
}

if ( $flat )
if ( $flat ) {
$return .= implode( ', ', $variation_list );
else
} else {
$return .= implode( '', $variation_list );
}

if ( ! $flat )
if ( ! $flat ) {
$return .= '</dl>';

return $return;
}
}

return '';
return $return;
}

/**
Expand Down

0 comments on commit 8815e2f

Please sign in to comment.