Como migrar seu site Magento 1 para a plataforma Shopify?
Como o Magento 1 foi descontinuado em junho de 2020, todos os proprietários de lojas Magento estão tentando migrar seus sites existentes para o Magento 2 ou para outra plataforma de e-commerce popular, como Shopify ou WooCommerce.
Recentemente, migrei um dos sites Magento 1 de um cliente para o Shopify. Inicialmente, estávamos planejando usar alguma ferramenta popular de migração de dados para migrar dados do Magento para o Shopify, mas não funcionou bem para nós.
Aqui estão os passos que segui para uma migração bem-sucedida.
1 – Preparando os dados do Magento para o formato Shopify
Getbras.com está vendendo roupas íntimas femininas e o produto foi adicionado nos sites Magento como produtos configuráveis e variações filhas com base em tamanho e cor. Portanto, precisamos seguir a mesma estrutura no site Shopify também.
Podemos exportar dados diretamente do Magento para CSV, mas não conseguimos obter a estrutura exata de como precisamos importar para o Shopify. Então, decidi escrever um script PHP personalizado para gerar dados do Magento 1 e salvá-los em uma tabela MYSQL. Você pode exportar diretamente para CSV; armazenar em uma tabela pode nos ajudar a fazer algum processamento mais tarde, se necessário.
Os dados necessários que precisamos para importar produtos configuráveis para o Shopify são:
- Manipular
- Título
- Corpo HTML
- Fornecedor
- Tipo
- Tags
- Publicado
- Nome da Opção 1
- Valor da Opção 1
- Nome da Opção 2
- Valor da Opção 2
- SKU da variante
- Gramas Variante
- Variant_Inventory_Tracke
- Variant_Inventory_Qty
- Política_de_Inventário_de_Variantes
- Serviço_de_Atendimento_a_Variantes
- Preço_Variável
- Variant_Compare_At_Price
- Variant_Requires_Shipping
- Variant_Taxable
- Código_de_Barras_Variável
- Image_Src
- Imagem_Posição
- Texto_Alternativo_Imagem
- SEO_Título
- SEO_Description
- Variant_Weight_Unit
- Código_Taxa_Variant
Eu criei uma tabela mysql para armazenar os dados acima e gerar dados usando um script personalizado do Magento 1. Aqui está o código php usado.
<?php
ini_set('memory_limit','2048M');
ini_set('max_execution_time',12000);
require_once "app/Mage.php";
$root=$_SERVER['DOCUMENT_ROOT'];
Mage::app("default");
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND,Mage_Core_Model_App_Area::PART_EVENTS);
//Mage::init();
$connection = Mage::getSingleton('core/resource')->getConnection('dbname');
$_helper = Mage::helper('catalog/output');
$helper = Mage::helper('shoppersettings/image');
$imgX = 252;
$imgY = $helper->calculateHeight($imgX);
//$filename = 'google_pla_feed_magento.csv';
$link=mysql_connect("localhost",'','');
mysql_select_db('dbname',$link);
https://bras-honey.myshopify.com/search?type=product&q=Loungeable%2Bboutique
$_productCollection = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect(array('pre_order','name', 'price','special_price','brand','color','size','lingerie_type', 'image', 'status','short_description','description','sku','created_at'))
->addAttributeToFilter('type_id', array('eq' => 'configurable'))
->addAttributeToFilter('entity_id', array('gt' => $last_id))
->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
//->setPageSize(10);
//->setCurPage($p)
$i=0;
$k=0;
foreach ($_productCollection as $_product):
$name= $_product->getName();
$name=str_replace("&","&",$name);
$sku=$_product->getSku();
$created_at=$_product->getCreatedAt();
$text=explode(" ",$sku);
$sku=$text[0];
$url_key = $_product->getProductUrl();
$full_url_key = $_product->getProductUrl();
//preparing unique handle for shopify
$url_key = str_replace("https://www.example.com/", "", $url_key);
$url_key = str_replace(".html", "", $url_key);
$id=$_product->getId();
$pre_order_status=$_product->getPreOrder();
if($pre_order_status==""):
$pre_order_status=0;
endif;
$product = Mage::getModel('catalog/product')->load($id);
$desc=strip_tags($product->getDescription());
$desc=str_replace(" "," ",$desc);
$desc=str_replace("&","&",$desc);
$desc1=$product->getDescription();
$short_desc1=$product->getShortDescription();
$productMediaConfig = Mage::getModel('catalog/product_media_config');
$image_url = $productMediaConfig->getMediaUrl($product->getImage());
$final_price=$product->getFinalPrice();
$meta_title=$product->getMetaTitle();
$meta_desc=$product->getMetaDescription();
$special_price=$product->getSpecialPrice();
$type_id=$product->getLingerieType();
$brand_id=$product->getBrand();
$final_price=number_format($final_price, 2, '.', '');
$desc1=str_replace(" "," ",$desc1);
$desc1=str_replace("&","&",$desc1);
$desc1=str_replace('\\',"",$desc1);
$desc1=str_replace("'","\'",$desc1);
$short_desc1=str_replace(" "," ",$short_desc1);
$short_desc1=str_replace("&","&",$short_desc1);
$short_desc1=str_replace('\\',"",$short_desc1);
$short_desc1=str_replace("'","\'",$short_desc1);
$desc1 = $short_desc1.$desc1;
preg_match_all('~<a(.*?)href="([^"]+)"(.*?)>~', $desc1, $matches);
foreach ($matches[2] as $key => $value) {
$value = str_replace("https://www.example.com/", "", $value);
$value = str_replace("http://www.example.com/", "", $value);
// echo '-----';
//replacing magento url in the content with shopify url
$sql1="SELECT id_path FROM mg_core_url_rewrite WHERE request_path='$value'";
$res1=mysql_query($sql1,$link) or die(mysql_error());
if(mysql_num_rows($res1)>0){
while($rs1=mysql_fetch_object($res1)){
$id_path = $rs1->id_path;
if(strpos($id_path,'product/') !== false){
$value1 = 'products/'.$value;
$desc1 = str_replace($value,$value1,$desc1);
}elseif(strpos($id_path,'category/') !== false){
$text = explode("/",$value);
$l = count($text);
$value1 = 'collections/'.$text[$l-1];
$desc1 = str_replace($value,$value1,$desc1);
}
}
}
if(strpos($value,'catalogsearch/') !== false){
$text = explode("?q=",$value);
$value1 = 'search?type=product&q='.$text[1];
$desc1 = str_replace($value,$value1,$desc1);
}
}
$desc1 = str_replace(".html","",$desc1);
$pId="";
$status=0;
$lingerie_type="";
$brand = Mage::getModel('catalog/product')->load($id)->getAttributeText('brand');
$brand1=$brand;
$brand=str_replace("&","&",$brand);
$lingerie_type = Mage::getModel('catalog/product')->load($id)->getAttributeText('lingerie_type');
$lingerie_type1=$lingerie_type;
$lingerie_type=str_replace("&","&",$lingerie_type);
if($lingerie_type==""):
$lingerie_type="Lingerie";
endif;
$product = Mage::getModel('catalog/product')->load($id);
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
$cats = $_product->getCategoryIds();
$j=0;
$category_name="";
foreach ($cats as $category_id){
$_cat = Mage::getModel('catalog/category')->load($category_id) ;
if($j<10):
$category_name.=trim($_cat->getName()).',';
endif;
$j++;
}
$category_name=substr($category_name,0,strlen($category_name)-1);
//getting child variants of magento configurable products
foreach($childProducts as $child) {
$k++;
$child_sku =$child->getSku();
$child_id=$child->getId();
$child_name=$child->getName();
$weight=$child->getWeight();
$qty=$child->getQty();
$size_id=$child->getSize();
$color_id=$child->getColor();
$type_id =$child->getLingerieType();
$size = Mage::getModel('catalog/product')->load($child_id)->getAttributeText('size');
$color = Mage::getModel('catalog/product')->load($child_id)->getAttributeText('color');
$lingerie_type = Mage::getModel('catalog/product')->load($child_id)->getAttributeText('lingerie_type');
$text=explode("-",$child_sku);
$text1=explode(" ",$text[2]);
$child_sku=$text[0].'-'.$text[1].'-'.$text1[0];
$name = mysql_real_escape_string($name);
$meta_title = mysql_real_escape_string($meta_title);
$meta_desc = mysql_real_escape_string($meta_desc);
//adding product temp mysql table
$sql="INSERT INTO magento_shopify(Handle,Title,Body_HTML,Vendor,Type,Tags,Option1_Value,Option2_Value,Variant_SKU,Variant_Grams,Variant_Inventory_Qty,Variant_Price,Variant_Compare_At_Price,Variant_Barcode,Image_Src,Image_Position,Image_Alt_Text,SEO_Title,SEO_Description,Variant_Tax_Code) VALUES ('$url_key','$name','$desc1','$brand','$lingerie_type','$category_name','$color','$size','$child_sku','$weight','$qty','$final_price','$special_price','','$image_url','','$name','$meta_title','$meta_desc','')";
mysql_query($sql,$link) or die(mysql_error());
}
$i++;
endforeach;
exit;
?>
After run above script you can see all of your necessary magento data in mysql table. You can check and verify using phpmyadmin
An example screenshot here:

Agora você pode exportar dados do phpmyadmin.

Exporte os dados no formato CSV e adicione o nome da coluna como cabeçalho.

Após exportar os dados, o arquivo csv precisa ser aberto no Excel e atualizar o cabeçalho das colunas que correspondem ao modelo de csv de importação do Shopify, um exemplo de CSV que usamos está abaixo.
