Jump to content

Edit History

sanctusmob

sanctusmob


SQL format to be more readable

Αν και δεν συμφωνώ με τα περιεχόμενα που διάλεξες για να μπούνε στο Meta title (με το full category path). Ορίστε το query

SELECT 
	info.ProductID, 
	info.id_lang,
	LEFT(CONCAT(info.ManufacturerName," ", info.ProductName, " ",info.reference," ", info.CategoryPath),128) AS MetaTitle
FROM 
	(
		SELECT 
			p.id_product AS ProductID,
			pl.NAME AS ProductName, 
			m.NAME AS ManufacturerName,
			p.reference,
			pl.id_lang,
			(
				SELECT GROUP_CONCAT(cl.name ORDER BY c2.level_depth ASC SEPARATOR ' > ')
				FROM ps_category_lang AS cl
				JOIN ps_category AS c2 ON c2.id_category = cl.id_category
				WHERE c2.nleft <= c.nleft AND c2.nright >= c.nright AND c2.id_category > '2'
			) AS CategoryPath
		FROM ps_product_lang AS pl
			LEFT JOIN ps_product AS p ON p.id_product = pl.id_product
			LEFT JOIN ps_manufacturer AS m ON m.id_manufacturer = p.id_manufacturer
			LEFT JOIN ps_category_lang AS cl ON cl.id_category = p.id_category_default
			LEFT JOIN ps_category AS c ON c.id_category = cl.id_category
		WHERE pl.id_lang = cl.id_lang
	) AS info

Απλός πρόσθεσα το όνομα του κατασκευαστή και το reference σε περίπτωση που δεν είναι μέσα στο Product Name (και έτσι πρέπει).

Από εδώ και πέρα ο καθένας μπορεί εύκολα να το αλλάξει το παραπάνω select (π.χ. αν θέλει να προσθέσει το ean13 ή να αφαιρέσει το Manufacturer Name) και μετά να κάνει το update με join το παραπάνω query.

UPDATE ps_product_lang AS ppl
JOIN 
(
	SELECT 
		info.ProductID, 
		info.id_lang,
		LEFT(CONCAT(info.ManufacturerName," ", info.ProductName, " ",info.reference," ", info.CategoryPath),128) AS MetaTitle
	FROM 
		(
			SELECT 
				p.id_product AS ProductID,
				pl.NAME AS ProductName, 
				m.NAME AS ManufacturerName,
				p.reference,
				pl.id_lang,
				(
					SELECT GROUP_CONCAT(cl.name ORDER BY c2.level_depth ASC SEPARATOR ' > ')
					FROM ps_category_lang AS cl
					JOIN ps_category AS c2 ON c2.id_category = cl.id_category
					WHERE c2.nleft <= c.nleft AND c2.nright >= c.nright AND c2.id_category > '2'
				) AS CategoryPath
			FROM ps_product_lang AS pl
				LEFT JOIN ps_product AS p ON p.id_product = pl.id_product
				LEFT JOIN ps_manufacturer AS m ON m.id_manufacturer = p.id_manufacturer
				LEFT JOIN ps_category_lang AS cl ON cl.id_category = p.id_category_default
				LEFT JOIN ps_category AS c ON c.id_category = cl.id_category
			WHERE pl.id_lang = cl.id_lang
		) AS info
) AS MetaInfo ON MetaInfo.ProductID = ppl.id_product SET ppl.meta_title = MetaInfo.MetaTitle
WHERE ppl.id_lang = MetaInfo.id_lang

 

sanctusmob

sanctusmob

Αν και δεν συμφωνώ με τα περιεχόμενα που διάλεξες για να μπούνε στο Meta title (με το full category path). Ορίστε το query

SELECT 
	info.ProductID, 
	info.id_lang,
LEFT(CONCAT(info.ManufacturerName," ", info.ProductName, " ",info.reference," ", info.CategoryPath),128) AS MetaTitle
FROM 
	(
SELECT 
		p.id_product AS ProductID,
		pl.NAME AS ProductName, 
		m.NAME AS ManufacturerName,
		p.reference,
		pl.id_lang,
		(
SELECT GROUP_CONCAT(cl.name
ORDER BY c2.level_depth ASC SEPARATOR ' > ')
FROM ps_category_lang AS cl
JOIN ps_category AS c2 ON c2.id_category = cl.id_category
WHERE c2.nleft <= c.nleft AND c2.nright >= c.nright AND c2.id_category > '2') AS CategoryPath
FROM ps_product_lang AS pl
LEFT JOIN ps_product AS p ON p.id_product = pl.id_product
LEFT JOIN ps_manufacturer AS m ON m.id_manufacturer = p.id_manufacturer
LEFT JOIN ps_category_lang AS cl ON cl.id_category = p.id_category_default
LEFT JOIN ps_category AS c ON c.id_category = cl.id_category
WHERE pl.id_lang = cl.id_lang) AS info

Απλός πρόσθεσα το όνομα του κατασκευαστή και το reference σε περίπτωση που δεν είναι μέσα στο Product Name (και έτσι πρέπει).

Από εδώ και πέρα ο καθένας μπορεί εύκολα να το αλλάξει το παραπάνω select (π.χ. αν θέλει να προσθέσει το ean13 ή να αφαιρέσει το Manufacturer Name) και μετά να κάνει το update με join το παραπάνω query.

UPDATE ps_product_lang AS ppl
JOIN 
(
SELECT 
	info.ProductID, 
	info.id_lang,
LEFT(CONCAT(info.ManufacturerName," ", info.ProductName, " ",info.reference," ", info.CategoryPath),128) AS MetaTitle
FROM 
	(
SELECT 
		p.id_product AS ProductID,
		pl.NAME AS ProductName, 
		m.NAME AS ManufacturerName,
		p.reference,
		pl.id_lang,
		(
SELECT GROUP_CONCAT(cl.name
ORDER BY c2.level_depth ASC SEPARATOR ' > ')
FROM ps_category_lang AS cl
JOIN ps_category AS c2 ON c2.id_category = cl.id_category
WHERE c2.nleft <= c.nleft AND c2.nright >= c.nright AND c2.id_category > '2') AS CategoryPath
FROM ps_product_lang AS pl
LEFT JOIN ps_product AS p ON p.id_product = pl.id_product
LEFT JOIN ps_manufacturer AS m ON m.id_manufacturer = p.id_manufacturer
LEFT JOIN ps_category_lang AS cl ON cl.id_category = p.id_category_default
LEFT JOIN ps_category AS c ON c.id_category = cl.id_category
WHERE pl.id_lang = cl.id_lang) AS info) AS MetaInfo ON MetaInfo.ProductID = ppl.id_product SET ppl.meta_title = MetaInfo.MetaTitle
WHERE ppl.id_lang = MetaInfo.id_lang

 

×
×
  • Create New...