wie prüfen wir in frontend plugin ob der artikel deaktiv ist? wie setzten wir eine 301 weiterleitung auf seine kategorie listing? ich muss ein plugin schreiben der deaktiv artikel urls auf die artikel kategorie listing url weiterleitet, als 301, vor denn 404 (was google nicht mag). ich dachte ich prüfe ob der artikel deaktiv ist in Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Detail aber da kann ich die artikel nicht mal holen wenn es deaktiv ist... $article = Shopware()-\>Modules()-\>Articles()-\>sGetArticleById($id); gibt object(stdClass)#2027 (5) { ["\_\_CLASS\_\_"]=\> string(16) "RuntimeException" ["message"]=\> string(37) "Product not available in current shop" ["code"]=\> int(0) ["file"]=\> string(106) "/home/vagrant/foo/engine/Shopware/Bundle/StoreFrontBundle/Service/Core/ProductNumberService.php" ["line"]=\> int(95) } und das beste, für nicht existierende artikeln bekommen wir object(stdClass)#2028 (5) { ["\_\_CLASS\_\_"]=\> string(16) "RuntimeException" ["message"]=\> string(29) "No valid product number found" ["code"]=\> int(0) ["file"]=\> string(106) "/home/vagrant/foo/engine/Shopware/Bundle/StoreFrontBundle/Service/Core/ProductNumberService.php" ["line"]=\> int(79) } und beide haben die selbe code, also leider nutzlos... da gibts doch ne bessere lösung, oder? (wenn ich jetzt sGetArticleById lese, wäre es eh unnötig teuer zu prüfen ob artikel deaktiv) ps. wir sind immer noch auf shopware 5.0.3, falls es was aus macht...
hab es mit sql queries gelöst, ist wahrscheinlich eh am schnellsten
private function ffs ($str)
{
return str_replace(
["ö", "ä", "ü", "ß"],
["oe", "ae", "ue", "ss"],
$str
);
}
// ripped from engine/Shopware/Core/sExport.php sGetArticleCategoryPath
private function getCategoryPath($categoryID)
{
$breadcrumb = array_reverse(Shopware()->Modules()->sCategories()->sGetCategoriesByParent($categoryID));
foreach ($breadcrumb as $breadcrumbObj) {
$breadcrumbs[] = $breadcrumbObj['name'];
}
return '/' . $this->ffs(strtolower(implode('/', $breadcrumbs))) . '/';
}
public function onFrontendDetail(Enlight_Event_EventArgs $args)
{
$req = $args->getRequest();
$id = (int) $req->sArticle;
$sql = 'SELECT active FROM s_articles WHERE id = ?';
$active = Shopware()->Db()->fetchOne($sql, $id);
if ($active === '0') {
$subject = $args->getSubject();
$sql = 'SELECT categoryID from s_articles_categories WHERE articleID = ?';
$catId = Shopware()->Db()->fetchOne($sql, $id);
if ($catId) {
$catPath = $this->getCategoryPath($catId);
return $subject->redirect($catPath, ['code' => 301]);
}
}
}
arme alte ich!
- shopware article id is NICHT eindeutig (siehe varianten).
- alle? shopware php apis ignorieren deaktive artikeln (zbs. Shopware()>Modules()>Articles()->sGetArticleById() und productGateway->getList() haben keine hinweis in name das es deaktive artikeln ignoriert, also nehme ich an es ist eine shopware standard das deaktive artikeln implizit ignoriert werden.)
- deaktive varianten detailseite leitet auf die haupt artikel detailseite.