ref #90632 Changed the logic of customer subscriptions to promotional newsletters
This commit is contained in:
commit
2df9ee64c4
@ -1,3 +1,6 @@
|
||||
## 2023-07-19 4.6.9
|
||||
* Changed the logic of customer subscriptions to promotional newsletters
|
||||
|
||||
## 2023-06-27 4.6.8
|
||||
* Added the ability to select CRM warehouses to synchronize the balance of offers
|
||||
|
||||
|
@ -420,3 +420,6 @@ msgstr "Almacenes disponibles en CRM"
|
||||
|
||||
msgid "Select warehouses to receive balances from CRM. To select several warehouses, hold down CTRL (for Windows and Linux) or ⌘ Command (for MacOS)"
|
||||
msgstr "Selecciona los almacenes para recibir el stock desde CRM. Para seleccionar varios mantén pulsado CTRL (para Windows y Linux) o ⌘ Command (para MacOS)"
|
||||
|
||||
msgid "I agree to receive promotional newsletters"
|
||||
msgstr "Estoy de acuerdo en recibir los boletines informativos"
|
@ -429,3 +429,6 @@ msgstr "Склады, доступные в CRM"
|
||||
|
||||
msgid "Select warehouses to receive balances from CRM. To select several warehouses, hold down CTRL (for Windows and Linux) or ⌘ Command (for MacOS)"
|
||||
msgstr "Выберите склады для получения остатков из CRM. Для выбора нескольких складов зажмите CTRL (для Windows и Linux) или ⌘ Command (для MacOS)"
|
||||
|
||||
msgid "I agree to receive promotional newsletters"
|
||||
msgstr "Согласен на рекламно-информационные рассылки"
|
||||
|
@ -99,6 +99,18 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
add_action('admin_enqueue_scripts', [$this, 'include_files_for_admin'], 101);
|
||||
add_action('woocommerce_new_order', [$this, 'create_order'], 11, 1);
|
||||
|
||||
// Subscribed hooks
|
||||
add_action('register_form', [$this, 'subscribe_register_form'], 99);
|
||||
add_action('woocommerce_register_form', [$this, 'subscribe_woocommerce_register_form'], 99);
|
||||
|
||||
if (get_option('woocommerce_enable_signup_and_login_from_checkout') === static::YES) {
|
||||
add_action(
|
||||
'woocommerce_before_checkout_registration_form',
|
||||
[$this, 'subscribe_woocommerce_before_checkout_registration_form'],
|
||||
99
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!$this->get_option('deactivate_update_order')
|
||||
|| $this->get_option('deactivate_update_order') == static::NO
|
||||
@ -175,6 +187,34 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displaying the checkbox in the WP registration form(wp-login.php).
|
||||
*
|
||||
*/
|
||||
public function subscribe_register_form()
|
||||
{
|
||||
echo $this->getSubscribeCheckbox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displaying the checkbox in the WC registration form.
|
||||
*
|
||||
*/
|
||||
public function subscribe_woocommerce_register_form()
|
||||
{
|
||||
echo $this->getSubscribeCheckbox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displaying the checkbox in the Checkout order form.
|
||||
*
|
||||
*/
|
||||
public function subscribe_woocommerce_before_checkout_registration_form()
|
||||
{
|
||||
echo $this->getSubscribeCheckbox();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If you change the time interval, need to clear the old cron tasks
|
||||
*
|
||||
@ -356,6 +396,9 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post = $this->get_post_data();
|
||||
$this->customers->isSubscribed = !empty($post['subscribe']);
|
||||
|
||||
$this->customers->registerCustomer($customerId);
|
||||
}
|
||||
|
||||
@ -882,5 +925,21 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
'default-crm-field#tags' => __('tags', 'retailcrm'),
|
||||
];
|
||||
}
|
||||
|
||||
private function getSubscribeCheckbox()
|
||||
{
|
||||
$style = is_wplogin()
|
||||
? 'margin-left: 2em; display: block; position: relative; margin-top: -1.4em; line-height: 1.4em;'
|
||||
: '';
|
||||
|
||||
return sprintf(
|
||||
'<div style="margin-bottom:15px">
|
||||
<input type="checkbox" id="subscribeEmail" name="subscribe" value="subscribed"/>
|
||||
<label style="%s" for="subscribeEmail">%s</label>
|
||||
</div>',
|
||||
$style,
|
||||
__('I agree to receive promotional newsletters', 'retailcrm')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,9 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
/**@var array */
|
||||
private $customFields = [];
|
||||
|
||||
/**@var null */
|
||||
public $isSubscribed = null;
|
||||
|
||||
/**
|
||||
* WC_Retailcrm_Customers constructor.
|
||||
*
|
||||
@ -95,6 +98,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$wcCustomer = new WC_Customer($customerId);
|
||||
$email = $wcCustomer->get_billing_email();
|
||||
|
||||
@ -123,8 +127,8 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
$builder = new WC_Retailcrm_WC_Customer_Builder();
|
||||
$builder
|
||||
->setWcCustomer($wcCustomer)
|
||||
->setPhones(isset($customer['phones']) ? $customer['phones'] : [])
|
||||
->setAddress(isset($customer['address']) ? $customer['address'] : false)
|
||||
->setPhones(!empty($customer['phones']) ? $customer['phones'] : [])
|
||||
->setAddress(!empty($customer['address']) ? $customer['address'] : false)
|
||||
->build()
|
||||
->getResult()
|
||||
->save();
|
||||
@ -134,6 +138,11 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
} else {
|
||||
$this->createCustomer($customerId);
|
||||
|
||||
$message = $this->isSubscribed
|
||||
? 'The client has agreed to receive promotional newsletter, email: '
|
||||
: 'The client refused to receive promotional newsletters, email: ';
|
||||
|
||||
WC_Retailcrm_Logger::addCaller('subscribe', $message . $email);
|
||||
WC_Retailcrm_Logger::add('Customer was created, externalId: ' . $wcCustomer->get_id());
|
||||
}
|
||||
}
|
||||
@ -384,10 +393,6 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
$firstName = $order->get_billing_first_name();
|
||||
$lastName = $order->get_billing_last_name();
|
||||
|
||||
if (empty($firstName)) {
|
||||
$firstName = $customer->get_username();
|
||||
}
|
||||
|
||||
if (empty($email)) {
|
||||
$email = $order->get_billing_email();
|
||||
}
|
||||
@ -403,7 +408,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
|
||||
$customerData = [
|
||||
'createdAt' => $createdAt->date('Y-m-d H:i:s'),
|
||||
'firstName' => $firstName ? $firstName : $customer->get_username(),
|
||||
'firstName' => !empty($firstName) ? $firstName : $customer->get_username(),
|
||||
'lastName' => $lastName,
|
||||
'email' => $email,
|
||||
'address' => $this->customer_address->build($customer, $order)->getData()
|
||||
@ -413,6 +418,15 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
$customerData['externalId'] = $customer->get_id();
|
||||
}
|
||||
|
||||
// The guest client is unsubscribed by default
|
||||
if ($customer->get_id() === 0 && $customer->get_date_created() === null) {
|
||||
$customerData['subscribed'] = false;
|
||||
}
|
||||
|
||||
if ($this->isSubscribed !== null) {
|
||||
$customerData['subscribed'] = $this->isSubscribed;
|
||||
}
|
||||
|
||||
if (!empty($billingPhone)) {
|
||||
$customerData['phones'][] = [
|
||||
'number' => $billingPhone
|
||||
|
@ -144,7 +144,7 @@ class WC_Retailcrm_WC_Customer_Builder extends WC_Retailcrm_Abstract_Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill WC_Customer fields with customer data from retailCRM.
|
||||
* Fill WC_Customer fields with customer data from RetailCRM.
|
||||
* If field is not present in retailCRM customer - it will remain unchanged.
|
||||
*
|
||||
* @return $this|\WC_Retailcrm_Builder_Interface
|
||||
@ -152,11 +152,13 @@ class WC_Retailcrm_WC_Customer_Builder extends WC_Retailcrm_Abstract_Builder
|
||||
public function build()
|
||||
{
|
||||
$this->checkBuilderValidity();
|
||||
WC_Retailcrm_Logger::debug(__METHOD__, array('Building WC_Customer from data:', $this->data));
|
||||
|
||||
WC_Retailcrm_Logger::debug(__METHOD__, ['Building WC_Customer from data:', $this->data]);
|
||||
|
||||
$this->customer->set_first_name($this->dataValue('firstName', $this->customer->get_first_name()));
|
||||
$this->customer->set_last_name($this->dataValue('lastName', $this->customer->get_last_name()));
|
||||
$this->customer->set_billing_email($this->dataValue('email', $this->customer->get_billing_email()));
|
||||
$phones = $this->dataValue('phones', array());
|
||||
$phones = $this->dataValue('phones', []);
|
||||
|
||||
if ((is_array($phones) || $phones instanceof Countable) && count($phones) > 0) {
|
||||
$phoneData = reset($phones);
|
||||
|
@ -191,4 +191,3 @@ function writeBaseLogs($message)
|
||||
{
|
||||
WC_Retailcrm_Logger::addCaller(__METHOD__, $message);
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
|
||||
Requires PHP: 7.0
|
||||
Requires at least: 5.3
|
||||
Tested up to: 6.2
|
||||
Stable tag: 4.6.8
|
||||
Stable tag: 4.6.9
|
||||
License: GPLv1 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-1.0.html
|
||||
|
||||
@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
|
||||
|
||||
|
||||
== Changelog ==
|
||||
= 4.6.9 =
|
||||
* Changed the logic of customer subscriptions to promotional newsletters
|
||||
|
||||
= 4.6.8 =
|
||||
* Added the ability to select CRM warehouses to synchronize the balance of offers
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Description: Integration plugin for WooCommerce & Simla.com
|
||||
* Author: RetailDriver LLC
|
||||
* Author URI: http://retailcrm.pro/
|
||||
* Version: 4.6.8
|
||||
* Version: 4.6.9
|
||||
* Tested up to: 6.2
|
||||
* WC requires at least: 5.4
|
||||
* WC tested up to: 7.8
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
*
|
||||
* @version 4.6.8
|
||||
* @version 4.6.9
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
@ -83,6 +83,9 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
|
||||
|
||||
update_option(WC_Retailcrm_Base::$option_key, $options);
|
||||
|
||||
//Need for subscribe_woocommerce_before_checkout_registration_form
|
||||
update_option('woocommerce_enable_signup_and_login_from_checkout', 'yes');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
@ -259,6 +259,20 @@ class WC_Retailcrm_Base_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
public function test_subscribed_checkbox()
|
||||
{
|
||||
ob_start();
|
||||
|
||||
$this->baseRetailcrm->subscribe_register_form();
|
||||
$this->baseRetailcrm->subscribe_woocommerce_register_form();
|
||||
$this->baseRetailcrm->subscribe_woocommerce_before_checkout_registration_form();
|
||||
|
||||
$this->assertContains('subscribeEmail', ob_get_contents());
|
||||
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
|
||||
public function test_initialize_whatsapp()
|
||||
{
|
||||
ob_start();
|
||||
|
@ -144,6 +144,8 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
|
||||
$crmCustomer = $this->getRetailcrmCustomer($retailcrm);
|
||||
|
||||
$crmCustomer->isSubscribed = true;
|
||||
|
||||
$id = $crmCustomer->registerCustomer($this->customer->get_id());
|
||||
$customer = $crmCustomer->getCustomer();
|
||||
|
||||
@ -158,6 +160,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$this->assertEquals($customer['firstName'], $this->customer->get_first_name());
|
||||
$this->assertEquals($customer['email'], $this->customer->get_email());
|
||||
$this->assertEquals($customer['customFields']['crm_customer'], 'test_custom_fields');
|
||||
$this->assertTrue($customer['subscribed']);
|
||||
} else {
|
||||
$this->assertEquals(null, $id);
|
||||
$this->assertEquals([], $customer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user