title: Problems accessing and updating data within serialized array
body: <p>I was hoping someone might be able to help me out or point me in the right direction. I've spent a week trying to figure out how to access and update  the weight field in WP ecommerce and Ive had no success at accessing it and updating new values.</p>
  
  <p>The script I'm using access a website to scrape comic book info. It then parses the data from the xml file and assigns variables for the second is for values that are specific to WP Ecommerce.</p>
  
  <p>The whole script works beautifully and creates product pages for each comic book and all data is added into each product. Except for one! and I've been stuck for a week trying to figure out how to access the meta and update it. That's the _wpsc_product_metadata array for weight and weight_unit and other meta values that are stored within.</p>
  
  <p>A comic weighs roughly 3 ounces and I've been trying to assign this value to each card as it's created "3" and "ounce" - I've been unsuccessful.</p>
  
  <p>I've tried probably over so many different ways from digging into the ecommerce code to looking on the net, reading about multidimensional arrays, serialized arrays and it isn't clicking in my noggin'.  Keep in mind I've only been programming in PHP for the past month, and prior to a month ago I knew nothing about code other than when I dabbled in C and C++ 15 years ago. Back then, it was mainly copying existing code and changing the outputs in MUDS (multi-user dungeons) - back when online gaming was text-based, lol.</p>
  
  <p>I assumed I could access  WP Ecommerce meta by using:</p>
  
  <pre><code>get_post_meta($post_id, '_wpsc_product_metadata', true);  That did not work.
  </code></pre>
  
  <p>Other methods of accomplishing this I tried:</p>
  
  <pre><code>get_post_meta(get_the_id($post_id), '_wpsc_product_metadata', true); // no success
  </code></pre>
  
  <p>I tried specific product ids using it like so: </p>
  
  <pre><code>get_the_id(300), or just '300', i've used single quotes double quotes no qoutes, "{}", etc etc etc etc
  </code></pre>
  
  <p>Now when I've used:</p>
  
  <pre><code>  get_post_meta($post_id, ''); //while in the loop
  </code></pre>
  
  <p>The values for  SKU and price are outputted but not what's within _wpsc_product_metadata</p>
  
  <p>Then when i use this:</p>
  
  <pre><code>$product_data['meta'] = array();
  $product_data['meta'] = maybe_unserialize(get_post_meta('$post_id', '' ));
  </code></pre>
  
  <p>This is what I get when I print_r</p>
  
  <pre><code>Array ( [_wpsc_price] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 19.99 ) ) 
  [_wpsc_sku] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 978-0-7851-5209-5 ) ) )
  </code></pre>
  
  <p>So I tried one more thing I went into a specific product and i manually set weight to 5 and I changed the code as follows:</p>
  
  <pre><code>$product_data['meta'] = array();
  $product_data['meta'] = maybe_unserialize(get_post_meta( '44317', '' ));
  </code></pre>
  
  <p>This is the output: </p>
  
  <pre><code>Array ( [_wpsc_stock] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; ) ) 
  [_wpsc_product_metadata] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 
  a:19:{s:25:"wpec_taxes_taxable_amount";s:0:"";s:13:"external_link";s:0:
  "";s:18:"external_link_text";s:0:"";s:20:"external_link_target";s:0:"";s:6:
  "weight";s:3:"0.3";s:11:"weight_unit";s:5:"pound";s:10:"dimensions";a:6:
  {s:6:"height";s:1:"0";s:11:"height_unit";s:2:"in";s:5:"width";s:2:"0 
  ";s:10:"width_unit";s:2:"in";s:6:"length";s:1:"0";s:11:"length_unit";
  s:2:"in";}s:8:"shipping";a:{s:5:"local";s:1:"0";s:13:"international";s:1:"0";}
  s:14:"merchant_notes";s:0:"";s:8:"engraved";s:1:"0";s:23:
  "can_have_uploaded_image";s:1:"0";s:15:"enable_comments";s:0:"";
  s:24:"unpublish_when_none_left";s:1:"0";s:11:"no_shipping";s:1:"0";s:16:
  "quantity_limited";s:1:"0";s:7:"special";s:1:"0";s:17:"display_weight_as";s:5:
  "pound";s:16:"table_rate_price";a:2:{s:8:"quantity";a:0:{}s:11:"table_price";a:0:
  {}}s:17:"google_prohibited";s:1:"0";} ) ) [_wpsc_special_price] =&gt; Array ( [0] =&gt;
  Array ( [0] =&gt; 0 ) ) [_edit_last] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 1 ) ) 
  [_edit_lock] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 1333358836:1 ) ) [_wpsc_sku] =&gt; 
  Array ( [0] =&gt; Array ( [0] =&gt; 978-0-7851-6421-0 ) ) [_wpsc_price] =&gt; Array 
  ( [0] =&gt; Array ( [0] =&gt; 24.99 ) ) [_wpsc_is_donation] =&gt; Array ( [0] =&gt; Array ( 
  [0] =&gt; 0 ) ) [_wpsc_currency] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; a:0:{} ) ) ) 
  </code></pre>
  
  <p>I was hoping, no I'm begging that someone might be able to enlighten me and show me how to access and update this data that is stored in _wpsc_product_metadata specifically weight and weight_unit and it would be even better if you do know how, you could show me an example of updating a newly created posts weight to a value and changing the default weight_unit from pounds to ounces.</p>
  
  <p>Here is the code for reference:</p>
  
  <pre><code>&lt;?php
      function scraping_comic()
      {
          $html = file_get_html('http://site-to-strip.com/');
          $matches = str_replace (' ', ' ', $article);
  
          foreach($html-&gt;find('li.browse_result') as $article)
          {
              // get comic title
              $item['title'] = trim($article-&gt;find('h4', 0)-&gt;find('span',0)-&gt;outertext);
              // get comic title url
              $item['title_url'] = trim($article-&gt;find('h4', 0)-&gt;find('a.grid-hidden',0)-&gt;href);
              // get comic image
              $item['image_url'] = trim($article-&gt;find('img.main_thumb',0)-&gt;src);
              // get comic excerpt
              $item['excerpt'] = trim($article-&gt;find('p.browse_result_description_release', 0)-&gt;plaintext);
              // get comic sales info
              $item['on_sale'] = trim($article-&gt;find('.browse_comics_release_dates', 0)-&gt;plaintext);
              // strip numbers and punctuations
              $item['title2'] = trim(preg_replace("/[^A-Za-z-\t\n\s]/","",$article-&gt;find('h4',0)-&gt;find('span',0)-&gt;plaintext));
              $item['title3'] = trim(preg_replace("/[^A-Za-z]/","",$article-&gt;find('h4',0)-&gt;find('span',0)-&gt;plaintext));
              $ret[] = $item;
          }
          $html-&gt;clear();
          unset($html);
          return $ret;
      }
  
      $ret = scraping_comic();
      if ( ! empty($ret))
      {
          foreach($ret as $v)
          {
              //download the image
              $url = $v['image_url'];
              $title = $v['title3'];
              $now = time();
              $num = date("w");
              if ($num == 0)
              { $sub = 6; }
              else { $sub = ($num-1); }
              $WeekMon  = mktime(0, 0, 0, date("m", $now)  , date("d", $now)-$sub, date("Y", $now));
              $todayh = getdate($WeekMon);
              $d = $todayh[mday];
              $m = $todayh[mon];
              $y = $todayh[year];
              $date_stamp = $d.$m.$y;
  
              //scrape inside pages
              $scrape = 'http://domain.com';
              $comic_details = $v['title_url'];
              $comic_details_url = $scrape.$comic_details;
              $url2 = file_get_html($comic_details_url);
  
              foreach($url2-&gt;find('.comics_detail_lead_left_panel_content') as $the_details);
              $matches = str_replace (' ', ' ', $the_details);
              {
                  $item2['image2_url'] = trim($the_details-&gt;find('img.frame-img',0)-&gt;src);
                  $item2['full_desc'] = trim($the_details-&gt;find('p',0)-&gt;plaintext);
                  $item2['data'] = trim($the_details-&gt;find('dl',0)-&gt;plaintext);
              }
  
              $url2-&gt;clear();
              unset($url2);                           
  
              //download medium-sized image
              $root2 = ('/home/****/public_html/wp-content/blogs.dir/14/files/comics/' .$title.$date_stamp. '-medium.jpg');
              $image2 = $item2['image2_url'];
              copy($image2, $root2);
  
              unset($root2);
              unset($image2);
  
              //match specific data and assign variables
              $string = $item2['data'];
              $number = preg_match("/(Comic|Hardcover|Paperback)[^A-Za-z]+/", $string, $fields);
              switch ($fields[1])
              {
                  case ('Comic'):
                      $cat = array(51, 52);
                      break;
                  case ('Hardcover'):
                      $cat = array(85, 52);
                      break;
                  case ('Paperback'):
                      $cat = array(95, 52);
                      break;
                  default: "";
               }
  
               $number = preg_match("/((January)|(February)|(March)|(April)|(May)|(June)|(July)|(August)|(September)|(October)|(November)|(December))[^A-Za-z0-9,]+[A-Za-z0-9,\s]+/", $string, $fields);
               $date = $fields[0];
               $number = preg_match("/((UPC)|(ISBN))[^0-9-]+([0-9-]+)/", $string, $fields);
               $upc = $fields[4];
               $number = preg_match("/((Price))[^0-9.]+([0-9.\s]+)/", $string, $fields);
               $price = $fields[3];
  
               $full_desc = $item2['full_desc'];
               $maintitle = $v['title'];
               $excerpt   = $v['excerpt'];
  
               $comic_post = array();
               $comic_post['post_title'] = wp_strip_all_tags($maintitle);
  
               $comic_post['post_content'] = wp_strip_all_tags($full_desc);
               $comic_post['post_status'] = 'publish';
               $comic_post['post_author'] = 1;
               $comic_post['post_type'] = 'wpsc-product';
               $comic_post['post_category'] = $cat;
               $comic_post['comment_status'] = 'closed';
               $comic_post['ping_status'] = 'closed';
               $comic_post['post_excerpt'] =  wp_strip_all_tags($excerpt);      
  
               // create comic book
               $post_id = wp_insert_post( $comic_post );
               // category insertion does not work fixed this by calling wp_set_post_terms
               wp_set_post_terms($post_id, $cat, 'wpsc_product_category' );
  
               $wpsc_custom = update_post_meta;
               $wpsc_custom($post_id, '_wpsc_price', $price);
               $wpsc_custom($post_id, '_wpsc_sku', $upc);
  
              //Gain access to WP Ecommerce meta data and assign new values to weight ***IN PROGRESS***
               $product_data['meta'] = array();
               $product_data['meta'] = maybe_unserialize(get_post_meta( $post_id, '' ));
  
               //***TESTING***//
               echo '&lt;br /&gt; the data &lt;br /&gt;';
               print_r($product_data['meta']);
  
               //Set featured image for product
               $filename = ('comics/' .$title .$date_stamp. '-medium.jpg');
               update_post_meta( $post_ID, 'image_thumbnail', $imgloc );
               set_featured_image($post_id, $filename);
          }
      }
      else { echo 'Could not scrape site!'; }
  ?&gt;
  </code></pre>