Ich habe mit folgendem Script den ListProductService um weitere Bilder dekoriert. Das funktioniert auch soweit. Es existieren Objekte mit weiteren Bilddaten.
Nun habe ich Verständnisprobleme wie ich in meinem Smarty Template darauf zugreife. Kann mir jemand ein konkretes Beispiel geben?
<?php
namespace ShopwarePlugins\AmbicoAddDataToProduct\StoreFrontBundle;
use Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface;
use Shopware\Bundle\StoreFrontBundle\Service\MediaServiceInterface;
use Shopware\Bundle\StoreFrontBundle\Struct;
class ListProductService implements ListProductServiceInterface {
private $service;
private $mediaService;
function __construct(ListProductServiceInterface $service, MediaServiceInterface $mediaService) {
$this->service = $service;
$this->mediaService = $mediaService;
}
public function getList(array $numbers, Struct\ProductContextInterface $context) {
$products = $this->service->getList($numbers, $context);
$media = $this->mediaService->getProductsMedia($products, $context);
foreach($numbers as $number) {
$product = $products[$number];
if(isset($media[$number])) {
$attribute = new Struct\Attribute(['images' => $media[$number]]);
$product->addAttribute('moreimages', $attribute);
}
$products[$number] = $product;
}
return $products;
}
public function get($number, Struct\ProductContextInterface $context) {
$products = $this->getList([$number], $context);
return array_shift($products);
}
}
In meinem Smarty Template sehe ich mit folgendem Script das Objekte weiterer Bilder existieren. Möchte ich jedoch auf ein Feld zugreifen kommt folgende Fehlermeldung
Cannot use object of type Shopware\Bundle\StoreFrontBundle\Struct\Attribute as array in ...
{if $sArticle.attributes.moreimages} {$ambicomoreimages = $sArticle.attributes.moreimages} {$moreimages=$ambicomoreimages->get('images')} {foreach $moreimages as $image} {$image|@var_dump} {/foreach} {/if}