1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\OrderBundle\DataSet\Transformer; |
14
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\Criteria; |
16
|
|
|
use WellCommerce\Bundle\CoreBundle\Doctrine\Repository\RepositoryInterface; |
17
|
|
|
use WellCommerce\Bundle\OrderBundle\Entity\OrderProduct; |
18
|
|
|
use WellCommerce\Component\DataSet\Transformer\AbstractDataSetTransformer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class OrderProductsTransformer |
22
|
|
|
* |
23
|
|
|
* @author Adam Piotrowski <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class OrderProductsTransformer extends AbstractDataSetTransformer |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var RepositoryInterface |
29
|
|
|
*/ |
30
|
|
|
private $repository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* OrderProductsTransformer constructor. |
34
|
|
|
* |
35
|
|
|
* @param RepositoryInterface $repository |
36
|
|
|
*/ |
37
|
|
|
public function __construct(RepositoryInterface $repository) |
38
|
|
|
{ |
39
|
|
|
$this->repository = $repository; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function transformValue($value) |
46
|
|
|
{ |
47
|
|
|
$identifiers = explode(',', $value); |
48
|
|
|
$criteria = new Criteria(); |
49
|
|
|
$criteria->where($criteria->expr()->in('id', $identifiers)); |
50
|
|
|
$orderProducts = $this->repository->matching($criteria); |
51
|
|
|
$lines = []; |
52
|
|
|
|
53
|
|
|
$orderProducts->map(function (OrderProduct $orderProduct) use (&$lines) { |
54
|
|
|
$product = $orderProduct->getProduct(); |
55
|
|
|
$fullName = $product->translate()->getName(); |
|
|
|
|
56
|
|
|
|
57
|
|
|
if ($orderProduct->hasVariant()) { |
58
|
|
|
foreach ($orderProduct->getOptions() as $name => $value) { |
59
|
|
|
$fullName .= ' - ' . $value; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$lines[] = sprintf('%s x %s', $orderProduct->getQuantity(), $fullName); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
return implode('<br /><br />', $lines); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.