如何在Prestashop中实现导出和导入订单数据


How to implement export nad import orders data in Prestashop?

我需要将客户订单所有数据从旧Prestashop 1.3迁移到新Prestashop 1.6。

我是一名中级presta开发人员,这对我来说不是一个微不足道的问题,我没有找到任何模块或教程来管理这个问题。presta-mySQL中的订单数据被分隔在十几个表中,1.3版和1.6版之间的差异导致了额外的兼容性问题。数据量对它的小店来说不是问题。

我想知道,您是如何处理此类问题的

我有一些想法,但没有一个听起来足够好:

  1. 将数据导出到csv,将compabile设置为1.6,然后导入(通过php脚本或从csv导入到mysql)
  2. 制作php脚本,从数据库中读取旧数据,使数据兼容,然后插入到新的商店数据库

这两个想法都非常耗时,也许有人有更好的想法/链接/解决方案?

我还没有见过这样一个免费的模块来导入客户订单或。。我自己进口的类别和产品从一个不熟悉的cms到presta商店1.6在presta1.6后台,如果你制作了你想要导入的实体,它在te右侧有一个菜单,说明哪些字段应该在你生成的csv文件中进行导入。如果你的csv文件不匹配,你应该用一种语言(比如php)获取csv文件,然后解析该文件并生成合适的csv档案导入prestashop。

我认为用csv文件导入数据更容易。上传csv文件导入presta后,询问您csv文件中的每一列与您的presta系统的哪一列相关。

这个php脚本有4个函数。

  • getHeader()函数将CSV文件的头作为数组获取
  • getCategories()从CSV文件中再次获取类别名称作为数组
  • getRecords()函数将所有记录(不包括标头)作为二维数组
<?php
function getHeader()
{
    $filename  = "past_cms_csv_file.csv";
    $contents = file_get_contents($filename);
    $records = explode('EOREOR', $contents);
    $header = explode(';', $records[0]);
    array_splice($header, count($header)-1, 1);
    return $header; 
}

function getCategories()
{
    $header = getHeader();
    $index = array_search('v_categories_name_1_4', $header);
    $filename  = "past_cms_csv_file.csv";
    $contents = file_get_contents($filename);
    $records = explode('EOREOR', $contents);
    $cats = array();
    for($i=1;$i<count($records);$i++)
    {
        $record = $records[$i];
        $items = explode('";"', $record);
        array_push($cats,$items[$index] );
    }
    $newCats = array_unique($cats);

    $mycats = [];
    foreach($newCats as $cat)
    {
        array_push($mycats, $cat);
    }
    array_splice($mycats, count($mycats)-1 , 1);
    return $mycats;
}
function getRecords()
{
    $filename  = "past_cms_csv_file.csv";
    $contents = file_get_contents($filename);
    $records = explode('EOREOR', $contents);
    $header = getHeader();
    $index = array_search('v_categories_name_1_4', $header);
    $cats = getCategories();
    for($i=1;$i<count($records);$i++)
    {
        $record = $records[$i];
        $items = explode('";"', $record);
        array_push($cats,$items[$index] );

        for($j=0;$j<count($items);$j++)
        {
            $results[$i][$j] = $items[$j];
        }
    }   
    return $results;
}
function makecsvfile($filename , $start_index)
{
    $header = getHeader();
    $results = getRecords();
    $active_index = array_search('v_status', $header);
    $name_index = array_search('v_products_name_4', $header);
    $desc_index = array_search('v_products_description_4', $header);
    $meta_title_index = array_search('v_products_meta_title_4', $header);
    $meta_keywords_index = array_search('v_products_meta_keywords_4', $header);
    $meta_desc_index = array_search('v_products_meta_description_4', $header);
    $price_index = array_search('v_products_price', $header);
    $quantity_index = array_search('v_products_quantity', $header);
    $category_index = array_search('v_categories_name_1_4', $header);
    $subcategory_index = array_search('v_categories_name_2_4', $header);

    $string  = '';
    $string .= '"ID";"Active";"Name";"Description";"Meta_title";"Meta_keywords";"Meta_Description";"Categories";"Quantity";"tax_rule";"Price";"Image URLs"';
    $string .= PHP_EOL;
    for($i=1;$i<count($results);$i++)
    {
        if( $results[$i][$category_index] != 'Schoenen en sokjes'  &&
            $results[$i][$category_index] != 'Accessoires meisjes' &&
            $results[$i][$category_index] != 'Accessoires jongens' &&
            $results[$i][$category_index] != 'Communie -en doopkleding' &&
            $results[$i][$category_index] != 'Aanbiedingen'
            )
            {
                $string .= '"';
                $string .= $i+$start_index;
                $string .= '";"';
                if($results[$i][$active_index] == 'Active')
                    $string .= 1;
                else if($results[$i][$active_index] == 'Inactive')
                    $string .= 0;   
                $string .= '";"';
                $string .= $results[$i][$name_index];
                $string .= '";"';
                $string .= $results[$i][$desc_index];
                $string .= '";"';
                $string .= $results[$i][$meta_title_index];
                $string .= '";"';
                if(strlen($results[$i][$meta_keywords_index]) < 255)
                    $string .= $results[$i][$meta_keywords_index];
                else
                {
                    $meta_key_words = substr($results[$i][$meta_keywords_index],0,254);
                    $last_comma_pos = strrpos($meta_key_words , ',');
                    $meta_key_words = substr($meta_key_words,0,$last_comma_pos);
                    $string .= $meta_key_words;
                }
                $string .= '";"';
                $string .= $results[$i][$meta_desc_index];
                $string .= '";"';
                if($results[$i][$subcategory_index] == '' && 
                    $results[$i][$category_index] != 'Tiara''s & Kroontjes' &&
                    $results[$i][$category_index] != 'Feest / Gala jurken' &&
                    $results[$i][$category_index] != 'Ringkussens' &&
                    $results[$i][$category_index] != 'Bolero''s en Jasjes')
                    $string .= $results[$i][$category_index];
                else if($results[$i][$category_index] == 'Tiara''s & Kroontjes')
                    $string .= 'Kroontjes, diademen & tiara''s';
                else if($results[$i][$category_index] == 'Feest / Gala jurken')
                    $string .= 'Feest- en galajurken';          
                else if($results[$i][$category_index] == 'Ringkussens')
                    $string .= 'kado kussens';
                else if($results[$i][$category_index] == 'Bolero''s en Jasjes')
                    $string .= 'Bolero’s & jasjes';         
                else 
                    $string .= $results[$i][$subcategory_index];
                $string .= '";"';
                $string .= $results[$i][$quantity_index];
                $string .= '";"';
                $string .= 53;
                $string .= '";"';
                $string .= $results[$i][$price_index];
                $string .= '";"';
                $string .= 'http://example.com/path/to/myimage.jpg';        
                $string .= '"';
                $string .= PHP_EOL;
            }
    }
    file_put_contents($filename, $string);
}
makecsvfile('products.csv' , 100);
?>