PayU integration by Krzysztof Gzocha
  • Namespace
  • Class

Namespaces

  • Team3
    • PayU
      • Annotation
      • Communication
        • CurlRequestBuilder
        • HttpStatusParser
        • Notification
        • Process
          • NotificationProcess
          • ResponseDeserializer
        • Request
          • Model
        • Response
          • Model
        • Sender
      • Configuration
        • Credentials
      • Order
        • Autocomplete
          • Strategy
        • Model
          • Buyer
          • Money
          • Products
          • ShippingMethods
          • Traits
        • Transformer
          • UserOrder
            • Strategy
              • Product
              • ShippingMethod
      • PropertyExtractor
        • Reader
      • Serializer
      • SignatureCalculator
        • Encoder
          • Algorithms
          • Strategy
        • ParametersSorter
        • Validator
      • ValidatorBuilder

Classes

  • Team3\PayU\ValidatorBuilder\ValidatorBuilder

Interfaces

  • Team3\PayU\ValidatorBuilder\ValidatorBuilderInterface
 1 <?php
 2 /**
 3  * @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl>
 4  */
 5 namespace Team3\PayU\Order\Transformer\UserOrder\Strategy\Product;
 6 
 7 use Team3\PayU\Order\Model\OrderInterface;
 8 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
 9 use Team3\PayU\PropertyExtractor\ExtractorResult;
10 use Team3\PayU\Order\Transformer\UserOrder\Strategy\UserOrderTransformerStrategyInterface;
11 use Team3\PayU\Order\Transformer\UserOrder\UserOrderTransformerException;
12 
13 class ProductCollectionTransformer implements UserOrderTransformerStrategyInterface
14 {
15     /**
16      * @var SingleProductTransformer
17      */
18     protected $singleProductTransformer;
19 
20     /**
21      * @param SingleProductTransformer $singleProductTransformer
22      */
23     public function __construct(
24         SingleProductTransformer $singleProductTransformer
25     ) {
26         $this->singleProductTransformer = $singleProductTransformer;
27     }
28 
29     /**
30      * @inheritdoc
31      */
32     public function transform(
33         OrderInterface $order,
34         ExtractorResult $extractorResult
35     ) {
36         $usersProductCollection = $extractorResult->getValue();
37         $this->checkProductCollection($usersProductCollection);
38 
39         foreach ($usersProductCollection as $userProduct) {
40             $order
41                 ->getProductCollection()
42                 ->addProduct(
43                     $this
44                         ->singleProductTransformer
45                         ->transform($userProduct)
46                 );
47         }
48 
49         return $order;
50     }
51 
52     /**
53      * @inheritdoc
54      */
55     public function supports($propertyName)
56     {
57         return TransformerProperties::PRODUCT_COLLECTION === $propertyName;
58     }
59 
60     /**
61      * Checks if product collection is array or object which implements Traversable.
62      * If not throws UserOrderTransformerException.
63      *
64      * @param mixed $productCollection
65      *
66      * @return bool
67      * @throws UserOrderTransformerException
68      */
69     private function checkProductCollection(
70         $productCollection
71     ) {
72         if (!is_array($productCollection)
73             && !$productCollection instanceof \Traversable) {
74             throw new UserOrderTransformerException(sprintf(
75                 'Value should be an array or object which implements \Traversable, but it returns %s',
76                 gettype($productCollection)
77             ));
78         }
79     }
80 }
81 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen