Announcement

Collapse
No announcement yet.

How to parse user submitted csv?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to parse user submitted csv?

    Howdy Howdy Howdy ,


    So we recently have seen an increase in our B2B side and are getting requests to add the ability to add products to basket via CSV. I have done some digging thru the Merchant-Source and found "ADPM" will add an array of products. Now it seems that i am stuck when it comes to reading in the csv. Has anyone had any luck with reading in a csv and mapping out the data? If so would you mind sharing how you accomplished it?

    Below is the current chunk of code i am working with. I am using the Tool Belt to fetch product data from a code currently. Im thinking the main loop would also take advantage of the g.found and skip an add attempt if the code is not found.

    Code:
    <form method="post" action="&mvte:global:sessionurl;Screen=BASK">
            <input type="hidden" name="Action" value="ADPM">
            <input type="hidden" name="Attributes" value="Yes">
            <input type="hidden" name="Store_Code" value="&mvte:store:code;">
    
            <input type="file" accept=".csv" />
    
    
            <mvt:item name="ry_toolbelt" param="Product_Load|g.found|'84-1011-22'|myproduct" />
            <mvt:assign name="l.settings:category_listing:products[1]" value="l.settings:myproduct" />
    
            <mvt:item name="ry_toolbelt" param="Product_Load|g.found|'80-14110-20'|myproduct" />
            <mvt:assign name="l.settings:category_listing:products[2]" value="l.settings:myproduct" />
    
            <mvt:item name="ry_toolbelt" param="Product_Load|g.found|'25-banditng'|myproduct" />
            <mvt:assign name="l.settings:category_listing:products[3]" value="l.settings:myproduct" />
    
            <mvt:foreach iterator="product" array="category_listing:products">
    
                 <input type="hidden" name="Products[ &mvt:product:id; ]:code" value="&mvte:product:code;">
                <input type="hidden" name="Products[ &mvt:product:id; ]:quantity" value="1">
    
            <mvt:item name="product_attributes" param="product:id" />
    
            </mvt:foreach>
    
            <input type="submit" value="Add to Basket">
        </form>

  • Check out this example.

    https://docs.miva.com/template-language/read-csv-file

    However some things to note:

    Its dangerous to let users upload any file type to your web server. I would recommend you setup a subdomain or a 3rd party file storage as the location the csv files get uploaded to.
    Always limit the file type to just csv and verify that with the Content-Type header.

    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


    • Another option is to do something like this:

      (piece the url together as we don't want bots coming in just yet)

      dev2 dot redrivercatalog.com slash category slash quickadd.html

      This makes it easier for customers (not just B2B) to add products when they know the code. Additionally, you can (not hooked up yet) verify that the product code is correct before submitting.
      Bruce Golub
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment


      • Brennan Thank you for the link. It seems like this might be the route to go if we were to proceed. It does seem however that we would need to have the file stored locally first before we can run that, so as you pointed out the security implications might be bad. I was hoping there might be a way to use " <input type="file" accept=".csv" /> " to take in a user submitted file then parse it with JavaScript all without actually uploading it to the server, or any server for that mater.

        Bruce - PhosphorMedia This is really interesting! Its not exactly what i was looking for but its certainly a good idea. One thing that might make it go to the next level is having the enter key start a new line instead of submit the products. Then the end user *could* use a barcode scanner with auto carriage return and scan products in a bit faster.

        Comment


        • Yes, the best methodology depends on where your customers data is coming from. In our case, it was just what the customers where used to. (Interesting idea of using enter key to add a new line.)
          Another thought is to use a textarea where users could paste their file contents and then parse it on submit.
          Bruce Golub
          Phosphor Media - "Your Success is our Business"

          Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
          phosphormedia.com

          Comment

          Working...
          X

          This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

          This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.

          Accept