Skip to content

Commit

Permalink
fix bug where date was not formatted correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Penz committed Jul 7, 2019
1 parent db91436 commit ea09f80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Gateway/Request/OrderBuilder.php
Expand Up @@ -7,6 +7,7 @@

use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface;
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Sales\Api\Data\OrderInterface as MagentoOrderInterface;
use Magento\Sales\Model\Order as MagentoOrder;

Expand All @@ -25,21 +26,30 @@ class OrderBuilder
*/
private $customerRepository;

/**
* @var TimezoneInterface
*/
private $timezone;

/**
* @param ConfigHelper $configHelper
* @param CustomerRepositoryInterface $customerRepository
* @param TimezoneInterface $timezone
*/
public function __construct(
ConfigHelper $configHelper,
CustomerRepositoryInterface $customerRepository
CustomerRepositoryInterface $customerRepository,
TimezoneInterface $timezone
) {
$this->configHelper = $configHelper;
$this->customerRepository = $customerRepository;
$this->timezone = $timezone;
}

/**
* @param MagentoOrderInterface|MagentoOrder $magentoOrder
* @return array
* @throws \Exception
*/
public function build(MagentoOrderInterface $magentoOrder): array
{
Expand All @@ -50,7 +60,7 @@ public function build(MagentoOrderInterface $magentoOrder): array
'source' => 1,
'email' => $magentoOrder->getCustomerEmail(),
'orderNumber' => $magentoOrder->getIncrementId(),
'orderDate' => $magentoOrder->getCreatedAt(),
'orderDate' => $this->formatDateTime($magentoOrder->getCreatedAt()),
'shippingMethod' => $magentoOrder->getShippingMethod(),
'totalPrice' => $this->convertToCent((float)$magentoOrder->getGrandTotal()),
'currency' => $magentoOrder->getBaseCurrencyCode(),
Expand Down Expand Up @@ -80,4 +90,14 @@ private function convertToCent(float $amount): int
{
return (int)($amount * 100);
}

/**
* @param string $date
* @return string
* @throws \Exception
*/
private function formatDateTime(string $date): string
{
return (new \DateTime($date))->format(\DateTime::W3C);
}
}
1 change: 1 addition & 0 deletions MessageQueue/Sales/ExportOrderConsumer.php
Expand Up @@ -72,6 +72,7 @@ public function __construct(
/**
* @param string $message
* @throws CouldNotSaveException
* @throws \Exception
*/
public function consume(string $message): void
{
Expand Down

0 comments on commit ea09f80

Please sign in to comment.