Thread tagged as: Question, Shop

Product import with blocks

I've written an import script to directly inject some products into an installation of perch_shop. This is working perfectly.

I now need to extend this a little to insert some content into a block which exists in my product template. This is also seems simple enough except for the _block_id. Is this unique to an individual product or across all blocks and does it have any other links/tie-ins that I need to be aware of? I couldn't find any other reference to this ID.


Caleb Evans

Caleb Evans 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It just needs to be unique for the block.

Thanks Drew

Hi Caleb, as product import is still on the roadmap for perch shop, are you able to give us a clue about your import script - cheeky I know but I am looking at upgrading a perch paypal shop to perch shop and client is getting anxious if they have to manually port across their hundreds of products. Many thanks for any response.

Hi Charlie

It was a very custom script that I would be happy to share but it would certainly need quite a bit of work depending on your situation. Below is breakdown of what I/it did.

  • I manually exported the relevant fields from their old database and imported this into a temporary table in the Perch DB.
  • I manually input all the product categories in Perch and built a category map within the script (This just meant that parenting of categories was taken care of without me having to worry about it). I'm sure the categories could have been imported easily enough.
  • I created a product within Perch containg dummy data for what I needed to import and then used that as a guide to write the structure of the import script.
  • The script loops through my temporary table, reconfigures the data from that into the correct format for the fixed fields and the dynamic field and then inserts it into the Perch database. It also creates entries in the index table.
  • Additionally I ended up needing to link datasheets to products (all PDFs) so was able to do this by looking at the assets system and an example product with dummy data and following a similar route to above.

The one thing I was unable to figure out in a reasonable amount of time was how to link up the images and carry out the resizing necessary for this. I was fortunate in that my client needed to change most of the images anyway so uploading them is not too much of a problem.

An additional issue I faced was that after the import, there were 27 pages of products in the backend and no way to filter or search them. I did a small hack that shows a quick find field on the product page.

I'd be happy to share the scripts and if you think that would be useful but I do stress that it's not a generic solution and will need to modified for your situation.

Thanks so much Caleb. I am meeting with client later to discuss our best options, so may well get back to you. Your breakdown of what you did is extremely helpful.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'd stress that if you're going down that route, we can't offer support if things aren't working or if problems arise due to the data being malformed.

Ah, yes. That's a really important point I should have mentioned. It was a risk I was willing to take but a critical point when doing this.

Yes I realise that Drew. Risk : Reward assessment while waiting for shop import (official)... Thanks Caleb