|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Apache OSL-2 |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\AmazonPay\Dependency\Client; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\AddressTransfer; |
|
11
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
12
|
|
|
use Generated\Shared\Transfer\ShipmentTransfer; |
|
13
|
|
|
use RuntimeException; |
|
14
|
|
|
|
|
15
|
|
|
class AmazonPayToShipmentBridge implements AmazonPayToShipmentInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var \Spryker\Client\Shipment\ShipmentClientInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $shipmentClient; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param \Spryker\Client\Shipment\ShipmentClientInterface $shipmentClient |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct($shipmentClient) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->shipmentClient = $shipmentClient; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
32
|
|
|
* |
|
33
|
|
|
* @throws \RuntimeException |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Generated\Shared\Transfer\ShipmentMethodsTransfer |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getAvailableMethods(QuoteTransfer $quoteTransfer) |
|
38
|
|
|
{ |
|
39
|
|
|
if (method_exists($this->shipmentClient, 'getAvailableMethodsByShipment') === true) { |
|
40
|
|
|
foreach ($quoteTransfer->getItems() as $itemTransfer) { |
|
41
|
|
|
$itemTransfer->setShipment(new ShipmentTransfer()); |
|
42
|
|
|
$itemTransfer->getShipment()->setShippingAddress(new AddressTransfer()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$shipmentMethodsCollectionTransfer = $this->shipmentClient->getAvailableMethodsByShipment($quoteTransfer); |
|
46
|
|
|
|
|
47
|
|
|
if ($shipmentMethodsCollectionTransfer->getShipmentMethods()->count() > 1) { |
|
48
|
|
|
throw new RuntimeException('Split shipping is not supported'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
foreach ($quoteTransfer->getItems() as $itemTransfer) { |
|
52
|
|
|
$itemTransfer->setShipment(null); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$shipmentMethodsTransfer = $shipmentMethodsCollectionTransfer |
|
56
|
|
|
->getShipmentMethods() |
|
57
|
|
|
->getIterator() |
|
58
|
|
|
->current(); |
|
59
|
|
|
|
|
60
|
|
|
return $shipmentMethodsTransfer; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $this->shipmentClient->getAvailableMethods($quoteTransfer); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.