Jump to content

joshlevinson

New Members
  • Posts

    3
  • Joined

  • Last visited

joshlevinson's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. My plugin is a custom export/update plugin that lets the user export his products, update the price grids, and upload the csv to change the data quicker than using the visual editor. The price grids are stored as a serialized array in the post's meta (_cp_array). To test my plugin, I uploaded a csv with data identical to that which was already in the DB. The function below informed that the Table Rates had not changed (because they hadn't!). Next, I changed ONE value in ONE row of the csv. Tested again. This time, the function informed that for the product I changed, the post meta had been updated. However, the meta is never actually updated. Looking in the DB for the meta (_cp_array), the serialized string stays the same after running my upload function multiple times, with update_post_meta returning true each time, and echoing the "updated" message. For debugging purposes, I used var_export($unserialized) to see what it outputted, and also var_export(serialize($unserialized)) to see what the data should look like when writing the serialized array/string to the DB. The var_export (serialized and not) on my plugin screen always displays the new, changed data from the csv. It gets even stranger...next I tried adding new metadata to a product that didn't have anything for that specific metadata (it was empty and the meta key didn't exist for that product). The function displays that it updated the metadata for that product. However, looking in the DB reveals that the serialized value for that product's meta (_cp_array) was very different from the data I entered! The var_export displays the correct array and serialized string, but the DB had very different keys and values! All relevant examples/info: http://pastebin.com/jYjuzg6G Why is the plugin not changing the metadata, even though the function returns true? And why, when it added new metadata, did it add incorrect metadata, even though the serialized array was correct when outputted to the screen? The below code is responsible for updating the product's _cp_array: if(update_post_meta($id, '_cp_array', $unserialized)) echo 'Table Rate Prices Updated.<br />'; else echo 'No Table Rate Change.'; var_export($unserialized); echo '<br />'; var_export(serialize($unserialized));
  2. I know I am reviving this super old thread, but I just wanted to comment that this is exactly the code I needed to help me parse a csv I was using for an e-commerce system. I had a column with data like 11:15.75|100:14.94|250:14.16 and needed the data before the colon to be the index for the data after the colon. I exploded the string into an array like $array[0] = '11:15.75' and so on, and this code helped me build an array like $array[11]='15.75' and so on. Thanks heaps for your insight!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.