commerceleague /
magento2-module-activecampaign
| 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\Quote\Model\Quote; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Class AbandonedCartRequestBuilder |
||
| 14 | */ |
||
| 15 | class AbandonedCartBuilder extends AbstractBuilder |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var ConfigHelper |
||
| 19 | */ |
||
| 20 | private $configHelper; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var CustomerRepositoryInterface |
||
| 24 | */ |
||
| 25 | private $customerRepository; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param ConfigHelper $configHelper |
||
| 29 | * @param CustomerRepositoryInterface $customerRepository |
||
| 30 | */ |
||
| 31 | public function __construct( |
||
| 32 | ConfigHelper $configHelper, |
||
| 33 | CustomerRepositoryInterface $customerRepository |
||
| 34 | ) { |
||
| 35 | $this->configHelper = $configHelper; |
||
| 36 | $this->customerRepository = $customerRepository; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param Quote $quote |
||
| 41 | * @return array |
||
| 42 | * @throws \Exception |
||
| 43 | */ |
||
| 44 | public function build(Quote $quote): array |
||
| 45 | { |
||
| 46 | $customer = $this->customerRepository->getByMagentoCustomerId($quote->getData('customer_id')); |
||
| 47 | |||
| 48 | $request = [ |
||
| 49 | 'externalcheckoutid' => $quote->getId(), |
||
| 50 | 'source' => 1, |
||
| 51 | 'email' => $quote->getData('customer_email'), |
||
| 52 | 'externalCreatedDate' => $this->formatDateTime($quote->getCreatedAt()), |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 53 | 'externalUpdatedDate' => $this->formatDateTime($quote->getUpdatedAt() ?: $quote->getCreatedAt()), |
||
| 54 | 'abandonedDate' => $this->formatDateTime($quote->getUpdatedAt() ?: $quote->getCreatedAt()), |
||
| 55 | 'totalPrice' => $this->convertToCent((float)$quote->getData('grand_total')), |
||
| 56 | 'currency' => $quote->getData('base_currency_code'), |
||
| 57 | 'connectionid' => $this->configHelper->getConnectionId(), |
||
| 58 | 'customerid' => $customer->getActiveCampaignId(), |
||
| 59 | 'orderProducts' => [] |
||
| 60 | ]; |
||
| 61 | |||
| 62 | foreach ($quote->getAllVisibleItems() as $quoteItem) { |
||
| 63 | $request['orderProducts'][] = [ |
||
| 64 | 'externalid' => $quoteItem->getSku(), |
||
| 65 | 'name' => $quoteItem->getName(), |
||
| 66 | 'price' => $this->convertToCent((float)$quoteItem->getPriceInclTax()), |
||
| 67 | 'quantity' => (int)$quoteItem->getQty(), |
||
| 68 | 'productUrl' => $quoteItem->getProduct()->getProductUrl(), |
||
| 69 | ]; |
||
| 70 | } |
||
| 71 | |||
| 72 | return $request; |
||
| 73 | } |
||
| 74 | } |
||
| 75 |