Added new export record, path building and sql script to get data.
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
-- SQL script to get shopware 5 seo paths with article number to later build new seo path for shopware 6
|
||||||
|
|
||||||
|
SELECT b.productID AS product_id, a.name, atri.attr1, LOWER(b.path) AS path, s.name AS shop_name, s.host, b.subshopID AS subshop_id
|
||||||
|
FROM s_articles as a
|
||||||
|
LEFT JOIN s_articles_attributes as atri ON a.id = atri.articleID
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT seo.path, seo.org_path, SUBSTRING_INDEX(seo.org_path,'=',-1) AS productID, seo.subshopID
|
||||||
|
FROM `s_core_rewrite_urls` as seo
|
||||||
|
) AS b ON a.id = b.productID
|
||||||
|
LEFT JOIN s_core_shops AS s on s.id = b.subshopID;
|
||||||
+45
-14
@@ -1,6 +1,17 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
struct ExportRecord {
|
||||||
|
product_id: String,
|
||||||
|
name: Option<String>,
|
||||||
|
attr1: Option<String>,
|
||||||
|
path: String,
|
||||||
|
shop_name: Option<String>,
|
||||||
|
host: Option<String>,
|
||||||
|
subshop_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
struct Record {
|
struct Record {
|
||||||
source_url: String,
|
source_url: String,
|
||||||
@@ -18,31 +29,51 @@ fn main() -> Result<(), csv::Error> {
|
|||||||
let mut records: Vec<Record> = Vec::new();
|
let mut records: Vec<Record> = Vec::new();
|
||||||
|
|
||||||
for result in rdr.deserialize() {
|
for result in rdr.deserialize() {
|
||||||
let mut record: Record = result?;
|
let record: ExportRecord = result?;
|
||||||
//println!("{:?}", record);
|
println!("{:?}", record);
|
||||||
|
|
||||||
let mut temp_target_url: Vec<String> = record.source_url.split("/").map(|s| s.to_string()).collect();
|
let mut temp_target_url: Vec<String> = record.path.split("/").map(|s| s.to_string()).collect();
|
||||||
|
|
||||||
// Modify to new target url
|
// Modify to new target url
|
||||||
temp_target_url.remove(temp_target_url.len() - 2); // Remove number before product name
|
if temp_target_url[0].eq("gewuerze") {
|
||||||
|
temp_target_url.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_target_url.insert(0, String::from("public/lgw")); // For testing environment
|
||||||
|
temp_target_url.remove(temp_target_url.len() - 2); // Remove number before product name
|
||||||
|
|
||||||
|
if !record.attr1.clone().unwrap().eq("NULL") {
|
||||||
|
temp_target_url.push(record.attr1.unwrap()); // Add article number if not null
|
||||||
|
}
|
||||||
|
|
||||||
// Combine to new target url
|
// Combine to new target url
|
||||||
let target_url = temp_target_url.join("/");
|
let target_url = temp_target_url.join("/");
|
||||||
record.target_url = Some(target_url);
|
|
||||||
|
|
||||||
record.http_code = Some("301".to_string());
|
|
||||||
record.enabled = Some("1".to_string());
|
|
||||||
record.query_params_handling = Some("0".to_string());
|
|
||||||
record.sales_channel_id = Some("".to_string());
|
|
||||||
|
|
||||||
records.push(record)
|
// Build source url
|
||||||
|
let mut source_url_vec: Vec<String> = Vec::new();
|
||||||
|
source_url_vec.insert(0, String::from("public/lgw")); // For testing environment
|
||||||
|
source_url_vec.push(record.path);
|
||||||
|
|
||||||
|
// Combine source url
|
||||||
|
let source_url = source_url_vec.join("/");
|
||||||
|
|
||||||
|
|
||||||
|
records.push(Record{
|
||||||
|
source_url,
|
||||||
|
target_url: Some(target_url),
|
||||||
|
http_code: Some("301".to_string()),
|
||||||
|
enabled: Some("1".to_string()),
|
||||||
|
query_params_handling: Some("".to_string()),
|
||||||
|
sales_channel_id: Some("".to_string()),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let new_csv = File::create("redirects.csv")?;
|
let new_csv = File::create("redirects.csv")?;
|
||||||
let mut wtr = csv::Writer::from_writer(new_csv);
|
|
||||||
|
let mut wtr = csv::WriterBuilder::new()
|
||||||
|
.delimiter(b';')
|
||||||
|
.from_writer(new_csv);
|
||||||
|
|
||||||
for record in records {
|
for record in records {
|
||||||
wtr.serialize(record)?;
|
wtr.serialize(record)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user