parent
9c7b5ebf60
commit
31eb5cbde5
3 changed files with 12 additions and 20 deletions
|
@ -346,25 +346,19 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
|
|||
return $discountLp;
|
||||
}
|
||||
|
||||
public function isValidOrder($wcUser, $wcOrder)
|
||||
public function isValidOrder($wcCustomer, $wcOrder)
|
||||
{
|
||||
if (!$wcUser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$wcCustomer = new WC_Customer($wcUser->ID);
|
||||
|
||||
return !(!$wcCustomer || (isCorporateUserActivate($this->settings) && isCorporateOrder($wcCustomer, $wcOrder)));
|
||||
}
|
||||
|
||||
public function isValidUser($wcUser)
|
||||
public function isValidUser($wcCustomer)
|
||||
{
|
||||
if (empty($wcUser)) {
|
||||
if (empty($wcCustomer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->getLoyaltyAccounts($wcUser->ID);
|
||||
$response = $this->getLoyaltyAccounts($wcCustomer->get_id());
|
||||
} catch (Throwable $exception) {
|
||||
writeBaseLogs('Exception get loyalty accounts: ' . $exception->getMessage());
|
||||
|
||||
|
|
|
@ -104,16 +104,20 @@ if (!class_exists('WC_Retailcrm_Orders')) :
|
|||
if ($this->loyalty) {
|
||||
$privilegeType = 'none';
|
||||
$discountLp = $this->loyalty->deleteLoyaltyCouponInOrder($wcOrder);
|
||||
$wcUser = $wcOrder->get_user();
|
||||
$data = $wcOrder->get_data();
|
||||
|
||||
if (!$this->loyalty->isValidOrder($wcUser, $wcOrder)) {
|
||||
if (isset($data['customer_id'])) {
|
||||
$wcCustomer = new WC_Customer($data['customer_id']);
|
||||
}
|
||||
|
||||
if (!$this->loyalty->isValidOrder($wcCustomer ?? null, $wcOrder)) {
|
||||
if ($discountLp > 0) {
|
||||
writeBaseLogs('The user does not meet the requirements for working with the loyalty program. Order Id: ' . $orderId);
|
||||
}
|
||||
|
||||
$discountLp = 0;
|
||||
$privilegeType = 'none';
|
||||
} elseif ($this->loyalty->isValidUser($wcUser)) {
|
||||
} elseif ($this->loyalty->isValidUser($wcCustomer ?? null)) {
|
||||
$privilegeType = 'loyalty_level';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,12 +121,6 @@ class WC_Retailcrm_Loyalty_Test extends WC_Retailcrm_Test_Case_Helper
|
|||
*/
|
||||
public function testIsValidOrder($customer, $corporate_enabled, $expected, $orderCorporate)
|
||||
{
|
||||
$wp_user = null;
|
||||
|
||||
if ($customer) {
|
||||
$wp_user = get_user_by('ID', $customer->get_id());
|
||||
}
|
||||
|
||||
$this->loyalty = new WC_Retailcrm_Loyalty($this->apiMock, ['corporate_enabled' => $corporate_enabled]);
|
||||
$wcOrder = new WC_Order();
|
||||
|
||||
|
@ -134,7 +128,7 @@ class WC_Retailcrm_Loyalty_Test extends WC_Retailcrm_Test_Case_Helper
|
|||
$wcOrder->set_billing_company('OOO TEST');
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $this->loyalty->isValidOrder($wp_user, $wcOrder));
|
||||
$this->assertEquals($expected, $this->loyalty->isValidOrder($customer, $wcOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue