/
ListProductService.php
69 lines (56 loc) · 1.98 KB
/
ListProductService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace KSchmidExtendListing\StoreFrontBundle;
use Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface;
use Shopware\Bundle\StoreFrontBundle\Struct\Attribute;
use Shopware\Bundle\StoreFrontBundle\Struct\ListProduct;
use Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface;
use Shopware\Bundle\StoreFrontBundle\Service\PropertyServiceInterface;
class ListProductService implements ListProductServiceInterface
{
/**
* @var ListProductServiceInterface
*/
private $service;
/**
* @var PropertyServiceInterface
*/
private $propertyService;
/**
* @param ListProductServiceInterface $service
* @param PropertyServiceInterface $propertyService
*/
public function __construct(ListProductServiceInterface $service, PropertyServiceInterface $propertyService)
{
$this->service = $service;
$this->propertyService = $propertyService;
}
/**
* @inheritdoc
*/
public function getList(array $numbers, ProductContextInterface $context)
{
$products = $this->service->getList($numbers, $context);
$properties = $this->propertyService->getList($products, $context);
//Iterate over all products an add the property attribute
/**
* @var $product ListProduct
*/
foreach ($products as $product) {
$attribute = new Attribute();
$product->addAttribute('kschmidExtendListing', $attribute);
if (isset($properties[$product->getNumber()])) {
$attribute->set('productProperties', $properties[$product->getNumber()]->getGroups());
}
//SetManufacturerLink for Frontend
$attribute->set('supplierLink', $product->getManufacturer()->getLink());
}
return $products;
}
/**
* @inheritdoc
*/
public function get($number, ProductContextInterface $context)
{
return array_shift($this->getList([$number], $context));
}
}