Hello!
Hopefully someone here can help us out with the following.
What we want to achieve:
Display some products from a specific productcategory below the shopping cart ({url}/checkout/cart).
Our idea:
Fetch the products via an Event Subscriber that add the data to the pagelet for use in the template; as explained here:
https://docs.shopware.com/en/shopware-platform-dev-en/how-to/add-data-to-a-storefront-page
The problem:
While trying to fetch a category (by ‚name‘ / or ‚active == 1‘ for example) and it’s assosiated products, we get the following 500 error:
MappingEntityClassesException - ‚Mapping definition neither have entities nor collection.‘
Somehow the same code (follows below) works fine when we try to access the productRepository instead of the productCategoryRespository.
Can someone please help us out?
Thank you in advance!
Code snippets follow below.
UpsellSubscriber.php
productRepository = $productRepository;
$this->productCategoryRepository = $productCategoryRepository;
}
public static function getSubscribedEvents(): array
{
return [
FooterPageletLoadedEvent::class => 'getProductsFromCategory'
];
}
public function getProductsFromCategory(FooterPageletLoadedEvent $event): void
{
$criteria = new Criteria();
//$criteria->addFilter(new EqualsFilter('name', 'Minicontainer'));
$criteria->addFilter(new EqualsFilter('active', '1'));
$entities = $this->productCategoryRepository->search(
$criteria,
$event->getContext()
);
var_dump($entities);
die();
//$event->getPagelet()->addExtension('custom_upsell', $category);
}
}
Services.xml