1 | <?php |
||||
2 | declare(strict_types=1); |
||||
3 | /** |
||||
4 | */ |
||||
5 | |||||
6 | namespace CommerceLeague\ActiveCampaign\Gateway\Request; |
||||
7 | |||||
8 | use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface; |
||||
9 | use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
||||
10 | use Magento\Sales\Api\Data\OrderInterface as MagentoOrderInterface; |
||||
11 | use Magento\Sales\Model\Order as MagentoOrder; |
||||
12 | |||||
13 | /** |
||||
14 | * Class OrderBuilder |
||||
15 | */ |
||||
16 | class OrderBuilder extends AbstractBuilder |
||||
17 | { |
||||
18 | /** |
||||
19 | * @var ConfigHelper |
||||
20 | */ |
||||
21 | private $configHelper; |
||||
22 | |||||
23 | /** |
||||
24 | * @var CustomerRepositoryInterface |
||||
25 | */ |
||||
26 | private $customerRepository; |
||||
27 | |||||
28 | /** |
||||
29 | * @param ConfigHelper $configHelper |
||||
30 | * @param CustomerRepositoryInterface $customerRepository |
||||
31 | */ |
||||
32 | public function __construct( |
||||
33 | ConfigHelper $configHelper, |
||||
34 | CustomerRepositoryInterface $customerRepository |
||||
35 | ) { |
||||
36 | $this->configHelper = $configHelper; |
||||
37 | $this->customerRepository = $customerRepository; |
||||
38 | } |
||||
39 | |||||
40 | /** |
||||
41 | * @param MagentoOrderInterface|MagentoOrder $magentoOrder |
||||
42 | * @return array |
||||
43 | * @throws \Exception |
||||
44 | */ |
||||
45 | public function build(MagentoOrderInterface $magentoOrder): array |
||||
46 | { |
||||
47 | $customer = $this->customerRepository->getByMagentoCustomerId($magentoOrder->getCustomerId()); |
||||
48 | |||||
49 | $request = [ |
||||
50 | 'externalid' => $magentoOrder->getId(), |
||||
51 | 'source' => 1, |
||||
52 | 'email' => $magentoOrder->getCustomerEmail(), |
||||
53 | 'orderNumber' => $magentoOrder->getIncrementId(), |
||||
54 | 'orderDate' => $this->formatDateTime($magentoOrder->getCreatedAt()), |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
55 | 'shippingMethod' => $magentoOrder->getShippingMethod(), |
||||
0 ignored issues
–
show
The method
getShippingMethod() does not exist on Magento\Sales\Api\Data\OrderInterface . Did you maybe mean getShippingAmount() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. ![]() |
|||||
56 | 'totalPrice' => $this->convertToCent((float)$magentoOrder->getGrandTotal()), |
||||
57 | 'currency' => $magentoOrder->getBaseCurrencyCode(), |
||||
58 | 'connectionid' => $this->configHelper->getConnectionId(), |
||||
59 | 'customerid' => $customer->getActiveCampaignId(), |
||||
60 | 'orderProducts' => [] |
||||
61 | ]; |
||||
62 | |||||
63 | /** @var MagentoOrder\Item $magentoOrderItem */ |
||||
64 | foreach ($magentoOrder->getAllVisibleItems() as $magentoOrderItem) { |
||||
65 | $request['orderProducts'][] = [ |
||||
66 | 'externalid' => $magentoOrderItem->getSku(), |
||||
67 | 'name' => $magentoOrderItem->getName(), |
||||
68 | 'price' => $this->convertToCent((float)$magentoOrderItem->getPriceInclTax()), |
||||
69 | 'quantity' => (int)$magentoOrderItem->getQtyOrdered(), |
||||
70 | 'productUrl' => $magentoOrderItem->getProduct()->getProductUrl(), |
||||
71 | ]; |
||||
72 | } |
||||
73 | |||||
74 | return $request; |
||||
75 | } |
||||
76 | } |
||||
77 |