Skip to main contentSkip to navigationSkip to footer
Punchmark Charlotte, NC

Challenge 1: CSV Merge

Challenge Level: easy

Background

Punchmark accepts inventory data from industry vendors in order for our retail website clients to display this inventory on their websites.
A few months ago we received an inventory CSV file from one of our suppliers (download: OriginalInventory.csv). 

Preview (click to enlarge):

Last month, we received an updated inventory CSV file (download: UpdatedInventory.csv). 
The updated inventory file contains important updates for some of the original products, but it is missing some critical information, such as Item Title and Image.

Preview (click to enlarge):


Instructions

Download the two CSV files from the links above.
Your task is to create a command line PHP script that reads these two CSV files, and outputs one final CSV file with the correct columns taken from both CSV files. Each line of the first CSV file will need to be matched with the correct line of the second CSV file using the Item # field, so that all the columns in each row represent the same item.

Required Rows and Columns

The output file should contain all the products from the updated CSV. 
It needs to contain the columns: 'Style #', 'Item #', 'Item Title', 'Unit Price', 'MSRP', 'On-Hand', 'WebDescription', 'Collection', 'Product Type', and Image in that order.

Column Sources

The columns: 'Style #', 'Item #', 'Unit Price', 'MSRP', 'On-Hand', and 'WebDescription' come from the updated inventory CSV. The columns: 'Item Title', 'Collection', 'Product Type', and 'Image' come from the orignal inventory CSV.

Please note that the information in the two CSV files must be matched by 'Item #' for the data to be correct. The order of the products in the updated CSV do not match the order of the products in the orignal CSV, and in fact, some products may be missing from each one. The second CSV also contains some duplicate Item #'s. It is also missing some. You willl make note of these discrepancies in your output.

Output

After completing the task, the script should output the number of duplicate Style #s, if any, in the update CSV file, as well as any products that exist in the Update CSV that are not found in the original CSV, like this: 

Total Lines (original): 999
Duplicate Style #s: 999
Items missing from Original CSV: 999

The output csv file should be named: FullInventory-merged.csv
Your PHP script should be named: csvMerge.php

Submissions

Send your submissions to careers@punchmark.com in the form of a zip folder.
The zip folder should contain your PHP script as well as the output CSV file. Please include any notes in a README file inside the zip, or inside the body of the email.

Happy coding! We hope you enjoy this challenge as much as we enjoyed creating it.