| Line 353: |
Line 353: |
| | print line | | print line |
| | print "\n"+("That was "+fname+".").center(40) | | print "\n"+("That was "+fname+".").center(40) |
| | + | </source> |
| | + | === CSV === |
| | + | <source lang="python"> |
| | + | import csv |
| | + | |
| | + | def createCSV(simpleProducts, configProducts, shopName): |
| | + | ''' |
| | + | Remaps a CSV filce created with tiendalistas magento exporter to |
| | + | match the Shopify CSV import file |
| | + | ''' |
| | + | |
| | + | counter = 0 |
| | + | with open(OUTPUT_DIALETCT_TEMPLATE, 'rb') as csvDialectTemplate: |
| | + | exportDialect = csv.Sniffer().sniff(csvDialectTemplate.read(1024)) |
| | + | |
| | + | # Create file and write headers |
| | + | with open(OUTPUT_PATH + shopName + '_shopify.csv', 'w') as csvoutFile: |
| | + | csvWriter = csv.writer(csvoutFile, dialect=exportDialect) |
| | + | csvWriter.writerow(shopyheader) |
| | + | counter += 1 |
| | + | |
| | + | # Write lines for simple products |
| | + | for prod in simpleProducts: |
| | + | tmp = shopifyCSVitem(prod) |
| | + | csvWriter.writerow(tmp.productCSVline()) |
| | + | counter += 1 |
| | + | |
| | + | for subP in prod.subProducts: |
| | + | tmp2 = shopifyCSVitem(subP) |
| | + | csvWriter.writerow(tmp2.subProductCSVline()) |
| | + | counter += 1 |
| | + | |
| | + | # Write lines for configurable products |
| | + | for prod in configProducts: |
| | + | tmp1 = shopifyCSVitem(prod) |
| | + | csvWriter.writerow(tmp1.productCSVline()) |
| | + | counter += 1 |
| | + | logWrite(logFile, 'Configurable product should be reviewed', tmp1.productCSVline()[0]) |
| | + | |
| | + | for subP in prod.subProducts: |
| | + | tmp2 = shopifyCSVitem(subP) |
| | + | csvWriter.writerow(tmp2.productCSVline()) |
| | + | counter += 1 |
| | + | |
| | + | for sub in subP.subProducts: |
| | + | # @ToDo: Check if this for is ever used. |
| | + | tmp3 = shopifyCSVitem(sub) |
| | + | csvWriter.writerow(tmp3.subProductCSVline()) |
| | + | counter += 1 |
| | + | return counter |
| | </source> | | </source> |
| | | | |