python实现zencart产品数据导入到magento(python导入数据)

python版本要求在3.3.x,需要mysql connector for python第三方库支持

不适用所有的zencart导入到magento

代码如下:

#encoding=utf-8
#@ author:凋零
#@ contact:342103944@qq.com
import mysql.connector
import sys
import time
import glob
import os
import re
import shutil
config={'host':'127.0.0.1','user':'root','password':'1','port':3306 ,'database':'zencart','charset':'utf8'} 
config1={'host':'127.0.0.1','user':'root','password':'1','port':3306 ,'database':'magento','charset':'utf8'}
zencart_image_dir="D:/wamp/www/public/images/"#此处改为自己实际路径
magento_image_dir="D:/wamp/www/public1/media/catalog/product/"#此处改为自己实际路径
#所有产品信息,列表类型
products=[]

#连接到zencart数据库
try: 
    cnn=mysql.connector.connect(**config)

except mysql.connector.Error as e: 
    print('connect fails!{}'.format(e))

#连接到magento数据库

try: 
    cnn_magento=mysql.connector.connect(**config1)

except mysql.connector.Error as e: 
    print('connect fails!{}'.format(e))

#连接到magento数据库

try: 
    cnn_magento1=mysql.connector.connect(**config1)

except mysql.connector.Error as e: 
    print('connect fails!{}'.format(e))

#--------------获取产品信息函数块开始---------------#
#(获取产品描述,返回字典)
def get_productdescription(product_id):
    global cnn
    product_id=str(product_id)
    description={}
    cursor_des=cnn.cursor()

cursor_des.execute("select products_name,products_url from products_description where products_id="+product_id)
    temp_description=cursor_des.fetchone()
    description['name']=temp_description[0]
    description['url']=temp_description[1]

return  description

#(获取产品多图,返回列表)
def get_productaddtionimage(product_image):

base_dir="D:\\wamp\www\\public\\images\\"#此处改为自己实际路径
    addtion_image=[]
    image_uri=(base_dir+product_image).replace('.jpg','')
    for i in range(16):
        if os.path.isfile(image_uri+'_'+str(i)+'.jpg'):
            addtion_image.append(product_image.replace('.jpg','')+'_'+str(i)+'.jpg')

else:
        #print ("none")
        pass
    return addtion_image

#(获取产品对应目录,返回列表)
def get_product_categories(product_id):

product_id=str(product_id)

categories=[]
    cursor=cnn.cursor()

cursor.execute("select categories_id from products_to_categories where products_id="+product_id)

for row in cursor.fetchall():

for r in row:
            categories.append(r)

return categories

#--------------获取产品信息函数块结束---------------#

#分类id对应字典
categories_to={\
'2':'10','3':'13','4':'18','139':'37','176':'38','201':'70','202':'71','203':'69','204':'76','205':'77',\
'206':'66','207':'73','208':'72','209':'78','210':'79','211':'68','212':'74','213':'59','214':'60','215':'58','216':'62','217':'63','218':'64','219':'65','222':'54',\
'223':'53','224':'56','225':'80','230':'81','231':'48','232':'49','233':'50','234':'82','235':'83','236':'84','237':'45','238':'46',\
'239':'85','240':'51','241':'52','242':'86','245':'40','247':'44','248':'87','249':'43','250':'88','251':'89','252':'42',\
'260':'38','261':'38','271':'41',\
'279':'90','280':'39','281':'61','282':'91'\
}

#替换特殊字符函数
def cleanchar(str):

str=str.replace('?','oe')
    str=str.replace('é','e')
    str=str.replace('è','e')
    str=str.replace('?','e')
    str=str.replace('?','i')
    str=str.replace('ê','e')
    str=str.replace('a','a')
    str=str.replace('à','a')
    str=str.replace('?','u')
    str=str.replace('ü','u')
    str=str.replace('?','ae')              
    str=str.replace('?','o')
    str=str.replace('?','o')
    str=str.replace('?','c')
    str=str.replace('?','i')
    str=str.replace('?','i')
    str=str.replace('?','i')
    str=str.replace("'","")
    str=str.lower()

str=str.strip()

return str

#函数,检查是否有相同的url,有则返回新url
def check_url(product_name,sku):
    cursor1=cnn_magento1.cursor()

cursor1.execute("select value from catalog_product_entity_varchar where entity_type_id=10 and attribute_id=96 and value='"+str.strip(product_name)+"'")
    #result=cursor1.execute("select value_id from catalog_product_entity_varchar where entity_type_id=10 and attribute_id=96 and value='"+str.strip(test)+"'")
    #print ("select value_id from catalog_product_entity_varchar where entity_type_id=10 and attribute_id=96 and value='"+str.strip(product_name)+"'")
    row=cursor1.fetchall()

if len(row)!=0:

rstr = r"[\/\\\:\*\?\"\<\>\|]"
        url=str.strip(re.sub(rstr, "-", product_name))
        url=url.replace('?','oe')
        url=url.replace('é','e')
        url=url.replace('è','e')
        url=url.replace('?','e')
        url=url.replace('?','i')
        url=url.replace('ê','e')
        url=url.replace('a','a')
        url=url.replace('à','a')
        url=url.replace('?','u')
        url=url.replace('ü','u')
        url=url.replace('?','ae')              
        url=url.replace('?','o')
        url=url.replace('?','o')
        url=url.replace('?','c')
        url=url.replace('?','i')
        url=url.replace('?','i')
        url=url.replace('?','i')
        url=url.replace("'","")    
        url=url.lower()
        url=url.replace(' ','-')+'_'+sku.lower()

return url
    else:

rstr = r"[\/\\\:\*\?\"\<\>\|]"
        url=str.strip(re.sub(rstr, "-", product_name))
        url=url.replace('?','oe')
        url=url.replace('é','e')
        url=url.replace('è','e')
        url=url.replace('?','e')
        url=url.replace('?','i')
        url=url.replace('ê','e')
        url=url.replace('a','a')
        url=url.replace('à','a')
        url=url.replace('?','u')
        url=url.replace('ü','u')
        url=url.replace('?','ae')              
        url=url.replace('?','o')
        url=url.replace('?','o')
        url=url.replace('?','c')
        url=url.replace('?','i')
        url=url.replace('?','i')
        url=url.replace('?','i')
        url=url.replace("'","")
        url=url.lower()
        url=url.replace(' ','-')

return url

#函数,拷贝zencart产品图片到magento目录并根据产品名重命名
def copy_image_to_magento(image,sku,product_name,if_addition_image=False):
    if if_addition_image:
        #去除路径,获取图片名称
        image_name=os.path.basename(zencart_image_dir+image)
        #获取图片类型(后缀)
        extension = os.path.splitext(image_name)[1]
        #分拆图片名称
        image_all=image_name.split('_')

#新的图片名称重命名后与产品名称一样(正则替换掉非法字符如/,\,|,*等)
        rstr = r"[\/\\\:\*\?\"\<\>\|]"
        new_image_name_noextension=str.strip(re.sub(rstr, "-", product_name))

new_image_name_noextension=cleanchar(new_image_name_noextension)

new_image_name=new_image_name_noextension+"_"+image_all[1]

#判断图片是否存在
        if os.path.isfile(magento_image_dir+new_image_name):
            print ("\t\t\t\t存在图片"+new_image_name)
            shutil.copy(zencart_image_dir+image,magento_image_dir+new_image_name_noextension+"_"+sku+"_"+image_all[1])
            return '/'+new_image_name_noextension+"_"+sku+"_"+image_all[1]
        else:
            print ("\t\t\t不存在图片"+new_image_name+",执行拷贝图片并重命名")
            #不存在图片则拷贝图片到magento目录并重命名
            shutil.copy(zencart_image_dir+image, magento_image_dir+new_image_name)
            return '/'+new_image_name

else:
        #去除路径,获取图片名称
        image_name=os.path.basename(zencart_image_dir+image)
        #获取图片类型(后缀)
        extension = os.path.splitext(image_name)[1]
        #新的图片名称重命名后与产品名称一样(正则替换掉非法字符如/,\,|,*等)

rstr = r"[\/\\\:\*\?\"\<\>\|]"
        new_image_name_noextension=str.strip(re.sub(rstr, "-", product_name))
        new_image_name_noextension=cleanchar(new_image_name_noextension)

new_image_name=cleanchar(str.strip(re.sub(rstr, "-", product_name)))+extension

#先判断图片是否存在
        if os.path.isfile(magento_image_dir+new_image_name):
            print ("\t\t\t\t存在图片"+magento_image_dir+new_image_name+"\n")
            #存在图片,则加sku
            shutil.copy(zencart_image_dir+image, magento_image_dir+new_image_name_noextension+"_"+sku+extension)
            return '/'+new_image_name_noextension+"_"+sku+extension

else:
            print ("\t\t\t\t不存在图片"+magento_image_dir+new_image_name+",执行拷贝图片并重命名\n")
            #不存在图片则拷贝图片到magento目录并重命名
            shutil.copy(zencart_image_dir+image, magento_image_dir+new_image_name)
            return '/'+new_image_name

product_sql='select * from products'
cursor=cnn.cursor()
cursor1=cnn.cursor()
cursor.execute(product_sql)
cursor.fetchall()

#返回产品总个数
numrows = cursor.rowcount

i=0
cursor1.execute(product_sql)
print ("作者:凋零(qq:342103944)")
print ("开始获取zencart数据库产品信息..........")
time.sleep(3)
for row in cursor1.fetchall():
    #临时产品列表
    temp_product=[]

#存放产品信息,字典类型
    product_info={}

for r in row:
        #循环存放产品信息到产品列表
        temp_product.append(r)

product_info['product_id']=temp_product[0]
    product_info['sku']=temp_product[3]
    product_info['product_image']=temp_product[4]
    product_info['price']=temp_product[5]
    product_info['silhouette']=temp_product[6].replace('\n','')
    product_info['neckline']=temp_product[7].replace('\n','')
    product_info['waist']=temp_product[8].replace('\n','')
    product_info['hemline']=temp_product[9].replace('\n','')
    product_info['sleeve_length']=temp_product[10].replace('\n','')
    product_info['sleeve_type']=temp_product[11].replace('\n','')
    product_info['fabric']=temp_product[12].replace('\n','')
    product_info['embellishment']=temp_product[13].replace('\n','')
    product_info['belt_fabric']=temp_product[14].replace('\n','')
    product_info['back_detail']=temp_product[15].replace('\n','')
    product_info['fully_lined']=temp_product[16].replace('\n','')
    product_info['built_in_bra']=temp_product[17].replace('\n','')
    product_info['body_shape']=temp_product[18].replace('\n','')
    product_info['season']=temp_product[19].replace('\n','')
    product_info['color']=temp_product[20].replace('\n','')
    product_info['special_price']=temp_product[42]
    product_info['master_categories_id']=temp_product[43]
    product_info['product_name']=get_productdescription(product_info['product_id'])['name']
    product_info['addtion_image']=get_productaddtionimage(product_info['product_image'])
    product_info['product_categories']=get_product_categories(product_info['product_id'])

products.append(product_info)

i=i+1

cursor1.close
print ("获取数据完毕总共数据为:"+str(i)+"条")
time.sleep(1)
print ("开始转存数据到magento库.......")
time.sleep(1)
#----------------------------------------#
#------                              ----#
#------   开始存储数据到magento库      ----#
#------                              ----#
#----------------------------------------#

cursor=cnn_magento.cursor()
cursor.execute("set foreign_key_checks = 0")
not_import_categores_id=[]
p=0
for j in range(len(products)):

product_id=products[j]['product_id']

product_sku=products[j]['sku']
    product_baseimage=products[j]['product_image']
    product_price=products[j]['price']
    product_silhouette=products[j]['silhouette']
    product_neckline=products[j]['neckline']
    product_waist=products[j]['waist']
    product_hemline=products[j]['hemline']
    product_sleeve_length=products[j]['sleeve_length']
    product_sleeve_type=products[j]['sleeve_type']
    product_fabric=products[j]['fabric']
    product_embellishment=products[j]['embellishment']
    product_belt_fabric=products[j]['belt_fabric']
    product_back_detail=products[j]['back_detail']
    product_fully_lined=products[j]['fully_lined']
    product_built_in_bra=products[j]['built_in_bra']
    product_body_shape=products[j]['body_shape']
    product_season=products[j]['season']
    product_color=products[j]['color']
    product_special_price=products[j]['special_price']
    product_master_categories_id=products[j]['master_categories_id']
    product_name=products[j]['product_name']
    product_addtion_image=products[j]['addtion_image']
    product_to_categories=products[j]['product_categories']

#判断两个数据库之间分类是否对应,然后插入数据到magneto库,没有则不执行
    if str(product_master_categories_id) in categories_to.keys():
        p=p+1
        print ("---第【"+str(p)+"】条:"+product_sku)

#开始转存数据到catalog_product_entity表
        cursor.execute("insert into catalog_product_entity set entity_type_id=10,attribute_set_id=9,type_id='simple',sku='"+product_sku+"',created_at='2013-05-27 03:18:42',updated_at='2013-05-29 07:59:35',has_options=1,required_options=1")

#获取实体(产品)id
        catalog_entity_id=cursor.lastrowid

#插入数据到产品分类对应表
        for categories_id in product_to_categories:

if str(categories_id) in categories_to.keys():
                 cursor.execute("insert into catalog_category_product set category_id="+categories_to[str(categories_id)]+",product_id="+str(catalog_entity_id)+",position=1")
                 for i in range(1,4):

cursor.execute("insert into catalog_category_product_index set category_id="+str(categories_id)+",product_id="+str(catalog_entity_id)+",position=1,is_parent=1,store_id="+str(i)+",visibility=4")

#插入产品相关值到实体时间值表
        cursor.execute("insert into catalog_product_entity_datetime set entity_type_id=10,attribute_id=704,store_id=0,entity_id="+str(catalog_entity_id)+",value='2013-05-19 00:00:00'")
        cursor.execute("insert into catalog_product_entity_datetime set entity_type_id=10,attribute_id=705,store_id=0,entity_id="+str(catalog_entity_id)+",value='2013-05-25 00:00:00'")
        cursor.execute("insert into catalog_product_entity_datetime set entity_type_id=10,attribute_id=572,store_id=0,entity_id="+str(catalog_entity_id))
        cursor.execute("insert into catalog_product_entity_datetime set entity_type_id=10,attribute_id=573,store_id=0,entity_id="+str(catalog_entity_id))

#插入促销价格,如果没促销价格则不执行
        if product_special_price!='':

cursor.execute("insert into catalog_product_entity_decimal set entity_type_id=10,attribute_id=567,store_id=0,entity_id="+str(catalog_entity_id)+",value="+str(product_special_price))

#插入产品重量,产品价格
        cursor.execute("insert into catalog_product_entity_decimal set entity_type_id=10,attribute_id=101,store_id=0,entity_id="+str(catalog_entity_id)+",value=2")
        cursor.execute("insert into catalog_product_entity_decimal set entity_type_id=10,attribute_id=99,store_id=0,entity_id="+str(catalog_entity_id)+",value="+str(product_price))
        cursor.execute("insert into catalog_product_entity_decimal set entity_type_id=10,attribute_id=943,store_id=0,entity_id="+str(catalog_entity_id))

#插入产品相关值到实体整型表(产品状态,关税,前台可见,制造商,enable_googlecheckout)

cursor.execute("insert into catalog_product_entity_int set entity_type_id=10,attribute_id=273,store_id=0,entity_id="+str(catalog_entity_id)+",value=1")
        cursor.execute("insert into catalog_product_entity_int set entity_type_id=10,attribute_id=274,store_id=0,entity_id="+str(catalog_entity_id)+",value=1")
        cursor.execute("insert into catalog_product_entity_int set entity_type_id=10,attribute_id=526,store_id=0,entity_id="+str(catalog_entity_id)+",value=4")
        cursor.execute("insert into catalog_product_entity_int set entity_type_id=10,attribute_id=102,store_id=0,entity_id="+str(catalog_entity_id))
        cursor.execute("insert into catalog_product_entity_int set entity_type_id=10,attribute_id=903,store_id=0,entity_id="+str(catalog_entity_id)+",value=1")
        cursor.execute("insert into catalog_product_entity_int set entity_type_id=10,attribute_id=935,store_id=0,entity_id="+str(catalog_entity_id)+",value=0")

#####拷贝产品图片到magento目录并插入到数据库#######

#拷贝并插入主图
        base_image_in_magento=copy_image_to_magento(product_baseimage,product_sku,product_name,False)
        cursor.execute("insert into catalog_product_entity_media_gallery set attribute_id=703,entity_id="+str(catalog_entity_id)+",value='"+base_image_in_magento+"'")
        gallery_id=cursor.lastrowid
        cursor.execute("insert into catalog_product_entity_media_gallery_value set value_id="+str(gallery_id)+",store_id=0,position=1,disabled=0")
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=493,store_id=0,entity_id="+str(catalog_entity_id)+",value='"+base_image_in_magento+"'")
        #small_image
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=109,store_id=0,entity_id="+str(catalog_entity_id)+",value='"+base_image_in_magento+"'")
        #image
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=106,store_id=0,entity_id="+str(catalog_entity_id)+",value='"+base_image_in_magento+"'")

#拷贝并插入附加图
        if len(product_addtion_image)!=0:
            iii=2
            for each_image in product_addtion_image:
                addition_image_in_magento=copy_image_to_magento(each_image,product_sku,product_name,True)
                cursor.execute("insert into catalog_product_entity_media_gallery set attribute_id=703,entity_id="+str(catalog_entity_id)+",value='"+addition_image_in_magento+"'")
                addition_id=cursor.lastrowid
                cursor.execute("insert into catalog_product_entity_media_gallery_value set value_id="+str(addition_id)+",store_id=0,position="+str(iii)+",disabled=0")
                iii=iii+1

#插入产品相关值到实体文本表(产品描述,段描述等)
        cursor.execute("insert into catalog_product_entity_text set entity_type_id=10,attribute_id=506,store_id=0,entity_id="+str(catalog_entity_id)+",value='short_description&&nbsp&&nbsp'")
        cursor.execute("insert into catalog_product_entity_text set entity_type_id=10,attribute_id=531,store_id=0,entity_id="+str(catalog_entity_id))
        cursor.execute("insert into catalog_product_entity_text set entity_type_id=10,attribute_id=104,store_id=0,entity_id="+str(catalog_entity_id))
        cursor.execute("insert into catalog_product_entity_text set entity_type_id=10,attribute_id=97,store_id=0,entity_id="+str(catalog_entity_id)+",value='description&&nbsp&&nbsp'")

#插入产品到catalog_product_entity_varchar(产品名称,url等)
        #插入name
        product_name=product_name.replace("'","")
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=96,store_id=0,entity_id="+str(catalog_entity_id)+",value='"+str.strip(product_name)+"'")
        #插入url_key
        url=check_url(product_name,product_sku)
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=481,store_id=0,entity_id="+str(catalog_entity_id)+",value='"+str.strip(url)+"'")
        #manufacture
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=940,store_id=0,entity_id="+str(catalog_entity_id))
        #msrp_enabled
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=941,store_id=0,entity_id="+str(catalog_entity_id)+",value=2")
        #msrp_display_actual_price_type
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=942,store_id=0,entity_id="+str(catalog_entity_id)+",value=4")
        #meta_title
        #cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=103,store_id=0,entity_id="+str(catalog_entity_id)+",value=4")
        #meta_description
        #cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=105,store_id=0,entity_id="+str(catalog_entity_id)+",value=4")

#thumbnail
        #print ("insert into `catalog_product_entity_varchar` set `entity_type_id`=10,`attribute_id`=493,`store_id`=0,`entity_id`="+str(catalog_entity_id)+",`value`='no_selection'")
        #input()
        #cursor.execute("insert into `catalog_product_entity_varchar` set `entity_type_id`=10,`attribute_id`=493,`store_id`=0,`entity_id`="+str(catalog_entity_id)+",`value`='no_selection'")

#custom_design
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=571,store_id=0,entity_id="+str(catalog_entity_id))
        #options_container
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=836,store_id=0,entity_id="+str(catalog_entity_id)+",value='container2'")
        #page_layout
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=931,store_id=0,entity_id="+str(catalog_entity_id))
        #gift_message_available
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=562,store_id=0,entity_id="+str(catalog_entity_id)+",value=1")

#thumbnail_label
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=881,store_id=0,entity_id="+str(catalog_entity_id))
        #small_image_label
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=880,store_id=0,entity_id="+str(catalog_entity_id))

#image_label
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=879,store_id=0,entity_id="+str(catalog_entity_id))

#url_path
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=570,store_id=0,entity_id="+str(catalog_entity_id)+",value='"+str.strip(url)+"'")
        cursor.execute("insert into catalog_product_entity_varchar set entity_type_id=10,attribute_id=570,store_id=1,entity_id="+str(catalog_entity_id)+",value='"+str.strip(url)+"'")

#插入catalog_product_flat(1,2,3)表
        for aa in range(1,4):
            cursor.execute("insert into catalog_product_flat_"+str(aa)+" set entity_id="+str(catalog_entity_id)+",attribute_set_id=9,type_id='simple',created_at='2013-05-31 06:43:21'\
            ,description='test test ,&&nbsp',enable_googlecheckout=1,has_options=1,image='"+base_image_in_magento+"',is_recurring=0,msrp_display_actual_price_type=4\
            ,msrp_enabled=2,name='"+product_name+"',price="+str(product_price)+",required_options=1,short_description='short description &&nbsp',sku='"+product_sku+"'\
            ,small_image='"+base_image_in_magento+"',special_from_date='2013-05-19 00:00:00',special_price="+str(product_special_price)+",special_to_date='2014-06-27 00:00:00'\
            ,tax_class_id=1,thumbnail='no_selection',updated_at='2013-05-31 10:38:25',url_key='"+url+"',url_path='"+url+"',visibility=4,weight=2")
        for aa in range(1,4):
            cursor.execute("insert into catalog_product_index_eav set entity_id="+str(catalog_entity_id)+",attribute_id=903,store_id="+str(aa)+",value=1")
            cursor.execute("insert into catalog_product_index_eav set entity_id="+str(catalog_entity_id)+",attribute_id=971,store_id="+str(aa)+",value=128")

#catalog_product_index_eav_idx
        for aa in range(1,4):
            cursor.execute("insert into catalog_product_index_eav_idx set entity_id="+str(catalog_entity_id)+",attribute_id=903,store_id="+str(aa)+",value=1")

#catalog_product_index_price
        for aa in range(5):
            cursor.execute("insert into catalog_product_index_price set entity_id="+str(catalog_entity_id)+",customer_group_id="+str(aa)+",website_id=1,tax_class_id=1,price="+str(product_price)+"\
            ,final_price="+str(product_special_price)+",min_price="+str(product_special_price)+",max_price="+str(product_special_price))
        #catalog_product_index_price_idx
        for aa in range(5):
            cursor.execute("insert into catalog_product_index_price_idx set entity_id="+str(catalog_entity_id)+",customer_group_id="+str(aa)+",website_id=1,tax_class_id=1,price="+str(product_price)+"\
            ,final_price="+str(product_special_price)+",min_price="+str(product_special_price)+",max_price="+str(product_special_price))   
        #catalog_product_website
        cursor.execute("insert into catalog_product_website set product_id="+str(catalog_entity_id)+",website_id=1")

#cataloginventory_stock_item
        cursor.execute("insert into cataloginventory_stock_item set product_id="+str(catalog_entity_id)+",stock_id=1,qty=1000,min_qty=0,use_config_min_qty=1,is_qty_decimal=0,\
        backorders=0,use_config_backorders=1,min_sale_qty=1,use_config_min_sale_qty=1,max_sale_qty=0,use_config_max_sale_qty=1,is_in_stock=1,use_config_notify_stock_qty=1,\
        manage_stock=0,use_config_manage_stock=1,stock_status_changed_auto=0,use_config_qty_increments=1,qty_increments=0,use_config_enable_qty_inc=1,enable_qty_increments=0,\
        is_decimal_divided=0")
        #cataloginventory_stock_status
        cursor.execute("insert into cataloginventory_stock_status set product_id="+str(catalog_entity_id)+",website_id=1,stock_id=1,qty=1000,stock_status=1")
        #cataloginventory_stock_status_idx
        cursor.execute("insert into cataloginventory_stock_status_idx set product_id="+str(catalog_entity_id)+",website_id=1,stock_id=1,qty=1000,stock_status=1")
        cnn_magento.commit()
    else:
        print ("\t\t\tid["+str(product_master_categories_id)+"]在magneto库中没有与之对应的id,跳过此分类")
        not_import_categores_id.append(str(product_master_categories_id))

cursor.execute("set foreign_key_checks = 1")
cursor.close
print ("导入完成")
print ("一共有"+str(len(not_import_categores_id))+"没导入")

(0)

相关推荐

  • Zend Framework基本页面布局分析

    本文实例讲述了Zend Framework基本页面布局方法.分享给大家供大家参考,具体如下: Zend Framework 的页面布局模块--Zend_Layout--既可以跟 MVC 一起使用,也可以单独使用.本文只讨论与 MVC 一起使用的情况. 1.布局脚本 在 application/views 下创建一个 layouts 的文件夹.主布局脚本 layout.phtml 代码如下: <?php echo $this->doctype('XHTML1_STRICT') ?> <

  • zen cart实现订单中增加paypal中预留电话的方法

    本文实例讲述了zen cart实现订单中增加paypal中预留电话的方法.分享给大家供大家参考,具体如下: 在PayPal的IPN返回值中联系电话是 contact_phone, 前提是你帐户设定了买家在付款时预留电话,如果没有要求的话,该值默认是不会返回的. 但在zen cart的PAYPAL的支付插件里是不获取这个信息的,需要手动修改PAYPAL的程序.下面我们就修改: 一.在 paypal 表中增加 contact_phone 字段 ALTER TABLE `paypal` ADD `co

  • Zend Framework教程之Bootstrap类用法概述

    本文实例讲述了Zend Framework中Bootstrap类用法.分享给大家供大家参考,具体如下: Zend_Application_Bootstrap_Bootstrapper Zend_Application_Bootstrap_Bootstrapper是所有引导类必须实现的基本接口.基本功能是用于配置,注册资源,引导(无论是单个资源或整个应用程序),并运行应用程序. 接口方法: Zend_Application_Bootstrap_Bootstrapper Interface Meth

  • Zend Framework入门知识点小结

    本文总结分析了Zend Framework入门知识点.分享给大家供大家参考,具体如下: zend framework是MVC模式的一种实现,要快速的入门差不多只看Zend_Controller Zend_View 部分就可以了吧. 1.Zend_Controller部分.最重要的类是Zend_Controller_Front.使用它的经典代码很 简单: $front=Zend_Controller_Front::getInstance(); $front-> setControllerDirec

  • Zend Framework缓存Cache用法简单实例

    本文实例讲述了Zend Framework缓存Cache用法.分享给大家供大家参考,具体如下: <?php require 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Cache'); Zend_Loader::loadClass('Zend_Config'); Zend_Loader::loadClass('Zend_Registry'); $config = new Zend_Config_Ini('configsecr/config.in

  • php 修改zen-cart下单和付款流程以防止漏单

    用过zen-cart的人都知道,zen-cart中下单步骤是下面这样的(其中[]中的表示不是必须的): 1. 购物车(shopping cart) 2. [货运方式(delivery method)] 3. 支付方式(payment method) 4. 订单确认(confirmation) 5. [第三方网站支付] 6. 订单处理(checkout process)--这一步比较重要,因为会在这里将购物车中的信息写入订单 7. 下单成功(checkout success) 这样的流程在正常情况

  • Zend Framework+smarty用法实例详解

    本文实例讲述了Zend Framework+smarty用法.分享给大家供大家参考,具体如下: 一.Zend Framework简介 Zend Framework使用模型-视图-控制器(Model-View-Controller(MVC))结构.这个用来把你的程序分离成不同部分使得开发和维护变得容易. 运行Zend Framework需要:PHP 5.1.4 (或更高) .Web 服务器支持 mod_rewrite功能,本实例采用Apache. 从这里http://framework.zend.

  • zen_cart实现支付前生成订单的方法

    本文实例讲述了zen_cart实现支付前生成订单的方法.分享给大家供大家参考,具体如下: 除了paypal之外. 客户通过其他的支付方式进入index.php?main_page=checkout_confirmation这个页面就能生出订单. 但是!! paypal就有点与众不同, 它只能是从它的官网 [paypal.com] 返回来并且进入checkout_process这个页面后,才能生出订单 而意外常会发生:比如网络不顺. 又比如客户不小心在返回前就关了页面. 那么,我们的网站后台就看不

  • zen cart新进商品的随机排序修改方法

    zencart新进商品的随机排序修改方法第一步:首先,新进商品可以自己定义时间段:商店设置-最大值-新进商品的定义 zencart新进商品的随机排序修改方法第二步: 修改首页上新进商品: /includes/modules/new_products.php 在$new_products_query里增加相应ORDER BY xxx 例:select distinct p.products_id, p.products_image,p.products_tax_class_id, pd.produ

  • python实现zencart产品数据导入到magento(python导入数据)

    python版本要求在3.3.x,需要mysql connector for python第三方库支持 不适用所有的zencart导入到magento 复制代码 代码如下: #encoding=utf-8#@ author:凋零#@ contact:342103944@qq.comimport mysql.connectorimport sysimport timeimport globimport osimport reimport shutilconfig={'host':'127.0.0.

  • Python操作SQLite数据库的方法详解【导入,创建,游标,增删改查等】

    本文实例讲述了Python操作SQLite数据库的方法.分享给大家供大家参考,具体如下: SQLite简介 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中.它是D.RichardHipp建立的公有领域项目.它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了.它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如 Tcl.C

  • 3个用于数据科学的顶级Python库

    Python有许多吸引力,如效率,代码可读性和速度,使其成为数据科学爱好者的首选编程语言.Python通常是希望升级其应用程序功能的数据科学家和机器学习专家的首选. 由于其广泛的用途,Python拥有大量的库,使数据科学家可以更轻松地完成复杂的任务,而无需很多编写代码的麻烦.以下是数据科学的前3个Python库. 使用这些库将Python转化为一个科学的数据分析和建模工具. 1.NumPy NumPy(Numerical Python的缩写)是配备有用资源的顶级库之一,可帮助数据科学家将Pyth

  • 在 Jupyter 中重新导入特定的 Python 文件(场景分析)

    Jupyter 是数据分析领域非常有名的开发环境,使用 Jupyter 写数据分析相关的代码会大大节约开发时间. 设想这样一个场景:别的部门的同事传给你一个数据分析的模块,用于实现对数据的高级分析.模块里面有上百个函数. 如果直接写 Python 文件来调用数据分析模块,那么使用方法非常简单: from analyze import FathersAnalyzer data = [...] father = FathersAnalyzer(data) result = father.analyz

  • Python遍历目录下文件、读取、千万条数据合并详情

    目录 一.使用Python进行文件和文件夹的判断 二.使用Python完整的获取所有文件及文件夹并读取相应的文件 三.使用Python合并数据 append的使用 一.使用Python进行文件和文件夹的判断 递归 :主要目的就是遍历文件夹和文件 对文件夹和文件进行属性判断 首先对文件夹进行遍历,看文件夹里有什么样的文件,读取出文件夹中的所有文件 import os path= "./data" #路径 files = os.listdir(path) #os.listdir() 方法用

  • SQL Server导入、导出、备份数据方法

    一.导出导入SQL Server里某个数据库 1.在SQL Server企业管理器里选中要转移的数据库,按鼠标右键,选所有任务->备份数据库. 2.备份 选数据库-完全, 目的 备份到 按添加按钮 文件名 在SQL Server服务器硬盘下输入一个自定义的备份数据库文件名(后缀一般是bak) 重写 选重写现有媒体 最后按确定按钮. 如果生成的备份数据库文件大于1M,要用压缩工具压缩后再到Internet上传输. 3.通过FTP或者remote desktop或者pcanywhere等方法 把第二

  • 使用python获取csv文本的某行或某列数据的实例

    站长用Python写了一个可以提取csv任一列的代码,欢迎使用.Github链接 csv是Comma-Separated Values的缩写,是用文本文件形式储存的表格数据,比如如下的表格: 就可以存储为csv文件,文件内容是: No.,Name,Age,Score 1,Apple,12,98 2,Ben,13,97 3,Celia,14,96 4,Dave,15,95 假设上述csv文件保存为"A.csv",如何用Python像操作Excel一样提取其中的一列,即一个字段,利用Pyt

  • Python Pandas中根据列的值选取多行数据

    Pandas中根据列的值选取多行数据 # 选取等于某些值的行记录 用 == df.loc[df['column_name'] == some_value] # 选取某列是否是某一类型的数值 用 isin df.loc[df['column_name'].isin(some_values)] # 多种条件的选取 用 & df.loc[(df['column'] == some_value) & df['other_column'].isin(some_values)] # 选取不等于某些值的

  • Python使用import导入本地脚本及导入模块的技巧总结

    本文实例讲述了Python使用import导入本地脚本及导入模块的技巧.分享给大家供大家参考,具体如下: 导入本地脚本 import 如果你要导入的 Python 脚本与当前脚本位于同一个目录下,只需输入 import,然后是文件名,无需扩展名 .py. 伪代码如下: import useful_functions useful_functions.add_five([1, 2, 3, 4]) 我们可以为导入模块添加别名,以使用不同的名称引用它. import useful_functions

  • python读取word 中指定位置的表格及表格数据

    1.Word文档如下: 2.代码 # -*- coding: UTF-8 -*- from docx import Document def readSpecTable(filename, specText): document = Document(filename) paragraphs = document.paragraphs allTables = document.tables specText = specText.encode('utf-8').decode('utf-8') f

随机推荐