Di seguito un elenco di operazioni da effettuare per andare online
Partiamo dall’individuare i prodotti che verranno poi messi in bozza su WooCommerce, tabella prodotti-bozza
SELECT
p.entity_id AS product_id,
p.sku AS product_sku,
v.value AS product_name,
s.qty AS quantity_available,
s.is_in_stock AS stock_status,
s.manage_stock AS manage_stock,
stat.value AS status
FROM
catalog_product_entity AS p
JOIN
cataloginventory_stock_item AS s ON p.entity_id = s.product_id
JOIN
catalog_product_entity_varchar AS v ON p.entity_id = v.entity_id
JOIN
eav_attribute AS a ON v.attribute_id = a.attribute_id
JOIN
catalog_product_entity_int AS stat ON p.entity_id = stat.entity_id
JOIN
eav_attribute AS a_stat ON stat.attribute_id = a_stat.attribute_id
WHERE
a.attribute_code = 'name'
AND v.store_id = 0
AND a_stat.attribute_code = 'status'
AND stat.value = 2; -- 2 indica che il prodotto è disabilitato
Per estrarre i volumi che dovranno avere il template Librerie – tabella prodotti-librerie
SELECT DISTINCT cpe.entity_id, cpe.sku, cpev_name.value AS product_name
FROM catalog_product_entity AS cpe
JOIN catalog_product_entity_int AS cpei_visibility ON cpe.entity_id = cpei_visibility.entity_id
JOIN catalog_product_entity_int AS cpei_status ON cpe.entity_id = cpei_status.entity_id
JOIN cataloginventory_stock_item AS csi ON cpe.entity_id = csi.product_id
JOIN catalog_product_entity_varchar AS cpev_name ON cpe.entity_id = cpev_name.entity_id
WHERE cpei_status.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'status' AND entity_type_id = 4)
AND cpei_status.value = 1 /* Stato abilitato */
AND cpei_visibility.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'visibility' AND entity_type_id = 4)
AND cpei_visibility.value = 2 /* Visibilità solo catalogo */
AND csi.manage_stock = 1 /* Gestione inventario non disponibile */
AND cpev_name.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 4)
AND cpe.type_id != 'virtual'; /* Escludi prodotti virtuali */
Va estrapolato il vecchia/nuova edizione
SELECT
p.entity_id AS product_id,
p.sku AS product_sku,
nva.value AS new_version_available
FROM
catalog_product_entity AS p
JOIN
catalog_product_entity_varchar AS nva ON p.entity_id = nva.entity_id
JOIN
eav_attribute AS a ON nva.attribute_id = a.attribute_id
WHERE
a.attribute_code = 'newVersionAvailable'
AND
a.entity_type_id = 4
AND
nva.value IS NOT NULL
AND
nva.value != '0'; -- Assicurati che l'entity_type_id sia corretto per i prodotti
Bisogna estrarre e sincronizzare la data di pubblicazione del prodotto
SELECT entity_id AS product_id,
sku,
created_at AS data_di_creazione,
updated_at AS data_di_modifica
FROM catalog_product_entity;
Vanno estratti e aggiornati tutti gli attributi SEO
SELECT
p.entity_id AS product_id,
p.sku AS product_sku,
name.value AS product_name,
url_key.value AS url_key,
meta_title.value AS meta_title,
meta_description.value AS meta_description,
meta_keyword.value AS meta_keyword
FROM
catalog_product_entity AS p
LEFT JOIN
catalog_product_entity_varchar AS name ON p.entity_id = name.entity_id
AND name.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 4)
LEFT JOIN
catalog_product_entity_varchar AS url_key ON p.entity_id = url_key.entity_id
AND url_key.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'url_key' AND entity_type_id = 4)
LEFT JOIN
catalog_product_entity_varchar AS meta_title ON p.entity_id = meta_title.entity_id
AND meta_title.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'meta_title' AND entity_type_id = 4)
LEFT JOIN
catalog_product_entity_text AS meta_description ON p.entity_id = meta_description.entity_id
AND meta_description.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'meta_description' AND entity_type_id = 4)
LEFT JOIN
catalog_product_entity_text AS meta_keyword ON p.entity_id = meta_keyword.entity_id
AND meta_keyword.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'meta_keyword' AND entity_type_id = 4)
posizione del prodotto all’interno della categoria
SELECT
c.entity_id AS category_id,
cev.value AS category_name,
p.entity_id AS product_id,
p.sku AS product_sku,
cp.position AS product_position
FROM
catalog_category_product cp
INNER JOIN
catalog_category_entity c ON cp.category_id = c.entity_id
INNER JOIN
catalog_product_entity p ON cp.product_id = p.entity_id
LEFT JOIN
catalog_category_entity_varchar cev ON c.entity_id = cev.entity_id
AND cev.attribute_id = (
SELECT attribute_id FROM eav_attribute
WHERE attribute_code = 'name' AND entity_type_id = (
SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category'
)
)
ORDER BY
c.entity_id ASC, cp.position ASC;
Lista dei prodotto e categorie di appartenenza
SELECT
cpe.entity_id AS 'Product_ID',
cpev.value AS 'Product_Name',
GROUP_CONCAT(DISTINCT ccv.value) AS 'Category_Names',
GROUP_CONCAT(DISTINCT ccp.category_id) AS 'Category_IDs',
MAX(ur.request_path) AS 'Product_URL'
FROM
catalog_product_entity AS cpe
JOIN
catalog_product_entity_varchar AS cpev ON cpe.entity_id = cpev.entity_id AND cpev.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product'))
LEFT JOIN
catalog_category_product AS ccp ON cpe.entity_id = ccp.product_id
LEFT JOIN
catalog_category_entity_varchar AS ccv ON ccp.category_id = ccv.entity_id AND ccv.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category'))
LEFT JOIN
url_rewrite AS ur ON ur.entity_id = cpe.entity_id AND ur.entity_type = 'product' AND ur.redirect_type = 0 AND ur.store_id = 1
GROUP BY
cpe.entity_id, cpev.value;
Estrarre dettagli di un singolo prodotto
SELECT
e.entity_id,
e.sku,
e.created_at,
e.updated_at,
ea.attribute_code,
CASE ea.backend_type
WHEN 'varchar' THEN ev.value
WHEN 'int' THEN ei.value
WHEN 'decimal' THEN ed.value
WHEN 'text' THEN et.value
WHEN 'datetime' THEN edate.value
ELSE NULL
END AS value
FROM catalog_product_entity AS e
JOIN eav_attribute AS ea ON ea.entity_type_id = 4 -- 4 is typically for products in Magento 2
LEFT JOIN catalog_product_entity_varchar AS ev ON ev.attribute_id = ea.attribute_id AND ev.entity_id = e.entity_id AND ea.backend_type = 'varchar'
LEFT JOIN catalog_product_entity_int AS ei ON ei.attribute_id = ea.attribute_id AND ei.entity_id = e.entity_id AND ea.backend_type = 'int'
LEFT JOIN catalog_product_entity_decimal AS ed ON ed.attribute_id = ea.attribute_id AND ed.entity_id = e.entity_id AND ea.backend_type = 'decimal'
LEFT JOIN catalog_product_entity_text AS et ON et.attribute_id = ea.attribute_id AND et.entity_id = e.entity_id AND ea.backend_type = 'text'
LEFT JOIN catalog_product_entity_datetime AS edate ON edate.attribute_id = ea.attribute_id AND edate.entity_id = e.entity_id AND ea.backend_type = 'datetime'
WHERE e.entity_id = 6018; -- id prodotto magento
Estrazione url prodotto
Estrazione URL categorie
SELECT
c.entity_id AS category_id,
ccev.value AS category_name,
ur.request_path AS category_url
FROM
catalog_category_entity AS c
JOIN
catalog_category_entity_varchar AS ccev ON c.entity_id = ccev.entity_id
JOIN
eav_attribute AS a ON ccev.attribute_id = a.attribute_id
JOIN
url_rewrite AS ur ON c.entity_id = ur.entity_id
WHERE
ur.entity_type = 'category'
AND
a.attribute_code = 'name'
AND
ur.redirect_type = 0 -- Assicurati che non sia un redirect