Track purchases regardless of status but return revenue status correctly
When we apply this commit every purchase will be tracked. When the shop manager updates an order the status will be updated. For the statistics it will only return values for purchases with the 'completed' status [MAILPOET-5485]
This commit is contained in:
@@ -7,11 +7,27 @@ use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\SendingQueueEntity;
|
||||
use MailPoet\Entities\StatisticsClickEntity;
|
||||
use MailPoet\Entities\StatisticsWooCommercePurchaseEntity;
|
||||
use MailPoet\WooCommerce\Helper;
|
||||
use MailPoetVendor\Doctrine\DBAL\Connection;
|
||||
use MailPoetVendor\Doctrine\DBAL\ParameterType;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @extends Repository<StatisticsWooCommercePurchaseEntity>
|
||||
*/
|
||||
class StatisticsWooCommercePurchasesRepository extends Repository {
|
||||
|
||||
/** @var Helper */
|
||||
private $wooCommerceHelper;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $entityManager,
|
||||
Helper $wooCommerceHelper
|
||||
) {
|
||||
parent::__construct($entityManager);
|
||||
$this->wooCommerceHelper = $wooCommerceHelper;
|
||||
}
|
||||
|
||||
protected function getEntityClassName() {
|
||||
return StatisticsWooCommercePurchaseEntity::class;
|
||||
}
|
||||
@@ -50,6 +66,7 @@ class StatisticsWooCommercePurchasesRepository extends Repository {
|
||||
}
|
||||
|
||||
public function getRevenuesByCampaigns(string $currency): array {
|
||||
$revenueStatus = $this->wooCommerceHelper->getPurchaseStates();
|
||||
$revenueStatsTable = $this->entityManager->getClassMetadata(StatisticsWooCommercePurchaseEntity::class)->getTableName();
|
||||
$newsletterTable = $this->entityManager->getClassMetadata(NewsletterEntity::class)->getTableName();
|
||||
|
||||
@@ -72,12 +89,19 @@ class StatisticsWooCommercePurchasesRepository extends Repository {
|
||||
n.id = swp.newsletter_id
|
||||
WHERE
|
||||
swp.order_currency = :currency
|
||||
AND swp.status IN (:revenue_status)
|
||||
AND swp.click_id IN (SELECT MIN(click_id) FROM ' . $revenueStatsTable . ' ss GROUP BY order_id)
|
||||
GROUP BY campaign_id, n.type;
|
||||
', [
|
||||
'notification_history_type' => NewsletterEntity::TYPE_NOTIFICATION_HISTORY,
|
||||
'notification_type' => NewsletterEntity::TYPE_NOTIFICATION,
|
||||
'currency' => $currency,
|
||||
'revenue_status' => $revenueStatus,
|
||||
], [
|
||||
'notification_history_type' => ParameterType::STRING,
|
||||
'notification_type' => ParameterType::STRING,
|
||||
'currency' => ParameterType::STRING,
|
||||
'revenue_status' => Connection::PARAM_STR_ARRAY,
|
||||
])->fetchAllAssociative();
|
||||
|
||||
$data = array_map(function($row) {
|
||||
|
Reference in New Issue
Block a user