Convert variable names to camel case

[MAILPOET-1796]
This commit is contained in:
Jan Jakeš
2020-01-09 15:02:58 +01:00
committed by Jan Jakeš
parent f5da704106
commit 54549ff037
687 changed files with 15890 additions and 15887 deletions

View File

@@ -32,7 +32,7 @@ class FirstPurchase {
}
$this->helper = $helper;
$this->scheduler = new AutomaticEmailScheduler();
$this->logger_factory = LoggerFactory::getInstance();
$this->loggerFactory = LoggerFactory::getInstance();
}
public function init() {
@@ -46,9 +46,9 @@ class FirstPurchase {
], 10, 4);
// We have to use a set of states because an order state after checkout differs for different payment methods
$accepted_order_states = WPFunctions::get()->applyFilters('mailpoet_first_purchase_order_states', ['completed', 'processing']);
$acceptedOrderStates = WPFunctions::get()->applyFilters('mailpoet_first_purchase_order_states', ['completed', 'processing']);
foreach ($accepted_order_states as $state) {
foreach ($acceptedOrderStates as $state) {
WPFunctions::get()->addAction('woocommerce_order_status_' . $state, [
$this,
'scheduleEmailWhenOrderIsPlaced',
@@ -82,19 +82,19 @@ class FirstPurchase {
public function handleOrderDateShortcode($shortcode, $newsletter, $subscriber, $queue) {
$result = $shortcode;
if ($shortcode === self::ORDER_DATE_SHORTCODE) {
$default_value = WPFunctions::get()->dateI18n(get_option('date_format'));
$defaultValue = WPFunctions::get()->dateI18n(get_option('date_format'));
if (!$queue) {
$result = $default_value;
$result = $defaultValue;
} else {
$meta = $queue->getMeta();
$result = (!empty($meta['order_date'])) ? WPFunctions::get()->dateI18n(get_option('date_format'), $meta['order_date']) : $default_value;
$result = (!empty($meta['order_date'])) ? WPFunctions::get()->dateI18n(get_option('date_format'), $meta['order_date']) : $defaultValue;
}
}
$this->logger_factory->getLogger(self::SLUG)->addInfo(
$this->loggerFactory->getLogger(self::SLUG)->addInfo(
'handleOrderDateShortcode called', [
'newsletter_id' => ($newsletter instanceof Newsletter) ? $newsletter->id : null,
'subscriber_id' => ($subscriber instanceof Subscriber) ? $subscriber->id : null,
'task_id' => ($queue instanceof SendingQueue) ? $queue->task_id : null,
'task_id' => ($queue instanceof SendingQueue) ? $queue->taskId : null,
'shortcode' => $shortcode,
'result' => $result,
]
@@ -105,19 +105,19 @@ class FirstPurchase {
public function handleOrderTotalShortcode($shortcode, $newsletter, $subscriber, $queue) {
$result = $shortcode;
if ($shortcode === self::ORDER_TOTAL_SHORTCODE) {
$default_value = $this->helper->wcPrice(0);
$defaultValue = $this->helper->wcPrice(0);
if (!$queue) {
$result = $default_value;
$result = $defaultValue;
} else {
$meta = $queue->getMeta();
$result = (!empty($meta['order_amount'])) ? $this->helper->wcPrice($meta['order_amount']) : $default_value;
$result = (!empty($meta['order_amount'])) ? $this->helper->wcPrice($meta['order_amount']) : $defaultValue;
}
}
$this->logger_factory->getLogger(self::SLUG)->addInfo(
$this->loggerFactory->getLogger(self::SLUG)->addInfo(
'handleOrderTotalShortcode called', [
'newsletter_id' => ($newsletter instanceof Newsletter) ? $newsletter->id : null,
'subscriber_id' => ($subscriber instanceof Subscriber) ? $subscriber->id : null,
'task_id' => ($queue instanceof SendingQueue) ? $queue->task_id : null,
'task_id' => ($queue instanceof SendingQueue) ? $queue->taskId : null,
'shortcode' => $shortcode,
'result' => $result,
]
@@ -125,77 +125,77 @@ class FirstPurchase {
return $result;
}
public function scheduleEmailWhenOrderIsPlaced($order_id) {
$order_details = $this->helper->wcGetOrder($order_id);
if (!$order_details || !$order_details->get_billing_email()) {
$this->logger_factory->getLogger(self::SLUG)->addInfo(
public function scheduleEmailWhenOrderIsPlaced($orderId) {
$orderDetails = $this->helper->wcGetOrder($orderId);
if (!$orderDetails || !$orderDetails->get_billing_email()) {
$this->loggerFactory->getLogger(self::SLUG)->addInfo(
'Email not scheduled because the order customer was not found',
['order_id' => $order_id]
['order_id' => $orderId]
);
return;
}
$customer_email = $order_details->get_billing_email();
$customer_order_count = $this->getCustomerOrderCount($customer_email);
if ($customer_order_count > 1) {
$this->logger_factory->getLogger(self::SLUG)->addInfo(
$customerEmail = $orderDetails->get_billing_email();
$customerOrderCount = $this->getCustomerOrderCount($customerEmail);
if ($customerOrderCount > 1) {
$this->loggerFactory->getLogger(self::SLUG)->addInfo(
'Email not scheduled because this is not the first order of the customer', [
'order_id' => $order_id,
'customer_email' => $customer_email,
'order_count' => $customer_order_count,
'order_id' => $orderId,
'customer_email' => $customerEmail,
'order_count' => $customerOrderCount,
]
);
return;
}
$meta = [
'order_amount' => $order_details->get_total(),
'order_date' => $order_details->get_date_created()->getTimestamp(),
'order_id' => $order_details->get_id(),
'order_amount' => $orderDetails->get_total(),
'order_date' => $orderDetails->get_date_created()->getTimestamp(),
'order_id' => $orderDetails->get_id(),
];
$subscriber = Subscriber::getWooCommerceSegmentSubscriber($customer_email);
$subscriber = Subscriber::getWooCommerceSegmentSubscriber($customerEmail);
if (!$subscriber instanceof Subscriber) {
$this->logger_factory->getLogger(self::SLUG)->addInfo(
$this->loggerFactory->getLogger(self::SLUG)->addInfo(
'Email not scheduled because the customer was not found as WooCommerce list subscriber',
['order_id' => $order_id, 'customer_email' => $customer_email]
['order_id' => $orderId, 'customer_email' => $customerEmail]
);
return;
}
$check_email_was_not_scheduled = function (Newsletter $newsletter) use ($subscriber) {
$checkEmailWasNotScheduled = function (Newsletter $newsletter) use ($subscriber) {
return !$newsletter->wasScheduledForSubscriber($subscriber->id);
};
$this->logger_factory->getLogger(self::SLUG)->addInfo(
$this->loggerFactory->getLogger(self::SLUG)->addInfo(
'Email scheduled', [
'order_id' => $order_id,
'customer_email' => $customer_email,
'order_id' => $orderId,
'customer_email' => $customerEmail,
'subscriber_id' => $subscriber->id,
]
);
$this->scheduler->scheduleAutomaticEmail(WooCommerce::SLUG, self::SLUG, $check_email_was_not_scheduled, $subscriber->id, $meta);
$this->scheduler->scheduleAutomaticEmail(WooCommerce::SLUG, self::SLUG, $checkEmailWasNotScheduled, $subscriber->id, $meta);
}
public function getCustomerOrderCount($customer_email) {
public function getCustomerOrderCount($customerEmail) {
// registered user
$user = WPFunctions::get()->getUserBy('email', $customer_email);
$user = WPFunctions::get()->getUserBy('email', $customerEmail);
if ($user) {
return $this->helper->wcGetCustomerOrderCount($user->ID);
}
// guest user
return $this->getGuestCustomerOrderCountByEmail($customer_email);
return $this->getGuestCustomerOrderCountByEmail($customerEmail);
}
private function getGuestCustomerOrderCountByEmail($customer_email) {
private function getGuestCustomerOrderCountByEmail($customerEmail) {
global $wpdb;
$count = $wpdb->get_var( "SELECT COUNT(*)
FROM $wpdb->posts as posts
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
WHERE meta.meta_key = '_billing_email'
AND posts.post_type = 'shop_order'
AND meta_value = '" . WPFunctions::get()->escSql($customer_email) . "'
AND meta_value = '" . WPFunctions::get()->escSql($customerEmail) . "'
" );
return (int)$count;
}