Warning: The magic method Math_Captcha::__wakeup() must have public visibility in /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/wp-math-captcha.php on line 87

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/wp-math-captcha.php:87) in /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/includes/class-cookie-session.php on line 46

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/wp-math-captcha.php:87) in /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/includes/class-cookie-session.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/wp-math-captcha.php:87) in /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/includes/class-cookie-session.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/wp-math-captcha.php:87) in /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/includes/class-cookie-session.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/wp-math-captcha.php:87) in /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/includes/class-cookie-session.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/wp-math-captcha.php:87) in /usr/www/users/seowme/siekiera-online.de/wp-content/plugins/wp-math-captcha/includes/class-cookie-session.php on line 49
Einzelnes Produkt ausgeben – vom entwickler für entwickler

Einzelnes Produkt ausgeben

Der einfachste Weg um ein „vollständiges“ formatiertes Produkt über den Productservice zu erhalten ist über die Artikelnummer.

Dazu wird zuerst das Produkt über den Service als Objekt geholt:


$_product = $this->container->get('shopware_storefront.product_service')->get(
	$article_sku,
	$this->container->get('shopware_storefront.context_service')->getProductContext()
);

Danach wird mit dem Struct-Converter alles für das Template strukturiert und vorformatiert:


$productArray = $this->get('legacy_struct_converter')->convertListProductStruct($_product);

Damit das Produkt auch verlinkt werden kann, ermitteln wir dazu direkt noch die SEO-URL:


$productArray['link'] = $this->Front()->Router()->assemble([
	'controller' => 'detail',
	'sArticle' => $_product->getId(),
	'number' => $_product->getNumber(),
	'title' => $_product->getName(),
]);

Komplett könnte das etwa so aussehen:


try {
	
	$_product = $this->container->get('shopware_storefront.product_service')->get(
		$article_sku,
		$this->container->get('shopware_storefront.context_service')->getProductContext()
	);
	
	if(!is_object($_product))
	{
		continue;
	}
	
	$productArray = $this->get('legacy_struct_converter')->convertListProductStruct($_product);
	
	$productArray['link'] = $this->Front()->Router()->assemble([
		'controller' => 'detail',
		'sArticle' => $_product->getId(),
		'number' => $_product->getNumber(),
		'title' => $_product->getName(),
	]);
	
	$view->assign('sArticle', $productArray);
	
} catch(Throwable $t) {
	echo "Captured Throwable: " . $t->getMessage() . PHP_EOL;
}
Scroll to Top