1 | <?php |
||
30 | final class OrderProductCollectionToArrayTransformer extends CollectionToArrayTransformer |
||
31 | { |
||
32 | /** |
||
33 | * @var OrderProductManagerInterface |
||
34 | */ |
||
35 | private $manager; |
||
36 | |||
37 | /** |
||
38 | * @var ImageHelperInterface |
||
39 | */ |
||
40 | private $imageHelper; |
||
41 | |||
42 | public function setOrderProductManager(OrderProductManagerInterface $manager) |
||
46 | |||
47 | public function setImageHelper(ImageHelperInterface $imageHelper) |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function transform($modelData) |
||
56 | { |
||
57 | $values = []; |
||
58 | |||
59 | if ($modelData instanceof Collection) { |
||
60 | $modelData->map(function (OrderProduct $orderProduct) use (&$values) { |
||
61 | |||
62 | $variantId = $orderProduct->hasVariant() ? $orderProduct->getVariant()->getId() : 0; |
||
63 | $photo = $orderProduct->getProduct()->getPhoto(); |
||
64 | $photoPath = $photo instanceof ProductPhoto ? $photo->getPath() : ''; |
||
65 | $symbol = $orderProduct->hasVariant() ? $orderProduct->getVariant()->getSymbol() : $orderProduct->getProduct()->getSku(); |
||
66 | |||
67 | $values[] = [ |
||
68 | 'id' => $orderProduct->getId(), |
||
69 | 'product_id' => $orderProduct->getProduct()->getId(), |
||
70 | 'product_name' => $orderProduct->getProduct()->translate()->getName(), |
||
|
|||
71 | 'gross_amount' => $orderProduct->getSellPrice()->getGrossAmount(), |
||
72 | 'quantity' => $orderProduct->getQuantity(), |
||
73 | 'ean' => $symbol, |
||
74 | 'previousquantity' => $orderProduct->getQuantity(), |
||
75 | 'trackstock' => $orderProduct->getProduct()->getTrackStock(), |
||
76 | 'tax_rate' => $orderProduct->getSellPrice()->getTaxRate(), |
||
77 | 'tax_value' => $orderProduct->getSellPrice()->getTaxAmount(), |
||
78 | 'previousvariant' => $variantId, |
||
79 | 'variant' => $variantId, |
||
80 | 'variant_options' => $this->getVariantOptions($orderProduct), |
||
81 | 'weight' => $orderProduct->getWeight(), |
||
82 | 'stock' => $orderProduct->getProduct()->getStock(), |
||
83 | 'thumb' => null !== $photoPath ? $this->imageHelper->getImage($photoPath, 'medium') : '', |
||
84 | ]; |
||
85 | }); |
||
86 | } |
||
87 | |||
88 | return $values; |
||
89 | } |
||
90 | |||
91 | protected function getVariantOptions(OrderProduct $orderProduct) |
||
104 | |||
105 | public function reverseTransform($modelData, PropertyPathInterface $propertyPath, $values) |
||
117 | |||
118 | private function setProducts(Order $order, Collection $products) |
||
130 | } |
||
131 |
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.